tf.InteractiveSession和tf.Session的区别

tf.InteractiveSession:可以在运行图的时候,插入新的图,可以方便的使用可交互环境来执行

用法:

sess = tf.InteractiveSession()
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
# We can just use 'c.eval()' without passing 'sess'
print(c.eval())
sess.close()

tf.Session:先用操作构建好图后,再创建session,再执行图。

用法:

# Build a graph.
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b

# Launch the graph in a session.
sess = tf.Session()

# Evaluate the tensor `c`.
print(sess.run(c))


原文地址:https://www.cnblogs.com/wangxuanran/p/10189325.html