Tensorflow 2.0 - AttributeError: 模块“tensorflow"没有属性“Session" [英] Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'
问题描述
当我在 Tensorflow 2.0 环境中执行命令 sess = tf.Session()
时,我收到如下错误消息:
回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中.AttributeError: 模块tensorflow"没有属性Session"
<块引用>
系统信息:
- 操作系统平台和发行版:Windows 10
- Python 版本:3.7.1
- Tensorflow 版本:2.0.0-alpha0(使用 pip 安装)
重现步骤:
安装:
- pip install --upgrade pip
- pip install tensorflow==2.0.0-alpha0
- pip 安装 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 的行为,可以运行
将 tensorflow.compat.v1 导入为 tftf.disable_v2_behavior()
但是人们无法从 TF 2.0 中的许多改进中受益.有关更多详细信息,请参阅迁移指南https://www.tensorflow.org/guide/migrate
When I am executing the command sess = tf.Session()
in Tensorflow 2.0 environment, I am getting an error message as below:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'Session'
System Information:
- OS Platform and Distribution: Windows 10
- Python Version: 3.7.1
- Tensorflow Version: 2.0.0-alpha0 (installed with pip)
Steps to reproduce:
Installation:
- pip install --upgrade pip
- pip install tensorflow==2.0.0-alpha0
- pip install keras
- pip install numpy==1.16.2
Execution:
- Execute command: import tensorflow as tf
- Execute command: sess = tf.Session()
According to TF 1:1 Symbols Map
, in TF 2.0 you should use tf.compat.v1.Session()
instead of tf.Session()
https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0
To get TF 1.x like behaviour in TF 2.0 one can run
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
but then one cannot benefit of many improvements made in TF 2.0. For more details please refer to the migration guide https://www.tensorflow.org/guide/migrate
这篇关于Tensorflow 2.0 - AttributeError: 模块“tensorflow"没有属性“Session"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!