[英]TensorFlow why we still use tf.name_scope when we already have the function tf.variable_scope
I do not understand why we also need the function tf.name_scope
when we already have tf.variable_scope
. 我不明白,为什么我们还需要功能
tf.name_scope
时,我们已经有了tf.variable_scope
。 From the Tensorflow official API, I see that the tf.variable_scope
is more powerful because it can have an effect on tf.get_variable
. 从Tensorflow官方API中,我看到
tf.variable_scope
更强大,因为它可以对tf.get_variable
产生影响。 When we create layers and want to share variables, we always use tf.variable_scope
and tf.name_scope
. 当我们创建图层并希望共享变量时,我们总是使用
tf.variable_scope
和tf.name_scope
。 However, I try to learn something new from code released by Nvidia on GitHub. 但是,我尝试从Nvidia在GitHub上发布的代码中学到一些新知识。 I found that it is frequent for coders to use
tf.name_scope
. 我发现编码人员经常使用
tf.name_scope
。 Why do we still need this function? 为什么我们仍然需要此功能?
You can use tf.variable_scope
to add a prefix on both variables created with tf.get_variable
and operations: as you said, this allows also variable sharing but it also makes the first call to tf.get_variable
the definition of new variable under this scope. 您可以使用
tf.variable_scope
到与创建两个变量添加前缀tf.get_variable
和操作:如你所说,这也让变量共享,但它也使第一次调用tf.get_variable
在此范围内的新变量的定义。
tf.name_scope
adds a prefix only at the operations: variables defined outside the tf.name_scope
using tf.get_variable
are not prefixed thus the tf.name_scope
is ignored completely for this variable: you're not declarning a variable prefixed in any way. tf.name_scope
仅在操作处添加前缀:使用tf.get_variable
在tf.name_scope
外部定义的变量没有前缀,因此该变量的tf.name_scope
被完全忽略:您不会以任何方式声明前缀。
This can be useful when you want to create an operation block (using tf.name_scope
) that uses a variable declared outside of it. 当您要创建使用在其外部声明的变量的操作块(使用
tf.name_scope
)时,此功能很有用。 This variable can be even used by multiple operation blocks at the same time. 该变量甚至可以同时被多个操作块使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.