0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09The forger and the detective
Imagine a forger trying to produce fake banknotes, and a detective trying to spot them. At first, the fakes are crude and the detective catches them easily. So the forger improves. That forces the detective to look more closely, which forces the forger to improve again. Locked in this contest, both get better and better, until the fakes are almost impossible to tell from the real thing. In two thousand fourteen, that idea became one of the most influential inventions in deep learning: the generative adversarial network, or GAN.
Two neural networks, a generator and a discriminator, trained against each other. GANs produced the first truly sharp, photo-realistic generated images. Today, let's see exactly how the contest works, and why it's so hard to referee.
1:01Where we are: GANs
Season Three, Module Twelve, stop two: generative adversarial networks.
1:08The generator and the discriminator
A GAN has two networks. The generator takes a random vector, a handful of numbers drawn from a normal distribution, like the VAE's latent space, and turns it into an image. At first, its images are noise. The discriminator is an ordinary image classifier, like the CNNs from Season Two. Show it an image, and it outputs the probability that the image is real rather than generated. During training, the discriminator sees a mix: real Brightcart product photos, and the generator's fakes. Its job is to tell them apart. The generator's job is to fool it.
1:50The losses
The discriminator is trained exactly like the logistic regression from episode eleven: binary cross-entropy, with real images labelled one and fakes labelled zero. Suppose it says ninety percent real for a real photo, and twenty percent real for a fake. Its loss is minus the log of zero point nine, plus minus the log of zero point eight: about zero point three three. Pretty good. The generator wants the opposite: it wants the discriminator to say "real" for its fakes. The original formulation had the generator minimise the log of one minus the discriminator's score.
But early in training, when the discriminator easily spots the fakes, that curve is almost flat, so the generator gets almost no gradient to learn from. So in practice, the generator maximises the log of the discriminator's score instead, by minimising minus the log. When the discriminator gives a fake only twenty percent, this loss is about one point six: a strong push. As the fakes improve to fifty percent, it drops to about zero point seven. Same goal, much better gradients exactly when the generator needs them.
3:10The training dance
Training alternates. First, update the discriminator for a step, on a batch of real and fake images. Then update the generator: generate fakes, pass them through the discriminator, and backpropagate the discriminator's verdict all the way back into the generator's weights, while holding the discriminator fixed. Picture it as a chase. The real data has a certain distribution. The generator's fakes start somewhere else. The discriminator learns where the boundary lies, and its gradients tell the generator which way to move to look more real.
Step by step, the fake distribution slides towards the real one. In theory, the contest ends when the generator's images are indistinguishable from real ones. At that point the discriminator can do no better than a coin flip: it says fifty percent for everything.
4:05Why GANs are hard to train
That's the theory. In practice, GANs are famously hard to train. Instead of both players steadily improving, the losses can see-saw back and forth without ever settling. If the discriminator gets too strong, too fast, it rejects every fake with total confidence, and the generator's gradients dry up. If it's too weak, it gives useless feedback. And there's no single number that tells you training is going well. In the digit reader, a falling validation loss meant progress. Here, two losses are fighting each other, so neither one alone tells you whether the images are getting better.
Researchers developed many stabilising tricks: special architectures, normalisation inside the discriminator, alternative loss functions, and careful balancing of the two learning rates.
4:57Mode collapse
One failure is so common it has a name: mode collapse. Brightcart's catalogue contains many kinds of products: mugs, lamps, kettles, cushions. A collapsed generator discovers one kind of image that fools the discriminator, say a particular blue mug, and produces nothing else. Every sample looks almost the same. Sometimes it becomes a chase: the discriminator learns to reject blue mugs, so the generator switches to producing only lamps, and so on, never covering the full variety of the real data. Many later GAN designs include tricks specifically to encourage diversity.
5:37Measuring a generator (FID)
How do you measure whether generated images are good? Looking at them helps, but it's subjective. A widely used automatic score, the Fréchet Inception Distance, passes real and generated images through a pre-trained image network, and compares the statistics of the features it extracts. If the generated images' features are spread out like the real ones, the score is low, which is good. It captures both realism and variety, though only roughly. Human judgement still matters.
6:11Steering GANs: conditional and style-based
GANs grew very capable. Conditional GANs take a label as an extra input, so you can ask for a mug or a lamp. Image-to-image GANs turn one kind of picture into another: a sketch into a photo, a day scene into night, or a product outline into a rendered product image. And style-based generators separated coarse features, like shape and pose, from fine ones, like texture and colour, producing strikingly realistic faces with fine control. For turning text descriptions into images, though, a newer approach called diffusion took over, because it's more stable to train and covers variety better.
GAN ideas still live on, especially where speed matters, like fast image enhancement. A quick note: names, prices and rankings in AI change fast. Everything on screen was accurate when this video was made, but some of it may have changed by the time you're watching.
7:11Deepfakes and responsible use
Realistic generated faces brought real risks. Face-swapped videos, often called deepfakes, can impersonate people, enable fraud and spread misinformation. Responses include consent and clear policies, labelling synthetic media and recording where content came from, detection tools, which are themselves in a kind of adversarial race, and laws and platform rules. For Brightcart, the policy is simple: generated imagery only for its own products, clearly disclosed, and never imitating real people.
7:47Pause & Predict: the loss at equilibrium
Earlier, a confident discriminator had a loss of about zero point three three. Now suppose it says zero point six for a real image and zero point six for a fake. Its loss jumps to about one point four three: it's being fooled. So what's its loss at the perfect equilibrium, where it can only say a half for everything? Pause.
Minus the log of a half, twice: about one point three nine. Here's the counter-intuitive part. In a GAN, a discriminator loss hovering around one point three nine can be a good sign: it may mean the generator's images are hard to tell from real ones. Unlike normal training, a falling loss isn't the goal.
8:37Why the generator's loss was flipped
Why did practitioners switch to the non-saturating loss? Let's measure it. Early on, the generator is terrible, and the discriminator gives its fakes a score of zero point zero one. With the original loss, the gradient flowing back is about zero point zero one: almost no signal, exactly when the generator needs help the most. With the non-saturating loss, it's about zero point nine nine, ninety-nine times stronger. Same goal, completely different learning speed.
9:11Reading GAN training curves
Reading GAN curves takes practice. If the discriminator's loss falls to zero, it's winning too easily, and the generator gets little useful signal; weaken or regularise the discriminator. If the losses swing wildly, the players are chasing each other in circles; lower the learning rates. And the sneakiest case: the losses look fine, but every sample looks the same. That's mode collapse, and only looking at the samples reveals it. With GANs, always look at the pictures, not just the numbers.
9:47Try it yourself: a one-dimensional FID
FID compares the average and the spread of features from real and generated images. Here's a one-dimensional version. Real features are centred at zero with a spread of one. Generator A is centred at a half, with the right spread. Generator B is perfectly centred, but its spread is only zero point three: too little variety. Which scores worse? Pause.
Generator A scores zero point two five. Generator B scores zero point four nine, worse, even though its average is perfect. FID punishes a lack of variety, which is exactly what mode collapse looks like.
10:33Translating images: paired and unpaired
GANs can also translate one kind of image into another. If Sana has product sketches with matching finished renders, a conditional GAN can learn to turn a new sketch into a render. But what if there are no matching pairs, say daytime and night-time shop photos? A clever trick uses two generators, day to night and night to day, and adds a rule: translating a photo to night and back again should return the original. That round-trip check lets the model learn without a single matched pair.
11:07Where GANs still work today
Diffusion models now lead much of image generation, but GANs haven't disappeared. They're used to upscale low-resolution photos. Their key idea, a discriminator that punishes unrealistic output, lives on inside other systems: the autoencoders that latent diffusion models depend on are often trained with a discriminator to keep images sharp, and several speech systems use GAN training to produce realistic audio. And when generation must happen in a single fast pass, GANs remain attractive.
11:41Proving what's real
Can we detect fakes? Detectors help, but it's an arms race: as detectors improve, generators improve too. So there's a complementary approach: proving what's real. Cameras and editing software can attach signed records showing where an image came from and how it was edited, and generators can add invisible watermarks. Neither is perfect, but together they help. For Brightcart, the policy is simple: label AI-generated images, and keep the original files.
12:15Myth vs Fact
Myth: you can tell how good a GAN's generator is from the discriminator's accuracy. Fact: in the ideal case, the discriminator ends at fifty percent, but fifty percent can also mean the discriminator has simply stopped learning. You have to judge the generated samples themselves, for realism and for variety.
12:37Recap
Let's recap. A GAN pits a generator, which turns noise into images, against a discriminator, which judges real versus fake. The discriminator learns with binary cross-entropy, and the generator uses the non-saturating loss for strong gradients early on. In the ideal end state, the discriminator can only guess. In practice, training is unstable and prone to mode collapse. Conditional and style-based GANs added control, and realistic generation brought deepfake risks that demand responsible use. One sentence to remember: a forger and a detective, improving each other until fake looks real.
13:20Next: diffusion models
Mission complete. Brightcart can generate sharp images through a contest between two networks, if it can keep the contest stable. Next, the method behind many of today's leading image generators. Instead of a contest, it learns to undo noise: start from pure static, and remove noise step by step until an image appears. The mathematics of noise: diffusion models. See you on the map.