tensorflow session会话控制

import tensorflow as tf

# create two matrixes

matrix1 = tf.constant([[3,3]])
matrix2 = tf.constant([[2],
                       [2]])
product = tf.matmul(matrix1,matrix2)
#method1
sess = tf.Session()
result = sess.run(product)
print(result)
sess.close()

#method2
with tf.Session() as sess:
    result2 = sess.run(product)
    print(result2)

  Session 是 Tensorflow 为了控制,和输出文件的执行的语句. 运行 session.run() 可以获得你要得知的运算结果, 或者是你所要运算的部分.

原文地址:https://www.cnblogs.com/Michael2397/p/7997899.html