3

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))

jbplasma
  • 385
  • 4
  • 14
  • since you are importing meta_graph, try giving the meta file name like `RNN_plasma.ckpt.meta` which will be created when you called saver.save method – Hari Krishnan Aug 14 '18 at 05:43

2 Answers2

1

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()
swiftg
  • 346
  • 1
  • 9
0

You save a simple checkpoint but then you are trying load it as a meta graph. This cannot work. There is a writeup on the TensorFlow website explaining the differences

https://www.tensorflow.org/mobile/prepare_models#what_is_up_with_all_the_different_saved_file_formats

There must be a file ending with .meta.

Patwie
  • 4,360
  • 1
  • 21
  • 41