Generating Images from Labels with the CGAN

Create a model to generate images from labels with CGAN using MNIST dataset.

We have already defined the architecture of both generator and discriminator networks of the CGAN. Now, let’s write the code for model training. In order to make it easy to reproduce the results, we will use MNIST as the training set to see how the CGAN performs in image generation. What we want to accomplish here is that, after the model is trained, it can generate the correct digit image we tell it to, with extensive variety.

One-stop model training API

First, let’s create a new Model class that serves as a wrapper for different models and provides the one-stop training API. Create a new file named build_gan.py and import the necessary modules:

Get hands-on with 1200+ tech skills courses.