首页 > 解决方案 > 如何修复:模块“tensorflow”没有属性“会话”

问题描述

import tensorflow as tf
a=tf.constant(2)
b=tf.constant(3)
c=a+b
sess=tf.Session(c)
sess.run()

我收到错误消息模块“tensorflow”没有属性“会话”

标签: pythontensorflowmachine-learningdata-science

解决方案


从官方文档中尝试以下操作:

# 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))

推荐阅读