问题
I am trying to restore a saved model . But it is returning me an error. Please help me out. code to save the model : save_model.py
import tensorflow as tf
v1 = tf.Variable(1.32, name="v1")
v2 = tf.Variable(1.33, name="v2")
init = tf.initialize_all_variables()
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(init)
save_path = saver.save(sess, "model.ckpt")
code to restore model : restore_model.py
import tensorflow as tf
v1 = tf.Variable(0, name="v1")
v2 = tf.Variable(0, name="v2")
saver = tf.train.Saver()
with tf.Session() as sess:
saver.restore(sess, "model.ckpt")
print("Model restored.")
I have saved both the files in the same directory.
回答1:
I suspect the error is raised because in save_model.py
you declare the variables as having type tf.float32
(the implicit type of 1.32
and 1.33
), whereas in restore_model.py
you define the variables as having type tf.int32
(the implicit type of 0
).
The easiest solution would be to modify restore_model.py
to declare the variables as tf.float32
. For example, you could do the following:
v1 = tf.Variable(0.0, name="v1")
v2 = tf.Variable(0.0, name="v2")
来源:https://stackoverflow.com/questions/37187597/unable-to-restore-models-in-tensorflow-v0-8