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

  • 相关阅读:
    基于WebBrowser 的爬虫程序
    面向对象基础 理解
    ubuntu系统lamp环境搭建、数据库迁移、设置数据库外部访问
    js控制 固定框架内图片 按比例显示 以及 占满框架 居中显示
    图片垂直居中 和 float
    px和em区别-在font-size的 css 的使用
    ps6 安装失败-FATAL: Payload '{3F023875-4A52-4605-9DB6-A88D4A813E8D} Camera Profiles Installer 6.0.98.0' information not found in Media_db.
    sublime test 3 使用及常用插件
    常使用的插件和网站
    php递归函数--遍历
  • 原文地址:https://www.cnblogs.com/YouXiangLiThon/p/7737377.html
Copyright © 2011-2022 走看看