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 6

Implementation of InfoGAN in Keras

To implement InfoGAN on MNIST dataset, there are some changes that need to be

made in the base code of ACGAN. As highlighted in following listing, the generator

concatenates both entangled (z noise code) and disentangled codes (one-hot label

and continuous codes) to serve as input. The builder functions for the generator

and discriminator are also implemented in gan.py in the lib folder.

The complete code is available on GitHub:

https://github.com/PacktPublishing/Advanced-Deep-

Learning-with-Keras

Listing 6.1.1, infogan-mnist-6.1.1.py shows us how the InfoGAN generator

concatenates both entangled and disentangled codes to serve as input:

def generator(inputs,

image_size,

activation='sigmoid',

labels=None,

codes=None):

"""Build a Generator Model

Stack of BN-ReLU-Conv2DTranpose to generate fake images.

Output activation is sigmoid instead of tanh in [1].

Sigmoid converges easily.

# Arguments

inputs (Layer): Input layer of the generator (the z-vector)

image_size (int): Target size of one side (assuming square

image)

activation (string): Name of output activation layer

labels (tensor): Input labels

codes (list): 2-dim disentangled codes for InfoGAN

# Returns

Model: Generator Model

"""

image_resize = image_size // 4

# network parameters

kernel_size = 5

layer_filters = [128, 64, 32, 1]

if labels is not None:

if codes is None:

[ 167 ]

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

Saved successfully!

Ooh no, something went wrong!