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 ...
随机推荐
- 动手动脑-java重载
有以下例子: 例: Using overloaded methods public class MethodOverload { public static void main(String[] ar ...
- redis如何随系统启动
Redis可以通过命令redis-server启动,但这种启动方式适用于开发环境,对于生产环境来说,配置好redis的配置文件,并使redis随linux启动则更加方便些,下面则记录下redis如何随 ...
- Java7 新特性: try-with-resources
Try-with-resources是java7中一个新的异常处理机制,它能够很容易地关闭在try-catch语句块中使用的资源. 利用Try-Catch-Finally管理资源(旧的代码风格)在ja ...
- 【eclipse jar包】在编写java代码时,为方便编程,常常会引用别人已经实现的方法,通常会封装成jar包,我们在编写时,只需引入到Eclipse中即可。
Eclipse中导入外部jar包 在编写java代码时,为方便编程,常常会引用别人已经实现的方法,通常会封装成jar包,我们在编写时,只需引入到Eclipse中即可. 工具/原料 Eclipse 需要 ...
- python-路径处理path
#-*- coding:utf-8 -*- # file: class_01_path.py #本次学习:OS模块--处理路径 #F:\pythonzhm\study_181112 import os ...
- uva10603-倒水问题-暴力枚举-隐式图搜索
题意: 给你三个杯子,a,b,c,没有刻度,刚开始c杯是满的,倒水的要求,要么倒出水的杯子倒空,要么倒入杯子倒满. 结果: 要求某个杯子内有d水量,并且倒出的水量最少,如果倒不出d水量,那么倒出d1( ...
- 好久没玩docker了,温下手
好久没玩docker了,温下手 安装 Docker Docker 软件包已经包括在默认的 CentOS-Extras 软件源里.因此想要安装 docker,只需要运行下面的 yum 命令: yum i ...
- 1.js简介
1.JavaScript 诞生于1995年,起初主要用于处理网页中的前端验证. 2.前端验证:指检查用户输入的内容是否符合一定规则. 3.JavaScript 由网景公司发明. 4.JS 的标准命名为 ...
- python中的type
我们常用type()来查看类型,使用方法如下: 1 a = "zzzq" 2 b = 1 3 c = (1, "zzq123") 4 d = [2, " ...
- Flex学习笔记--多层菜单按钮
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...