I have been working on this for a while now and can't seem to crack it. In other questions I have seen them use these code samples in order to save and restore a model using the metagraph and checkpoint files, but when I do something similar to this it says that w1
is undefined when I have the savemodel and restore model as separate python files. It works ok when I just have the restore at the end of the saving portion but it defeats the purpose to have to hand define everything all over again in a seperate file. I have looked into the checkpoint file and it seems bizarre that it only has two lines and it doesnt seem to reference any variables or have any values. it is only 1kb. I have tried putting in 'w1' as a string in the print function instead and that returns a None rather than the values I am looking for. Does this work for anyone else? if so, what do your checkpoint files look like?
#Saving
import tensorflow as tf
w1 = tf.Variable(tf.random_normal(shape=[2]), name='w1')
w2 = tf.Variable(tf.random_normal(shape=[5]), name='w2')
saver = tf.train.Saver([w1,w2])
sess = tf.Session()
sess.run(tf.global_variables_initializer())
saver.save(sess, 'my_test_model',global_step=1000)
#restoring
with tf.Session() as sess:
saver = tf.train.import_meta_graph('my_test_model-1000.meta',clear_devices=True)
saver.restore(sess,tf.train.latest_checkpoint('./'))
print sess.run(w1)