Example of DCGAN with TensorFlow

In this example, we want to build a DCGAN (proposed in Unsupervised Representation Learning with Deep Convolutional Generative Adversarial NetworksRadford A., Metz L., Chintala S., , arXiv:1511.06434 [cs.LG]) with the Fashion-MNIST dataset (obtained through the keras helper function). As the training speed is not very high, we limit the number of samples to 5,000, but I suggest repeating the experiment with larger values. The first step is loading and normalizing (between -1 and 1) the dataset:

import numpy as npfrom keras.datasets import fashion_mnistnb_samples = 5000(X_train, _), (_, _) = fashion_mnist.load_data()X_train = X_train.astype(np.float32)[0:nb_samples] / 255.0X_train = (2.0 * X_train) - 1.0 ...

Get Mastering Machine Learning Algorithms now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.