我尝试使用以下方法加载模型和图形:
saver = tf.train.import_meta_graph(tf.train.latest_checkpoint(model_path)+".meta")
graph = tf.get_default_graph()
outputs = graph.get_tensor_by_name('output:0')
outputs = tf.cast(outputs,dtype=tf.float32)
X = graph.get_tensor_by_name('input:0')
sess = tf.Session()
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
if(tf.train.checkpoint_exists(tf.train.latest_checkpoint(model_path))):
saver.restore(sess, tf.train.latest_checkpoint(model_path))
print(tf.train.latest_checkpoint(model_path) + "Session Loaded for Testing")
它有效!...
但是当我尝试运行会话时,出现以下错误:
y_test_output= sess.run(outputs, feed_dict={X: x_test})
错误是:
Caused by op 'output', defined at:
File "testing_reality.py", line 21, in <module>
saver = tf.train.import_meta_graph(tf.train.latest_checkpoint(model_path)+".meta")
File "C:\Python35\lib\site-packages\tensorflow\python\training\saver.py", line 1674, in import_meta_graph
meta_graph_or_file, clear_devices, import_scope, **kwargs)[0]
File "C:\Python35\lib\site-packages\tensorflow\python\training\saver.py", line 1696, in _import_meta_graph_with_return_elements
**kwargs))
File "C:\Python35\lib\site-packages\tensorflow\python\framework\meta_graph.py", line 806, in import_scoped_meta_graph_with_return_elements
return_elements=return_elements)
File "C:\Python35\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
return func(*args, **kwargs)
不明白是什么问题给我造成了这个问题。
请帮我获取丢失的链接。
我检查过:
>>> outputs
<tf.Tensor 'output:0' shape=(?, 1) dtype=float32>
仍然无法理解错误的原因。
我在 Windows 10 操作系统上使用最新版本的 Tensorflow '1.12.0'。
相关分类