Develop a GAN with Pytorch
Implement and train GAN in Python and Pytorch.
We'll cover the following
Let’s see all of that in action and build a GAN from scratch.
After importing our standard Pytorch modules, we will define the generator and the discriminator. Both of them are simple multi-layer networks.
Generator
- Receives as input 100-length noise vector sampled from a distribution
- Outputs a flattened image in the dimensions of the cifar10 dataset:
Discriminator
- The discriminator receives an input of size = 3072, which is again the flattened cifar10 image or the output of the generator.
- It outputs a scalar in [0,1].
- The binary cross-entropy loss is computed based on the output of the discriminator and the data label.
Note that when we train the discriminator, the generated images have the label of 0, and the real images have the label of 1.
Get hands-on with 1400+ tech skills courses.