16.03.2021 Views

Advanced Deep Learning with Keras

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7

kernel_size=kernel_size)

e3 = encoder_layer(e2,

128,

activation='leaky_relu',

kernel_size=kernel_size)

e4 = encoder_layer(e3,

256,

activation='leaky_relu',

kernel_size=kernel_size)

d1 = decoder_layer(e4,

e3,

128,

kernel_size=kernel_size)

d2 = decoder_layer(d1,

e2,

64,

kernel_size=kernel_size)

d3 = decoder_layer(d2,

e1,

32,

kernel_size=kernel_size)

outputs = Conv2DTranspose(channels,

kernel_size=kernel_size,

strides=1,

activation='sigmoid',

padding='same')(d3)

generator = Model(inputs, outputs, name=name)

return generator

The discriminator of CycleGAN is similar to vanilla GAN discriminator. The input

image is downsampled several times (in this example, three times). The final layer

is a Dense(1) layer which predicts the probability that the input is real. Each layer

is similar to the encoder layer of the generator except that no IN is used. However,

in large images, computing the image as real or fake with a single number turns

out to be parameter inefficient and results in poor image quality for the generator.

The solution is to use PatchGAN [6] which divides the image into a grid of patches

and use a grid of scalar values to predict the probability that the patches are real.

The comparison between the vanilla GAN discriminator and a 2 × 2 PatchGAN

discriminator is shown in Figure 7.1.7. In this example, the patches do not overlap

and meet at their boundaries. However, in general, patches may overlap.

[ 215 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!