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的区别
tensorflow函数解析:Session.run和Tensor.eval 翻译 2017年04月20日 15:05:50 标签: tensorflow / 机器学习 / 深度学习 / python ...
- 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+")");//”呢? 原因在于: ...
随机推荐
- 【STM32H7教程】第51章 STM32H7的LTDC应用之LCD汉字显示和2D图形显示
完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第51章 STM32H7的LTDC应用之LCD汉字 ...
- 一百、SAP中ALV事件之十三,给ALV的自定义按钮添加事件
一.我们查看定义的按钮,有一个名字是ZADD的自定义按钮 二.代码如下,用于判断点击了哪个按钮 三.点击测试按钮之后,会弹出一个弹窗 完美
- APIO 2010 特别行动队 斜率优化DP
Description 你有一支由 n 名预备役士兵组成的部队,士兵从 1 到 n 编号,要将他们拆分 成若干特别行动队调入战场.出于默契的考虑,同一支特别行动队中队员的编号 应该连续,即为形如 (i ...
- getClass兼容ie
if (!document.getElementsByClassName) { document.getElementsByClassName = function(className, elemen ...
- Win7微信DLL劫持反弹SHELL(10.9 第十七天)
(该文参考自网络其他人资料,仅为学习,不得用于非法用途) 准备的工具:kali虚拟机 W7虚拟机 微信 ProcessExplorer the-backdoor-factory-master 打开微信 ...
- 【Vue中的坑】路由相同参数不同无法触发路由
场景: vue实现导航栏,二级导航栏跳转到相同页面,通过参数来实现到该页面后,根据参数来滚动到对应到位置 网上的解决方法: 通常情况下我们喜欢设置keepAlive 包裹 router-view &l ...
- /etc/apt/sources.list.d
deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main# deb-src http://ppa.launchpad.net/w ...
- Python学习——购物车程序
问题需求: 1.启动程序,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 4.可随时退出,退出时,打印已购买的商品和余 ...
- 第三章,数据和C
3.1 数据类型关键字 位:计算机内部数据存储的最小存储单位(bit). 字节:计算机中数据处理的基本单位(Byte)),1B=8bit. 字:计算机进行数据处理时,一次存取,加工和传送的数据长度.( ...
- 使用navicat连接mysql8.0.12版本 出现client does not support。。。解决办法
navicat版本的问题 出现连接失败的原因:mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password ...