【问题标题】:Trouble running tf.InteractiveSession() in Jupyter在 Jupyter 中运行 tf.InteractiveSession() 时遇到问题
【发布时间】:2020-12-16 16:07:59
【问题描述】:

我在 Jupyter 中运行 tf.InteractiveSession() 时遇到问题,我不知道如何修改它。我是初学者,希望得到一些指导!

在此处输入此代码:

import tensorflow as tf
sess = tf.InteractiveSession()

x = tf.constant([[1, 2]])
negMatrix = tf.negative(x)

result = negMatrix.eval()
print(result)

sess.close()

产生此错误消息:

**AttributeError**: module 'tensorflow' has no attribute 'InteractiveSession'

【问题讨论】:

标签: python tensorflow jupyter interactive


【解决方案1】:

使用 TensorFlow 2.6.0。你可以导入 tf.compat.v1.InteractiveSession()

下面的示例工作代码

import tensorflow as tf
tf.compat.v1.disable_eager_execution()
sess = tf.compat.v1.InteractiveSession()
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
# We can just use 'c.eval()' without passing 'sess'
print(c.eval())
sess.close()

输出

30.0

【讨论】:

    猜你喜欢
    • 2020-09-09
    • 2018-10-15
    • 2018-10-15
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    相关资源
    最近更新 更多