Tensorflow 2.0 - AttributeError:模块'tensorflow'没有属性'Session'
当我sess = tf.Session()
在 Tensorflow 2.0 环境中执行命令时,我收到如下错误消息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'Session'
系统信息:
- 操作系统平台和发行版:Windows 10
- Python版本:3.7.1
- Tensorflow 版本:2.0.0-alpha0(用 pip 安装)
重现步骤:
安装:
- 点安装——升级点
- pip install tensorflow==2.0.0-alpha0
- 点安装 keras
- pip install numpy==1.16.2
执行:
- 执行命令:import tensorflow as tf
- 执行命令:sess = tf.Session()
-
根据
TF 1:1 Symbols Map
,在 TF 2.0
中,您应该使用tf.compat.v1.Session()
而不是tf.Session()
https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0
要在 TF 2.0 中获得类似 TF 1.x 的行为,可以运行
import tensorflow.compat.v1 as tf tf.disable_v2_behavior()
但随后无法从 TF 2.0 中的许多改进中受益。有关更多详细信息,请参阅迁移指南
https://www.tensorflow.org/guide/migrate
-
Tensorflow 2.0-AttributeError:模块'tensorflow'没有属性'Session'
2021-01-29 关注 0 浏览78 1答案
-
AttributeError:模块“ tensorflow”没有属性“ get_default_graph”
2021-01-29 关注 0 浏览125 1答案
-
AttributeError:模块“ tensorflow”没有属性“ reset_default_graph”
2021-01-29 关注 0 浏览79 1答案
-
AttributeError:模块“ tensorflow.python.training.checkpointable”没有属性“ CheckpointableBase”
2021-01-29 关注 0 浏览232 1答案
-
TensorFlow:AttributeError:'Tensor'对象没有属性'shape'
2021-01-29 关注 0 浏览121 1答案
-
AttributeError:加载tf.compat.v1.train.SessionRunHook时,模块'tensorflow'没有属性'compat'
2021-01-29 关注 0 浏览259 1答案
-
AttributeError:模块“ tensorflow”不具有Keras属性“ name_scope”
2021-01-29 关注 0 浏览52 1答案
-
TensorFlow,“'模块'对象没有属性'占位符'”
2021-01-29 关注 0 浏览49 1答案
-
{AttributeError:模块'tensorflow_core._api.v2.config'没有属性'experimental_list_devices'}我如何解决此错误?
2021-01-29 关注 0 浏览86 1答案
-
Tensorflow ImportError:Windows 10上没有名为'_pywrap_tensorflow_internal'的模块
2021-01-29 关注 0 浏览92 1答案