There are two python files, The first one is for saving the tensorflow model. The second one is for restoring the saved model.
Question:
When I run the two files one after another, it's ok.
When I run the first one, restart the edit and run the second one,it tells me that the w1 is not defined?
What I want to do is:
Save a tensorflow model
Restore the saved model
What's wrong with it? Thanks for your kindly help?
model_save.py
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()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver.save(sess, 'SR\\my-model')
model_restore.py
import tensorflow as tf
with tf.Session() as sess:
saver = tf.train.import_meta_graph('SR\\my-model.meta')
saver.restore(sess,'SR\\my-model')
print (sess.run(w1))