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)
系统信息:
重现步骤:
安装:
执行:
我正在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)