71 min total

Generative AI

GAN loss functions

GAN loss functions

Q1) Discuss 5 different loss functions used in GAN with clear advantages / disadvantages.

1. Binary Cross-Entropy Loss (Original GAN Loss)

5. Relativistic Loss (RGAN)

Measures the probability that real data is more realistic than fake data, rather than absolute realism.

Loss function treats GAN as a binary classification problem, Discriminator tries to maximize the probability of correctly classifying real and fake samples while generator tries to minimize it.

⨁ More stable training by considering relative differences

⨁ Reduces mode collapse by maintaining relative relationships

⨁ Can generate higher quality samples with better color and contrast

⊖ Additional computational overhead from paired comparisons

⊖ May struggle with complex multi-modal distributions

⨁ Simple formulation that maps well to the minimax game concept

⊖ Can be sensitive to batch size and sampling strategy

⨁ Works well for basic image generation tasks

⨁ Provides clear learning signal when discriminator is not too strong

⊖ Suffers from vanishing gradients when discriminator becomes too good

2. Wasserstein Loss (WGAN)

⊖ Can lead to mode collapse as generator optimizes for fooling discriminator rather than diversity

Measures the Earth Mover's distance between real and generated distributions, using a 1-Lipschitz constrained discriminator (critic).

⊖ Training instability due to non-convergent game dynamics

⨁ Provides meaningful loss metric that correlates with generated sample quality

⨁ More stable training dynamics compared to original GAN loss

⨁ Better theoretical properties with respect to convergence

⊖ Requires careful weight clipping or gradient penalty to enforce Lipschitz constraint

⊖ Computationally expensive due to multiple critic updates per generator update

3. Least Squares Loss (LSGAN)

⊖ May still experience mode collapse in some cases

Replaces the sigmoid cross-entropy loss with a least squares loss function, penalizing samples based on their distance from decision boundary.

⨁ More stable training due to smoother gradients

⨁ Penalizes samples that are "too real" or "too fake", encouraging better quality

⨁ No vanishing gradient problem like in original GAN

⊖ Can be sensitive to outliers due to squared error term

⊖ May generate samples that are overly "safe" or average

⊖ Less theoretically justified compared to WGAN

4. Hinge Loss

Uses a max-margin principle similar to SVMs, creating a clear decision boundary between real and fake samples.

⨁ Works well with spectral normalization

⨁ Generally stable training behavior

⨁ Good performance on image generation tasks

⊖ Can be less effective when real and fake distributions have significant overlap

⊖ May lead to conservative generator behavior

⊖ Limited flexibility in shaping the decision boundary