问题描述
限时送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"
.
似乎出现了一个问题:如果 x
是 tf.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.Variable
与 tf.Tensor
几乎没有区别—因为它可以用在相同的地方—我们决定制作变量名称类似于张量名称,因此 Variable.name
属性返回可变张量的名称.(这与 tf.QueueBase
和 tf.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:关键词]
发布评论