当我在Tensorflow 2.0环境中执行命令sess = tf.Session()时,我得到了一个错误消息,如下所示:
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安装——升级PIP
PIP install tensorflow==2.0.0-alpha0
PIP安装keras
PIP install numpy==1.16.2
执行:
执行命令:import tensorflow as tf
执行命令:sess = tf.Session()
使用Anaconda + Spyder (Python 3.7)
(代码)
import tensorflow as tf
valor1 = tf.constant(2)
valor2 = tf.constant(3)
type(valor1)
print(valor1)
soma=valor1+valor2
type(soma)
print(soma)
sess = tf.compat.v1.Session()
with sess:
print(sess.run(soma))
[控制台]
import tensorflow as tf
valor1 = tf.constant(2)
valor2 = tf.constant(3)
type(valor1)
print(valor1)
soma=valor1+valor2
type(soma)
Tensor("Const_8:0", shape=(), dtype=int32)
Out[18]: tensorflow.python.framework.ops.Tensor
print(soma)
Tensor("add_4:0", shape=(), dtype=int32)
sess = tf.compat.v1.Session()
with sess:
print(sess.run(soma))
5