Difference Between Session.run and Tensor.eval
【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.
----------------------------------------------------------
参考:
- http://blog.csdn.net/zcf1784266476/article/details/70259676
Difference Between Session.run and Tensor.eval的更多相关文章
- tensorflow函数解析:Session.run和Tensor.eval的区别
tensorflow函数解析:Session.run和Tensor.eval 翻译 2017年04月20日 15:05:50 标签: tensorflow / 机器学习 / 深度学习 / python ...
- tensorflow函数解析:Session.run和Tensor.eval
原问题链接: http://stackoverflow.com/questions/33610685/in-tensorflow-what-is-the-difference-between-sess ...
- tf.session.run()单函数运行和多函数运行区别
tf.session.run()单函数运行和多函数运行区别 觉得有用的话,欢迎一起讨论相互学习~Follow Me problem instruction sess.run([a,b]) # (1)同 ...
- Session.run() & Tensor.eval()
如果有一个Tensor t,在使用t.eval()时,等价于: tf.get_defaut_session().run(t) t = tf.constant(42.0) sess = tf.Sessi ...
- [图解tensorflow源码] Session::Run() 分布式版本
- [图解tensorflow源码] Session::Run()流程图 (单机版)
- Tensorflow中的run()函数
1 run()函数存在的意义 run()函数可以让代码变得更加简洁,在搭建神经网络(一)中,经历了数据集准备.前向传播过程设计.损失函数及反向传播过程设计等三个过程,形成计算网络,再通过会话tf.Se ...
- Tensorflow (1)
'tf.placeholder' or 'tf.Variable' The difference is that with tf.Variable you have to provide an ini ...
- [翻译] TensorFlow Programmer's Guide之Frequently Asked Questions(问得频率最多的几个问题)
目录: 特点和兼容性(Features and Compatibility) 建立一个TensorFlow图(Building a TensorFlow graph) 运行一个TensorFlow计算 ...
随机推荐
- 安装64位office时,弹出提示,要求卸载32位office
运行 regedit,进入到HKEY_CLASSES_ROOT\Installer\Products下,删除0000510开头的项或00002开头项.然后重启计算机. 参考: https://blo ...
- ExecuteNonQuery()
ExecuteNonQuery():执行一个SQL语句,返回受影响的行数,这个方法主要用于执行对数据库执行增加.更新.删除操作,注意查询的时候不是调用这个方法.用于完成insert,delete,up ...
- 获取MessageBox按钮本地字符串(OK、Cancel、Yes、No等)
问题仍然由定制MessageBox引发. 定制MessageBox,虽加入自定义些东西,但仍然希望,最大限度接近系统原生框.碰到的问题,就是其钮文本. 即如MessageBox.Show()之Mess ...
- [leetcode]14. Longest Common Prefix 最长公共前缀
Write a function to find the longest common prefix string amongst an array of strings. If there is n ...
- linux下apt安装mysql导致mysql.user table is damaged
笔者在ubuntu下用 apt install mysql-server类似的命令安装mysql, 安装了最新版的mysql5.7,覆盖了操作系统内置的数据库mysql系统库. 最初启动mysql出错 ...
- rpo攻击
0 什么是RPO攻击? RPO(Relative Path Overwrite)相对路径覆盖,是一种新型攻击技术,最早由Gareth Heyes在其发表的文章中提出.主要是利用浏览器的一些特性和部分服 ...
- 要开始学习C#
之前有涉及ASP.NET,但是就仅涉及workflow这点,现在再接触还是有点陌生. 整理一些VS使用小技巧: 1,for cw ctor 按两下Tab键会出现整个的语句 2,Ctrl+shift ...
- Android 软件管理工具类Utils
Android 软件管理工具类Utils /** * Created by uilubo on 2015/9/30. * 工具类 */ public class Utils { public stat ...
- redis集群部署那点事
[CentOS]make cc Command not found,make: *** [adlist.o] Error 127” 参考:https://blog.csdn.net/wzygis/ar ...
- drf8 解析器
解析器的介绍 解析器的作用就是服务端接收客户端传过来的数据,把数据解析成自己想要的数据类型的过程. 本质就是对请求体中的数据进行解析. Accept与ContentType请求头. Accept是告诉 ...