即日起在codingBlog上分享您的技术经验即可获得积分,积分可兑换现金哦。

Tensorflow session

编程语言 zeroQiaoba 9℃ 0评论

传送门


Tensorflow定义完图结构,并不会直接计算,需要利用session才能激活。一般直接利用第一种session机制就足够了。

# View more python learning tutorial on my Youtube and Youku channel!!!

# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
# Youku video tutorial: http://i.youku.com/pythontutorial

"""
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
"""
from __future__ import print_function
import tensorflow as tf

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:
    result2 = sess.run(product)
    print(result2)

转载请注明:CodingBlog » Tensorflow session

喜欢 (0)or分享 (0)
发表我的评论
取消评论

*

表情