Discriminator

 

Next up, we need to implement the discriminator part of the network, which will be used to judge whether the incoming input is coming from the real dataset or generated by the generator. Again, we'll use the TensorFlow feature of tf.variable_scope to prefix some variables with discriminator so that we can retrieve and reuse them.

So, let's define the function which will return the binary output of the discriminator as well as the logit values:

# Defining the discriminator function
def discriminator(input_imgs, reuse=False):
# using variable_scope to reuse variables
with tf.variable_scope('discriminator', reuse=reuse):
# leaky relu parameter
leaky_param_alpha = 0.2

# defining the layers
conv_layer_1 = tf.layers.conv2d(input_imgs, 64, 5, 2, 'same')
leaky_relu_output = tf.maximum(leaky_param_alpha * conv_layer_1, conv_layer_1)

conv_layer_2 = tf.layers.conv2d(leaky_relu_output, 128, 5, 2, 'same')
normalized_output = tf.layers.batch_normalization(conv_layer_2, training=True)
leay_relu_output = tf.maximum(leaky_param_alpha * normalized_output, normalized_output)

conv_layer_3 = tf.layers.conv2d(leay_relu_output, 256, 5, 2, 'same')
normalized_output = tf.layers.batch_normalization(conv_layer_3, training=True)
leaky_relu_output = tf.maximum(leaky_param_alpha * normalized_output, normalized_output)

# reshaping the output for the logits to be 2D tensor
flattened_output = tf.reshape(leaky_relu_output, (-1, 4 * 4 * 256))
logits_layer = tf.layers.dense(flattened_output, 1)
output = tf.sigmoid(logits_layer)

return output, logits_layer
..................Content has been hidden....................

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