AI

Generative Adversarial Network (GAN), Explained

Generative adversarial network explained: how a GAN's generator and discriminator compete, a worked loss example, GAN types, uses and GAN vs diffusion.

By OmniAI Editorial · Nov 22, 2026 · 11 min read

A generative adversarial network (GAN) is a deep learning model made of two neural networks that compete: a generator creates fake data, such as images, from random noise, and a discriminator tries to tell those fakes from real examples. Each improves by beating the other, until the generator produces outputs realistic enough to fool the discriminator. GANs, introduced in 2014, were the leading way to generate realistic images for several years, and they're still used for fast image synthesis, super-resolution and editing, though diffusion models now dominate text-to-image generation.

This guide explains what is GAN in machine learning, the GAN deep learning architecture, how training works with a worked loss example, the main GAN types, generative adversarial networks examples in practice, GAN vs diffusion model, common problems and how they're fixed. It goes deeper than the GAN section in our diffusion model explainer.

What Is GAN in Machine Learning?

In machine learning, a GAN is a framework for training a generative model, one that produces new data resembling its training data. Ian Goodfellow and colleagues introduced it in the 2014 paper "Generative Adversarial Nets." Its abstract describes two models trained together: "a generative model G that captures the data distribution, and a discriminative model D that estimates the probability that a sample came from the training data rather than G."

A common analogy is a counterfeiter and a detective. The counterfeiter (generator) prints fake banknotes; the detective (discriminator) inspects notes and says real or fake. Every time the detective catches a fake, the counterfeiter learns what gave it away; every time a fake slips through, the detective learns to look closer. Over many rounds, the fakes become very hard to tell from real notes.

The paper frames this as "a minimax two-player game" and shows that in the ideal case a unique solution exists, with the generator recovering the training data distribution and the discriminator outputting one half everywhere: it can no longer tell real from fake.

The GAN Deep Learning Architecture

A GAN has two networks with opposite jobs:

PartInputOutputGoal
Generator (G)A random noise vector, often 100 to 512 numbers; optionally a label or imageA fake sample, such as an imageMake samples the discriminator classifies as real
Discriminator (D)A real sample or a generated oneA probability that the input is realCorrectly label real as real and fake as fake

For images, the generator is usually a stack of layers that upsample noise into a picture, often transposed convolutions or upsampling plus convolutions; the discriminator is a convolutional classifier that downsamples an image to a single score. The noise vector, the latent vector, acts like a set of dials: moving through this "latent space" changes the generated image smoothly, which is what made GAN face editing possible.

A small checkered noise square, an ink arrow to a grey box, then to a light picture card; that card and a second picture card below send ink arrows into another grey box, which points to an orange dot.
The generator turns noise into a sample; the discriminator judges real against fake.

How Generative Adversarial Network Training Works

Training alternates between the two networks:

  1. Train the discriminator. Take a batch of real images and a batch of images from the generator. Update the discriminator to output a high probability for the real ones and a low probability for the fakes.
  2. Train the generator. Generate a new batch, pass it through the discriminator, and update only the generator so that the discriminator's output on its fakes goes up.
  3. Repeat for many thousands of steps.

The generator never sees real images directly. It learns entirely from the discriminator's feedback: the gradient of the discriminator's judgment tells it which direction makes the fake look more real.

Worked example: reading the losses

The discriminator uses a standard classification loss: −[log D(real) + log(1 − D(fake))]. In practice, the generator usually minimizes −log D(fake), a "non-saturating" version the original paper suggested because it gives stronger gradients early in training.

SituationD(real)D(fake)Discriminator lossGenerator loss
Discriminator winning0.90.20.3291.609
Closer contest0.60.51.2040.693
Theoretical equilibrium0.50.51.3860.693

When the discriminator is confident (it rates real images 0.9 and fakes 0.2), its loss is low and the generator's loss is high, so the generator gets a strong signal to improve. At the theoretical equilibrium, the discriminator outputs 0.5 for everything: it's guessing. Unlike most models, a GAN's losses don't steadily fall to zero; they bounce as the two networks trade advantages, which is why practitioners judge progress by looking at samples and using quality metrics rather than loss curves alone.

Types of Generative Adversarial Networks

GAN typeKey ideaWhat it enabled
Original GAN (2014)Generator and discriminator as simple networksProof of concept on small images
DCGANConvolutional generator and discriminator with design rules for stable trainingThe first reliably good GAN images; became the standard starting point
Conditional GANFeed a label or other input to both networksGenerate a specific class, such as "a digit 7" or "a dog"
pix2pixConditional GAN that maps one image to another using paired examplesSketch to photo, map to satellite, day to night
CycleGANImage-to-image translation without paired examples, using cycle consistencyHorses to zebras, photos to paintings
Wasserstein GAN (WGAN)A different loss based on the Wasserstein distanceMore stable training and more meaningful losses
StyleGAN family (NVIDIA)Style-based generator that controls features at different scalesPhotorealistic faces with controllable attributes
Super-resolution GANs (such as SRGAN, ESRGAN)Adversarial loss for sharper upscalingDetailed image upscaling and restoration

NVIDIA's StyleGAN paper described "an alternative generator architecture" borrowed from style transfer that led to "an automatically learned, unsupervised separation of high-level attributes," such as pose and identity in faces, and "intuitive, scale-specific control of the synthesis." It was behind the realistic fake portraits that became famous online around 2019.

Generative Adversarial Networks Examples

AreaGenerative adversarial networks examples
Image synthesisRealistic faces, products and scenes from random noise
Image editingChanging age, expression or lighting in a photo by moving through latent space
Image-to-image translationSketches to photos, summer to winter scenes, maps to satellite imagery
Super-resolution and restorationUpscaling low-resolution images, restoring old photos and video
Data augmentationCreating extra training images, including synthetic medical images for research
Video and animationFace reenactment and some deepfake techniques
AudioFast speech synthesis vocoders and sound effects
ScienceSimulating particle physics events and other expensive simulations
Anomaly detectionLearning what normal data looks like and flagging what the generator can't reproduce

The realism that makes GANs useful also enables deepfakes; our guide on how to spot a deepfake covers practical checks.

Left: a small checkered square with one ink arrow to a light picture card. A dotted ink divider. Right: a checkered square, four small blocks in a row joined by tiny ink arrows, and a light picture card with an orange dot.
A GAN generates in one pass; a diffusion model refines noise over many steps.

GAN vs Diffusion Model

Diffusion models learn to remove noise step by step, starting from pure noise and refining it into an image over many steps. They overtook GANs for text-to-image generation in the early 2020s.

GANDiffusion model
How it generatesOne pass through the generatorMany denoising steps (tens to hundreds, fewer with distillation)
Generation speedVery fastSlower, though distilled models narrow the gap
Training stabilityTricky: adversarial balance, mode collapseStable: a simple denoising objective
Output diversityCan collapse to a few modesHigh diversity and coverage
Image qualityExcellent in narrow domains (faces, specific objects)Excellent across very broad domains
Text conditioningHarder to scale to open-ended promptsScales well with text encoders; powers most text-to-image tools
Typical use todayReal-time synthesis, super-resolution, specific domains, as a component in other systemsText-to-image, video, image editing, audio

The two also mix: some fast image generators distill a diffusion model into a few-step generator using an adversarial loss, combining diffusion's quality with GAN-like speed. Our explainer on AI image generators covers the tools built on these models.

Common GAN Problems and Fixes

Google's machine learning course on GANs lists the classic training problems:

ProblemWhat happensCommon fixes
Vanishing gradientsIf the discriminator becomes too good, the generator gets almost no useful gradient and stops learningWasserstein loss, the non-saturating generator loss
Mode collapseThe generator finds a few outputs that fool the discriminator and keeps producing themWasserstein loss, unrolled GANs, minibatch discrimination
Failure to convergeThe two networks oscillate instead of reaching a balanceRegularization: adding noise to discriminator inputs, penalizing discriminator weights, gradient penalties
Evaluation difficultyLosses don't show qualityLook at samples; use metrics such as Fréchet Inception Distance (FID)

A Short History of GANs

Ian Goodfellow and colleagues at the University of Montreal published the GAN framework in 2014, and early results were blurry, low-resolution images. Progress came quickly: DCGAN in 2015 showed convolutional GANs could train reliably; conditional GANs, pix2pix and CycleGAN between 2014 and 2017 turned them into practical image-translation tools; the Wasserstein GAN in 2017 improved stability; and NVIDIA's progressive and style-based GANs in 2017 to 2019 reached photorealistic, high-resolution faces. From around 2021, diffusion models overtook GANs on broad image generation, but adversarial training lives on inside many modern systems, from super-resolution to fast distilled image generators.

How GANs Are Evaluated

Because GAN losses don't track quality, researchers use separate measures:

  • Fréchet Inception Distance (FID): compares statistics of generated and real images, computed with a pretrained image network. Lower is better, and it rewards both quality and diversity.
  • Inception Score (IS): an earlier metric that rewards images a classifier recognizes confidently and a variety of classes; it ignores how close images are to the real data.
  • Precision and recall for generative models: measure realism and coverage separately, which helps diagnose mode collapse.
  • Human evaluation: still the final check for perceived realism and usefulness.

GANs, Deepfakes and Responsible Use

The same techniques that create convincing faces can create convincing fakes of real people. GAN-generated profile photos have been used for fake social media accounts, and face-swapping tools have drawn on adversarial training. Detection tools look for statistical artifacts, but they lag behind generators. Responsible use means consent for any real person's likeness, labeling synthetic media, and following platform rules and laws on deepfakes, which are expanding in many countries.

How to Build a Simple GAN

A first GAN is a classic learning project:

  1. Pick a small dataset, such as handwritten digits or small clothing images.
  2. Build a small generator that maps a noise vector to an image, and a discriminator that classifies images as real or fake.
  3. Alternate training steps as described above, using the binary cross-entropy loss available in PyTorch or Keras.
  4. Save sample images every few hundred steps to watch progress.
  5. Try DCGAN design rules (strided convolutions, batch normalization, specific activations) if training is unstable.

PyTorch and TensorFlow both publish official DCGAN tutorials that walk through this exact setup.

FAQ

What is a GAN in simple terms?

It's an AI model made of two networks that compete: one creates fake data, the other tries to spot the fakes. Their competition teaches the creator to produce very realistic results.

Are GANs still used?

Yes, though less for text-to-image generation, where diffusion models lead. GANs remain common for fast image synthesis, super-resolution, restoration, data augmentation and as a component that speeds up other generators.

Is a GAN supervised or unsupervised learning?

Usually considered unsupervised or self-supervised, because it learns from unlabeled data. Conditional GANs add labels or paired data, which makes them partly supervised.

What is mode collapse in GANs?

It's when the generator produces only a few kinds of outputs because they reliably fool the discriminator, instead of covering the full variety of the training data.

What is the difference between a GAN and a diffusion model?

A GAN generates an image in one pass, trained through competition with a discriminator. A diffusion model generates by removing noise over many steps, trained with a simpler and more stable objective, and it handles broad text prompts better.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog