0
0
PyTorchml~8 mins

GAN training loop in PyTorch - Model Metrics & Evaluation

Choose your learning style9 modes available
Metrics & Evaluation - GAN training loop
Which metric matters for GAN training loop and WHY

In GANs, we want the generator to create data that looks real, and the discriminator to tell real from fake. The key metrics are discriminator loss and generator loss. These losses show how well each part is learning. Lower loss means better performance. We also look at Inception Score or FID to measure how real the generated images look overall. These metrics help us know if the GAN is improving or stuck.

Confusion matrix or equivalent visualization
Discriminator predictions:

           | Real Data | Fake Data
-----------|-----------|----------
Pred Real  |    TP     |    FP    
Pred Fake  |    FN     |    TN    

Where:
- TP (True Positive): Discriminator correctly says real data is real
- FP (False Positive): Discriminator wrongly says fake data is real
- FN (False Negative): Discriminator wrongly says real data is fake
- TN (True Negative): Discriminator correctly says fake data is fake

Losses are computed from these predictions to update both networks.
    
Precision vs Recall tradeoff in GANs with examples

GAN training balances two goals:

  • Discriminator precision: How often it correctly identifies fake images. High precision means few fake images are mistaken as real.
  • Generator recall: How well the generator fools the discriminator. High recall means many generated images look real enough to fool the discriminator.

If the discriminator is too strong (high precision), the generator struggles and produces poor images (low recall). If the generator is too strong (high recall), the discriminator fails to learn (low precision). Good GAN training finds a balance where both improve together.

What "good" vs "bad" metric values look like for GAN training

Good:

  • Discriminator loss and generator loss both decrease steadily and stabilize.
  • Generated images look realistic and diverse.
  • Inception Score or FID improves over time (higher IS, lower FID).

Bad:

  • Discriminator loss quickly goes to zero while generator loss stays high (discriminator too strong).
  • Generator loss goes to zero but discriminator loss stays high (generator collapses to few outputs).
  • Generated images are blurry, repetitive, or obviously fake.
Common pitfalls in GAN metrics
  • Mode collapse: Generator produces limited variety of outputs. Losses may look good but diversity is poor.
  • Overfitting discriminator: Discriminator becomes too perfect, causing generator to fail learning.
  • Ignoring qualitative checks: Only looking at loss numbers without checking generated samples can mislead.
  • Data leakage: Using test data in training can inflate metrics falsely.
Self-check question

Your GAN training shows discriminator loss near zero but generator loss remains high. Generated images look poor and repetitive. Is this good?

Answer: No. This means the discriminator is too strong and easily spots fakes. The generator is not learning well and may be stuck producing limited outputs. You should adjust training to balance both networks better.

Key Result
In GAN training, balanced discriminator and generator losses plus improved image quality metrics indicate good progress.