Reputation: 3514
I trained a deep neural network on tensorflow and used to predict some examples but, when I try to save it using train.Saver()
I get the error:
"No variables to save"
Already tried train.Saver
like this:
tf.train.Saver(classi.get_variable_names())
But still no luck, any suggestions?
Upvotes: 1
Views: 2052
Reputation: 4821
So I ran into the same issue (Estimators don't have save/restore functions yet). I tried savers and CheckpointSaver
to try and save checkpoints but turns out it's much simpler; just specify the model_dir
when instantiating the Estimator. This will automatically save checkpoints that can be restored simply by creating an Estimator with the same model_dir
. Documentation for Estimators here.
Thanks to @ilblackdragon for the solution here.
Upvotes: 4
Reputation: 2455
Here's a code sample from the tf.variable docs that might clarify:
# Create some variables.
v1 = tf.Variable(..., name="v1")
v2 = tf.Variable(..., name="v2")
...
# Add an op to initialize the variables.
init_op = tf.initialize_all_variables()
# Add ops to save and restore all the variables.
saver = tf.train.Saver()
# Later, launch the model, initialize the variables, do some work, save the
# variables to disk.
with tf.Session() as sess:
sess.run(init_op)
# Do some work with the model.
..
# Save the variables to disk.
save_path = saver.save(sess, "/tmp/model.ckpt")
print("Model saved in file: %s" % save_path)
Upvotes: -1