[英]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
orVariableScope
: the scope to open.name_or_scope
:string
或VariableScope
:要打开的范围。default_name
: The default name to use if thename_or_scope
argument isNone
, this name will be uniquified.default_name
:如果name_or_scope
参数为None
,则使用的默认名称,该名称将是唯一的。 Ifname_or_scope
is provided it won't be used and therefore it is not required and can beNone
.如果提供了
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.