import tensorflow as tf
hello_constant = tf.constant('Hello World!')
with tf.Session() as sess:
output=sess.run(hello_constant)
print(output)
执行出错:
module 'tensorflow' has no attribute 'Session'
原因:tensorflow2没有Session模块了
修改一些代码就能跑起来了,代码里面做了注释:
import tensorflow as tf
# 修改1:添加下面这行代码
tf.compat.v1.disable_eager_execution()
hello_constant = tf.constant('Hello World!')
# 修改2:tf.Session()修改为tf.compat.v1.Session()
with tf.compat.v1.Session() as sess:
output=sess.run(hello_constant)
print(output)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。