import tensorflow as tf
tf.compat.v1.disable_eager_execution()
# tensorflow 2.5.0
# two methods for opening Session
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.compat.v1.Session()
# result = sess.run(product) # 每run一下执行一次product的结构
# print(result)
# sess.close() # 可加可不加
# method 2 会自动关上Session
with tf.compat.v1.Session() as sess: # 打开了session
result2 = sess.run(product)
print(result2)
Session会话控制
最新推荐文章于 2021-09-30 08:11:01 发布