8
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”不是指变量lie在特定设备上。那么变量名称中的“:0”是什么意思foo和bar在这个例子中)?在TensorFlow中,变量名称中“:0”的含义是什么?
assert是否返回true?你读过'tensorflow.Variable'类的文档吗? –
@ cricket_007是的,它返回true,并且在[tensorflow doc](https://www.tensorflow.org/versions/master/how_tos/variable_scope/index.html)中,可以找到一些类似的代码,但是doc永远不要解释“:0”的含义。 – EncodeTS
Gotcha。我只是在阅读源代码。虽然不能轻易发现它。 –