【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.

----------------------------------------------------------

参考:

  1. http://blog.csdn.net/zcf1784266476/article/details/70259676

Difference Between Session.run and Tensor.eval的更多相关文章

  1. tensorflow函数解析:Session.run和Tensor.eval的区别

    tensorflow函数解析:Session.run和Tensor.eval 翻译 2017年04月20日 15:05:50 标签: tensorflow / 机器学习 / 深度学习 / python ...

  2. tensorflow函数解析:Session.run和Tensor.eval

    原问题链接: http://stackoverflow.com/questions/33610685/in-tensorflow-what-is-the-difference-between-sess ...

  3. tf.session.run()单函数运行和多函数运行区别

    tf.session.run()单函数运行和多函数运行区别 觉得有用的话,欢迎一起讨论相互学习~Follow Me problem instruction sess.run([a,b]) # (1)同 ...

  4. Session.run() & Tensor.eval()

    如果有一个Tensor t,在使用t.eval()时,等价于: tf.get_defaut_session().run(t) t = tf.constant(42.0) sess = tf.Sessi ...

  5. [图解tensorflow源码] Session::Run() 分布式版本

  6. [图解tensorflow源码] Session::Run()流程图 (单机版)

  7. Tensorflow中的run()函数

    1 run()函数存在的意义 run()函数可以让代码变得更加简洁,在搭建神经网络(一)中,经历了数据集准备.前向传播过程设计.损失函数及反向传播过程设计等三个过程,形成计算网络,再通过会话tf.Se ...

  8. Tensorflow (1)

    'tf.placeholder' or 'tf.Variable' The difference is that with tf.Variable you have to provide an ini ...

  9. [翻译] TensorFlow Programmer's Guide之Frequently Asked Questions(问得频率最多的几个问题)

    目录: 特点和兼容性(Features and Compatibility) 建立一个TensorFlow图(Building a TensorFlow graph) 运行一个TensorFlow计算 ...

随机推荐

  1. python中sys.path--学习

    本着下定义开头吧:python中import某个A模块时,首先会从python的内置模块中查找是否含义该模块的定义若未查询到会从sys.path对应的模块路径查询是否含有对应模块的定义,如果搜索完成依 ...

  2. Go学习笔记:Win7+LiteIDE+Go+Beego 环境搭建

    安装过程比较简单 1.安装go语言环境: 2.安装git: 3.git bash      安装beego,输入“go get github.com/astaxie/beego”,等待一会儿,在D盘的 ...

  3. Android 面试问答

    Android 面试问答 目录 数据结构和算法 java核心知识 Android核心知识 架构 设计相关问题 相关工具和技术 Android 测试驱动开发 其他 数据结构和算法 ******关于此类问 ...

  4. 【转】Cron表达式详解

    Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: (1) Seconds Minutes Hours DayofMonth Mo ...

  5. ES6 Rest参数

    Rest参数接收函数的多余参数,组成一个数组,放在形参的最后,形式如下: function func(a, b, ...theArgs) { // ... } rest参数只包括那些没有给出名称的参数 ...

  6. windows远程桌面连接时,显示发生身份验证错误,给函数提供的身份无效

    摘自:https://www.landui.com/help/show-7787 初次看到这个错误的时候懵了.访问给的地址一看,发现大概意思是不安全了,微软要更新一下 凭据安全支持提供程序协议 (Cr ...

  7. solr7.7.0搜索引擎使用(二)(添加搜索)

    一.安装完毕之后,需要为solr添加core,每一个搜索server就是一个core,solr可以有很多core,我们需要创建一个core用于我们的搜索 添加core的方式有两种: 第一种进入solr ...

  8. USART of STM32

    /*************************************************************************** * 文件名:USART.h * * 编写人:离 ...

  9. Python序列结构--列表(一)

    列表 列表**包含若干元素的有序连续内存空间**,当列表增加或删除元素时,**列表对象自动进行内存的扩展或收缩**,从而**保证相邻元素之间没有缝隙**.但插入和删除非尾部元素时涉及列表元素大量的移动 ...

  10. 背水一战 Windows 10 (81) - 全球化

    [源码下载] 背水一战 Windows 10 (81) - 全球化 作者:webabcd 介绍背水一战 Windows 10 之 全球化 Demo 格式化数字 示例1.演示全球化的基本应用Locali ...