简体   繁体   English

为什么tf.variable_scope具有default_name参数?

[英]Why does tf.variable_scope has a default_name argument?

The first two arguments of tf.variable_scope 's __init__ method are tf.variable_scope__init__方法的前两个参数是

  • name_or_scope : string or VariableScope : the scope to open. name_or_scopestringVariableScope :要打开的范围。
  • default_name : The default name to use if the name_or_scope argument is None , this name will be uniquified. default_name :如果name_or_scope参数为None ,则使用的默认名称,该名称将是唯一的。 If name_or_scope is provided it won't be used and therefore it is not required and can be None . 如果提供了name_or_scope ,则将不使用它,因此它不是必需的,并且可以为None

If I understand correctly, this argument is equivalent to (and therefore could be easily replaced with) 如果我理解正确,则此参数等效于(因此可以很容易地替换为)

if name_or_scope is None:
  name_or_scope = default_name
with tf.variable_scope(name_or_scope, ...):
  ...

Now, I am not sure I understand why it was deemed necessary to have this special treatment for the scope name — after all, many parameters could use a parameterizable default argument. 现在,我不确定我是否理解为什么必须对作用域名称进行这种特殊处理-毕竟,许多参数可以使用可参数化的默认参数。

So what is the rationale behind the introduction of this argument? 那么,引入该论点的背后原理是什么?

You are right. 你是对的。 It is just a convenience. 这只是一个方便。

Take the case of TensorFlow models defined here . 这里定义的TensorFlow模型为例。 If you take a specific look at InceptionV4.py , you will see that it has a scope argument in its definition. 如果您专门查看InceptionV4.py ,您会看到它的定义中有一个范围参数。 Just below you will see that InceptionV4 has been passed as a default scope. 在下面,您将看到InceptionV4已作为默认范围传递。 Therefore it was entirely not required to even has a scope argument in the definition. 因此,完全不需要在定义中甚至包含scope参数。 But it makes sense, if somebody gives scope=None . 但是,如果有人给出scope=None ,这是有道理的。

Think about it. 想一想。 Model definitions can get very comples very quickly. 模型定义可以很快变得非常复杂。 Therefore, a default_scope argument, helps in reinforcing the wisdom of the model definition writer to introduce some sort of deliberate structure in the model definition, even if the end user is very naive about it. 因此,default_scope参数有助于增强模型定义编写者的智慧,即使最终用户对此非常幼稚,也可以在模型定义中引入某种有意的结构。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TensorFlow为什么我们已经拥有函数tf.variable_scope时仍然使用tf.name_scope - TensorFlow why we still use tf.name_scope when we already have the function tf.variable_scope 如何将 tf.layers 变量放入 tf.name_scope/tf.variable_scope? - How to put tf.layers variables in tf.name_scope/tf.variable_scope? 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? 我可以不带“ with”语句调用tf.variable_scope吗? - Can I call tf.variable_scope without a “with” statement? 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()和tf.train.Saver()有什么区别? - What is the difference between tf.variable_scope() and tf.train.Saver()? 哪个初始值设定项受tf.variable_scope影响(“Model”,reuse = None,initializer = initializer)? - Which initializers are affected by tf.variable_scope(“Model”, reuse=None, initializer=initializer)? 为什么tf.get_variable('test')返回名称为test_1的变量? - Why does tf.get_variable('test') returns a variable with name test_1? 使用默认范围名称时,不会重用variable_scope - variable_scope does not get reused when using default scope name 使用 tf.compat.v1.variable_scope 会产生错误 - Tensorflow has no attribute variable_scope - Using tf.compat.v1.variable_scope produces an error - Tensorflow has no attribute variable_scope
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM