问题产生的原因:无法执行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))