Coding a GAN in Keras

Of course, the best way to learn is by doing, so let's jump in and start coding our first GAN. In this example, we will be building the basic DCGAN and then modifying it later for our purposes. Open up Chapter_3_2.py and follow these steps:

This code was originally pulled from https://github.com/eriklindernoren/Keras-GAN, which is the best representation of GANs in Keras anywhere, and is all thanks to Erik Linder-Norén. Great job, and thanks for the hard work, Erik. An alternate listing a vanilla GAN has been added as Chapter_3_1.py for your learning pleasure.
  1. We start by importing libraries:
from __future__ import print_function, divisionfrom keras.datasets import mnistfrom keras.layers import Input, Dense, Reshape ...

Get Hands-On Deep Learning for Games 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.