In TensorFlow,what's the meaning of “:0” in a Variable's name?

后端 未结 1 391
余生分开走
余生分开走 2021-02-05 05:18
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.Vari         


        
1条回答
  •  粉色の甜心
    2021-02-05 05:38

    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 :0, :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'
    

    How to understand the term `tensor` in TensorFlow?

    0 讨论(0)
提交回复
热议问题