在 TensorFlow 中,“:0"是什么意思?以变​​量的名称? [英] In TensorFlow,what's the meaning of ":0" in a Variable's name?

查看:191
本文介绍了在 TensorFlow 中,“:0"是什么意思?以变​​量的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)?

The above code returns true.I use with tf.device here to illustrate that the ":0" doesn't mean the variable lie on the specific device.So what's the meaning of the ":0" in the variable's name(foo and bar in this example)?

推荐答案

它与底层 API 中张量的表示有关.张量是与某些操作的输出相关联的值.对于变量,有一个带有一个输出的 Variable 操作.一个操作可以有多个输出,所以这些张量被引用为 :0:1 等.例如,如果你使用tf.nn.top_k,这个op创建了两个值,所以你可能会看到TopKV2:0TopKV2:1

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

如何理解术语张量"TensorFlow?

这篇关于在 TensorFlow 中,“:0"是什么意思?以变​​量的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆