'Adds ops to save and restore model parameters.
Args:
slim_model: whether only averaged variables are saved.
Returns:
the saver object.'

def AddSaver(self, slim_model=False):

    with tf.name_scope(None):
        variables_to_save = self.params.copy()
        variables_to_save.update(self.variables)
        if slim_model:
            for key in variables_to_save.keys():
                if (not key.endswith('avg_var')):
                    del variables_to_save[key]
        self.saver = tf.train.Saver(variables_to_save)
    return self.saver
