Unable to restore models in tensorflow v0.8

孤街浪徒 提交于 2019-12-11 12:17:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!