plumSemPy plumSemPy - 1 year ago 254
Python Question

Saving tensorflow model after training is finished

I have finished running a big model in tensorflow python. But I have not saved it inside the session. Now that the training is over, I want to save the variables. I am doing the following:

with tf.Session(graph=graph) as sess:
save_path =, "86_model.ckpt")
print("Model saved in file: %s" % save_path)

This returns : ValueError: No variables to save. According to their website what is missing is initialize_all_variables(). The documentation says little about what exactly that does. The word "initialize" scares me, I do not want to reset all my trained values. Any way to save my model without re-running it?

Answer Source

It seems like from the tensorflow documentation, the "session" is the thing that holds the information from the trained model. So presumably somewhere you called to train your model - what you want to do is call using THAT session, not a new one you create with this saver object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download