<p>I have to supplement the answer from @chrert.</p>

<p>The challenge of the <a href="https://arxiv.org/pdf/1406.4773.pdf" rel="nofollow noreferrer">paper</a> is that it has two loss functions (<code>l1</code> and <code>l2</code>) and you have to update SOME variables with the gradients related with both functions.</p>

<p>Before using <code>opt.apply_gradients</code>, you have to find pairs <code>(grad1, var1)</code> computed by <code>l1</code> and pairs <code>(grad2, var2)</code> computed by <code>l2</code>, and combine them where <code>var1.name==var2.name</code>.</p>

<p>A simple solution I found is that the pairs computed by <code>opt.compute_gradients</code> are of the same order.</p>
Tensorflow get all gradient_and_variable pairs in scopes
<p>I am implementing a <a href="https://arxiv.org/pdf/1406.4773" rel="nofollow noreferrer">paper</a> and the requirement is abstracted as follows. I have a CNN which has multiple layers, each of which is scoped. As the paper needs two example, I have used <code>opt.compute_gradients(loss)</code> and <code>tf.get_variable_scope().reuse_variables()</code> to obtain <code>[grad_and_vars1, grad_and_vars2]</code> (where <code>grad_and_vars</code> means gradient and variable pairs and the 1 represents first example).</p>

<p>How could I get the gradient and variable pairs which the corresponding variables are among the required scopes?</p>

<p>Thank you in advance.</p>