# 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. Linux的tail命令查看文件

    小文件一般用cat  查看,但是如果文件内容过多,用cat就不合适了 可以用tail命令 # 默认显示文件最后十行 tail a.txt # 监视文件的尾部内容,默认十行, 可以-n 20显示20行 ...

  2. Windows + Ubuntu 16.04 双系统安装详细教程(转)

    转载自:http://www.cnblogs.com/Duane/p/6776302.html 前言:本篇文章是对之前文章的更新,更新的主内容是把原来用手机拍摄的图片换成了虚拟机的截图,以及对磁盘划分 ...

  3. SpringBoot使用webservice

    Pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  4. Oracle数据库的下载与安装

    Oracle数据库下载: 推荐去Oracle官网下载 官方网址链接:https://www.oracle.com/database/technologies/oracle-database-softw ...

  5. [ZJOI2009]取石子游戏

    瞪了题解两三天,直接下转第二篇题解就康懂了 首先我们令 : \(L[i][j]\) 表示当前 \([i,j]\) 区间左侧放置 \(L[i,j]\) 数量的石子后先手必败 \(R[i][j]\) 表示 ...

  6. Elasticsearch7.X 入门学习第三课笔记----search api学习(URI Search)

    原文:Elasticsearch7.X 入门学习第三课笔记----search api学习(URI Search) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出 ...

  7. JavaScript高级笔记

    # 今日内容:     1. JavaScript:         1. ECMAScript:         2. BOM:         3. DOM:             1. 事件 ...

  8. more 分页显示文件内容

    1.命令功能 more 分页显示文件内容 2.语法格式 more  option file 参数说明 参数 参数说明 -num 指定屏幕显示大小为num行 +num 从行号num号开始显示 -s 把连 ...

  9. prufer 序列 学习笔记

    prufer 序列是一种无根树的序列,对于一个 \(n\) 个点的树,其 prufer 序列的长度为 \(n-2\). prufer 序列和原树之间都可以唯一地相互转化. 构造 构造 prufer 序 ...

  10. 配置 Kibana

    Products Cloud Services Customers Learn downloads EN Docs Kibana 用户手册 » 搭建 » 配置 Kibana «  在 Windows ...