AttributeError: 模块“tensorflow”没有属性“InteractiveSession”

Sau*_*v-- 5 python tensorflow

我已经在 Ubuntu 16.10 环境中从 Source 安装了 tensorflow。一切都很顺利,但现在在编译程序时,它显示以下错误:

Traceback (most recent call last):
  File "ff.py", line 3, in <module>
    sess = tf.InteractiveSession()
AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'
Run Code Online (Sandbox Code Playgroud)

没有找到与此相关的帖子。有人可以帮忙吗?

小智 12

sess=tf.compat.v1.InteractiveSession()
Run Code Online (Sandbox Code Playgroud)

sess = tf.InteractiveSession()如果您使用的是 tesorflow 2.0.0 版本,请使用上面的行而不是行


Ogu*_*bas 9

错误由 Tensorflow 版本引起。当您安装 v2.x 并尝试使用 v1.x 时,您将收到此错误。为了避免这种情况,

import tensorflow as tf
import tensorflow.compat.v1 as tfc
Run Code Online (Sandbox Code Playgroud)

当您在其他函数上遇到相同的错误时,请使用tfc而不是tf

sess = tfc.InteractiveSession()

my_tensor = tfc.random_uniform((4, 4), 0, 1)
print(my_tensor)
Run Code Online (Sandbox Code Playgroud)


Meh*_*ban 1

今天安装后也出现同样的错误tenserflow-serving-api。我再次安装tensorflow,一切恢复正常。