I want to use my neural network without training the net again. I read about
save_path = saver.save(sess, "model.ckpt")
print("Model saved in file: %s" % save_path)
and now I have 3 files in the folder: checkpoint
, model.ckpt
, and model.ckpt.meta
I want, in another class in python to restore the data, get the weights of my neural network and make a single prediction.
How can I do this?
To save the model you can do like this:
model_checkpoint = 'model.chkpt'
# Create the model
...
...
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
# Create a saver so we can save and load the model as we train it
tf_saver = tf.train.Saver(tf.all_variables())
# (Optionally) do some training of the model
...
...
tf_saver.save(sess, model_checkpoint)
I assume you have already done this, since you have gotten three files. When you want to load the model in another class, you can do it like this:
# The same file as we saved earlier
model_checkpoint = 'model.chkpt'
# Create the SAME model as before
...
...
with tf.Session() as sess:
# Restore the model
tf_saver = tf.train.Saver()
tf_saver.restore(sess, model_checkpoint)
# Now your model is loaded with the same values as when you saved,
# and you can do prediction or continue training
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With