tf.identity 个人理解
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 个人理解的更多相关文章
- 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 ...
- 『TensorFlow』流程控制之tf.identity
一个详细介绍 下面程序要做的是,5次循环,每次循环给x加1,赋值给y,然后打印出来, x = tf.Variable(0.0) #返回一个op,表示给变量x加1的操作 x_plus_1 = tf.as ...
- tf.tile()函数理解
转载:https://blog.csdn.net/tsyccnh/article/details/82459859 tensorflow中的tile()函数是用来对张量(Tensor)进行扩展的,其特 ...
- tf.metrics.sparse_average_precision_at_k 和 tf.metrics.precision_at_k的自己理解
tensorflow最大的问题就是大家都讲算法,不讲解用法,API文档又全是英文的,看起来好吃力,理解又不到位.当然给数学博士看的话,就没问题的. 最近看了一系列非常不错的文章,做一下记录: http ...
- 『TensorFlow』通过代码理解gan网络_中
『cs231n』通过代码理解gan网络&tensorflow共享变量机制_上 上篇是一个尝试生成minist手写体数据的简单GAN网络,之前有介绍过,图片维度是28*28*1,生成器的上采样使 ...
- 跌倒了,再爬起来:ASP.NET 5 Identity
"跌倒了"指的是这一篇博文:爱与恨的抉择:ASP.NET 5+EntityFramework 7 如果想了解 ASP.NET Identity 的"历史"及&q ...
- ASP.NET 5 Identity
ASP.NET 5 Identity “跌倒了”指的是这一篇博文:爱与恨的抉择:ASP.NET 5+EntityFramework 7 如果想了解 ASP.NET Identity 的“历史”及“ ...
- [三]java8 函数式编程Stream 概念深入理解 Stream 运行原理 Stream设计思路
Stream的概念定义 官方文档是永远的圣经~ 表格内容来自https://docs.oracle.com/javase/8/docs/api/ Package java.util.s ...
- 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 ...
随机推荐
- Centos7使用pxe安装KVM虚拟机
Centos7使用pxe安装KVM虚拟机 一.安装服务所需的软件 [root@localhost ~]yum install nginx dhcp vsftpd syslinux -y [root@l ...
- SQL Server 导入超大脚本
另外使用window server 版操作系统,执行脚本文件比普通版操作系统大大提升大小限制. 在执行SQL脚本的时候要是出现了这些情况我咋办呢? 步入正轨 应用场景:服务器升级,比如原来是2003的 ...
- BZOJ 3473: 字符串 (广义后缀自动机)
/* 广义后缀自动机, 每次加入维护 该right集合的set, 然后可以更新所有的parent,最终能够出现在k个串中right集合也就是set大小大于等于k的部分 这样的话就给了我们要跳的节点加了 ...
- python-路径处理path
#-*- coding:utf-8 -*- # file: class_01_path.py #本次学习:OS模块--处理路径 #F:\pythonzhm\study_181112 import os ...
- day2----python的基本类型
本文档的大致内容:(python使用版本3.6.4) 1 数字--int 2 布尔--bool 3 字符串--str 4 元祖--() 5 列表---['a','b'] 6 字典--{} 运算符: ...
- [Unity动画]05.Entry & Exit & Any State
0.状态机如下: Any State->Dying:isDying为true Dying->Reviving:isDying为false Reviving->Exit:isDying ...
- [Android] android.util.Log
android.util.Log常用的方法有以下5个:Log.v() Log.d() Log.i() Log.w() 以及 Log.e() .根据首字母对应VERBOSE,DEBUG,INFO, W ...
- asp.net(C#)文件操作
//创建文件夹路径 string path = "\\Files\\"; //判断文件夹是否存在 if (!Directory.Exists(path)) { Direct ...
- leetcode1013
class Solution(object): def canThreePartsEqualSum(self, A: 'List[int]') -> bool: n = len(A) sums ...
- elasticsearch相关