Generating new MNIST images with GANs and Keras

In this section, we'll demonstrate how to use GANs to generate new MNIST images with Keras. Let's start:

  1. Do the imports:
import matplotlib.pyplot as pltimport numpy as npfrom keras.datasets import mnistfrom keras.layers import BatchNormalization, Input, Dense, Reshape, Flattenfrom keras.layers.advanced_activations import LeakyReLUfrom keras.models import Sequential, Modelfrom keras.optimizers import Adam
  1. Implement the build_generator function. In this example, we'll use a simple fully-connected generator. However, we'll still follow the guidelines outlined in the DCGAN section:
def build_generator(latent_dim: int):    """    Build discriminator network    :param latent_dim: latent vector size """ ...

Get Python Deep Learning - Second Edition now with O’Reilly online learning.

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