GAN Training, Mode Collapse, and Conditional Generation
Module: Computer Vision | Difficulty: Premium
Minimax Game
Wasserstein Distance (WGAN)
Spectral Normalization
where is the largest singular value.
FID (Frechet Inception Distance)
| Architecture | FID down | IS up | Key Innovation |
|---|---|---|---|
| DCGAN | 37.3 | 6.64 | Transposed conv |
| WGAN-GP | 29.3 | 6.00 | Gradient penalty |
| ProGAN | 8.0 | 3.11 | Progressive training |
| StyleGAN2 | 2.8 | - | Style-based |
| StyleGAN3 | 2.4 | - | Aliasing-free |
import torch
import torch.nn as nn
class Discriminator(nn.Module):
def __init__(self, channels=3, features=64):
super().__init__()
self.block = nn.Sequential(
nn.utils.spectral_norm(nn.Conv2d(channels, features, 4, 2, 1)),
nn.LeakyReLU(0.2, inplace=True),
nn.utils.spectral_norm(nn.Conv2d(features, features*2, 4, 2, 1)),
nn.LayerNorm([features*2, 32, 32]),
nn.LeakyReLU(0.2, inplace=True),
nn.utils.spectral_norm(nn.Conv2d(features*2, features*4, 4, 2, 1)),
nn.LeakyReLU(0.2, inplace=True),
nn.utils.spectral_norm(nn.Conv2d(features*4, features*8, 4, 2, 1)),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(features*8, 1, 4, 1, 0),
)
def forward(self, x):
return self.block(x).view(-1)
def gradient_penalty(discriminator, real, fake, device):
alpha = torch.rand(real.size(0), 1, 1, 1, device=device)
interpolated = (alpha * real + (1 - alpha) * fake).requires_grad_(True)
d_interp = discriminator(interpolated)
gradients = torch.autograd.grad(
outputs=d_interp, inputs=interpolated,
grad_outputs=torch.ones_like(d_interp),
create_graph=True)[0]
gradients = gradients.view(gradients.size(0), -1)
return ((gradients.norm(2, dim=1) - 1) ** 2).mean()
Research Insight: GAN training has evolved from simple minimax formulations to sophisticated regularized objectives. The key breakthrough of StyleGAN was realizing that the latent space structure matters as much as the output quality: the mapping network enables disentangled control over attributes. Diffusion models have largely supplanted GANs for unconditional generation, but GANs remain crucial for real-time applications and as discriminators in diffusion training (e.g., eDiff-I). The hybrid approach combines the speed of GANs with the quality of diffusion.