I am trying to implement Adversarial NN, which requires to \'freeze\' one or the other part of the graph during alternating training minibatches. I.e. there two sub-networks
I don't know if my approach has down sides, but I solved this issue for myself with this construct:
do_gradient =
no_gradient = 1 - do_gradient
wrapped_op = do_gradient * original + no_gradient * tf.stop_gradient(original)
So if do_gradient = 1, the values and gradients will flow through just fine, but if do_gradient = 0, then the values will only flow through the stop_gradient op, which will stop the gradients flowing back.
For my scenario, hooking do_gradient up to an index of a random_shuffle tensor let me randomly train different pieces of my network.