Back to Articles Generative AI • 17 min read

GANs: How AI Generates Realistic Images from Scratch

AI generated abstract art

In 2014, Ian Goodfellow and colleagues published a paper that would become one of the most cited in AI history — introducing Generative Adversarial Networks (GANs). The idea was startling in its simplicity: pit two neural networks against each other in a game, and watch them collectively produce outputs indistinguishable from reality. Today, GANs generate photorealistic human faces, compose original artwork, synthesize medical imaging data, and drive the AI art revolution.

"The most interesting idea in the last ten years in machine learning." — Yann LeCun on GANs

1. The Generator vs. Discriminator Game

A GAN consists of two competing neural networks:

🎨 Generator (G)

Takes a random noise vector as input and outputs a synthetic sample (e.g., an image). Its goal: fool the Discriminator into believing the fake is real. Starts completely random; improves iteratively.

🔍 Discriminator (D)

Takes an image (real or generated) and outputs a probability: real or fake? Its goal: correctly distinguish authentic training data from Generator outputs. Trained simultaneously with G.

This adversarial setup is formalized as a minimax game:

min_G max_D [ E[log D(x)] + E[log(1 − D(G(z)))] ]

The Discriminator maximizes this objective (better at detecting fakes). The Generator minimizes it (better at fooling the Discriminator). At Nash equilibrium, G produces samples that D cannot distinguish from real with better than 50% accuracy — random guessing.


2. Training Walkthrough

  1. Sample real data — draw a batch of real images from the training dataset.
  2. Generate fakes — sample random noise vectors z and pass through G to create fake images.
  3. Train D — maximize D's ability to classify real as 1 and fake as 0. Update D's weights via backprop.
  4. Train G — freeze D, generate new fakes, compute D's output on them, and backpropagate the fooling loss into G's weights.
  5. Repeat — alternate thousands of times until G produces convincing outputs.
import torch
import torch.nn as nn

# Minimal Generator
class Generator(nn.Module):
    def __init__(self, noise_dim=100, img_dim=784):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(noise_dim, 256), nn.ReLU(),
            nn.Linear(256, 512),       nn.ReLU(),
            nn.Linear(512, img_dim),   nn.Tanh()
        )
    def forward(self, z):
        return self.net(z)

# Minimal Discriminator
class Discriminator(nn.Module):
    def __init__(self, img_dim=784):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(img_dim, 512), nn.LeakyReLU(0.2),
            nn.Linear(512, 256),     nn.LeakyReLU(0.2),
            nn.Linear(256, 1),       nn.Sigmoid()
        )
    def forward(self, x):
        return self.net(x)
            

3. GAN Variants Timeline

YearModelInnovation
2014Original GANAdversarial training concept introduced.
2015DCGANDeep Convolutional GAN. Used conv layers for stable image generation.
2017Progressive GANNVIDIA's method of growing both G and D progressively from low to high resolution.
2018StyleGANStyle-based generator enabling per-level style control. Powered thispersondoesnotexist.com.
2021StyleGAN3Alias-free generation; eliminated texture sticking artifacts.
2022+Diffusion ModelsGradually replaced GANs for highest-quality synthesis (DALL-E 2, Stable Diffusion).

4. Real-World Applications

While GANs have been significantly challenged by diffusion models in raw quality benchmarks, they remain faster to sample from and easier to condition, keeping them highly relevant in real-time and resource-constrained applications.

Reviewed by the Synapse Editorial Team

Last Updated: July 2026. Our content is rigorously reviewed by computer science educators and industry professionals to ensure accuracy, objectivity, and educational value.