【问题标题】:how to fix : module 'tensorflow' has no attribute 'Session' [duplicate]如何修复:模块“tensorflow”没有属性“会话”[重复]
【发布时间】:2020-07-02 08:27:50
【问题描述】:
import tensorflow as tf
a=tf.constant(2)
b=tf.constant(3)
c=a+b
sess=tf.Session(c)
sess.run()
我收到错误消息模块“tensorflow”没有属性“会话”
【问题讨论】:
标签:
python
tensorflow
machine-learning
data-science
【解决方案1】:
从官方文档中尝试以下操作:
# Build a graph.
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
# Launch the graph in a session.
sess = tf.compat.v1.Session()
# Evaluate the tensor `c`.
print(sess.run(c))
【解决方案2】:
试试这个方法:
with tf.compat.v1.Session() as sess:
a = tf.constant(5.0)
b = tf.constant(6.0)
c = tf.multiply(a, b)
result = sess.run(c)
print(result)