Reputation: 12175
I am wondering what exactly is saved when I use a tf.train.Saver() to save my model after every training epoch. The file seems kind of large compared to what I am used to with Keras models. Right now my RNN takes up 900 MB at each save. Is there any way to tell the saver to only save the trainable parameters? I would also like a way to save only part of the model. I know I can just get the variables I define and save them using the numpy format but when I use the RNN classes I don't directly have access to their weights and I looked through the code and there is nothing like get_weights that I can see.
Upvotes: 2
Views: 3520
Reputation: 805
It will save all variables._all_saveable_objects()
by default, if Saver
does not specify var_list
.
That is, Saver
will save all global variables and saveable variables by default.
def _all_saveable_objects():
"""Returns all variables and `SaveableObject`s that must be checkpointed.
Returns:
A list of `Variable` and `SaveableObject` to be checkpointed
"""
# TODO(andreasst): make this function public once things are settled.
return (ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES) +
ops.get_collection(ops.GraphKeys.SAVEABLE_OBJECTS))
Upvotes: 4
Reputation: 57893
You can provide a list of variables to save in the Saver
constructor, ie saver=tf.train.Saver(var_list=tf.trainable_variables())
Upvotes: 6