20171130_tensorflow_session

来源:互联网 发布:渔具招商 源码 编辑:程序博客网 时间:2024/06/15 02:29

此篇代码主要介绍Session的类似与python的with 用法,比较习惯with用法

#!/usr/bin/env python# -*- coding: utf-8 -*-# @Date    : 2017-11-30 19:27:06# @Author  : Lebhoryi@gmail.com# @Link    : https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/2-3-session/# @Version : Session 会话控制import tensorflow as tfmatrix1 = tf.constant([[3,3]])matrix2 = tf.constant([[2],                       [2]])product = tf.matmul(matrix1,matrix2)    # matrix multiply,np.dot(m1,m2)# method 1sess = tf.Session()result = sess.run(product)print(result)sess.close()# method2 推荐用后面一种with tf.Session() as sess:    result2 = sess.run(product)    print(result2)
原创粉丝点击