简体   繁体   English

TensorFlow为什么我们已经拥有函数tf.variable_scope时仍然使用tf.name_scope

[英]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_scopetf.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_variabletf.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.

相关问题 TensorFlow 2.0:如何使用tf.keras对图表进行分组? tf.name_scope / tf.variable_scope不再使用了? - TensorFlow 2.0: how to group graph using tf.keras? tf.name_scope/tf.variable_scope not used anymore? 如何将 tf.layers 变量放入 tf.name_scope/tf.variable_scope? - How to put tf.layers variables in tf.name_scope/tf.variable_scope? Tensorflow:tf.name_scope 没有“with” - Tensorflow: tf.name_scope without 'with' 了解 tf.name_scope - Understanding tf.name_scope Tensorflow 中的 tf.variable_scope 和 variable_scope.variable_scope 有什么区别? - What is difference between tf.variable_scope and variable_scope.variable_scope in Tensorflow? 为什么tf.variable_scope具有default_name参数? - Why does tf.variable_scope has a default_name argument? 张量流的tf.name_scope()中的deafult_name参数是什么? - What is deafult_name argument in tensorflow's tf.name_scope()? 我可以不带“ with”语句调用tf.variable_scope吗? - Can I call tf.variable_scope without a “with” statement? tf.variable_scope()和tf.train.Saver()有什么区别? - What is the difference between tf.variable_scope() and tf.train.Saver()? 如果我们无需初始化就可以直接使用变量,为什么还要在tensorflow中使用tf.Variable? - Why we use tf.Variable in tensorflow if we can directly use a variable without initialisation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM