关注微信公共号:小程在线
关注CSDN博客:程志伟的博客
源代码:
import tensorflow as tf
reset_graph()
x = tf.Variable(3, name="x")
y = tf.Variable(4, name="y")
f = x*x*y + y + 2
sess = tf.Session()
sess.run(x.initializer)
sess.run(y.initializer)
result = sess.run(f)
print(result)
AttributeError: module 'tensorflow' has no attribute 'Session'
改成:主要是增加了加粗字体的代码
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
reset_graph()
x = tf.Variable(3, name="x")
y = tf.Variable(4, name="y")
f = x*x*y + y + 2
f
sess = tf.Session()
sess.run(x.initializer)
sess.run(y.initializer)
result = sess.run(f)
print(result)
42