Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to re-enter previous name/variable-scoped context #1797

Closed
meereeum opened this issue Apr 6, 2016 · 7 comments
Closed

No way to re-enter previous name/variable-scoped context #1797

meereeum opened this issue Apr 6, 2016 · 7 comments
Assignees

Comments

@meereeum
Copy link

meereeum commented Apr 6, 2016

As far as I can tell, there is no way to re-enter the same name_scope or variable_scope (once closed) without the name being "unique-ified."

The example in the docs shows how to re-enter the original scope from within a nested scope - but not when context is closed.

Perhaps this could be solved by enabling access to the scope reference as tf.Variable.scope ?

Current hack-y workaround is to manually specify variable name as "{}/name".format(previous_scope_name)

@gaohuazuo
Copy link
Contributor

It is actually possible to re-enter a closed variable scope, as in the example below.

with tf.variable_scope('test') as vscope: pass
with tf.variable_scope(vs) as vscope_:
     assert vscope.name == vscope_.name

However, the re-entered variable scope does not copy the reuse status of the original one.

@meereeum
Copy link
Author

@gaohuazuo hmmm that assert statement returns True (as long as you are consistent about vscope vs vs); however...

with tf.variable_scope('foo') as vs:
    x = tf.Variable([1])
with tf.variable_scope(vs) as vs_:
    assert vs.name == vs_.name
    y = tf.Variable([1])
x.name
>>> u'foo/Variable:0'
y.name
>>> u'foo_1/Variable:0'

with corresponding non-overlapping name-scopes in tensorboard. This is not changed by passing reuse = True.

@meereeum
Copy link
Author

Anyway, if possible I think it would be useful to be able to access name-scope of a given variable....without writing a (simple but) hacky regex. The current approach I am using to build layers in a more functional manner does not lend itself to the workflow described above.

@girving
Copy link
Contributor

girving commented Jun 7, 2016

@ebrevdo: @meereeum's example with y.name == 'foo_1/Variable:0' looks like a bug. Could you take a look?

@ebrevdo
Copy link
Contributor

ebrevdo commented Jun 8, 2016

I'll assign to lukasz, he may have code fixing this.

@ebrevdo ebrevdo assigned lukaszkaiser and unassigned ebrevdo Jun 8, 2016
@lukaszkaiser
Copy link
Contributor

I'm working on a CL/PR that at least adds the name scope to variable scope. Will report back here once that's in.

benoitsteiner pushed a commit to benoitsteiner/tensorflow that referenced this issue Jun 15, 2016
…see tensorflow#1797, tensorflow#213.)

In particular, this decouples the uniquification of variable scope names
from the surrounding name scope. This is potentially a breaking change for
models that rely on those names, but name_scope was never meant or designed
to flow into variable scope names, so this bug must be corrected at some point.
Change: 124986168
@lukaszkaiser
Copy link
Contributor

A recent CL correcting this is now live on master. It includes a unit test that re-enters a variable scope and the original name scope this variable scope was created in (by using the new .original_name_scope property). See here: variable_scope_test. Closing this now, please re-open or make a new issue if you find more problems!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants