I know how to select which of the tf.Variables I create are subject to training: I call the optimizer with var_list=[]. My problem arises when I don't actually create the variables myself, and thus can't pass them explicitly to the optimizwer. Variables to be optimized are being created for me with the convenience function for a convolution: it will create Weight and Bias Variables and then add these to the trainable_variables() list.
x = tf.layers.conv2d(X, filters=64, kernel_size=4, strides=2, padding='same', activation=activation)
However I'm programming a GAN, so I need to alternate between training two sets of variables, one for the generator and one set for the discriminator. Thus I don't want to just train on the entire set of variables in tf.trainable_variables().
I'd like to use the convenience function to set up the model but then get handles to the variables in the model so I can choose which get passed to the optimizer.
Here's an example of the code for the generator. the dicriminator is analgous.
with tf.variable_scope("encoder", reuse=None):
X = tf.reshape(X_in, shape=[-1, 28, 28, 1])
x = tf.layers.conv2d(X, filters=64, kernel_size=4, strides=2, padding='same', activation=activation)
x = tf.nn.dropout(x, keep_prob)
x = tf.layers.conv2d(x, filters=64, kernel_size=4, strides=2, padding='same', activation=activation)
x = tf.nn.dropout(x, keep_prob)
x = tf.layers.conv2d(x, filters=64, kernel_size=4, strides=1, padding='same', activation=activation)
x = tf.nn.dropout(x, keep_prob)
x = tf.contrib.layers.flatten(x)