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)?
它与底层 API 中张量的表示有关。张量是与某些操作的输出相关的值。如果有变量,有一个Variable
具有一个输出的运算。一个操作可以有多个输出,因此这些张量被引用为<op>:0
, <op>:1
等等。例如,如果您使用tf.nn.top_k
,这个操作创建了两个值,所以你可能会看到TopKV2:0
and TopKV2:1
a,b=tf.nn.top_k([1], 1)
print a.name # => 'TopKV2:0'
print b.name # => 'TopKV2:1'
如何理解TensorFlow中的“张量”一词? https://stackoverflow.com/questions/37849322/how-to-understand-the-term-tensor-in-tensorflow/37870634#37870634
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)