TensorFlow: how to name operations for tf.get_variable
<p>My question is related to this <a href="http://stackoverflow.com/questions/36612512/tensorflow-how-to-get-a-tensor-by-name">Tensorflow: How to get a tensor by name?</a></p>

<p>I can give names to operations. But actually they named differently.
For example:</p>

<pre><code>In [11]: with tf.variable_scope('test_scope') as scope:
    ...:     a = tf.get_variable('a',[1])
    ...:     b = tf.maximum(1,2, name='b')
    ...:     print a.name
    ...:     print b.name
    ...:     
    ...:     
    ...:     
test_scope/a:0
test_scope_1/b:0

In [12]: with tf.variable_scope('test_scope') as scope:
    ...:     scope.reuse_variables()
    ...:     a = tf.get_variable('a',[1])
    ...:     b = tf.maximum(1,2, name='b')
    ...:     print a.name
    ...:     print b.name
    ...:     
    ...:     
    ...:     
test_scope/a:0
test_scope_2/b:0
</code></pre>

<p><code>tf.get_variable</code> creates variable with exactly the same name as I ask. Operations add prefixes to scope. </p>

<p>I want to name my operation so that I can get it. In my case I want to get <code>b</code> with <code>tf.get_variable('b')</code> in my scope.</p>

<p>How can I do it? I can't do it with <code>tf.Variable</code> because of this issue <a href="https://github.com/tensorflow/tensorflow/issues/1325" rel="nofollow">https://github.com/tensorflow/tensorflow/issues/1325</a>
May be I need to set addition parameters to variable scope, or to operation, or somehow use <code>tf.get_variable</code> ?</p>

<p><code>tf.get_variable()</code> won't work to get an operation. Therefore, I would define a new variable storing <code>tf.maximum(1,2)</code> to retrieve it later:</p>

<pre><code>import tensorflow as tf

with tf.variable_scope('test_scope') as scope:
    a1 = tf.get_variable('a', [1])
    b1 = tf.get_variable('b', initializer=tf.maximum(1, 2))

with tf.variable_scope('test_scope') as scope:
    scope.reuse_variables()
    a2 = tf.get_variable('a', [1])
    b2 = tf.get_variable('b', dtype=tf.int32)

assert a1 == a2
assert b1 == b2
</code></pre>

<p>Note that you need to define <code>b</code> using <code>tf.get_variable()</code> in order to retrieve it later.</p>

python tensorflow