AI State of the Art
Fundamentals/Deep Learning: Fundamental Architectures/33 min
Section 25

Generative Adversarial Networks (GAN)

Listen as a podcast →

The revolutionary idea: making two networks fight

In 2014, Ian Goodfellow invented the Generative Adversarial Network, almost always abbreviated GAN, during a discussion at a bar (according to legend). "Adversarial" here means "by confrontation": the approach is radical, instead of training a single network to generate data, you use two that train against each other.

The classic metaphor: a counterfeiter (the generator) producing fake bills versus a detective (the discriminator) trying to spot them. The counterfeiter improves to fool the detective, the detective improves to unmask the counterfeiter. Over a great many rounds of this game, the fake bills become hard to tell from real ones.

What makes this idea so remarkable is that it draws from game theory rather than classical statistics. You don't explicitly define what a "good" image is, you let the discriminator figure that out on its own, and the generator adapts accordingly.

Generative Adversarial Nets
Read this as a chapter of history

This page describes a technique that dominated image generation from 2014 to roughly 2021. It is not the approach used to produce images today: diffusion models replaced it, first matching it (already in 2020 the founding diffusion paper reported sample quality on a scene dataset "similar to ProgressiveGAN"), then clearly overtaking it from 2021-2022. The practical training advice further down belongs to that period: it is still instructive, but it is not a recommendation for a new project. What a GAN is worth in 2026 is twofold: it teaches the two-networks-in-confrontation principle, which turns up in many other places, and it lets you read the literature of the 2010s.

Architecture

Diagram of a GAN with generator and discriminator
This diagram illustrates the fundamental architecture of a GAN (Generative Adversarial Network). The generator creates images from random noise, while the discriminator evaluates their authenticity by comparing them to the training set.Source : Thalles Silva

The generator G

The generator is a neural network that transforms random noise z into synthetic data (typically images):

xfake=G(z),z∼N(0,I)x_{\text{fake}} = G(z), \quad z \sim \mathcal{N}(0, I)

Symbol by symbol: zz is a noise vector, i.e., simply a list of numbers drawn at random; the sign ∼\sim reads "is drawn at random from"; N(0,I)\mathcal{N}(0, I) is the normal, or Gaussian, distribution centred on zero, each coordinate of width 1 and independent of the others; GG is the function the generator computes; xfakex_{\text{fake}} is the manufactured image. Do not conflate them: GG holds the generator's learned weights, frozen after training, whereas xfakex_{\text{fake}} is recomputed for every fresh draw of zz.

This noise vector is the only "seed" from which the generator must create something realistic. Two different z values yield two different images. A slightly modified z yields a slightly modified image (in theory).

For image generation, the typical architecture starts with dense layers that transform the z vector into a small spatially arranged block of numbers (e.g., a 4x4 grid with many channels, a channel being one map of values stacked with the others), then transposed convolutions progressively increase the resolution: 4x4 -> 8x8 -> 16x16 -> 32x32 -> 64x64. Each step doubles the spatial resolution while reducing the number of channels, until you get a colour image (three channels: red, green, blue) at the desired resolution.

The discriminator D

The discriminator is a binary classifier that answers a single question: "is this image real or generated?"

D(x)→[0,1](probability that the image is real)D(x) \rightarrow [0, 1] \quad \text{(probability that the image is real)}

DD is the function the discriminator computes; xx is the image you hand it; the notation [0,1][0, 1] says its output is a number between 0 and 1, to be read as "probability that this image is real", 0 meaning "certainly fake", 1 "certainly real".

It's a standard convolutional network, Convolutional Neural Network, abbreviated CNN: convolutions that progressively reduce spatial resolution, followed by a dense layer and a sigmoid (an S-shaped curve that squashes any number into the 0-1 range). The architecture is essentially the inverse of the generator: where G upscales, D downscales.

The discriminator alternately receives real images from the dataset and images generated by G, and must learn to tell them apart. At first it's easy (the fake images are noise), but as G improves, the task becomes increasingly challenging.

The minimax game

The entire genius of GANs lies in their objective function:

min⁡Gmax⁡D  Ex∼pdata[log⁡D(x)]+Ez∼pz[log⁡(1−D(G(z)))]\min_G \max_D \; \mathbb{E}_{x \sim p_{\text{data}}}[\log D(x)] + \mathbb{E}_{z \sim p_z}[\log(1 - D(G(z)))]

Every symbol, one at a time:

  • GG is the generator, DD the discriminator; more precisely, they stand for those two networks' sets of learned weights, and it is those weights that the min⁡\min and the max⁡\max act on.
  • min⁡Gmax⁡D\min_G \max_D reads: the generator tries to make what follows as small as possible, the discriminator to make it as large as possible. Both pull on the same quantity, in opposite directions, hence the name "minimax" game.
  • E\mathbb{E} is the expectation, i.e., an average weighted by probabilities. Its subscript says what the average is taken over. It has its own lesson: expectation, variance and moments.
  • pdatap_{\text{data}} is the distribution of the real data, which in practice means the training image set: x∼pdatax \sim p_{\text{data}} means "take a real image from the set".
  • pzp_z is the noise distribution the seeds are drawn from, here the standard Gaussian: z∼pzz \sim p_z means "draw a noise vector".
  • log⁡\log is the logarithm, used here because it punishes confident mistakes very harshly: it equals 0 when its argument is 1, and plunges toward minus infinity as the argument approaches 0.

What each half does:

  • Ex[log⁡D(x)]\mathbb{E}_{x}[\log D(x)]: on real images x, the discriminator wants D(x)D(x) close to 1. Since log⁡1=0\log 1 = 0 and the logarithm is negative below that, 0 is the best value reachable here. So the discriminator maximizes this term.
  • Ez[log⁡(1−D(G(z)))]\mathbb{E}_{z}[\log(1 - D(G(z)))]: on fake images G(z), the discriminator wants D(G(z))D(G(z)) close to 0, giving log⁡(1−0)=0\log(1 - 0) = 0, the best value. The generator wants exactly the opposite: D(G(z))D(G(z)) close to 1, which sends the term plunging toward −∞-\infty. So the generator minimizes it.

In one sentence: the discriminator wants to be right about both populations, the generator wants it to be wrong about the second one. It's a zero-sum game: what one gains, the other loses. The vocabulary of such games (minimax, Nash equilibrium) is laid out in game theory.

Alternating training

Training is done by alternating two phases at each iteration:

Phase 1, Train D (the detective):

  • Take a batch of real images x from the dataset
  • Generate a batch of fake images G(z) from noise
  • The discriminator learns to give a high score to real images and low to fakes
  • Update only D's weights

Phase 2, Train G (the counterfeiter):

  • Generate a batch of fake images G(z) from noise
  • Pass them through D, whose weights are frozen for the duration of this phase: D acts as the judge and is not corrected
  • The generator learns to produce images that maximize D(G(z))
  • Update only G's weights

Back and forth, back and forth. The balance between the two is crucial: if one gets too far ahead, everything collapses.

The theoretical equilibrium

At the optimum, the generator produces data indistinguishable from real, and the discriminator can no longer decide, it answers 0.5 for any image. This is a Nash equilibrium: neither player can improve their situation by unilaterally changing strategy. In practice? This equilibrium is extremely hard to reach, and training is notoriously finicky.

Training catastrophes

GANs are famous not only for their spectacular results, but also for the difficulty of their training. Here are the most common problems.

Mode collapse

This is the most well-known plague. The generator learns to produce only a few types of outputs that effectively fool the discriminator, instead of covering the full diversity of real data.

Concrete example: you train a GAN on MNIST, the standard set of 70,000 handwritten digits. Instead of generating digits 0-9 in a balanced way, the generator specializes in producing perfect "9"s. Why? Because it's simpler to perfect a single mode than to master the full diversity. The generator finds a "recipe" that works and sticks to it.

It's a bit like a student who only studies one chapter for the exam: they know it perfectly, but fail everything else.

Evolution of GAN-generated digits over 1000K iterations
Each column shows the digits produced at one moment of training, later and later as you move right. On the top row the plain GAN ends up drawing nothing but 1s: this is the student who revised a single chapter. On the bottom row the WGAN variant keeps turning out varied digits.Source : Medium

Training instability

  • Oscillations: instead of converging to a Nash equilibrium, D and G oscillate indefinitely. The generator finds a trick, the discriminator adapts, the generator changes strategy, etc. The loss curves form waves that never dampen.
  • Vanishing gradient: if the discriminator is too good too quickly, it rejects all fake images with crushing confidence, say 99.99%. The generator then has nothing to work with. Here is why, with the numbers: its term equals log⁡(1−0.9999)=log⁡(0.0001)≈−9.2\log(1 - 0.9999) = \log(0.0001) \approx -9.2 in natural logarithm. The problem is not that value but its slope: the logarithm is so flattened in that region that an improvement by the generator barely moves the result. And it is the slope, not the value, that tells a network which way to correct itself. So the generator is "blind."
  • Imbalance: if one of the two networks dominates the other, the loser collapses and training never recovers.

Tuning the hand-set knobs (the hyperparameters: learning rates, architecture, number of D updates per G update) is absolutely critical and often more art than science.

The stabilization tricks of the era

Between 2015 and 2021 the community worked out many tricks to tame GANs. They are listed here to help you read the literature of that period, not as a method to follow today:

  • Label smoothing: D was trained with targets of 0.9 rather than 1.0 for real images, which kept it from becoming too sure of itself
  • Train D more often than G, typically a few D updates per G update, to maintain the detective's lead
  • Spectral normalization in D: a way of capping how sharply the discriminator's output can swing (its Lipschitz constant, see the WGAN section below)
  • Add noise to D's inputs, to prevent discrimination from being too easy at the start
  • Monitor FID, not the raw loss value, which is notoriously uninformative in a GAN

Non-convergence

Unlike classical models that minimize a single loss and converge to a minimum, GANs are a two-player game. There is no theoretical guarantee of convergence to a Nash equilibrium for deep networks. This is a fundamental problem of game theory applied to deep learning.

A surprising practical consequence: the loss value is often useless for judging quality. A model with high loss can generate excellent images, while a model with low loss can be in the middle of mode collapse. That's why the external measures below are used instead.

Evaluating GANs

How do you know if a GAN generates good images? You can't rely on the loss. You need dedicated measures. The two that follow both rest on Inception, an image-classification network trained once and for all on ImageNet and used here as a measuring instrument, rather as one uses a single, consistent judge to compare candidates.

The trap of two reading directions

The two measures below read in opposite directions, and this trips people up constantly:

  • FID is a distance: the lower, the better (0 would be perfection);
  • IS is a score: the higher, the better.

Another essential caution: neither one compares across datasets or across resolutions. An FID of 3 on small 32x32 images and an FID of 7 on 128x128 images cannot be ranked against each other.

FID (Fréchet Inception Distance)

"Fréchet distance" is the mathematical name for the way the two clouds are compared. This is the measure that became standard. The idea: you pass real images and generated images through the Inception network to extract their internal representations (features), the abstract descriptions the network forms of each image. Then you summarize each of the two clouds of descriptions by a Gaussian (a centre and a spread) and measure the gap between those two Gaussians.

Low FID = the two clouds are similar = the generated images are close to real ones. An FID of 0 would mean the two distributions are identical. You often see thresholds quoted such as "under 10 is excellent": those are rules of thumb, with no official definition, and they depend entirely on the image set. For a verifiable point of reference: on the small images of CIFAR-10 without conditioning, the founding diffusion paper reports an FID of 3.17, and the BigGAN paper reports an FID of 7.4 on ImageNet at 128x128, two figures which, precisely, do not compare to each other.

IS (Inception Score)

It evaluates two complementary aspects:

  • Quality: each generated image, taken on its own, should be clearly recognizable by the classifier, which should answer "that's a dog" with conviction rather than hesitate between ten categories
  • Diversity: the set of generated images should cover many different categories rather than pile up on one

IS is less reliable than FID because it never compares directly to real data: it only looks at what was produced. It is still quoted as a complementary measure.

GAN, VAE, and diffusion: who does what

GANs produce sharp images because the discriminator judges the whole image rather than pixel by pixel. Variational autoencoders (VAE) tend to produce blurry images because they optimize a pixel-by-pixel error (mean squared error, MSE), which does not measure what the eye perceives. Diffusion models produce very sharp images but originally demanded hundreds of denoising steps. Historically, GANs dominated image generation. Since 2021-2022, diffusion models have surpassed them in both quality and training stability, and have cut the cost of generation.

Key variants

Conditional GAN (cGAN)

The basic GAN generates images "at random", you have no control over the content. The cGAN solves this by conditioning generation on additional information y (a class, text, a reference image). "Conditioning" here means: hand that information to both networks, so that they learn to take it into account.

The generator receives z + y, the discriminator receives x + y. This way, you can ask "generate me a dog" or "transform this sketch into a realistic photo." It's the foundation of pix2pix and many practical applications.

Diagram of a Conditional GAN
This diagram illustrates the workings of a Conditional GAN where the generator produces images from noise and labels, while the discriminator evaluates the reality of images based on the same labels. This allows controlling image generation according to specific conditions.Source : GeeksforGeeks

DCGAN (Deep Convolutional GAN)

Before DCGAN (Deep Convolutional GAN, 2015), GANs were extremely unstable. Radford et al. proposed a set of architectural best practices that changed the game:

  • Strided convolutions (which move more than one pixel at a time, shrinking the output) instead of pooling, i.e., downsampling by grouping neighbouring values
  • Batch normalization (recentring the values flowing through the network, one batch of images at a time) in G and D
  • For the activation function (the small non-linear function applied at each neuron's output) ReLU (Rectified Linear Unit: it passes positive values through and replaces negative ones with zero) in G, and its LeakyReLU variant in D, which lets negative values leak a little instead of erasing them
  • No fully connected layers (except G's input and D's output)

These simple rules made GANs finally usable in a reliable way. DCGAN is the starting point for virtually all GAN architectures that followed.

DCGAN architecture: generator and discriminator
This image illustrates the DCGAN architecture with a generator (a) that transforms a latent vector into an image via deconvolution layers, and a discriminator (b) that evaluates the likelihood of an image via convolution layers. It shows how these two networks oppose each other to improve the quality of generated images.Source : Idiot Developer

Wasserstein GAN (WGAN)

WGAN (2017) replaces the Jensen-Shannon divergence (the measure of distance between distributions hidden inside the original minimax formula) with the Wasserstein distance, also called the "Earth Mover's Distance": imagine the cost of moving a pile of dirt, shovel by shovel, to give it a different shape. Instead of asking the discriminator "real or fake?", you ask it to score images with an unbounded real number: it becomes a critic rather than a classifier. The loss is more stable, gradients are more informative, and mode collapse is reduced. WGAN was a major theoretical advance for understanding and stabilizing GANs; it is covered in detail in the advanced GAN architectures lesson.

The legacy

Despite their training problems, GANs left a considerable mark:

  • The first photorealistic synthetic images (StyleGAN, ProGAN)
  • Super-resolution: turning a low-resolution image into a high-resolution one
  • Style transfer and face synthesis: FaceApp, deepfakes, portrait aging
  • Data augmentation: manufacturing synthetic data to pad out a training set that is too small
  • The confrontation principle itself, reused in model robustness and in domain adaptation (making a model trained on simulated data work on real data)
The post-GAN era

Diffusion models have surpassed GANs for high-quality image generation. GANs held on to a speed advantage for a while (a single computation pass against hundreds of denoising steps) but that advantage has largely eroded: distillation techniques now let a diffusion model produce an image in one to four steps. What survives of GANs is rather the ideas: the two-networks-in-confrontation principle, and the use of a learned judge rather than a fixed error formula. Several of today's fast generators are in fact trained with an adversarial component inherited directly from GANs.

Summary

GANs embody a bold idea: two networks that compete against each other to progress together. The generator creates, the discriminator judges, and from this competition emerge images of striking realism. But the approach comes with its share of difficulties: mode collapse, instability, no guaranteed convergence. Diffusion models took over as the dominant method from 2021-2022. Understanding GANs remains useful nonetheless: the confrontation principle turns up elsewhere in deep learning, from training against deceptive examples to assessing model robustness.

Images generated by StyleGAN
Images generated by StyleGANSource : Karras, Laine & Aila, A Style-Based Generator Architecture for Generative Adversarial Networks (arXiv:1812.04948), figure 2
Check your understanding0 / 5

1. A GAN trained on the 70,000 handwritten digits of MNIST ends up producing nothing but perfect 9s. What is this phenomenon called, and why does it happen?

2. During GAN training, the generator's loss is low. What does that tell you about the quality of the images it produces?

3. Model A scores an FID of 3 on the small images of CIFAR-10, model B an FID of 7 on ImageNet at 128x128. Which one generates better images?

4. At the theoretical equilibrium of the minimax game, what does the discriminator answer?

5. Why study GANs in 2026, when they are no longer the method used to generate images?