Enc*_*eTS 20 python tensorflow
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"
Run Code Online (Sandbox Code Playgroud)
上面的代码返回true.我with tf.device在这里用来说明":0"并不意味着变量位于特定的设备上.那么变量名称中":0"的含义是什么(本例中为foo和bar) )?
Yar*_*tov 23
它与底层API中的张量表示有关.张量是与某些操作的输出相关联的值.在变量的情况下,有Variable一个输出的操作.运算可以有一个以上的输出,所以这些张量获得参考的<op>:0,<op>:1等等.举例来说,如果你使用tf.nn.top_k,还有由此op创建两个值,所以你可能会看到TopKV2:0和TopKV2:1
a,b=tf.nn.top_k([1], 1)
print a.name # => 'TopKV2:0'
print b.name # => 'TopKV2:1'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4620 次 |
| 最近记录: |