共计 453 个字符,预计需要花费 2 分钟才能阅读完成。
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) |
正文完