在 TensorFlow 中,“:0"是什么意思?以变量的名称? [英] In TensorFlow,what's the meaning of ":0" in a Variable's name?
问题描述
import tensorflow as tf
with tf.device('/gpu:0'):
foo = tf.Variable(1, name='foo')
assert foo.name == "foo:0"
with tf.device('/gpu:1'):
bar = tf.Variable(1, name='bar')
assert bar.name == "bar:0"
上面的代码返回true.我在这里使用with tf.device
来说明:0"并不意味着变量位于特定设备上.那么的含义是什么?:0" 在变量名中(本例中为 foo 和 bar)?
The above code returns true.I use with tf.device
here to illustrate that the ":0" doesn't mean the variable lie on the specific device.So what's the meaning of the ":0" in the variable's name(foo and bar in this example)?
推荐答案
它与底层 API 中张量的表示有关.张量是与某些操作的输出相关联的值.对于变量,有一个带有一个输出的 Variable
操作.一个操作可以有多个输出,所以这些张量被引用为
、
等.例如,如果你使用tf.nn.top_k
,这个op创建了两个值,所以你可能会看到TopKV2:0
和TopKV2:1
It has to do with representation of tensors in underlying API. A tensor is a value associated with output of some op. In case of variables, there's a Variable
op with one output. An op can have more than one output, so those tensors get referenced to as <op>:0
, <op>:1
etc. For instance if you use tf.nn.top_k
, there are two values created by this op, so you may see TopKV2:0
and TopKV2:1
a,b=tf.nn.top_k([1], 1)
print a.name # => 'TopKV2:0'
print b.name # => 'TopKV2:1'
这篇关于在 TensorFlow 中,“:0"是什么意思?以变量的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!