TensorFlow 如何命名张量?

编程入门 行业动态 更新时间:2024-10-15 16:18:55
本文介绍了TensorFlow 如何命名张量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

不知道这样理解是否正确:

I wonder if this is the correct understanding:

所有张量都源自某个操作,并且操作要么在构造函数中给出一个名称,要么为特定类型的操作给出默认名称.如果名称不唯一,TensorFlow 会通过附加 "_1""_2" 等来自动处理此问题.具有 n 个张量输出的操作将这些张量命名为 "op_name:0", "op_name:1", ..., "op_name:n-1".

All tensors are derived from some operation, and operations are either given a name in the constructor, or given the default name for a particular kind of operation. If the name is not unique, TensorFlow automatically handles this by appending "_1", "_2", etc. An operation with n tensor outputs name these tensors "op_name:0", "op_name:1", ..., "op_name:n-1".

似乎出现了一个问题:如果 xtf.Variable,那么 x.name 给出 "variable_name:0".这令人困惑:"variable_name" 指的是什么?

One problem seems to arise: if x is a tf.Variable, then x.name gives "variable_name:0". This is confusing: to what does "variable_name" refer?

推荐答案

您对 Tensor 命名的观察是完全正确的:Tensor 的名称是 Tensor 的串联/p>

Your observations on Tensor naming are absolutely correct: the name of a Tensor is the concatenation of

产生它的操作的名称,一个冒号 (:) 和 该张量在产生它的操作的输出中的索引.

因此名为 "foo:2" 的张量是名为 "foo" 的操作在位置 2(索引从零开始)的输出.

Therefore the tensor named "foo:2" is the output of the op named "foo" at position 2 (with indices starting from zero).

命名a href="https://www.tensorflow/versions/r0.7/api_docs/python/state_ops.html#Variable" rel="noreferrer">tf.Variable物体略显奇怪.每个 tf.Variable 都包含一个 可变张量 对象,用于保存变量(以及其他一些张量)的状态."Variable" 操作(在您的示例中名称为 "variable_name")每次作为第 0 个输出运行时都会产生"这个可变张量,因此名称可变张量是 "variable_name:0".

The naming of tf.Variable objects is slightly strange. Every tf.Variable contains a mutable tensor object that holds the state of the variable (and a few other tensors). A "Variable" op (which has the name "variable_name" in your example) "produces" this mutable tensor each time it is run as its 0th output, so the name of the mutable tensor is "variable_name:0".

因为 tf.Variabletf.Tensor 几乎没有区别—因为它可以用在相同的地方—我们决定制作变量名称类似于张量名称,因此 Variable.name 属性返回可变张量的名称.(这与 tf.QueueBasetf.ReaderBase 对象,它们不能直接用作张量(相反,您必须对它们调用方法以创建对其状态进行操作的操作),因此这些对象没有张量-就像名字一样.)

Since a tf.Variable is mostly indistinguishable from a tf.Tensor—in that it can be used in the same places—we took the decision to make variable names resemble tensor names, so the Variable.name property returns the name of the mutable tensor. (This contrasts with tf.QueueBase and tf.ReaderBase objects, which are not usable directly as tensors (instead you have to call methods on them to create ops that operate on their state), so these do not have a tensor-like name.)

这篇关于TensorFlow 如何命名张量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 05:34:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405478.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:张量   TensorFlow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!