tf.identity is useful when you want to explicitly transport tensor between devices (like, from GPU to a CPU). The op adds send/recv nodes to the graph, which make a copy when the devices of the input and the output are different.

A default behavior is that the send/recv nodes are added implicitly when the operation happens on a different device but you can imagine some situations (especially in a multi-threaded/distributed settings) when it might be useful to fetch the value of the variable multiple times within a single execution of the session.run. tf.identity allows for more control with regard to when the value should be read from the source device. Possibly a more appropriate name for this op would be read.

Also, please note that in the implementation of tf.Variable link, the identity op is added in the constructor, which makes sure that all the accesses to the variable copy the data from the source only once. Multiple copies can be expensive in cases when the variable lives on a GPU but it is read by multiple CPU ops (or the other way around). Users can change the behavior with multiple calls to tf.identity when desired.

EDIT: Updated answer after the question was edited.

In addition, tf.identity can be used used as a dummy node to update a reference to the tensor. This is useful with various control flow ops. In the CIFAR case we want to enforce that the ExponentialMovingAverageOp will update relevant variables before retrieving the value of the loss. This can be implemented as:

with tf.control_dependencies([loss_averages_op]):
  total_loss = tf.identity(total_loss)
Here, the tf.identity doesn't do anything useful aside of marking the total_loss tensor to be ran after evaluating loss_averages_op.

简单地说就是创建虚拟节点,为cpu gpu传输什么的提供更好的性能。就像你做一个电路板,有些地方要把线路引出来,调试的时候可以看中间结果一样,tf.identity就是为了在图上显示这个值而创建的虚拟节点(个人理解)

最新文章

  1. 黄聪:路由器WIFI连接无法正常访问个别网站及发送图片
  2. 对于大量left join 的表查询,可以在关键的 连接节点字段上创建索引。
  3. C# 值类型和引用类型
  4. hbase基本操作
  5. 不显示UITableView底部多余的分割线
  6. nyist 488 素数环(搜索+回溯)
  7. Generating Faces with Deconvolution Networks
  8. [Ccodeforces 736C] Ostap and Tree - 树形DP
  9. postcss的安装与使用
  10. lodash 实现一些常见的功能
  11. nginx系列2:搭建nginx环境
  12. 牛客网PAT乙级(Basic Level)真题-组个最小数 (20)
  13. 通过jpa getResultList 获取查询到的内容
  14. bus实现兄弟组件传值
  15. wikipedia 维基百科 语料 获取 与 提取 处理 by python3.5
  16. 通达OA在centos系统中快速部署文档(web和数据库)
  17. python基础数据类型考试题
  18. C++变量存储类别和内存四区
  19. Spark 实践——用 Scala 和 Spark 进行数据分析
  20. Linux下grep命令查找带有tab(退格)的字符

热门文章

  1. jQuery实现鼠标滑过图片列表加遮罩层
  2. [Android] android.util.Log
  3. system.data oracleClient 需要Oracle客户端8.1.7或high
  4. python学习笔记_week10
  5. Flex下打开新窗口链接
  6. Flex学习笔记-皮肤
  7. 利用STM32CubeMX生成HID双向通讯工程
  8. 浅谈 REST 和 RESTFul API
  9. day33-常见内置模块二(hashlib、shutil、configparse)
  10. hive基础操作