关于自动驾驶:学习笔记module-tensorflow-has-no-attribute-Session

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)

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理