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就是为了在图上显示这个值而创建的虚拟节点(个人理解)

tf.identity 个人理解的更多相关文章

  1. tensorflow笔记4:函数:tf.assign()、tf.assign_add()、tf.identity()、tf.control_dependencies()

    函数原型: tf.assign(ref, value, validate_shape=None, use_locking=None, name=None)   Defined in tensorflo ...

  2. 『TensorFlow』流程控制之tf.identity

    一个详细介绍 下面程序要做的是,5次循环,每次循环给x加1,赋值给y,然后打印出来, x = tf.Variable(0.0) #返回一个op,表示给变量x加1的操作 x_plus_1 = tf.as ...

  3. tf.tile()函数理解

    转载:https://blog.csdn.net/tsyccnh/article/details/82459859 tensorflow中的tile()函数是用来对张量(Tensor)进行扩展的,其特 ...

  4. tf.metrics.sparse_average_precision_at_k 和 tf.metrics.precision_at_k的自己理解

    tensorflow最大的问题就是大家都讲算法,不讲解用法,API文档又全是英文的,看起来好吃力,理解又不到位.当然给数学博士看的话,就没问题的. 最近看了一系列非常不错的文章,做一下记录: http ...

  5. 『TensorFlow』通过代码理解gan网络_中

    『cs231n』通过代码理解gan网络&tensorflow共享变量机制_上 上篇是一个尝试生成minist手写体数据的简单GAN网络,之前有介绍过,图片维度是28*28*1,生成器的上采样使 ...

  6. 跌倒了,再爬起来:ASP.NET 5 Identity

    "跌倒了"指的是这一篇博文:爱与恨的抉择:ASP.NET 5+EntityFramework 7 如果想了解 ASP.NET Identity 的"历史"及&q ...

  7. ASP.NET 5 Identity

    ASP.NET 5 Identity   “跌倒了”指的是这一篇博文:爱与恨的抉择:ASP.NET 5+EntityFramework 7 如果想了解 ASP.NET Identity 的“历史”及“ ...

  8. [三]java8 函数式编程Stream 概念深入理解 Stream 运行原理 Stream设计思路

    Stream的概念定义   官方文档是永远的圣经~     表格内容来自https://docs.oracle.com/javase/8/docs/api/   Package java.util.s ...

  9. TF之BN:BN算法对多层中的每层神经网络加快学习QuadraticFunction_InputData+Histogram+BN的Error_curve

    # 23 Batch Normalization import numpy as np import tensorflow as tf import matplotlib.pyplot as plt ...

随机推荐

  1. vue中实时监听对象或变量的变化

    demo中监听了Input的变化,主要用到的是watch 1. 监听单个对象: <template> <div class="personal-center"&g ...

  2. 【Selenium-WebDriver自学】Selenium测试设计技术(十三)

    Selenium页面对象模型 1.Selenium页面对象模型 优点 页面的对象模型是其中测试对象和功能被彼此分开,从而保持代码干净的实现. 对象保持独立的测试脚本.一个目的可以通过一个或多个测试脚本 ...

  3. LeetCode 4. Median of Two Sorted Arrays & 归并排序

    Median of Two Sorted Arrays 搜索时间复杂度的时候,看到归并排序比较适合这个题目.中位数直接取即可,所以重点是排序. 再来看看治阶段,我们需要将两个已经有序的子序列合并成一个 ...

  4. python入门-使用API

    python入门-使用API import requests #执行API调用并存储响应 url = 'https://api.github.com/search/repositories?q=lan ...

  5. 《算法》第三章部分程序 part 5

    ▶ 书中第三章部分程序,加上自己补充的代码,包含公共符号表.集合类型 ● 公共符号表,用于普通查找表的基本类 package package01; import java.util.NoSuchEle ...

  6. 列表、字典、append

    list[] 定义列表可以是空的也可以直接定义列表中的元素,例如:list = ["hello", "world", "dlrb"] dic ...

  7. python中len 小练习:获取并输出集合中的索引及对应元素

    len()用来获取长度.字节等数值 1 a = ["hello", "world", "dlrb"] 2 b = len(a) 3 for ...

  8. python中的jion

    on将列表或元组中的每个元素连接起来,举个例子: 1 a = ["hello", "world", "dlrb"] 2 a1 = " ...

  9. 增删改查列表angular.js页面实现

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  10. leetcode149

    /* * A line is determined by two factors,say y=ax+b * * If two points(x1,y1) (x2,y2) are on the same ...