I create relative name scopes with tf.name_scope
.
How can I get the current absolute name scope?
From the code, it looks like tf.get_default_graph()._name_stack
would give me that but that looks like a non-official way. Is there any official way? (I think not, thus I made an upstream feature request.)
(I implemented a bunch of functions like get_current_name_scope()
or reuse_name_scope()
here. Note that you need to be careful when mixing tf.name_scope
and tf.variable_scope
.)
Example:
import tensorflow as tf
with tf.name_scope("foo"):
with tf.name_scope("bar") as absolute:
print(absolute)
Output:
foo/bar/
EDIT:
Without access to the enclosing context manager I don't know of a specific function to access the current name scope. With a small detour it's possible as follows:
import tensorflow as tf
with tf.name_scope("foo"):
with tf.name_scope("bar") as absolute:
print(tf.no_op(name='.').name[:-1])
Relevant Doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With