Transforming the DCGAN into a WGAN

In this example, we will implement a DCGAN based on the Wasserstein distance, using the Fashion MNIST dataset (as provided directly by Keras). This set is made up of 60,000 28 × 28 grayscale images of clothes, and it was introduced by Zalando as a replacement for the standard MNIST dataset, whose classes are too easy to separate with many classifiers. Considering the training time required by this kind of network, we have decided to limit the process to 5,000 samples, but a reader with enough resources can choose to increase or remove this constraint.

The first step consists of loading, slicing, and normalizing the dataset (in the range (-1, 1)), as follows:

import numpy as npfrom keras.datasets import fashion_mnist ...

Get Hands-On Unsupervised Learning with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.