Reputation: 1463
In TensorFlow, the VariableScope
class has both a original_name_scope
and name
attribute. What are their differences and when should I use one over the other? I can't seem to find much documentation on them.
Use case:
I'm using the tf.get_collection(key, scope)
method. Its second argument expects a string, but my variable my_scope
has type VariableScope
. I'm trying both
tf.get_collection(key, my_scope.name)
and
tf.get_collection(key, my_scope.original_scope_name)
. Both seem to work, but I'm not sure which is "right" and won't give me problems later down the road.
Upvotes: 0
Views: 838
Reputation: 1463
foo.name
returns the name (String) of the scope. On the other hand, foo.original_name_scope
returns the same string as foo.name
, except when the scope is recreated. In that case, all sub-scopes are appended with a _#
as needed to make all calls to foo.original_name_scope
return something unique for each instance of a scope.
For example, in this code:
with tf.variable_scope('a') as a:
print(a.name)
print(a.original_name_scope)
print(a.original_name_scope)
with tf.variable_scope('a') as b:
print(b.name)
print(b.original_name_scope)
Returns
a
a/
a/
a
a_1/
Note that the calls to original_name_scope
corresponding to different scope instances a
return different values.
Presumably, this lets you distinguish between different scope instances with the same name.
Upvotes: 2