我正在尝试恢复TensorFlow模型.我按照这个例子:http: //nasdag.github.io/blog/2016/01/19/classifying-bees-with-google-tensorflow/
在示例代码的末尾,我添加了以下行:
saver = tf.train.Saver()
save_path = saver.save(sess, "model.ckpt")
print("Model saved in file: %s" % save_path)
Run Code Online (Sandbox Code Playgroud)
创建了两个文件:checkpoint和model.ckpt.
在一个新的python文件(tomas_bees_predict.py)中,我有这个代码:
import tensorflow as tf
saver = tf.train.Saver()
with tf.Session() as sess:
# Restore variables from disk.
saver.restore(sess, "model.ckpt")
print("Model restored.")
Run Code Online (Sandbox Code Playgroud)
但是,当我执行代码时,我收到此错误:
Traceback (most recent call last):
File "tomas_bees_predict.py", line 3, in <module>
saver = tf.train.Saver()
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 705, in __init__
raise ValueError("No variables to save")
Run Code Online (Sandbox Code Playgroud)
ValueError:没有要保存的变量
有没有办法读取mode.ckpt文件,看看保存了哪些变量?或者有人可以帮助保存模型并根据上述示例进行恢复?
编辑1:
我想我尝试运行相同的代码,以重新创建模型结构,我收到了错误.我认为这可能与这里描述的代码没有使用命名变量的事实有关:http: //nasdag.github.io/blog/2016/01/19/classifying-bees-with-google-tensorflow/
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1) …
Run Code Online (Sandbox Code Playgroud)