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
- 点安装numpy == 1.16.2
执行:
- 执行命令:将tensorflow导入为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所做的许多改进。
-
Tensorflow 2.0 - AttributeError:模块'tensorflow'没有属性'Session'
2022-07-28 关注 0 浏览25 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答案