【深度学习】Tensorflow:AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'

在运行Tensorflow时报错:

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

这其实不是包的安装错误,是因为在新的Tensorflow 2.0版本中已经移除了Session这一模块,改换运行代码:

sess = tf.InteractiveSession()

换成:

sess = tf.compat.v1.InteractiveSession()

同理,如果代码中还有类似的" tf.*** “之类的代码,应该都要在其后加上"compat.v1.”。

AttributeError: module 'tensorflow' has no attribute 'squared_difference'
AttributeError: module 'tensorflow' has no attribute 'global_variables_initializer'

如果用着不习惯,那就降低Tensorflow的版本也可以:

pip install tensorflow==1.14
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐