What it is
A generative adversarial network (GAN) is made of two networks that compete. The generator makes fake examples, for example images; the discriminator tries to tell fakes from real ones. Each improves by trying to beat the other, until the fakes are hard to tell apart from real data.
What it is for
Producing realistic images, faces and textures, translating one kind of image into another, and creating extra training data. Diffusion models have largely replaced GANs for general image generation, but GANs are still faster at generating and remain a good way to understand generative learning.
How to do it
- Pick the data you want to imitate, such as a folder of 64 by 64 pixel images, and prepare it at one size.
- Build or choose two networks: a generator that turns random numbers into an image, and a discriminator that outputs real or fake.
- Train in turns: show the discriminator real and fake images, then update the generator so its fakes fool the discriminator.
- Watch generated samples as training goes on, not only the loss, since a GAN's loss numbers say little about picture quality.
- Look out for the usual problems: training that never settles, and the generator repeating the same few outputs (mode collapse).
- Once it works, sample new images from random numbers, and check them for artefacts.