成功的案列:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
message=tf.constant('hello world')
with tf.compat.v1.Session() as se:
print(se.run(message).decode())
失败的总结:
import tensorflow as tf
message=tf.constant('hello world')
with tf.Session() as se:
print(se.run(message).decode())
会出现第一个问题:如下

解决办法:是因为tensorflow 升级后抛弃掉了这种写法== tf.Session() as se: 改写成 with tf.compat.v1.Session() as se:
第二个问题:

解决办法:
增加tf.compat.v1.disable_eager_execution() 即可解决 (版本问题引起的)
在尝试导入并运行TensorFlow代码时遇到了两个问题。首先,旧的`tf.Session()`用法不再适用,需要改用`tf.compat.v1.Session()`。其次,为了解决版本问题,需要添加`tf.compat.v1.disable_eager_execution()`来禁用即时执行模式。
1749

被折叠的 条评论
为什么被折叠?



