Does the entire scope path need to match for variable reuse in TensorFlow?
<p>Is the variable <code>Test</code> shared in these two scenarios?</p>

<pre class="lang-py prettyprint-override"><code>with tf.name_scope("ns1"):
  with tf.variable_scope("vs1"):
    var = tf.get_variable("Test", [1,2,3])

with tf.name_scope("ns2"):
  with tf.variable_scope("vs1", reuse=True):
    var = tf.get_variable("Test", [1,2,3])
</code></pre>

<p>and </p>

<pre class="lang-py prettyprint-override"><code>with tf.name_scope("ns1"):
  with tf.variable_scope("vs1"):
    var = tf.get_variable("Test", [1,2,3])

with tf.variable_scope("vs1", reuse=True):
  var = tf.get_variable("Test", [1,2,3])
</code></pre>

<p>Yes, the variable is shared. In general, name_scope does <em>not</em> influence variable names, only variable_scope does (but yes, the whole prefix of variable_scopes must match). I think that it is reasonable to try and not use name_scope at all, it can be confusing when mixed with variable_scope. Also note that you set reuse=True -- if the variable were not shared, you'd get an error. That's why it's there, so you can be sure it's shared.</p>

python tensorflow