It's important to focus on each of these components to understand how they come together. For each of these sections, I'll be highlighting the architecture pieces to make it more apparent.
Basic building block – generator
How to do it...
The following diagram represents the important pieces of the generator:
The focus in the diagram ensures that you see the core piece of code that you'll be developing in the generator section.
Here are a few steps to describe how we create a generator conceptually:
- First, the generator samples from a latent space and creates a relationship between the latent space and the output
- We then create a neural network that goes from an input (latent space) to output (image for most examples)
- We'll train the generator in an adversarial mode where we connect the generator and discriminator together in a model ( every generator and GAN recipe in this book will show these steps)
- The generator can then be used for inference after training
How it works...
Each of these building blocks is fairly unique, but the generator is arguably the most important concept to understand. Ultimately, the generator will produce the images or output that we see after this entire training process is complete. When we talk about training GANs, it refers directly to training the generator. As we mentioned in a previous section, the discriminator will need to train for a few epochs prior to beginning the training process in most architectures or it would never complete training.
For each of these sections, it is important to understand the structure of the code we'll start building through the course of this book. In each chapter, we're going to define classes for each of the components. The generator will need to have three main functions within the class:
The loss function will define a custom loss function in training the model (if needed for that particular implementation). The buildModel function will construct the actual model of the given neural network. Specific training sequences for a model will go inside this class though we'll likely not use the internal training methods for anything but the discriminator.Â