小编Dec*_*ent的帖子

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'
Run Code Online (Sandbox Code Playgroud)

系统信息:

  • 操作系统平台和发行版:Windows 10
  • python版本:3.7.1
  • Tensorflow版本:2.0.0-alpha0(随pip一起安装)

重现步骤:

安装:

  1. 点安装-升级点
  2. pip install tensorflow == 2.0.0-alpha0
  3. 点安装keras
  4. 点安装numpy == 1.16.2

执行:

  1. 执行命令:将tensorflow导入为tf
  2. 执行命令:sess = tf.Session()

python keras tensorflow tensorflow2.0

29
推荐指数
4
解决办法
4万
查看次数

Tensorflow 2中的执行急切

我正在Google Colab上测试代码。似乎Google Colab默认运行Tensorflow的版本2:

[In:]
import tensorflow as tf
print(tf.__version__)

[Out:]
2.0.0-dev20190130
Run Code Online (Sandbox Code Playgroud)

并且该版本没有急切执行的功能:

[In:]
tf.enable_eager_execution()

[Out:]
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-ddf3115bdcc7> in <module>()
----> 1 tf.enable_eager_execution()

AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'
Run Code Online (Sandbox Code Playgroud)

我在TensorFlow 2上找不到文档。我也无法运行TensorFlow的旧版本:

[In:]
!pip install tensorflow==1.12.0
import tensorflow as tf
print(tf.__version__)

[Out:]
Requirement already satisfied: tensorflow==1.12.0 in /usr/local/lib/python3.6/dist-packages (1.12.0)
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.12.0) (1.11.0)
Requirement already satisfied: absl-py>=0.1.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.12.0) (0.7.0)
Requirement already satisfied: astor>=0.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.12.0) …
Run Code Online (Sandbox Code Playgroud)

tensorflow google-colaboratory tensorflow2.0

7
推荐指数
1
解决办法
1050
查看次数