# tf.Session.run 方法是一个执行tf.Operation或者计算tf.Tensor的一个主要的机制
# 你可以传递一个或者多个tf.Operation或者tf.Tensor对象来给tf.Session.run
# TensorFlow会执行operation操作来计算结果
# tf.Session.run需要你来指定一系列的获取,这些决定了返回值
# 这些获取可以是 tf.Operation ,一个tf.Tensor 或者一个tensor-like type 列如tf.Variable
# 这些获取决定了子的计算图必须执行的操作来产生结果
import tensorflow as tf
x = tf.constant([[37.0, -23.0], [1.0, 4.0]])
w = tf.Variable(tf.random_uniform([2, 2]))
y = tf.matmul(x, w)
output = tf.nn.softmax(y)
init_op = w.initializer
with tf.Session() as sess:
# Run the initializer on 'w'
sess.run(init_op) # Evaluate 'output' , 'sess.run(output)' will return a NumPy array containing
# the result of the computation
print(sess.run(output)) # Evaluate 'y' and 'output'
# y will only be computed once,
# and its result used both to return
# y_valu and as an input to the tf.nn.softmax()
# op . both y_val and output_val will be NumPy arrays
y_val, output_val = sess.run([y, output]) # print result
print(y_val)
print(output_val)

126、TensorFlow Session的执行的更多相关文章

  1. (原)tensorflow中函数执行完毕,显存不自动释放

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/7608916.html 参考网址: https://stackoverflow.com/question ...

  2. tensorflow session会话控制

    import tensorflow as tf # create two matrixes matrix1 = tf.constant([[3,3]]) matrix2 = tf.constant([ ...

  3. 125、TensorFlow计算图的执行

    # TensorFlow使用tf.Session类来表示客户端程序之间的链接 # 虽然一个在其他语言中相似的接口也是可以使用的,列如C++ runtime # 一个tf.Session对象提供了访问本 ...

  4. What is a TensorFlow Session?

    Sep 26, 2016 I've seen a lot of confusion over the rules of tf.Graph and tf.Session in TensorFlow. I ...

  5. tensorflow session 和 graph

    graph即tf.Graph(),session即tf.Session(),很多人经常将两者混淆,其实二者完全不是同一个东西. graph定义了计算方式,是一些加减乘除等运算的组合,类似于一个函数.它 ...

  6. 用tensorflow的Eager执行模式

    一.即时执行模式 import tensorflow as tfimport tensorflow.contrib.eager as tfetfe.enable_eager_execution() a ...

  7. tensorflow基础架构 - 处理结构+创建一个线性回归模型+session+Variable+Placeholder

    以下仅为自己的整理记录,绝大部分参考来源:莫烦Python,建议去看原博客 一.处理结构 因为TensorFlow是采用数据流图(data flow graphs)来计算, 所以首先我们得创建一个数据 ...

  8. Tensorflow源码解析2 -- 前后端连接的桥梁 - Session

    Session概述 1. Session是TensorFlow前后端连接的桥梁.用户利用session使得client能够与master的执行引擎建立连接,并通过session.run()来触发一次计 ...

  9. TensorFlow源代码学习--1 Session API reference

    学习TensorFlow源代码,先把API文档扒出来研究一下整体结构: 一下是文档内容的整理,简单翻译一下 原文地址:http://www.tcvpr.com/archives/181 TensorF ...

随机推荐

  1. 通过挂载系统U盘搭建本地yum仓库

    首先打开hbza(CentOS)和yum,两者要连接上 第1步:在hbza中创建一个目录 输入mkdir /lxk,名字随便起.输入mount  /dev/cdrom  /lxk 第2步:打开yum, ...

  2. 1.Dockerfile

    1.docker build docker build 这个动作有一个context 上下文的概念 docker build -f /path/to/a/Dockerfile .这个动作 通过 -f ...

  3. 漫漫人生路,我们该何去何从! Python让我找到了方向

    互联网寒冬 2017年冬天,是我人生中最难熬的一个冬天,其实2017年的冬天并不算太冷,比这冬日的寒风还要严寒的要属这所谓的"互联网寒冬"吧!各大厂裁员的消息充斥着互联网,互联网表 ...

  4. SQL SERVER 数据库跨服务器备份

    原文:https://www.cnblogs.com/jaday/p/6088200.html 需求介绍:每天备份线上正式库并且把备份文件复制到测试服务器,测试服务器自动把数据库备份文件还原. 方案介 ...

  5. C#根据出生日期和当前日期计算精确年龄

    C#根据出生日期和当前日期计算精确年龄更多 0c#.net基础 public static string GetAge(DateTime dtBirthday, DateTime dtNow){ st ...

  6. 第一个chrome extension

    如今,chrome浏览器的使用如越来越流行,chrome extension往往能提供更多很丰富的功能.以前一直想了解这方面的东西,可是又担心很复杂.前段时间,在斗鱼看一个直播,想刷弹幕,但是每次自己 ...

  7. iOS 应用配置及证书生成教程

    简介 首先你需要有一个苹果的开发者帐号,一台苹果电脑.点击查看苹果开发者账号注册流程 本教程需完成应用信息配置,包括如下两个基本配置: AppID Bundle ID 同时,生成 如下三个证书文件及对 ...

  8. 查看Xcode里的描述文件

    iOS应用打包离不开描述文件,也就是mobileprovision文件. 一般我们的操作是双击,Xcode就会运行该文件.但是具体文件里是什么,Xcode又是否真的加载了该文件?文件里又描述了什么呢? ...

  9. TensorFlow——CNN卷积神经网络处理Mnist数据集

    CNN卷积神经网络处理Mnist数据集 CNN模型结构: 输入层:Mnist数据集(28*28) 第一层卷积:感受视野5*5,步长为1,卷积核:32个 第一层池化:池化视野2*2,步长为2 第二层卷积 ...

  10. Power Designer将数据库表结构导出到Word

     一.   安装与运行PowerDesigner(本例中用的版本是15.1) 二.“File”→“New Model”→“Categories”→“Information”→“Physical Dat ...