Save/Load tensorflow model
What is the best way to save a TensorFlow model, so I can load it fastly and easily?
What is the best way to save a TensorFlow model, so I can load it fastly and easily?
Just use tensorflow Saver class to save the graph in checkpoints.
saver = tf.train.Saver()
# ...
with tf.Session() as sess:
# your code here ...
save_path = saver.save(sess, "/path/model.ckpt")
print("Model saved in path: %s" % save_path)
and load with this way
# Add ops to save and restore all the variables.
saver = tf.train.Saver()
# Later, launch the model, use the saver to restore variables from disk, and
# do some work with the model.
with tf.Session() as sess:
# Restore variables from disk.
saver.restore(sess, "/path/model.ckpt")
print("Model restored.")
Here is the doc of tensorflow https://www.tensorflow.org/guide/saved_model