After you train a model in Tensorflow:
Wherever you want to save the model,
self.saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
...
self.saver.save(sess, filename)
Make sure, all your tf.Variable
have names, because you may want to restore them later using their names.
And where you want to predict,
saver = tf.train.import_meta_graph(filename)
name = 'name given when you saved the file'
with tf.Session() as sess:
saver.restore(sess, name)
print(sess.run('W1:0')) #example to retrieve by variable name
Make sure that saver runs inside the corresponding session.
Remember that, if you use the tf.train.latest_checkpoint('./')
, then only the latest check point will be used.