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.

Cross-Domain GANs

We introduce module mnist_svhn_utils.py to help us with this task. Listing 7.1.7

shows the initialization and training of the CycleGAN for cross-domain transfer.

The CycleGAN structure is same as in the previous section except that we use

a kernel size of 5 since the two domains are drastically different:

Figure 7.1.11: Two different domains with data that are not aligned. Original color photo can be

found on the book GitHub repository, https://github.com/PacktPublishing/Advanced-Deep-Learningwith-Keras/blob/master/chapter7-cross-domain-gan/README.md.

Remember to install keras-contrib before using instance

normalization:

$ sudo pip3 install git+https://www.github.com/kerasteam/keras-contrib.git

Listing 7.1.7, cyclegan-7.1.1.py shows us the CycleGAN for cross-domain style

transfer between MNIST and SVHN:

def mnist_cross_svhn(g_models=None):

"""Build and train a CycleGAN that can do mnist <--> svhn

"""

model_name = 'cyclegan_mnist_svhn'

batch_size = 32

train_steps = 100000

patchgan = True

kernel_size = 5

postfix = ('%dp' % kernel_size) if patchgan else ('%d' % kernel_

size)

data, shapes = mnist_svhn_utils.load_data()

source_data, _, test_source_data, test_target_data = data

[ 228 ]

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

Saved successfully!

Ooh no, something went wrong!