How to do it...

In the Adversarial attack to fool a neural network section, we discussed our strategy of how to generate an image that looks very similar to the original images. In this section, we will implement the process of generating a digit's image from the MNIST dataset (the code file is available as Vanilla_and_DC_GAN.ipynb in GitHub):

  1. Import the relevant packages:
import numpy as npfrom keras.datasets import mnistfrom keras.layers import Input, Dense, Reshape, Flatten, Dropoutfrom keras.layers import BatchNormalizationfrom keras.layers.advanced_activations import LeakyReLUfrom keras.models import Sequentialfrom keras.optimizers import Adamimport matplotlib.pyplot as plt%matplotlib inlineplt.switch_backend('agg')from keras.models ...

Get Neural Networks with Keras Cookbook 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.