Defining the discriminator

We learned that both the discriminator and Q network take the generator image and return the output so they both share some layers. Since they both share some layers, we attach the Q network to the discriminator, as we learned in the architecture of InfoGAN. Instead of using fully connected layers in the discriminator, we use a convolutional network, as we learned in the discriminator of DCGAN:

def discriminator(x,reuse=None):

Define the first layer, which performs the convolution operation followed by a leaky ReLU activation:

    conv1 = tf.layers.conv2d(x, 
filters=64,
kernel_size=4,
strides=2,
padding='same',
kernel_initializer=tf.contrib.layers.xavier_initializer(),
activation=None)
lrelu1 = lrelu(conv1, 0.2)

We also perform convolution operation in the second layer, which is followed by batch normalization and a leaky ReLU activation:

    conv2 = tf.layers.conv2d(lrelu1, 
filters=128,
kernel_size=4,
strides=2,
padding='same',
kernel_initializer=tf.contrib.layers.xavier_initializer(),
activation=None)
batch_norm2 = tf.layers.batch_normalization(conv2, training=is_train)
lrelu2 = lrelu(batch_norm2, 0.2)

Flatten the result of the second layer:

   lrelu2_flat = tf.reshape(lrelu2, [batch_size, -1])

Feed the flattened result to a fully connected layer which is the third layer and it is followed by batch normalization and leaky ReLU activation:

    full_connected = tf.layers.dense(lrelu2_flat, 
units=1024,
activation=None)
batch_norm_3 = tf.layers.batch_normalization(full_connected, training=is_train)
lrelu3 = lrelu(batch_norm_3, 0.2)

Compute the discriminator output:

    d_logits = tf.layers.dense(lrelu3, units=1, activation=None)

As we learned that we attach the Q network to the discriminator. Define the first layer of the Q network that takes the final layer of the discriminator as inputs:

    full_connected_2 = tf.layers.dense(lrelu3, 
units=128,
activation=None)

batch_norm_4 = tf.layers.batch_normalization(full_connected_2, training=is_train)
lrelu4 = lrelu(batch_norm_4, 0.2)

Define the second layer of the Q network:

    q_net_latent = tf.layers.dense(lrelu4, 
units=74,
activation=None)

Estimate c:

    q_latents_categoricals_raw = q_net_latent[:,0:10]

c_estimates = tf.nn.softmax(q_latents_categoricals_raw, dim=1)

Return the discriminator logits and the estimated c value as output:

    return d_logits, c_estimates
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset