I have created a variable scope in one part of my graph, and later in another part of the graph I want to add OPs to an existing scope. That equates to this distilled exampl
Answer mentioned by kmario23 is correct but there is a tricky case with variables created by tf.get_variable
:
with tf.variable_scope('myscope'):
print(tf.get_variable('var1', shape=[3]))
with tf.variable_scope('myscope/'):
print(tf.get_variable('var2', shape=[3]))
This snippet will output:
It seems that tensorflow
has not provided a formal way to handle this circumstance yet. The only possible method I found is to manually assign the correct name (Warning: The correctness is not guaranteed):
with tf.variable_scope('myscope'):
print(tf.get_variable('var1', shape=[3]))
with tf.variable_scope('myscope/') as scope:
scope._name = 'myscope'
print(tf.get_variable('var2', shape=[3]))
And then we can get the correct names: