最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

RuntimeError: The Session graph is empty.Add operations to the graph before calling run().

互联网 admin 0浏览 0评论

RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

执行sess.run()报错

import tensorflow.compat.v1 as tf
hello = tf.constant('Hello tensorflow')
sess = tf.Session()
print(sess.run(hello))
sess.close()


中文意思:会话图为空。在调用run()之前将操作添加到图中。

问题产生的原因:无法执行sess.run()的原因是tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.

解决方案:

import tensorflow.compat.v1 as tf
tf.disable_eager_execution()  #保证sess.run()能够正常运行
hello = tf.constant('Hello tensorflow')
sess = tf.Session()
print(sess.run(hello))
sess.close()


建议:tf2.X与1.X还是有很多不同,每次错误的地方,都要有意识的记忆,这也是成为优秀程序员的必经之路。不要一股脑的就百度找答案,先理解中文意思,然后尝试自己解决一下,会很有帮助。

RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

执行sess.run()报错

import tensorflow.compat.v1 as tf
hello = tf.constant('Hello tensorflow')
sess = tf.Session()
print(sess.run(hello))
sess.close()


中文意思:会话图为空。在调用run()之前将操作添加到图中。

问题产生的原因:无法执行sess.run()的原因是tensorflow版本不同导致的,tensorflow版本2.0无法兼容版本1.0.

解决方案:

import tensorflow.compat.v1 as tf
tf.disable_eager_execution()  #保证sess.run()能够正常运行
hello = tf.constant('Hello tensorflow')
sess = tf.Session()
print(sess.run(hello))
sess.close()


建议:tf2.X与1.X还是有很多不同,每次错误的地方,都要有意识的记忆,这也是成为优秀程序员的必经之路。不要一股脑的就百度找答案,先理解中文意思,然后尝试自己解决一下,会很有帮助。

发布评论

评论列表 (0)

  1. 暂无评论