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() 可以获得你要得知的运算结果, 或者是你所要运算的部分.

posted on 2017-12-07 10:36  Michael2397  阅读(162)  评论(0编辑  收藏  举报

导航