tensorflow函数解析:Session.run和Tensor.eval的区别
tensorflow函数解析:Session.run和Tensor.eval
原问题链接:
译:
问题:
tensorflow有两种方式:Session.run和 Tensor.eval,这两者的区别在哪?
答:
如果你有一个Tensor t,在使用t.eval()时,等价于:tf.get_default_session().run(t).
举例:
t = tf.constant(42.0)
sess = tf.Session()
with sess.as_default(): # or `with sess:` to close on exit
assert sess is tf.get_default_session()
assert t.eval() == sess.run(t)
这其中最主要的区别就在于你可以使用sess.run()在同一步获取多个tensor中的值,
例如:
t = tf.constant(42.0)
u = tf.constant(37.0)
tu = tf.mul(t, u)
ut = tf.mul(u, t)
with sess.as_default():
tu.eval() # runs one step
ut.eval() # runs one step
sess.run([tu, ut]) # evaluates both tensors in a single step
注意到:每次使用 eval 和 run时,都会执行整个计算图,为了获取计算的结果,将它分配给tf.Variable,然后获取。
原文如下:
Question:
TensorFlow has two ways to evaluate part of graph: Session.run on a list of variables and Tensor.eval. Is there a difference between these two?
Answer:
If you have a Tensor t, calling t.eval() is equivalent to calling tf.get_default_session().run(t).
You can make a session the default as follows:
t = tf.constant(42.0)
sess = tf.Session()
with sess.as_default(): # or `with sess:` to close on exit
assert sess is tf.get_default_session()
assert t.eval() == sess.run(t)
The most important difference is that you can use sess.run() to fetch the values of many tensors in the same step:
t = tf.constant(42.0)
u = tf.constant(37.0)
tu = tf.mul(t, u)
ut = tf.mul(u, t)
with sess.as_default():
tu.eval() # runs one step
ut.eval() # runs one step
sess.run([tu, ut]) # evaluates both tensors in a single step
Note that each call to eval and run will execute the whole graph from scratch. To cache the result of a computation, assign it to a tf.Variable.
tensorflow函数解析:Session.run和Tensor.eval的区别的更多相关文章
- tensorflow函数解析:Session.run和Tensor.eval
原问题链接: http://stackoverflow.com/questions/33610685/in-tensorflow-what-is-the-difference-between-sess ...
- Difference Between Session.run and Tensor.eval
[Question]: TensorFlow has two ways to evaluate part of graph: Session.run on a list of variables an ...
- tensorflow函数解析: tf.Session() 和tf.InteractiveSession()
链接如下: http://stackoverflow.com/questions/41791469/difference-between-tf-session-and-tf-interactivese ...
- [图解tensorflow源码] Session::Run() 分布式版本
- [图解tensorflow源码] Session::Run()流程图 (单机版)
- tensorflow函数介绍(1)
tensorflow中的tensor表示一种数据结构,而flow则表现为一种计算模型,两者合起来就是通过计算图的形式来进行计算表述,其每个计算都是计算图上的一个节点,节点间的边表示了计算之间的依赖关系 ...
- [图解tensorflow源码] [原创] Tensorflow 图解分析 (Session, Graph, Kernels, Devices)
TF Prepare [图解tensorflow源码] 入门准备工作 [图解tensorflow源码] TF系统概述篇 Session篇 [图解tensorflow源码] Session::Run() ...
- tf.session.run()单函数运行和多函数运行区别
tf.session.run()单函数运行和多函数运行区别 觉得有用的话,欢迎一起讨论相互学习~Follow Me problem instruction sess.run([a,b]) # (1)同 ...
- [转]javascript eval函数解析json数据时为什加上圆括号eval("("+data+")")
javascript eval函数解析json数据时为什么 加上圆括号?为什么要 eval这里要添加 “("("+data+")");//”呢? 原因在于: ...
随机推荐
- STM32 SPI接口的NSS引脚
SPI_NSS 设置 NSS 信号由硬件( NSS 管脚)还是软件控制,这里我们一般通过软件控制 NSS ,而不是硬件自动控制,所以选择 SPI_NSS_Soft 选择了软件NSS之后,引脚NSS就可 ...
- npm 国内淘宝镜像cnpm、设置淘宝源
1.下载和使用cnpm 某些插件很奇怪,需要用国内的镜像下载才可以 #安装淘宝镜像npm install cnpm -g --registry=https://registry.npm.taobao. ...
- 如何安装rockmongo(gui for mongodb)
1.下载rockmongo 下载地址: http://rockmongo.com/downloads 将下载下来的压缩包rockmongo-1.1.5.zip解压到web 发布目录(我这里使用的是ap ...
- C 字符串常量和字符串变量定义和区别
字符串常量 定义:在一个双引号""内的字符序列或者转义字符序列称为字符串常量 例如:"HA HA!" "abc" "\n\t& ...
- google protocol buffer的原理和使用(三)
介绍下怎么反序列化GoogleBuffer数据.并在最后提供本系列文章中所用到的代码整理供下载. 上一篇文章介绍了如何将数据序列化到了addressbook.data中.那么对于接受方而言该怎么解析出 ...
- cocos2d-x--精灵反转效果--CCOrbitCamera
CCSprite* pSprite = CCSprite::spriteWithFile("grossini.png"); pSprite->setPosition(ccp( ...
- JIT IR,C2
A Simple Graph-Based Intermediate Representation http://www.oracle.com/technetwork/java/javase/tech/ ...
- 每日英语:Skull Shakes Up Human Family Tree
A newly discovered 1.8 million-year-old skull offers evidence that humanity's early ancestors emerge ...
- 将socket通信变成并发的方式
一 利用multiprocessing模块,开启多进程,实现socket通信并发 1. 开启子进程的两种方式 import time import random from multiprocessin ...
- Date函数基础知识整理
Date类型:1.Date.parse()接收一个表示日期的字符串参数,然后再根据这个字符串返回响应的日期的毫秒数:如:创建一个日期: <script> // var someDate=n ...