Generative adversarial networks

Generative adversarial networks (GAN) are another very recent type of generative model that got attention due to their impressive results. A GAN is composed of two networks together: a generator network and a discriminator network. During training, they both play a zero-sum game, where the discriminator network tries to discover whether the images input to it are real or fake. At the same time, the generator network tries to create fake images that are good enough to fool the discriminator.

The idea is that after some time of training, both the discriminator and the generator become very good at their tasks. As a result, the generator is forced to try and create images that look closer and closer to the original dataset. To be able to do this, it must capture the probability distribution of the dataset.

The following diagram gives an overview of how this GAN model looks:

Both discriminator and generator will have their own loss function, but both of their losses depends on each other.

Let's summarize the two main blocks, or networks, of the GAN model:

  • Generator: Create images similar to the real images dataset using a size N, 1-D vector as input (Choice of N is up to us)
  • Discriminator: Verify that the image given to it is real or a fake generated one

Some practical usages for GANs are as follows:

  • Use the discriminator network weights as the initialization for a different task similar to what we can do with autoencoders
  • Use the generator network to create new images, possibly to augment your dataset, like we can do with the trained decoder of the VAE
  • Use the discriminator as a loss function (potentially, better than L1/L2 for images) and can also be used back in the VAE
  • Semi-supervised learning by mixing generated data with labeled data

We will now show you how to implement a very simple GAN in TensorFlow. Once it is trained, the generator part of our GAN can be used create MNIST handwritten digits from a 100 long vector of random noise. Let's get started!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset