为了账号安全,请及时绑定邮箱和手机立即绑定

由于张量数据类型和形状 Tensorflow,运行会话失败

由于张量数据类型和形状 Tensorflow,运行会话失败

慕田峪7331174 2021-10-26 10:23:37
我尝试使用以下方法加载模型和图形: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'。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 173 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号