Session 会话
1. 功能
管理程序运行的资源,完成计算之后需要关闭会话来让系统回收资源。否则资源可能就不够了。
2. Example
Matrix1=tf.constant([[3,3]])
Matrix2=tf.constant({[2],
[2]])
Product=tf.matmul(matrix1, matrix2) #matrix multiply np.dot(m1,m2)
#method 1
Sess=tf.Session()
Result=sess.run(product)
Print(result)
Sess.close()
#method 2
With tf.Session() as sess: #打开了Session会自动关闭
Result2=sess.run(product)
Print(result2)
网友评论