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计算 ...
随机推荐
- Windows server 2012 R2 解决“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同
Windows server 2012 R2 解决“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同.”使用克隆的系统时,加域是出现如下问题.“无法完成域加入,原因是试图加入的域的SI ...
- SD
Offer(Tcode:VA23;Table: vbak and vbap) billing(Tcode:VF03;Table:vbrk and vbrp) Offer(quotation)-> ...
- 源码安装 odoo12 -- 问题记录
odoo12启动过程中遇到的问题,及解决办法:1.ImportError: No module named ‘win32service’pipenv install pypiwin32 2.Impor ...
- 时间戳转中国人能看得懂的日期格式 yy-mm-dd
很多项目都会用到时间戳的转换 说实话 我现在的这家公司超级好 因为后太要求传数据的时候竟然可以是时间戳的格式 我觉得我好幸福 哈哈哈 不过 等后台转给你数据的时候很多时候都是时间戳 这时候就得前端转 ...
- epoll_wait会被系统中断唤醒
今天,当一个程序在epoll_wait阻塞时,用strace跟踪了一下,结果epoll_wait就被EINTR唤醒了,并且返回-1: 所以,当epoll_wait返回-1时,需要判断errno是不是E ...
- 通过JDBC进行简单的增删改查(以MySQL为例) 目录
通过JDBC进行简单的增删改查(以MySQL为例) 目录 前言:什么是JDBC 一.准备工作(一):MySQL安装配置和基础学习 二.准备工作(二):下载数据库对应的jar包并导入 三.JDBC基本操 ...
- MySQL InnoDB特性:两次写(Double Write)
http://www.ywnds.com/?p=8334 一.经典Partial page write问题? 介绍double write之前我们有必要了解partial page write(部分页 ...
- 开启hadoop集群
首先开启zookeeper zkServer.sh start start-all
- diango中的url路由系统
一.url配置 url本质是url与要为该url调用的视图函数之间的映射表 urlpatterns = [正则,视图函数[,别名]] 二.正则表达式 1.匹配原则 django是循环urlpatter ...
- java实现随机产生6位数的方法总结
package com.yin.test; import java.util.Random; import org.junit.Test; /** * @author v_yinyl * @date ...