Example of a deep convolutional GAN

We can now implement a DCGAN, based on the model proposed in Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks, Radford A., Metz L., and Chintala S., arXiv:1511.06434 [cs.LG], and the Olivetti faces dataset, which is small enough to allow for a quick training phase.

Let's start by loading the dataset and normalizing the values in the range (-1, 1), as follows:

from sklearn.datasets import fetch_olivetti_facesfaces = fetch_olivetti_faces(shuffle=True, random_state=1000)X_train = faces['images']X_train = (2.0 * X_train) - 1.0width = X_train.shape[1]height = X_train.shape[2]

A few sample faces are shown in the following screenshot:

Sample faces drawn from the Olivetti ...

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.