liveBook · Manning

Generative adversarial network

As explained in Learn Generative AI with PyTorch

A generative adversarial network, a model family trained with a generator and discriminator to synthesize realistic data or transform data between domains.

A generative adversarial network (GAN) trains two neural networks together. The generator makes samples intended to resemble the training data; the discriminator tries to tell those samples from real ones. Their competition helps the generator produce more realistic results. Unlike a discriminative model used to assign labels to inputs, the finished GAN is used to create new data. section 1.2.1 section 1.1.1

Figure 1.2 GANs architecture and its components. GANs employ a dual-network architecture comprising a generative model (left) tasked with capturing the underlying data distribution and a discriminative model (center) that serves to estimate the likelihood that a given sample originates from the authentic training dataset (considered as “real”) rather than being a product of the generative model (considered as “fake”).

Follow both paths into the discriminator: one carries training samples, and the other carries samples made by the generator. section 1.2.1

A first GAN project follows a short workflow:

  • Prepare examples of the pattern to reproduce. The generated content depends on this training data. section 3.6
  • Build a discriminator to classify real versus generated samples and a generator to make new samples. section 3.6
  • Train the networks, decide when to stop, then discard the discriminator and use the trained generator. section 3.6

Generate a number pattern

To generate sequences of ten integers that are multiples of 5, first turn the training integers into one-hot variables the networks can use. Build and train both networks, use early stopping, then convert the generator’s output back into readable integers. The same workflow can instead learn pairs of values following an exponential growth curve. section 3.5 section 3.6

The pattern need not be numeric. Training images can lead to generated clothing or face images; a CycleGAN can instead transform an image attribute, such as changing blond hair to black hair and back. GAN projects also extend to music, where choosing a digital representation is part of preparing the data. section 1.2.1 section 1.2.3 section 13.1

How Learn Generative AI with PyTorch covers it

How deep it goes
Develops a build-train-stop-use workflow, including data preparation and early stopping in a number-pattern project.
Examples
Works through exponential-curve data and sequences of multiples of 5, alongside face-image transformation and music generation.
What it assumes
Assumes basic deep-learning skills while preparing readers with PyTorch classification; teaches the generator–discriminator workflow from scratch.
What you can do after
Build it from scratch in PyTorch, then train, save, load, and use a generator to produce patterned samples.
How it connects
Connects binary classification and one-hot encoding to the discriminator, and CycleGAN to image-domain transformation.

Also explained in

Compare how 12 books explain generative adversarial network →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.