python - 在TensorFlow中,变量名称中的 ":0"是什么意思?

标签 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"

上面的代码返回true。我这里用with tf.device来说明“:0”并不代表变量位于特定的设备上。那么“”是什么意思:0"在变量名中(本例中为 foo 和 bar)?

最佳答案

这与底层 API 中张量的表示有关。张量是与某个操作的输出相关联的值。如果是变量,则有 Variable具有一个输出的操作。一个运算可以有多个输出,因此这些张量被引用为 <op>:0 , <op>:1等等。例如,如果您使用 tf.nn.top_k ,这个操作创建了两个值,所以你可能会看到 TopKV2:0TopKV2: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?

关于python - 在TensorFlow中,变量名称中的 ":0"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40925652/

相关文章:

python - 用 Python 抓取网站的第二页不起作用

python - 为什么 00100 = 64 在 python 中?

python - Tensorflow 教程 : Duplicated Shuffling in the Input Pipeline

python - 在 TensorFlow 中多次初始化变量会导致内存泄漏

python - 使用 SciPy 二维插值器时出错

python - TensorFlow 错误 : ValueError ("Shapes %s and %s are incompatible" % (self, 其他))

python - 在 Python 中将货币解析为数字

python - 如何将检查点转换为.pb模型以进行模型部署?

python - 关于 tensorflow 最大池化函数的困惑

c++ - 为 tensorflow c++ api session 选择特定的 gpu