For example I have code like this:
def test():
v = tf.get_variable('test') # => foo/test
with tf.variable_scope('foo'):
test()
Now I want to make a variable outside of scope 'foo':
def test():
with tf.variable_scope('bar'):
v = tf.get_variable('test') # foo/bar/test
But it is placed as 'foo/bar/test'. What should I do in test() body to place it as 'bar/test' without 'foo' root?
You can clear the current variable scope by providing an instance of an existing scope. So in order to pull this off, just make a reference to the top-level variable scope and use it:
Output:
tf.get_variable()
ignores thename_scope
but notvariable_scope
. If you want to obtain 'bar/test', you can try the following:Refer to this answer for a complete explanation: https://stackoverflow.com/a/37534656/8107620
A workaround would be to set the scope name directly: