From CycleGAN to Diffusion Models
Prerequisite Knowledge
This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.
Previously Covered in This Subject
- Generative Adversarial Networks — generator versus discriminator, min-max training — covered in Lecture 1
- Variational Autoencoders — latent spaces with a Gaussian constraint — covered in Lecture 1
- Normalizing Flow Models — transforming a simple base distribution under the bijectivity constraint — covered in Lecture 1
- Diffusion Models overview — noising forward, denoising backward — covered in Lecture 1
- Denoising Autoencoders — corrupt, encode, decode, compare with the clean original — covered in Lecture 4
- PixelCNN and autoregressive image generation — covered in Lecture 5
These notes close out the GAN family and open the door to diffusion models. We first recap CycleGAN, its losses, and where it breaks. Then come two high-end generators, BigGAN and the StyleGAN family. The second half builds the core idea of diffusion models: destroy data with noise step by step, then learn to undo it.
13.1 CycleGAN Recap and Its Limits
13.1.1 What CycleGAN Transfers, and Where Else It Shows Up
Here is the puzzle that motivates everything in this section: a zebra carries black-and-white body stripes, a horse does not. Can a network learn to move those stripes across - even though nobody can write down the stripes as numbers or rules?
Recall the motivating picture from last time: you have a set of images with horses and a set of images with zebras. The goal of CycleGAN (a GAN that learns translations between two image collections) is to learn a transfer that makes a horse look like a zebra, and one that goes back the other way. The interesting part is that stripes are hard to pin down quantitatively. You cannot say "add stripe at row 40, column 12." Stripes are abstract characteristics of the image style - a holistic look rather than a pixel recipe - yet the network learns to move them across.
The horse-and-zebra pair is only the teaching example, chosen because everyone can instantly see what "characteristics" means here. Think of it like an accent: you cannot list the physical movements of a person's tongue that make a Scottish accent, but you recognize one immediately and could ask an actor to adopt it. CycleGAN does the same job for images. Like an accent, though, the characteristic rides on top of the content - which is exactly where this method will later break down (an accent cannot turn a sentence into a different sentence, and CycleGAN cannot turn a horse into a cat).
The same machinery handles many other swaps of style:
- Text: take an informal passage and make it formal, or take a friendly tone and rewrite it as authoritative. This is characteristic transfer for language rather than pixels.
- Art: move between shape-driven modern art and the soft Impressionist manner of painters like Monet. You could add painterly characteristics to geometric-looking pictures or the reverse. Many photos and many Monet paintings exist, but no photo has a Monet "twin" - which is precisely the situation CycleGAN is built for.
So the general skill is: transfer qualities that resist quantitative description from one collection of data to another.
CycleGAN learns to move un-describable style characteristics between two collections of data that have no one-to-one correspondence - horses to zebras today, prose registers or painting styles tomorrow.
13.1.2 CycleGAN versus Pix2Pix: Paired versus Unpaired Data
It helps to separate CycleGAN from a cousin we saw earlier, the pix2pix GAN (a translation model trained on matched before/after pairs).
In pix2pix you train on paired images: the very same scene given to you twice. A grayscale photo together with the color photo of that same scene is the classic case. Another example: a picture of an animal together with a second image holding just its silhouette or edge map. Each training item is a matched couple, which makes the pairing requirement quite restrictive - somebody had to build those aligned pairs first, and building them is expensive manual labor.
CycleGAN drops that restriction. You only need two buckets of data - horses in one, zebras in the other - with no one-to-one alignment at all. That unpaired setting is what makes CycleGAN so versatile: any two collections of images (or texts) with different styles become usable training material.
| Dimension | Pix2Pix | CycleGAN |
|---|---|---|
| Training data | Paired: same scene twice (photo + its color version) | Unpaired: two separate collections |
| Pairing effort | High - pairs must be built by hand or special capture | None - just gather two buckets |
| Example task | Grayscale to color of the same scene | Horses vs zebras across unrelated photos |
| Supervision source | The ground-truth pair itself | A round-trip consistency demand (next subsections) |
When to pick which: if true aligned pairs exist (or can be made), pix2pix gives tighter control; if only two unrelated collections exist, CycleGAN is the option.
13.1.3 Two Generators, Two Critics
The architecture reflects the round trip. There are two generators:
- maps from domain to domain . With our example, takes a horse image and produces a zebra-looking image.
- maps back from to , turning a generated zebra into something horse-like again.
There are also two discriminators, sometimes called critics:
- judges whether an image is a real zebra from the zebra collection.
- judges whether an image is a real horse.
Picture two parallel conveyor belts running in opposite directions between two warehouses. Each belt has a quality inspector at its end who only knows what genuine goods from their own warehouse look like. This doubled setup - a pair of generators plus a pair of critics - is the fundamental structural difference between CycleGAN and the single-generator GANs we studied before it. Every piece of the loss machinery below belongs to one of these four players.
13.1.4 The Adversarial Loss Term
Each direction gets its own adversarial loss. For the horse-to-zebra side, the loss described in class was "maximise log of plus log of one minus ". Written out for samples drawn from the horses and drawn from the zebras:
Every symbol, named:
- outputs a realness score in - how confident the critic is that its input is a genuine zebra.
- is the fake zebra created from horse .
- is the empirical distribution of the dataset - averaging over it (the operator) means "average over many sampled images."
- and name the two domains (horses and zebras).
The push-pull works like this. Notice first that because , both logarithms are at most zero: is the best possible value, and values fall toward negative infinity as the argument approaches zero.
- For a real zebra , we want a high value of , so is close to zero - its best case.
- For a fake zebra , the critic should output a small score, pushing toward . Log of a small number is a strongly negative quantity, so this term rewards pushing toward zero.
We maximize the whole expression with respect to and minimize it with respect to . Minimizing means gets better and better until approaches one - the critic itself starts believing the fake zebras. When training succeeds, a horse is converted into a zebra so convincing that it looks like the true zebras sitting in the training set.
A tiny numerical feel for the tug-of-war. Let the critic score a real zebra at and a fake zebra at . Then
Now suppose the generator improves and the fake scores :
The value climbed from toward its ceiling of . If instead the critic wins and pushes the fake score to , the second term collapses to . One expression, two opposite desires: that is the whole adversarial game in three lines of arithmetic. Sense-check: both logs stay at most zero, so the sum can never exceed zero - matching the theory above.
13.1.5 The Cycle Consistency Loss
Adversarial pressure alone says "look like a zebra" but says nothing about preserving the horse underneath. A critic cannot see the original horse, so nothing stops from inventing a completely different zebra-scene. So CycleGAN adds a round-trip demand. Take the generated zebra , pass it through the backward generator , and compare the result with the original horse . The comparison uses the L1 norm - the sum of absolute pixel differences, written :
Walk through both halves:
- First half: horse to zebra (via ), then zebra back to horse (via ). The returned horse must nearly equal the starting horse, measured by the L1 norm.
- Second half: zebra to horse (via ), then horse back to zebra (via ). That loop must return the original zebra too.
Both directions must stay consistent, which is exactly why the method is called cycle consistency. The round trip acts as a virtual supervisor: even without a single matched pair, the demand "go there and come back unchanged" pins the translation down.
Why L1 rather than the squaring L2 norm? Absolute differences penalize every wrong pixel proportionally and tolerate a few extreme outliers, which discourages the blur that squared-error averages tend to produce on images. Texts on image translation routinely prefer L1 for exactly this reason.
Scope: cycle consistency quietly assumes the two domains are near-mirrors of each other - that every horse picture has a plausible zebra counterpart and the map can run both ways without losing information. It holds for texture-and-color swaps on similar scenes. It fails when the transformation discards or reorganizes information (changing an object's shape, moving limbs, altering layout), because no reversible round trip can pass through such an edit.
Exam note: be ready to state why there are two L1 terms and which generator pair each one supervises - the first supervises the then ordering starting from horses, the second the mirrored then ordering starting from zebras.
13.1.6 Full Objective, Minimax, and Patch-wise Scoring
Put the pieces together. The full objective collects the adversarial term for against (which drives high-quality zebra creation from horses), the mirrored adversarial term for against (zebra-to-horse generation judged by the real-horse critic), and the cycle terms:
Here (lambda) balances how strongly the round-trip constraint pulls against realism. In the discussion it was left implicit, but standard presentations include it explicitly - the original CycleGAN work sets , deliberately letting the consistency demand dominate so that content survives translation. We maximize this objective with respect to both discriminators and minimize it with respect to both generators - the same minimax game we solved for earlier GANs, now with four players instead of two.
One more practical detail: the discrimination is patch-wise. Instead of scoring every pixel jointly into a single real/fake verdict, the critic breaks the image into patches and evaluates realness patch by patch, averaging those local judgments. Concretely, the critic is a purely convolutional classifier whose every output unit looks at a small receptive field and votes on whether that region looks real. Local texture is what gives fakes away, so judging locally sharpens the learning signal. This is the same trick used in pix2pix, reused here for both critics.
Example generator and discriminator architectures were shared through the course portal if you want concrete layer-by-layer blueprints.
Exam note: given either domain pair, you should be able to assemble the full objective from memory - two adversarial expectations plus times the two L1 cycle terms - and say which player maximizes and which minimizes.
13.1.7 Where CycleGAN Breaks
CycleGAN has real limitations, and seeing them is instructive.
Whole-image transfer paints the rider too. There is a famous photograph of a national leader riding a horse. Run horse-to-zebra translation on it and the stripes land on the horse nicely - but they also land on the rider. That is a negative artifact: nobody asked for a striped human. Nothing in the model identifies "these pixels are the horse, those are the rider"; there is no object detector inside the loop. The overall image characteristics get moved wholesale, so every object in the frame picks up zebra texture. For conversions on images like this one, paired pix2pix training gives much better luck than CycleGAN, because the pairing pins down where changes should happen.
Second, some tasks need geometric change, and CycleGAN cannot handle it. Think about turning a dog into a cat: you are not just recoloring fur, you are reshaping the structure of the face - muzzle length, ear placement, eye size. As you try to impose cat characteristics, the object's geometry would have to deform, and the cycle-consistency machinery does not support that kind of structural edit. Characteristic-swap tasks suit CycleGAN; shape-reshaping tasks do not.
Two beginner traps worth flagging before you walk into an exam:
- Assuming CycleGAN understands objects. It matches global statistics between domains; it has no notion of "horse" or "person" as things. Any segmentation-like behavior you observe is an accident of the data, not a capability.
- Reaching for CycleGAN when pairs exist. With true paired data, pix2pix usually gives cleaner, more faithful results - CycleGAN's freedom becomes a liability, not a feature.
Real-world: this limitation profile matters wherever style migration meets people - photo editing apps translating portraits must either segment the human first or accept artifact bleed onto skin, hair, and clothing. The broader field lesson is that unsupervised translation trades supervision for a consistency assumption, and every assumption draws a boundary around the method.
13.2 BigGAN: Scale, Fidelity, and Control Knobs
13.2.1 Why "Big", and How Deep
BigGAN earns its name from its compute appetite. It generates very large images - on the order of 1024 by 1024 - while keeping crisp, fine detail. Large size alone is easy; the trick is doing it without blocky, low-resolution artifacts. BigGAN delivers high resolution and high fidelity (fine detail actually rendered, not smeared) together. At 128 by 128, a face may have no visible eyelashes or skin pores; at 1024 by 1024 those details exist and look right.
How does it get there? By stacking layers aggressively. The generator starts from a tiny spatial block produced from the random vector - think 4 by 4 - and climbs a long ladder:
| Stage | Spatial size |
|---|---|
| 1 | 4 x 4 |
| 2 | 8 x 8 |
| 3 | 16 x 16 |
| 4 | 32 x 32 |
| 5 | 64 x 64 |
| 6 | 128 x 128 |
| 7 | 256 x 256 |
| 8 | 512 x 512 |
| 9 | 1024 x 1024 |
Worked example: counting the ladder. Each stage doubles both width and height, so each stage multiplies the pixel count by four. From 4 to 1024 the side length grows by a factor of . Since means eight doublings, there are 8 upsampling stages:
Each stage holds around 2 convolution layers rather than one, so the generator lands near convolution layers, and the discriminator mirrors that depth. Sense-check: nine table rows minus the starting block equals eight growth steps, matching the factor-of- count.
Both networks are very large. A caution from class: you will not retrain BigGAN-scale models on the resources allotted in this course - treat it as an awareness-level architecture, with references provided for when a real need arises.
13.2.2 Stabilizers: Residual Blocks, Self-attention, Orthogonal Weights
Training networks this deep runs straight into vanishing and exploding gradients (gradients that shrink to nothing or blow up as they travel through many layers). So BigGAN borrows the standard remedies and adds its own:
- Residual blocks with skip connections. A residual block computes a small change and adds it back to the input: output equals input plus f(input). The skip connection is that identity path which carries the input around the transformation untouched. Gradients can then flow backward through the shortcut instead of squeezing through every layer, which keeps them healthy across sixteen-plus layers.
- Self-attention, the mechanism introduced in the SAGAN architecture, lets each output location decide where to draw information from when rendering a pixel. Attention tells the layer which regions matter most for the pixel being produced - so distant, coordinated parts of an image (an ear on one side, an eye on the other) can agree instead of being drawn independently.
- Orthogonal regularization: every layer of the generator holds a bundle of weight vectors. BigGAN adds a penalty encouraging these vectors to stay mutually orthogonal (at right angles to each other):
Here collects the weight vectors of a layer, and is their inner product - zero exactly when two vectors are orthogonal. Squaring and summing over all unequal pairs punishes any overlap between directions. Why bother? Orthogonal directions carry independent, non-overlapping information about the input, so each weight vector captures distinct, canonical factors rather than redundant copies of each other. It doubles as a regularizer that keeps the huge model from overfitting.
13.2.3 The Truncation Trick: Fidelity versus Variety
Here is one of the most exam-worthy ideas in BigGAN. The input to the generator is a random vector , drawn dimension by dimension from a Gaussian - a bell-shaped probability distribution centered on the mean. Sampling from the full bell curve sometimes lands you far out in the low-probability tails, and those rare far-out vectors produce strange, defective images.
The BigGAN inventors added a truncation trick: generate the random number, but keep it only if it falls near the mean, inside a high-probability band. Formally, restrict each component of the latent vector to a window of radius (psi, measured in standard deviations) around the center:
In practice this is implemented by rejection sampling: draw a candidate , measure how far it sits from the mean in standard deviations, and redraw it if it exceeds . Keeping the latent inside the high-probability range made the generated images noticeably clearer and higher in quality - even at 1024 by 1024.
But there is a price, and it was posed to the room as a question:
Q: If truncation lifts quality, what intuitively could go wrong with squeezing the random input into a high-probability band? A: You stop using the full spread of the distribution. Since variety of output comes from variety of the random input, capping that variety caps the diversity of the generated set - all images start looking close to each other, and scores that reward diversity sag. The window width becomes a knob trading fidelity against variety: widen it for more diverse outputs and fidelity drifts down; narrow it for crisper images and everything converges toward similar samples.
Q: Why feed random input at all? A: Because the whole point of a generative model is to produce a large number of realistic samples. Randomness is the source of that variety. Truly random inputs cost some clarity, especially at large output sizes; truncated inputs recover clarity but surrender diversity. Remember this trade-off - it is a favorite conceptual question.
Picture the bell curve with a shaded central band. Narrow the band and the shaded spike grows taller while its footprint shrinks - sharper samples, fewer distinct ones. Widen it toward the full curve and the opposite happens.
13.2.4 Conditional Generation: Class Information at Every Layer
BigGAN is a conditional GAN: besides the random vector, you specify a target class - dogs, outdoor scenes, even X-ray images (the same conditioning idea applies across domains). The class label passes through an embedding layer (a lookup table turning each label into a learned numeric vector), and the resulting embedding is injected into the generator and also into the discriminator, so the critic knows which class it should be judging.
The subtle part: class information is fed at every layer of the generator, not just at the input. If you inject it only at the first layer, the class signal fades away as activations pass through the many subsequent layers - like whispering instructions once at the start of an assembly line and hoping the last station still remembers them. Feeding it into every block keeps the conditioning alive all the way to the output.
13.2.5 Splitting the Latent Vector: Layer Specialization
The second structural innovation concerns how enters the network. Rather than handing the whole vector to the first layer, BigGAN splits into chunks - think - and sends different chunks to different layers of the generator.
Why bother? Feeding the entire vector only at the entrance entangles all the characteristics of the image into one mixed signal. Splitting lets different layers specialize: one subset of values steers texture types, another shapes, another controls how much a face smiles, another whether eyeglasses appear, another skin tone. Each layer becomes responsible for particular characteristics because its own chunk of randomness controls them.
If this rings a bell, it should. We met the same disease and cure in VAEs. Recall β-VAE: with beta equal to one you have a standard VAE whose latent space merely matches a Gaussian prior. Raising beta pushes the latent space to orient along the axes, making the covariance matrix diagonal instead of full of cross-terms - disentangled factors, meaning each coordinate controls one human-interpretable attribute. BigGAN achieves a similar disentangling effect architecturally: chunking the latent and routing chunks to dedicated layers separates the factors that previously got mixed.
13.2.6 Architecture Sketches, Huge Batches, and the SNGAN Link
A concrete sketch ties it together. In the walkthrough diagram, the raw latent was shown as a 160-dimensional vector, while earlier narration described a 128-dimensional ; published BigGAN models likewise use a 128-dimensional , so treat the exact figure as a course-diagram detail rather than a fixed constant. The number of classes was stated as 128, encoded through a learned embedding. Latent plus embedding together form the generator's input. Resolutions then climb stage by stage while channel counts shrink. The generator ends with a tanh hyperbolic activation, squashing outputs into a fixed range so they can represent an image. The discriminator runs the mirror-image pipeline, shrinking spatial size while growing channels, and it consumes the class information too.
Two more practical notes. First, BigGAN tolerates enormous batch sizes, and quality holds up - batch size should scale roughly in proportion to the total number of training samples. Second, model size can be pushed arbitrarily; quality keeps improving with scale.
On the family tree: BigGAN subsumes tricks from its predecessors. It incorporates spectral normalization (the stabilization device introduced in SNGAN, which rescales weight matrices so the discriminator cannot grow arbitrarily sharp), alongside self-attention from SAGAN, orthogonal regularization, per-layer conditioning, latent chunking, and truncation. Stack all of that and it outperforms techniques like SNGAN by a wide margin - at a matching compute cost.
Real-world: BigGAN-class conditional synthesis is the ancestor of today's high-resolution stock-image generators; the control knobs you just met (class conditioning, truncation strength) survive in modern production systems as the levers operators pull when outputs need to be sharper or more varied. For the exam, the architecture itself is awareness-level - the truncation trade-off is the part to know cold.
13.3 StyleGAN and Its Three Versions
13.3.1 Styles, and the Mapping Network from z to w
What is "style"? Nobody can define it precisely, yet everyone sees it instantly - a person looking old-fashioned versus modern, formal versus casual, stern versus warm. StyleGAN's job is to grab those elusive style attributes and control them, while producing extremely realistic faces.
Its key move reshapes what we did with the latent vector. In plain GANs, goes straight in. In BigGAN, got split into chunks. StyleGAN does neither: it passes through a mapping network built from 8 fully connected layers, producing a new vector . Training shapes so it aligns with the styles present in the training data - each coordinate of drifts toward representing one human-meaningful factor rather than an entangled mixture. Then, at every block of the generator, a learned affine transformation - a linear combination map of - converts into the style parameters that block will use.
Think of as raw pigment squeezed straight onto a canvas, and as a palette that has been organized first: same randomness, but arranged so a painter can reach for "warmer skin tone" or "grayer hair" deliberately. The analogy breaks where palettes are fixed by the manufacturer - here both the palette organization () and the mixing recipe () are learned.
So the pipeline becomes:
The network transforms raw randomness into style coordinates before touching the image.
13.3.2 AdaIN: Adaptive Instance Normalization
How do style parameters actually steer a block? Through adaptive instance normalization, or AdaIN. The formula discussed in class was read out as "x-i minus mu of x-i, divided by sigma of x-i, multiplied by y-s-i and y-b-i":
Read it piece by piece:
- is channel of the block's feature map.
- and are that channel's mean and standard deviation computed per instance - per single sample being generated, not across a batch like batch normalization.
- The fraction strips the channel down to zero mean and unit spread - wiping out its current contrast-and-brightness fingerprint.
- rescales and shifts the normalized channel; these are the learned style scale and shift derived from the affine transform of .
In one sentence: erase the channel's own statistics, then paint on the statistics the current style asks for. Before each convolution, the block normalizes its input and immediately restyles it this way. Every level of the generator gets its own styles, which is what makes fine stylistic steering possible - coarse blocks receive styles controlling pose and face shape, fine blocks receive styles controlling hair strands and freckles.
A tiny numeric trace of AdaIN. Suppose channel holds values with mean and standard deviation , and the current style says , . Take one activation :
The original value 0.8 becomes 2.15 - stretched by the new contrast and shifted by the new bias. Change only and every value in the channel moves together, which is exactly how one style vector re-grades a whole feature map at once. Sense-check: had equaled the mean 0.5, the output would be exactly , confirming the centering works.
13.3.3 Noise Injection for Stochastic Fine Texture
StyleGAN adds one more input: noise, injected directly into blocks at multiple levels. This noise supplies stochastic variation - the tiny random details real photos have. Compare renders with and without it: without noise, surfaces look flat, like airbrushed regions with unnaturally smooth "air" distribution; with noise, you get individual hair strands, pores, grain - genuine fine-grained texture. More noise injection means finer stochastic detail in the rendered result.
Why a separate noise path at all? Because randomness that should move whole styles (age, pose) and randomness that should scatter tiny details (exact positions of stubble hairs) are different kinds of variation. Giving each its own input lets the network keep them apart instead of entangling them in .
Real-world: the classic style-mixing demonstrations let you copy attributes between two synthesized people - take the hairstyle from source A and place it on the identity from source B, swap facial hair distributions, or exchange eyeglass styles. Each attribute lives in specific layers, so mixing at chosen depths moves exactly those characteristics.
13.3.4 Droplet Artifacts and the StyleGAN2 Remedy
Version 1 had a visible flaw: droplet artifacts. Blob-like marks resembling water droplets appear in flat regions of the image, seemingly out of nowhere. The culprit is AdaIN itself - the instance-level adaptive normalization leaves those traces, especially where the image is smooth.
This matters beyond aesthetics. Machine-generated faces became hard to distinguish by eye, so websites appeared that test whether a face photo is artificially generated - a useful reality check now that fakes look authentic unless you know the technology's tell-tale signs.
StyleGAN2 fixed the droplets by removing AdaIN. In class this was described as replacing version 1's mean-and-standard-deviation computation with a modified calculation of the statistics; standard accounts describe the same redesign more precisely as weight demodulation, where the normalization moves from the activations into scaled-down convolution weights whose per-channel gain is divided out after the convolution. Both descriptions point at the same fix: drop the per-instance normalization block, keep learned per-channel scaling. Droplet artifacts disappear once that normalization block is gone.
But StyleGAN2 introduces its own problem: phase artifacts.
13.3.5 Phase Artifacts, Texture Sticking, and StyleGAN3
Phase artifacts are hard to explain in words but obvious in pictures. Consider a synthesized smile: the teeth show left-right symmetry, and the tip of the nose sits centered above them. Now rotate or shift the face in the image. The head moves - but the midpoint of the teeth stays put. One part of the image lags while another swings away, a clear phase mismatch between image regions. Features literally stick in place. This failure is called texture sticking, and the normalization design of StyleGAN2 is again the responsible block.
Hold the professor's picture firmly: rotate the whole head, and the teeth-midpoint refuses to travel with it. Any generative model whose internal details refuse to move coherently with the global geometry has left a fingerprint that detectors can spot.
StyleGAN3 attacks it with a more complex architecture: extra layers in the generator working alongside the mapping network, plus query-based features for sampling detail at arbitrary positions - the phrase in class was partly garbled, but the standard account is a redesigned generator that treats the image as a continuous signal rather than a grid of pixels, so textures ride along when the content rotates or translates. Texture sticking goes away. The cost: StyleGAN3 is the most expensive of the three to run, and it also produces the best results.
The version story in one line: StyleGAN1 has droplets from AdaIN; StyleGAN2 removes AdaIN, killing droplets but adding texture sticking; StyleGAN3 kills sticking with more machinery and tops the quality charts.
| Version | Signature artifact | Root cause | Fix strategy |
|---|---|---|---|
| StyleGAN1 | Water droplets in flat regions | AdaIN instance normalization | Removed in v2 |
| StyleGAN2 | Texture sticking under rotation | Normalization/upsampling design | Continuous-signal generator |
| StyleGAN3 | None (best quality) | - | Most compute-hungry |
Extra reading lists further GAN variants; more pointers were promised for the course portal.
13.4 Diffusion Models: The Core Idea
13.4.1 Ink in Water: The Physical Picture
Post-GAN, the technique making the biggest impact on high-quality generation is the diffusion model.
Its name comes straight from physics class. Take a clear glass of water and drop red ink into it. The ink spreads from its high-concentration region into the low-concentration clear water, forming shifting patterns over time, until everything stabilizes as uniformly pale reddish water. That spreading process is diffusion: movement from high density toward low density until a balanced steady state is reached.
Two properties of the ink make it the perfect anchor for what follows. First, the spreading happens in many tiny, almost random nudges - not one big jump. Second, the end state carries no trace of where the drop landed: uniform pale water looks the same no matter which corner you dripped into. Diffusion models copy both properties exactly.
13.4.2 From Physics to Data: Noise Up, Then Learn to Undo
Apply the same idea to data. Start with real data - say a flower image. Add a little noise. Add some more. Keep going step by step, , iteratively. If you iterate long enough, the original character disappears completely and what remains looks like pure random data - asymptotically something like a Gaussian distribution, just like the pale uniform water at the end of the ink experiment.
Generation reverses the arrow, and this is the heart of the idea:
- Take original data and incrementally add noise of a specific nature, many times, until you reach a random distribution.
- Learn the noise reversal process using a deep network - a denoising operator that steps backward from noisier to cleaner.
- At generation time, sample from the Gaussian, then apply the learned reversal repeatedly. After enough reverse steps you get data obeying the same distribution as your training data, yet different from any actual training point.
How is the reversal learned? Through likelihood maximization: choose the reversal-network parameters so that the data regenerated along the reversed chain has maximal probability under the model. Section 13.4.9 makes this concrete.
Speed warning: iterative sampling makes generation slow - you create the image gradually, step after step, often hundreds or thousands of them. And the idea reaches beyond images: diffusion can serve natural language processing too, provided you move from a continuous distribution to a discrete one; latent diffusion models exist for text.
13.4.3 Closest Relatives: Variational Autoencoders and Flow Models
Which familiar model is closest? The variational autoencoder. In a VAE you sample from the latent space's Gaussian distribution and push the sample through the decoder once to get data. Training maximizes data likelihood minus the KL divergence between the encoder's output distribution and the standard Gaussian (KL divergence measures how one probability distribution differs from another). Diffusion differs in one key way: the VAE decodes in a single step, while diffusion walks through many steps.
The truer relative is the hierarchical VAE. There you chain latents - , then from it, then - with layered encoders and layered decoders unwinding them back to data. Those stacked decoding stages play the role of diffusion's repeated denoising iterations. A useful way to see diffusion: a hierarchical VAE whose encoder is fixed by design (it just adds known noise), so only the decoder chain needs learning.
Flow models share the skeleton too. A flow model applies bijective transformations - invertible maps where every input has exactly one output and back again - to warp the data distribution into a simple Gaussian, samples from that Gaussian, pushes the sample back through inverse transformations, and trains by maximizing likelihood. Same recipe as diffusion: sample simple noise, apply learned reversible steps, maximize likelihood. Diffusion belongs to this family in spirit; it just replaces clean invertible maps with learned incremental denoising.
| Model | Path from noise to data | Steps | Trained how |
|---|---|---|---|
| VAE | One decoder pass | 1 | Likelihood minus KL regularizer |
| Hierarchical VAE | Chained latents, layered decoders | Few | Lower bound on likelihood |
| Flow | Stack of invertible maps | Many (exact inverses) | Exact likelihood |
| Diffusion | Learned denoising chain | Many (hundreds to thousands) | Likelihood bound, denoising loss |
13.4.4 Text-to-Image: What Kind of Learning Is This?
Modern diffusion systems generate photorealistic scenes from typed prompts - "a robot cooking dinner in the kitchen", or "a bread, an apple, and a knife on a table". Where does the knowledge of what a bread or apple looks like come from? Several students pressed on exactly this point:
Q: When a text line like "a bread, an apple, and a knife on a table" drives image creation, what kind of learning lets the system render those objects, and where does the knowledge live? A: It is never one model - several trained components work together. On the vision side, networks are trained on large labeled collections such as ImageNet, which contains images of all kinds of things; a CNN trained there learns what bread means, what an apple means, storing that knowledge in its weights. Those learned features then move into the generative system via transfer learning, grafting recognition knowledge onto a GAN-like or diffusion architecture. On the text side, the prompt words are converted into embeddings - numeric vectors carrying meaning; not simple GloVe-style ones, but richer contextual embeddings whose values depend on the surrounding words. The diffusion model conditions its Gaussian prior on those text embeddings and generates, maximizing the probability that the output matches. Training taught it to produce this kind of data generally, not one particular picture.
Q: Did anything similar appear in the earlier deep neural network course? A: Not really. This pairing of a vision stack with a text-representation stack is newer material, built from pretrained transformer models on the language side.
There is also a self-training loop that sharpens prompt-matching. Given a generated image, run a captioner - a CNN followed by attention and an LSTM/RNN decoder - to describe the picture in words. Compare that machine-written caption with the input caption and train the generator to reduce the difference. Round after round, the system learns to emit images whose captions match their prompts. The same pattern extends to video: analyze the prompt, synthesize successive frames, use an image-to-next-frame transformation, and retrain so consecutive frames match the requested scene.
13.4.5 Missing Categories, Bias, and Hallucination
What happens when the prompt names something absent from training? This drew another cluster of questions:
Q: Suppose the training data contains no cat category at all. What happens to a prompt asking for a cat walking beside a sleeping owner? A: It will not render a proper cat. The word "cat" still gets converted into an embedding vector. The system searches the embeddings it did see during training, finds the closest one, and renders based on that nearest neighbor. The output is an interpolation from whatever category stood closest - in short, the system hallucinates.
Q: Would it be fair to say the model is biased by the text embedding? A: Yes - biased by the missing class information. The bias stems from the absence of that information in training, not from the prompt mechanism itself.
Q: How do we demarcate the two cases - a training-data problem versus a bad input prompt? A: You cannot inspect the training set upfront, so in practice the prompt is simply what you provide, and the system responds by generating whatever lies closest to it. If nothing similar was seen during training, it hallucinates - that is precisely what hallucination means here. The only real fix is retraining with that class included. Otherwise all it can do is interpolate from the closest known embedding. Pragmatically, if you dislike a result, rewrite the prompt: if "cat" keeps yielding dog-like images, try phrasing it as "a cat-like dog" and retry.
This leads to a law worth remembering.
A generative model reproduces its training distribution - nothing more. Picture the training data as one blob in space. Whatever you sample will land inside that blob: this point, that point, or points between. A perfectly learned generative model will not produce data outside the distribution. Out-of-distribution generation needs separate tricks, some of which arrive in the final sessions. Until then: unseen inputs interpolate, and interpolation shows up as hallucination.
13.4.6 A Quick Timeline of Generative Quality
Where do diffusion models sit historically?
- 2013 - original VAE: reasonable results on small images, with visible artifacts. (Not hierarchical VAEs or VQ-VAEs - the plain original.)
- 2014 - original GAN: worked on small black-and-white images in the CIFAR-10 era. A fascinating technique from the minimax-optimization standpoint: rather than learning the probability distribution directly, it learns it implicitly through the two-player game.
- 2016 - PixelCNN and its variants: autoregressive generation improves (the model writes the image pixel by pixel, each pixel conditioned on the previous ones).
- 2019 - BigGAN: sharp, large samples - the architecture we met in Section 13.2.
- After that - diffusion models: the biggest jump in quality, including systems that start from a textual description and render realistic scenes.
One caveat stands: generation stays slow, because quality emerges through many iterative refinement steps.
13.4.7 Forward Process Mathematics
Now the math. Notation first: is a sample from the training data distribution - randomly drawn from the dataset. indexes the noise step, running up to a final time , typically a reasonably large number like 1000. At the image has become , pure Gaussian noise. denotes the identity matrix, giving independent noise in every dimension.
Each forward step adds zero-mean Gaussian noise whose variance grows with . Written as a conditional distribution (shown in class for the first step):
In words: the distribution of given is Gaussian with mean - the previous image shrunk slightly - and covariance . One clarification the class discussion left open: because sits in the covariance slot, it plays the role of a variance, not a standard deviation; the standard treatment likewise treats as the variance of the injected noise at step . Equivalently, you scale by and add fresh noise :
Then repeat with : scale by , add new noise, and so on.
The schedule matters. Use a small at the start and increase the betas as time progresses - gentle perturbations early, heavy corruption late. Add noise enough times and the structure of the object in the image is completely destroyed, leaving standardized Gaussian noise.
Two structural facts. First, this is a Markov chain: the noise added at step depends only on the state at - "the noise here depends on what is here," nothing earlier. Second, training must learn the reverse conditionals: given , find ; given , find ; all the way down to .
13.4.8 One Closed-Form Jump via Reparameterization
Something convenient hides in the forward process: you can express the state at any time directly in terms of , skipping the intermediate steps. Introduce the reparameterization , so each step becomes:
Here is a fresh standard Gaussian drawn at every call - invoke the random number generator anew for each image and each step, so every sample receives different noise.
Now push symbols through the recursion until the chain collapses into one closed form. Start by substituting the formula for into the formula for :
The last two terms are independent zero-mean Gaussians, so their sum is Gaussian with variance equal to the sum of variances:
So - the same shape as one step, with the product in place of a single . Repeating the substitution folds every further step in the identical way (each new factor multiplies the running product, and the leftover variance shrinks to one minus the product), which proves the general pattern by induction - the whole recursion collapses into one jump.
Define the cumulative product:
- alpha-zero times alpha-one times alpha-two, onward to alpha-t; note these alphas shrink toward zero since each factor is below one. Then the marginal distribution of given is Gaussian:
Equivalently, assemble the noisy image directly: multiply the known image by , draw one noise vector, scale it by , and add. A note on indices: the bounds follow the class's zero-based beta indexing from ; common treatments index from beta-one (), which changes only the labels, not the mathematics.
Worked example: jumping straight to step 2 - and checking it numerically. Let (a single value, so all shapes are scalars), , . Then , and the closed form says:
Verify against walking both steps. Step 1: . Step 2 takes the mean of down by : expected mean , matching the one-jump mean. Variance check: step 1 injects variance ; step 2 shrinks it by to , then adds fresh variance ; total , matching . Sense-check passed: mean and spread both agree with the one-jump formula.
Why this matters: pick any training image and any target step , draw , and compute in closed form - no loop over intermediate images needed. This is exactly how training creates its corrupted inputs: jump straight to step , then ask the network to predict the noise that was mixed in, learning the removal process from there.
13.4.9 Reverse Process and the Likelihood Objective
The reverse side learns to walk back down. Learn , then , finally , where collects the neural network's parameters. Multiply the whole chain of conditionals - a product of probabilities:
Maximizing the likelihood of real data through this chain is the training objective. Products are awkward to optimize, so take the logarithm, using the identity that the log of a product equals the summation of logs: . The log turns the product into a sum, and minimizing the negated sum gives the same result:
That is the sketch presented in class: multiply the conditionals, take ln, minimize the negative summed log. How each reverse step is parameterized, and the fuller bound behind this objective - together with energy-based models, whose training ideas influence diffusion - arrives next session.
Sampling then works exactly as advertised. Draw from the Gaussian, apply the trained reversal repeatedly, and out comes an image statistically like the training set. Train two diffusion models on different datasets - flowers in one, dogs in the other - and the same kind of starting noise yields a flower from one and a dog from the other. The training data decides what emerges.
13.4.10 Denoising Autoencoder versus Diffusion Model
A sharp question pinned down the boundary with the denoising autoencoder studied before mid-sem:
Q: How does the denoising part differ from the denoising autoencoder we studied before mid-sem? A: The scope differs completely. In the autoencoder you corrupt the original data with noise you know exactly, then train an encoder-decoder pair to reconstruct the clean original - one step, and the reconstruction goal is recovery of that same input. It is not statistical in nature; it is not a generative model of the data distribution. In diffusion, corruption happens over many steps, and at inference time all you have is a final sample drawn from Gaussian noise - nothing else. Nobody tells you which noise entered; you must estimate the unknown noise at every step with a trained network, and the purpose is generating new data, not recovering a specific input.
Keep the contrast table in mind: known noise versus estimated noise; one step versus a thousand; reconstruct versus generate. Any exam question contrasting the two models resolves into one of these three rows.
13.4.11 Different Starting Noise, Different Flowers
One more exchange clarified what sampling variety really means:
Q: Two different draws of initial noise go through the same trained diffusion network. Do they give two different flowers? A: Yes. Sample the Gaussian once and you may get flower A; sample again and you may get flower B. Which starting draw yields which flower cannot be predicted in advance - but a trained system that removes noise well turns any draw into a plausible member of the class. Two important subtleties. First, the generated flower is generally NOT one of the exact images from the training set - it is a new variation, which is precisely the variation a generative network exists to create. Second, you can even land between two flowers, an interpolation of both. What you cannot do is systematically synthesize an unrelated vegetable, unless such an image could be composed from combinations of the training data.
Real-world: this noise-to-image pipeline is the engine inside modern text-to-image products and medical-imaging synthesis tools, where a hospital can train a generator on its own scans and then manufacture realistic-but-artificial training examples for rare conditions. The broader field placement: diffusion moved generation from adversarial games (GANs) to likelihood-based denoising, trading sampling speed for training stability and coverage - the defining trade-off of the current era.
Exam Guidance Summary
Exam note: expect questions tied to the assignment - likely items give a library call and test whether you can identify its inputs and expected outputs. No code writing happens in the exam itself.
- Exam note: the circulated sample papers do not include assignment-style questions, but live exams may - so participate actively in the assignment work.
- Assignment calibration: prior published results on CIFAR-10 define what a good result looks like, and grading compares against them. Plan to iterate more than 100 times, using a reasonably large number of epochs; image sizes are small, so single runs are not hours long, but parameter tuning takes real time.
- Practice past sample papers; generating and solving extra practice questions with ChatGPT was endorsed as preparation.
- The quiz opens right after the assignment deadline with a 7-day completion window - revise the material as you answer.
- Team note: the assignment is sized so that multiple contributors are needed to turn in strong work by the fixed deadline.
Concept-level emphasis flagged during discussion, collected in one place for revision:
- The truncation trick's fidelity-versus-variety trade-off (narrow the band: crisper but more alike).
- Choosing pix2pix versus CycleGAN for a given dataset type (paired data favors pix2pix; two unrelated buckets force CycleGAN).
- The denoising-autoencoder-versus-diffusion distinction (known noise/one step/reconstruct versus estimated noise/many steps/generate).
- The forward-process schedule - small noise early, heavy noise late - and the closed-form marginal .
Key Industry Applications
- Unpaired style translation between image collections (horse to zebra as the canonical demo): photo studios and dataset builders translate whole collections without paying for matched pairs.
- Text style transfer - informal to formal register, friendly to authoritative tone: writing assistants and customer-service rephrasers apply the same characteristic-moving machinery to language.
- Artistic style migration between genres, e.g., shape-driven modern art versus Impressionist painting in the manner of Monet: creative tools offer one-click genre conversion of user photos.
- Pix2pix paired translation - grayscale-to-RGB colorization, photos and silhouette/edge maps: restoration pipelines for archives, and sketch-to-render tools in design software.
- BigGAN-class systems for 1024 x 1024 high-fidelity synthesis; conditional class control supports domains from animals to outdoor scenes to X-ray imagery: stock-image synthesis and data augmentation where class labels steer output.
- StyleGAN face synthesis with controllable attributes - hairstyle, facial hair, eyeglasses - via style mixing between source identities: avatar creation for games and virtual presenters.
- Detecting synthetic media: websites exist that test whether a face photo is machine-generated, relevant because artifacts like droplets and texture sticking are the tells; each generator generation fixes old artifacts, so detectors must track new ones.
- ImageNet-trained classifiers supply visual knowledge to generative systems through transfer learning: recognition features learned once are reused wherever a generator must know what objects look like.
- Text-conditioned generation pipelines combine contextual text embeddings (beyond GloVe) with diffusion or GAN-like decoders; captioning networks (CNN plus attention plus LSTM/RNN) provide feedback for self-training: this is the architecture pattern behind prompt-to-image products.
- Prompt-driven video synthesis extends frame by frame with image-to-next-frame transformations matched to the prompt: storyboarding and pre-visualization tools generate moving scenes from scripts.
- Pretrained transformer models on the language side power the text understanding in modern generative stacks: every text-to-image system leans on a language model that turns your words into vectors the image side can condition on.
UDL Lecture 13 notes · From CycleGAN to Diffusion Models
Sections Breakdown
Unpaired style translation with two generators and two critics: adversarial loss, L1 cycle consistency, the full minimax objective, patch-wise critics, and where CycleGAN breaks.
Deep residual self-attention stacks reaching 1024x1024, orthogonal regularization, the truncation trick's fidelity-versus-variety trade-off, class conditioning at every layer, and latent chunking.
The mapping network from z to w, AdaIN style injection with noise for fine texture, droplet artifacts in v1, texture sticking in v2, and StyleGAN3's continuous-signal fix.
Forward noising Markov chain, closed-form marginal via reparameterization, reverse denoising chain trained by likelihood, VAE and flow relatives, hallucination limits, and sampling variety.
Assignment-linked exam logistics plus the four concept-level emphases flagged for revision.
Named industry uses across the GAN family and diffusion, from unpaired translation to text-to-image pipelines.
Exam Revision Notes
Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.
CycleGAN Recap and Its Limits
Must-know: CycleGAN needs only unpaired buckets of data while pix2pix needs matched pairs; its objective is two adversarial terms plus lambda-weighted two-way L1 cycle consistency.
⚠️ Top pitfall: Whole-image characteristic transfer paints every object in the frame (zebra stripes land on the rider), and geometric reshaping tasks like dog-to-cat are impossible under cycle consistency.
Self-check: Why does the full objective contain two L1 cycle terms, and which generator pair does each supervise?
Connects to: Section 13.2 (BigGAN's control knobs) and Section 13.4 (diffusion).
BigGAN: Scale, Fidelity, and Control Knobs
Must-know: The truncation trick restricts each latent component to a ±ψ band around the mean, raising fidelity while capping variety — the width is a fidelity-versus-diversity knob.
⚠️ Top pitfall: Forgetting that narrowing the truncation window makes outputs converge toward similar samples; also forgetting that class information must be injected at every generator layer or it fades.
Self-check: Why does squeezing the random input into a high-probability band reduce diversity of generated images?
Connects to: Section 13.1 (adversarial training shared with CycleGAN) and Section 13.3 (StyleGAN's latent redesign).
StyleGAN and Its Three Versions
Must-know: AdaIN rescales each per-instance normalized channel with learned style scale y_s,i and shift y_b,i from w; the three-version artifact chain is droplets (AdaIN) to texture sticking (StyleGAN2 normalization) to clean output (StyleGAN3).
⚠️ Top pitfall: Confusing instance-level statistics (per single generated sample, used by AdaIN) with batch statistics (batch normalization); also forgetting each version's signature artifact when asked to order the family.
Self-check: Which block causes droplet artifacts, and which failure does removing it introduce?
Connects to: Section 13.2 (latent handling in BigGAN versus StyleGAN's mapping network).
Diffusion Models: The Core Idea
Must-know: Forward step q(x_t|x_{t-1}) is Gaussian with scaled mean sqrt(1-beta_t) x_{t-1} and variance beta_t; the schedule grows betas over time; the closed form q(x_t|x_0)=N(sqrt(alpha_bar_t)x_0,(1-alpha_bar_t)I) lets training jump to any t.
⚠️ Top pitfall: Calling beta_t a standard deviation when it sits in the covariance slot as a variance; also confusing the denoising autoencoder (known noise, one step, reconstruct) with diffusion (estimated noise, many steps, generate).
Self-check: Derive x_2 = sqrt(alpha_1 alpha_2) x_0 + sqrt(1 - alpha_1 alpha_2) eps by substitution and variance addition — where does the alpha_2 term cancel?
Connects to: Section 13.1 (GANs as the contrast family) and Section 13.2 (BigGAN in the quality timeline).
Exam Guidance Summary
Must-know: Exam items may hand you a library call and ask for inputs and outputs without live coding; the quiz opens right after the assignment deadline with a 7-day window.
⚠️ Top pitfall: Skipping assignment work because sample papers omit such questions.
Self-check: Which four concept-level topics were flagged as exam emphasis?
Connects to: Sections 13.1, 13.2, and 13.4 (the four flagged emphasis areas live there).
Key Industry Applications
Must-know: Be able to name one concrete application per model family: CycleGAN unpaired translation, pix2pix paired colorization, BigGAN conditional high-res synthesis, StyleGAN controllable faces, diffusion text-to-image.
⚠️ Top pitfall: Describing applications vaguely ("used in engineering") instead of naming a concrete use case.
Self-check: Which artifact tells help detectors flag machine-generated faces?
Connects to: Sections 13.1, 13.2, 13.3, and 13.4 (one application thread per model family).
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.