What Is a GAN and How Does It Generate Images?

Updated

A GAN, or generative adversarial network, is a machine learning system built from two networks that compete during training: a generator that creates images and a discriminator that judges them. The generator learns by trying to fool the discriminator, and the discriminator learns by trying to catch fakes. Once training ends, the generator alone can turn a random noise vector into a realistic image. GANs are best known for face synthesis, image upscaling, and style transfer, and they differ from diffusion models like Stable Diffusion in both how they train and how they behave at output time.

The two networks and their roles

A GAN has no single model doing all the work. It has a pair with opposite goals.

  • Generator — takes a random input (a noise vector, often called z) and produces an image. Early in training this output looks like static; later it can resemble a face, a product shot, or a texture.
  • Discriminator — takes an image and outputs a score for whether it looks real or fake. It sees both real training images and the generator's fakes.

The two are trained together, and each one's loss depends on the other. That coupling is what makes the setup "adversarial."

The adversarial training loop

Training alternates between the two networks, roughly like this:

  1. Sample a batch of real images from the training set.
  2. Generate a batch of fake images by feeding random noise through the generator.
  3. Update the discriminator so it scores real images high and fake images low.
  4. Update the generator so its fakes score high with the discriminator — in other words, so it becomes more convincing.
  5. Repeat for many iterations.

The intended end state is a generator whose output the discriminator can only guess at (around 50% accuracy, i.e. no better than chance). At that point the generator has captured enough of the data distribution to produce plausible images. In practice, reaching that balance is the hard part.

How a trained generator makes an image

After training, you discard the discriminator and keep the generator. To create an image you:

  • Draw a random noise vector z (for example, 100 or 512 numbers).
  • Pass it through the generator's layers.
  • Read the output image.

Because different noise vectors map to different outputs, sampling new noise gives new images. Many GANs also learn a latent space where nearby vectors produce similar images, which is why you can interpolate between two faces or smoothly change attributes like age or expression. This latent-space structure is what enables editing and style transfer, not just generation.

Common image uses for GANs

  • Face synthesis — generating realistic human faces that don't belong to real people.
  • Super-resolution / upscaling — reconstructing detail in a low-resolution image.
  • Style transfer — restyling a photo to match a painting or another visual style.
  • Image-to-image translation — turning sketches into photos, day scenes into night, and similar mappings.
  • Data augmentation — producing extra training images when real data is scarce.

GANs vs. diffusion models like Stable Diffusion

Both generate images, but the training approach and output behavior differ.

Dimension GAN Diffusion model (e.g. Stable Diffusion)
Core mechanism Generator vs. discriminator competition Iterative denoising of noise into an image
Training signal Adversarial loss from the discriminator Reconstruction loss over many noise steps
Generation speed Usually one forward pass — fast Many denoising steps — typically slower
Output character Can be sharp but sometimes unstable Often more varied and stable
Common failure Mode collapse, artifacts Slow sampling, high compute

A practical way to think about it: a GAN learns to produce a convincing image in one shot, while a diffusion model learns to clean up noise step by step until an image emerges. Astria, for instance, builds its image production tools on Stable Diffusion and Dreambooth rather than a GAN, which reflects how much of today's commercial image generation has moved toward diffusion.

Typical GAN failure modes

  • Mode collapse — the generator produces only a narrow set of outputs, ignoring much of the training distribution. You might get the same few faces over and over.
  • Training instability — the generator and discriminator fall out of balance; one overwhelms the other and learning stalls.
  • Artifacts — checkerboard patterns, distorted edges, or unnatural textures, especially in high-frequency detail.
  • Memorization — the generator reproduces training images too closely instead of generalizing.

These issues are why GAN training is often described as delicate, and why diffusion models became the default for many image-generation products.

How to tell which method you're looking at

If a tool generates an image in a single fast pass and is described as "adversarial," it's likely a GAN. If it describes a denoising process, a number of sampling steps, or is built on Stable Diffusion or Dreambooth, it's a diffusion approach. Knowing the difference helps you set expectations: GANs tend to be fast and sharp but can be unstable, while diffusion models tend to be slower but more controllable and varied.