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+")");//”呢? 原因在于: ...
随机推荐
- eclipse中使用jstl
错误提示为"can not find the tag library for http://java.sun.com/jsp/jstl/core" 这是我在练习把axis2和普通j ...
- 一百零七、SAP的OO-ALV之一,新建程序
一.来带SE38模块,新建一个Z_TIANPAN_20190807_OOALV的本地程序 二.设置一个标题,点击对勾 三.选择保存为本地对象 我们下一篇来写创建屏幕
- Spring-ResolvableType可解决的数据类型
ResolvableType,可解决的数据类型.它为java语言中的所有类型提供了相同的数据结构,其内部封装了一个java.lang.reflect.Type类型的对象. 在讲解这个数据结构之前,首先 ...
- 最小生成树(Kruskal+Prim)--模板
最小生成树-----在连通网的所有生成树中,所有边的代价和最小的生成树,称为最小生成树. 应用场景 1.假设以下情景,有一块木板,板上钉上了一些钉子,这些钉子可以由一些细绳连接起来.假设每个钉子可以通 ...
- Python LMDB的使用
在python中使用lmdb linux中,可以使用指令 pip install lmdb 安装lmdb包. ---- lmdb 数据库文件生成 增 改 删 查 1.生成一个空的lmdb数据库文件 # ...
- Power Tower
题目大意:给出一段长为 \(n\) 的序列 \(a_1,a_2,\cdots,a_n\) ,一个模数 \(m\) .每次询问给定 \(l,r\) 求 \(a_l^{{a_{l+1}^\cdots}^{ ...
- POJ 2239:Selecting Courses 选课
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9380 Accepted: 4177 ...
- sping--事务
事务的四大特性(ACID): 原子性(Atomicity) 一致性(Consistency) 隔离性(Isolation) 持久性(Durability) 事务属性: 1. propagation : ...
- 19 01 15 js 尺寸相关 滚动事件
尺寸相关.滚动事件 1.获取和设置元素的尺寸 width().height() 获取元素width和height innerWidth().innerHeight() 包括padding的width和 ...
- ORA-00911
直接在PLSQL运行没问题,在java程序里面运行就报错:ORA-00911 select * from mytable; 亲测,改为: select * from mytable 看到区别没,去掉: ...