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