您的位置:首页 > 其它

Tensorflow中Session会话控制的两种打开模式

2017-04-11 10:46 330 查看
建立两个matrix并输出两个matrix矩阵想乘的结果

因为product不是直接计算的步骤,所以我们会用使用Session来激活product并得到计算结果,下面method1 和method2就是两种控制方式

import tensorflow as tf
matrix1=tf.constant([[3,3]])
matrix2=tf.constant([[2],
[2]])
product=tf.matmul(matrix1,matrix2)#matrix multiply np.dat(m1,m2)

#mothod 1

sess=tf.Session()
result=sess.run(product)
print(result)
sess.close()

# mothod 2

with tf.Session()as sess:
result2=sess.run(product)
print(result2)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  session