【问题标题】: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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-25
      • 2019-08-25
      • 2020-09-03
      • 2020-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多