tensorflow版本2.0和1.0兼容问题:The Session graph is empty. Add operations to the graph before calling run().解决方法

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

import tensorflow as tf
tf.compat.v1.disable_eager_execution() #保证sess.run()能够正常运行
hello = tf.constant('hello,tensorflow')
sess= tf.compat.v1.Session()#版本2.0的函数
print(sess.run(hello))

猜你喜欢

转载自www.cnblogs.com/peijz/p/12790498.html