Tensorflow 2.0-AttributeError:模块"tensorflow"没有属性"Session" [英] Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'
问题描述
在Tensorflow 2.0环境中执行命令sess = tf.Session()
时,出现如下错误消息:
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平台和发行版:Windows 10
- Python版本:3.7.1
- Tensorflow版本:2.0.0-alpha0(与pip一起安装)
- pip install --upgrade pip
- 点安装tensorflow == 2.0.0-alpha0
- pip install keras
- pip install numpy == 1.16.2
- pip install --upgrade pip
- pip install tensorflow==2.0.0-alpha0
- pip install keras
- pip install numpy==1.16.2
- 执行命令:将tensorflow导入为tf
- 执行命令:sess = tf.Session()
复制步骤:
Steps to reproduce:
安装:
执行:
推荐答案
根据TF 1:1 Symbols Map
,在TF 2.0中,您应该使用tf.compat.v1.Session()
而不是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
要获得TF 2.0中类似TF 1.x的行为,可以运行
To get TF 1.x like behaviour in TF 2.0 one can run
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
但是,这样的开发人员无法从TF 2.0中进行的许多改进中受益.有关更多详细信息,请参阅迁移指南 https://www.tensorflow.org/guide/migrate
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屋!