Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring a TensorFlow Model Without Explicitly Saving Session Variables

I've looked at many questions regarding saving a trained neural network, including Tensorflow: how to save/restore a model? and https://cv-tricks.com/tensorflow-tutorial/save-restore-tensorflow-models-quick-complete-tutorial/ but none of them save a model without explicitly saving specific variables along with it, as in my case. Here is my case:

# In session "sesh" saver = tf.train.Saver() saver.save(sesh,os.getcwd(),latest_filename= 'RNN_plasma.ckpt')

Now, I quit the session and want to restore the model I just saved. How can I do this? When trying:

import tensorflow as tf

with tf.Session() as session1:
    #First let's load meta graph and restore weights
    saver = tf.train.import_meta_graph('RNN_plasma.ckpt')#error-line
    saver.restore(session1,tf.train.latest_checkpoint('./'))

, the tf.train.import_meta_graph() call returns:

raise IOError("Cannot parse file %s: %s." % (filename, str(e)))
IOError: Cannot parse file RNN_plasma.ckpt: 1:1 : Message type "tensorflow.MetaGraphDef" has no field named "model_checkpoint_path"..

Can anyone give any insight as to what is going on here, and how to solve it?

(My version of TensorFlow doesn't come with tf.python.saved_model.simple_save(). (I have git_version 1.5.0))

like image 846
jbplasma Avatar asked Jun 21 '26 00:06

jbplasma


1 Answers

Save:

saver = tf.train.Saver()
saver.save(sess,"/tmp/network")

Restore:

sess =  tf.Session() 
saver = tf.train.import_meta_graph('/tmp/network.meta')
saver.restore(sess,tf.train.latest_checkpoint('/tmp'))
graph = tf.get_default_graph()
like image 182
swiftg Avatar answered Jun 22 '26 14:06

swiftg