0
0
PyTorchml~12 mins

GAN training loop in PyTorch - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - GAN training loop

This pipeline trains a Generative Adversarial Network (GAN) where two models, a Generator and a Discriminator, compete. The Generator tries to create fake data that looks real, while the Discriminator tries to tell real data from fake. Over time, both improve through this competition.

Data Flow - 5 Stages
1Load real data
1000 rows x 28 x 28 pixelsLoad and normalize images from dataset1000 rows x 28 x 28 pixels
Real image of handwritten digit '7' normalized between -1 and 1
2Generate fake data
1000 rows x 100 noise featuresGenerator transforms noise vector into fake images1000 rows x 28 x 28 pixels
Fake image generated from random noise resembling digit '3'
3Discriminator input
2000 rows x 28 x 28 pixelsCombine real and fake images for discriminator training2000 rows x 28 x 28 pixels
Batch of 1000 real and 1000 fake images
4Discriminator output
2000 rows x 28 x 28 pixelsDiscriminator predicts real (1) or fake (0)2000 rows x 1
Array of 1s for real images and 0s for fake images
5Generator update
1000 rows x 100 noise featuresGenerator updated to fool discriminator1000 rows x 28 x 28 pixels
Generator produces better fake images after update
Training Trace - Epoch by Epoch
Loss (D/G):
1.2 |*         
1.0 | *        
0.8 |  *       
0.6 |   *      
0.4 |    *     
    +----------
     1 2 3 4 5
     Epochs
EpochLoss ↓Accuracy ↑Observation
1Discriminator: 0.65, Generator: 1.20Discriminator: 0.60Discriminator starts learning to distinguish real and fake images
2Discriminator: 0.55, Generator: 1.10Discriminator: 0.68Discriminator accuracy improves, Generator loss decreases slightly
3Discriminator: 0.48, Generator: 0.95Discriminator: 0.74Generator starts producing more realistic images, fooling discriminator more
4Discriminator: 0.42, Generator: 0.85Discriminator: 0.78Both models improve steadily; discriminator accuracy rises
5Discriminator: 0.38, Generator: 0.75Discriminator: 0.82Generator creates convincing images; discriminator accuracy high but challenged
Prediction Trace - 3 Layers
Layer 1: Noise vector input
Layer 2: Generator network
Layer 3: Discriminator network
Model Quiz - 3 Questions
Test your understanding
What does the generator try to do during training?
AClassify images as real or fake
BReduce noise in input data
CCreate fake data that looks real
DIncrease discriminator accuracy
Key Insight
GAN training is a balance where the generator improves by trying to fool the discriminator, and the discriminator improves by learning to spot fakes. Over time, this competition leads to the generator creating realistic data.