GAN

On this page 7

A GAN (generative adversarial network) is a generative AI architecture in which two neural networks are trained against each other: a generator that turns random noise into synthetic samples and a discriminator that tries to tell those samples apart from real data. As the discriminator becomes a sharper critic, the generator is pushed to produce outputs that are statistically closer to the training distribution.

Within generative AI and the wider field of artificial intelligence, GANs were the dominant approach to high-fidelity image synthesis for most of the decade after their introduction in 2014. They remain important where single-pass, low-latency generation matters, even though diffusion models now lead in text-to-image quality and controllability.

How a GAN learns through adversarial training

A GAN learns by playing a two-player minimax game. The generator G receives a random vector z, usually drawn from a Gaussian distribution with 64 to 512 dimensions, and maps it to a sample such as an image. The discriminator D receives either a real sample or a generated one and outputs a probability that the input is real.

Training alternates between the two networks. The discriminator is updated to maximize its classification accuracy, and the generator is updated to make the discriminator wrong, using gradients that flow back through the discriminator. In theory the game converges to a Nash equilibrium in which the generated distribution matches the real one and the discriminator outputs 0.5 for every input. In practice that equilibrium is rarely reached exactly, and training is stopped when sample quality metrics stop improving.

The following table summarizes the components that every GAN contains and the role each plays.

ComponentInputOutputTraining goal
GeneratorRandom latent vector zSynthetic sampleFool the discriminator
DiscriminatorReal or generated sampleRealness scoreSeparate real from fake
Latent spacePrior distributionStructured codesEncode variation smoothly
Adversarial lossDiscriminator scoresGradient signalCouple both networks
Core components of a generative adversarial network

Loss functions and major GAN variants

The original formulation uses a binary cross-entropy loss, which corresponds to minimizing the Jensen-Shannon divergence between real and generated distributions. Because this divergence saturates when the two distributions barely overlap, the generator can receive vanishing gradients early in training. Most later variants change the loss, the architecture or the regularization to fix this.

VariantKey changeMain benefit
DCGANConvolutional layers, batch normalizationStable image training baseline
WGAN and WGAN-GPWasserstein distance, gradient penaltySmoother gradients, fewer collapses
Conditional GANClass label or text as extra inputControllable outputs
Pix2Pix and CycleGANImage-to-image translation lossesPaired or unpaired domain transfer
Progressive GANResolution grows during trainingStable megapixel synthesis
StyleGAN familyMapping network, style modulationDisentangled, editable latent space
Influential GAN variants and what each changed

Regularization techniques are as important as the loss. Spectral normalization constrains the discriminator’s Lipschitz constant, R1 gradient penalty stabilizes the critic around real data, and adaptive discriminator augmentation reduces overfitting when the dataset has only a few thousand images.

GANs compared with other generative models

A GAN differs from other generative models mainly in how it learns the data distribution and how many network passes sampling requires. Diffusion models learn to reverse a gradual noising process and need many denoising steps, while variational autoencoders optimize an explicit likelihood bound. The table compares the families that practitioners most often weigh against each other.

PropertyGANDiffusion modelVariational autoencoder
Sampling costOne forward passTens to hundreds of stepsOne forward pass
Sample sharpnessHighHighOften blurry
Mode coverageProne to gapsBroadBroad
Training stabilitySensitive to tuningStableStable
Likelihood estimateNoneApproximateLower bound
Text conditioningPossible, less commonStandardPossible
GANs versus neighboring generative model families

The practical consequence is a speed versus coverage trade-off. A trained GAN can generate an image in milliseconds, which suits real-time applications, but it may silently ignore rare parts of the data. Several modern diffusion systems even borrow adversarial losses to distill many sampling steps into a few, which shows that the adversarial idea remains useful beyond standalone GANs.

Where GANs are used and how to configure them

GANs are most valuable where fast inference and a narrow, well-defined domain coincide. Typical uses include super-resolution, face and portrait synthesis, image-to-image translation, data augmentation for scarce classes, and the adversarial loss inside neural audio vocoders and image tokenizers.

Configuration choices have a large effect on whether training succeeds. The ranges below are common starting points rather than guarantees, because the right values depend on dataset size, resolution and architecture.

SettingCommon rangeWhat it affects
Learning rate0.0001 to 0.0004Speed and stability of both networks
Adam beta10.0 to 0.5Momentum, oscillation between players
Batch size32 to 2,048Gradient noise, diversity of samples
Latent dimension64 to 512Capacity to encode variation
Discriminator steps per generator step1 to 5Balance of the two players
Evaluation metricFID, precision and recallQuality and diversity tracking
Typical GAN training settings and their effect

Quality is usually measured with Fréchet Inception Distance (FID), where lower is better, complemented by precision and recall for generative models to separate fidelity from diversity. A single FID number can hide mode collapse, so both views should be tracked.

Common failure modes and limitations

Most GAN problems stem from the imbalance between the two players. When one network learns much faster than the other, the useful gradient signal disappears or oscillates. The table maps the usual symptoms to their causes and remedies.

SymptomLikely causeTypical fix
Mode collapseGenerator exploits one weak spotMinibatch statistics, WGAN-GP, larger batch
Discriminator overfittingSmall dataset memorizedAdaptive augmentation, R1 penalty
Vanishing generator gradientsCritic too confidentNon-saturating or Wasserstein loss
Oscillating lossesLearning rates out of balanceTwo-timescale update rule, lower beta1
Visible artifactsUpsampling aliasingAlias-free layers, better upsampling
GAN training problems, causes and fixes
  • Loss values are not a quality signal: generator and discriminator losses can look stable while samples degrade, so inspect samples and FID regularly.
  • Memorization risk: with small datasets a GAN can reproduce training images, which raises privacy and copyright concerns.
  • Misuse potential: realistic synthetic faces are used in fraud and disinformation, so provenance marking and detection matter.
  • Limited compositional control: free-form text prompts are handled better by diffusion-based text-to-image systems.

Understanding it simply

Imagine an art forger and an art inspector who keep practicing against each other. The forger paints copies, and the inspector tries to spot which paintings are fake. Each time the inspector catches a mistake, the forger learns to avoid it, and each time the forger improves, the inspector has to look more closely.

A GAN works the same way with two computer programs. After enough rounds, the forger program becomes so good that its pictures look real to people as well. The key idea is learning through competition rather than by copying examples directly.

Applied in practice

A medical imaging team has only about 400 labeled scans of a rare lesion type, compared with 20,000 scans of healthy tissue. Their classifier keeps missing the rare cases because it has seen so few of them.

The team trains a conditional GAN with adaptive augmentation on the rare class at 256 by 256 pixels, tracks FID and per-class precision and recall, and has radiologists review samples to exclude implausible anatomy. They then add several thousand synthetic scans to the training set while keeping the test set strictly real.

The result is a measurable gain in sensitivity on rare lesions in the held-out test set. The team documents that synthetic data was used and keeps checking for memorized training images before each release.