Skip to content
AIAI Wranglers

13 GANs for Vision

From Theory to Pixels

In Chapters 9–11 we built the theoretical machinery of generative adversarial networks: the minimax game, the Wasserstein relaxation, and the optimisation algorithms that make training possible. In Chapter 12 we catalogued the core vision problems (denoising, super-resolution, inpainting, style transfer) and cast each as an inverse problem requiring a prior over natural images.

This chapter connects the two threads. We show how the GAN framework, when suitably conditioned, provides a powerful learned prior that can be plugged into each of those inverse problems. The journey proceeds in six steps:

  1. Conditional GANs (Conditional GANs): augment the vanilla GAN with side information to steer generation.

  2. Pix2Pix (Paired Image-to-Image Translation: Pix2Pix): paired image-to-image translation via a conditional GAN with a reconstruction loss.

  3. CycleGAN (Unpaired Translation: CycleGAN): unpaired translation via cycle-consistency.

  4. Progressive Growing (Progressive Growing of GANs): high-resolution synthesis through curriculum learning.

  5. StyleGAN (Style-Based Generation: StyleGAN): fine-grained style control via adaptive normalisation.

  6. SPADE / GauGAN (Semantic Image Synthesis: SPADE): semantic image synthesis with spatially-adaptive normalisation.

Key Idea.

Every architecture in this chapter injects structure into the generator through one of four mechanisms: conditioning (feeding side information), cycle-consistency (constraining two mappings to invert each other when no paired data exists), normalisation (modulating feature statistics), or curriculum (growing resolution gradually). Recognising which mechanism an architecture uses makes the design space far easier to navigate.

Conditional GANs

The vanilla GAN of Chapter 9 learns an unconditional generator G:𝒛↦𝒙. In most practical settings we want to control the output: generate a face with a particular attribute, synthesise an image from a text caption, or translate a sketch into a photograph. Conditional GANs (cGANs) [4] achieve this by feeding auxiliary information π’š (a class label, an image, a text embedding, etc.) to both the generator and the discriminator.

The cGAN Objective

Definition 1 (Conditional GAN Objective).

Let (𝒙,π’š)∼pdata(𝒙,π’š) denote data–condition pairs and let π’›βˆΌp𝒛(𝒛) be a latent noise vector. The conditional GAN objective is (CGAN)minG⁑maxD⁑𝔼(𝒙,π’š)∼pdata[log⁑D(𝒙,π’š)]⏟realΒ pairs+π”Όπ’›βˆΌp𝒛,π’šβˆΌp(π’š)[log⁑(1βˆ’D(G(𝒛,π’š),π’š))]⏟fakeΒ pairs. The generator G(𝒛,π’š) takes both noise and condition; the discriminator D(𝒙,π’š) receives an image together with the condition and returns the probability that the pair is real.

Note the key structural difference from the unconditional GAN: the discriminator does not merely judge whether an image looks realistic; it judges whether the image is consistent with the given condition. A photorealistic cat image paired with the label β€œdog” should still be rejected.

Optimal Discriminator and Generator

The analysis parallels the unconditional case (Chapter 9), but all densities are now conditioned on π’š.

Proposition 1 (Optimal cGAN Discriminator).

For a fixed generator G, the optimal discriminator is (Dstar)Dβˆ—(𝒙,π’š)=pdata(𝒙|π’š)pdata(𝒙|π’š)+pG(𝒙|π’š), where pG(𝒙|π’š) is the conditional density induced by G(𝒛,π’š).

Proof.

For each fixed (𝒙,π’š), the integrand of the value function is V(D;𝒙,π’š)=pdata(𝒙|π’š)log⁑D(𝒙,π’š)+pG(𝒙|π’š)log⁑(1βˆ’D(𝒙,π’š)). This is the same alog⁑t+blog⁑(1βˆ’t) form as in the unconditional derivation (see Proposition Proposition 1 in Chapter 9). Maximising over t=D(𝒙,π’š)∈[0,1] by setting the derivative to zero gives atβˆ’b1βˆ’t=0⟹tβˆ—=aa+b=pdata(𝒙|π’š)pdata(𝒙|π’š)+pG(𝒙|π’š).

Proposition 2 (cGAN Generator Minimises Conditional JSD).

Substituting Dβˆ— back into the value function and minimising over G yields (JSD)minGβ‘π”Όπ’šβˆΌp(π’š)[2𝖣JS⁑(pdata(β‹…|π’š)β€–pG(β‹…|π’š))]βˆ’log⁑4, so the generator minimises the expected conditional Jensen–Shannon divergence over the marginal distribution of conditions.

Proof.

Substituting into the value function and proceeding exactly as in the unconditional proof (Theorem Theorem 1 in Chapter 9), but with every density conditioned on π’š, gives V(G,Dβˆ—)=π”Όπ’š[∫pdata(𝒙|π’š)log⁑pdata(𝒙|π’š)pdata(𝒙|π’š)+pG(𝒙|π’š)d𝒙+∫pG(𝒙|π’š)log⁑pG(𝒙|π’š)pdata(𝒙|π’š)+pG(𝒙|π’š)d𝒙]=π”Όπ’š[2𝖣JS⁑(pdata(β‹…|π’š)β€–pG(β‹…|π’š))]βˆ’log⁑4. Since 𝖣JS⁑β‰₯0 with equality iff pG(β‹…|π’š)=pdata(β‹…|π’š) a.e., the global minimum is βˆ’log⁑4, attained when the generator perfectly matches the class-conditional data distribution for every π’š.

Example 1 (Class-Conditional MNIST).

Consider generating handwritten digits π’™βˆˆ[0,1]28Γ—28 conditioned on a digit label y∈{0,1,…,9}. The condition y is represented as a one-hot vector π’šβˆˆ{0,1}10. In the generator, π’š is concatenated with the noise vector π’›βˆˆβ„100⁑ before the first fully-connected layer; in the discriminator, π’š is concatenated with the flattened image. After training, fixing y=3 and varying 𝒛 produces diverse images of the digit β€œ3”, while fixing 𝒛 and varying y produces the same style rendered as different digits, demonstrating that 𝒛 controls style and π’š controls content.

Conditional GAN architecture. The generator receives both noise 𝒛 and condition π’š. The discriminator judges whether an image–condition pair (𝒙,π’š) is real, enforcing not just realism but also consistency with the condition.

Key Idea.

Conditioning transforms an unconditional density model pG(𝒙) into a family of conditional models {pG(𝒙|π’š)}π’š. The discriminator ensures that each conditional distribution is realistic and consistent with π’š; without seeing π’š, it could only enforce marginal realism and the generator could ignore the condition entirely.

Paired Image-to-Image Translation: Pix2Pix

When the condition π’š is itself an image (a sketch, a segmentation map, or a low-resolution photograph) the cGAN framework becomes an image-to-image translation engine. Pix2Pix [5] instantiates this idea with two key design choices: an β„“1 reconstruction loss to encourage pixel-level fidelity, and a PatchGAN discriminator to enforce local texture realism.

The Pix2Pix Objective

Definition 2 (Pix2Pix Loss).

Given paired training data {(𝒙i,π’ši)}i=1N where 𝒙i is the target image and π’ši is the input (condition) image, the Pix2Pix objective is (Pix2pix)minG⁑maxD⁑ℒcGAN(G,D)⏟adversarial+λ𝔼(𝒙,π’š)[β€–G(π’š)βˆ’π’™β€–1]⏟reconstruction, where β„’cGAN is the conditional GAN loss (without noise 𝒛, since the input image π’š provides all the stochasticity), and Ξ»>0 controls the reconstruction–realism trade-off.

Remark 1 (Why β„“1 Instead of β„“2?).

Minimising 𝔼[β€–G(π’š)βˆ’π’™β€–22] over G yields the posterior mean Gβˆ—(π’š)=𝔼[𝒙|π’š], which averages over all plausible outputs and produces blurry results (recall the MMSE estimator from Theorem Theorem 1 in Chapter 12).

Minimising 𝔼[β€–G(π’š)βˆ’π’™β€–1] instead yields the posterior median, which is sharper because the β„“1 loss corresponds to a Laplace likelihood rather than a Gaussian one: β„“2:p(𝒙|G(π’š))∝exp⁑(βˆ’12Οƒ2β€–π’™βˆ’G(π’š)β€–22)vs.β„“1:p(𝒙|G(π’š))∝exp⁑(βˆ’1bβ€–π’™βˆ’G(π’š)β€–1). The heavier tails of the Laplace distribution are more tolerant of sharp edges and outlier pixels, producing less blurring in practice.

The PatchGAN Discriminator

Definition 3 (PatchGAN Discriminator).

Instead of producing a single real/fake scalar for the entire image, the PatchGAN discriminator outputs a matrix D(𝒙,π’š)∈[0,1]MΓ—M, where entry (i,j) classifies whether the NΓ—N receptive-field patch centred at spatial location (i,j) is real or fake. The adversarial loss becomes (Patchgan)β„’PatchGAN=1M2βˆ‘i,j[log⁑D(𝒙,π’š)ij+log⁑(1βˆ’D(G(π’š),π’š)ij)].

Proposition 3 (PatchGAN as a Texture Loss).

Each element of the PatchGAN output depends only on the pixels within its NΓ—N receptive field. Consequently, the PatchGAN loss penalises the generator for producing unrealistic local texture within each patch, effectively acting as a learned texture/style discriminator. If N equals the full image size, PatchGAN reduces to a standard (global) discriminator; if N=1, it reduces to a per-pixel classifier (PixelGAN).

Proof.

Consider the discriminator as a fully convolutional network with effective receptive field of side length N. Each layer with kernel size kl and stride sl updates the receptive field r and the jump j by r←r+(klβˆ’1)j and j←jsl, starting from r=j=1. For k layers of 4Γ—4 convolutions with stride 2 this gives N=1+3βˆ‘l=0kβˆ’12l=3β‹…2kβˆ’2, so N=4,10,22,46 for k=1,2,3,4. Each output unit D(𝒙,π’š)ij is a function only of the NΓ—N sub-image centred at (i,j). The per-patch losses are then independent classification problems: each enforces realism within its own local region. Summing over all patches and dividing by M2 yields an average over all overlapping patches, equivalent to encouraging realistic local statistics everywhere, i.e., a learned texture loss.

Example 2 (Receptive Field Calculation).

The Pix2Pix β€œ70Γ—70” PatchGAN (the n_layers=3 configuration) uses 4Γ—4 convolutions throughout: three stride-2 layers, then a stride-1 layer, then the stride-1 output convolution. Writing r for the receptive field and j for the jump (the input-pixel spacing between adjacent units), each layer applies r←r+(kβˆ’1)j and then j←jβ‹…s:

LayerKernelJump inReceptive field
Input-11Γ—1
Conv1 (stride 2)4Γ—414Γ—4
Conv2 (stride 2)4Γ—4210Γ—10
Conv3 (stride 2)4Γ—4422Γ—22
Conv4 (stride 1)4Γ—4846Γ—46
Output (stride 1)4Γ—4870Γ—70
The stride-1 penultimate layer is easy to overlook, but it is what carries the receptive field from 46 to 70: after three stride-2 layers the jump is already 8, so each further 4Γ—4 convolution adds 3Γ—8=24 input pixels. Stopping at Conv3 would give a 46Γ—46 patch, not 70Γ—70. This 70Γ—70 PatchGAN is the default in the original Pix2Pix paper and strikes a good balance: large enough to capture texture patterns (brick walls, grass, sky), small enough to avoid penalising global structure (which the β„“1 loss already handles).

Insight.

Pix2Pix has the same two-part shape as a MAP estimate: a fidelity term plus a prior term. By Remark Remark 1 the β„“1 reconstruction loss is the negative log-likelihood of a Laplace observation model for the target given the prediction, βˆ’log⁑p(𝒙|G(π’š)), while the adversarial loss acts as a learned log-prior log⁑p(𝒙): the discriminator scores how plausible an image is, which is exactly the job a hand-crafted regulariser performs in classical MAP estimation (Chapter 12). The generator is therefore pushed towards outputs that are both faithful to the paired target and β€œlook real” according to the discriminator.

The correspondence is structural rather than literal: the β„“1 term is a supervised loss against a known ground-truth target, not a forward-model likelihood evaluated at test time. What carries over from Chapter 12 is the division of labour, with one term enforcing agreement with the data and the other enforcing plausibility, and the fact that the second term is now learned rather than hand-designed.

Unpaired Translation: CycleGAN

Pix2Pix requires paired examples: for every input sketch there must be a corresponding target photograph. In many settings such pairs are unavailable; we may have a collection of photographs and a collection of Monet paintings, but no β€œMonet version” of each photograph. CycleGAN [6] tackles this unpaired setting by introducing a cycle-consistency constraint.

Problem Setup

Let 𝒳 and 𝒴 be two image domains with marginal distributions p𝒳 and p𝒴. We seek two mappings: G:𝒳→𝒴,F:𝒴→𝒳, such that G(𝒙) looks like a sample from 𝒴 and F(π’š) looks like a sample from 𝒳, while the semantic content is preserved.

The CycleGAN Objective

Definition 4 (CycleGAN Loss).

The full CycleGAN objective combines two adversarial losses with a cycle-consistency loss: (Cyclegan)β„’(G,F,D𝒳,D𝒴)=β„’GAN(G,D𝒴)+β„’GAN(F,D𝒳)+Ξ»β„’cyc(G,F), where the adversarial losses are (ADV1)β„’GAN(G,D𝒴)=π”Όπ’š[log⁑D𝒴(π’š)]+𝔼𝒙[log⁑(1βˆ’D𝒴(G(𝒙)))],β„’GAN(F,D𝒳)=𝔼𝒙[log⁑D𝒳(𝒙)]+π”Όπ’š[log⁑(1βˆ’D𝒳(F(π’š)))], and the cycle-consistency loss is (CYC)β„’cyc(G,F)=𝔼𝒙[β€–F(G(𝒙))βˆ’π’™β€–1]⏟forwardΒ cycle+π”Όπ’š[β€–G(F(π’š))βˆ’π’šβ€–1]⏟backwardΒ cycle.

CycleGAN enforces two cycle-consistency constraints. Forward cycle: translate 𝒙 to domain 𝒴 via G, then back via F; the result should recover 𝒙. Backward cycle: translate π’š to 𝒳 via F, then back via G; the result should recover π’š.

Why Cycle-Consistency Works

Without the cycle-consistency loss, each generator could learn an arbitrary mapping that produces realistic outputs but bears no semantic relationship to the input (e.g., mapping every horse photograph to the same zebra). The cycle constraint prevents this by forcing the mappings to be approximately invertible.

Theorem 1 (Cycle-Consistency Implies Approximate Inverse).

Let G:𝒳→𝒴 and F:𝒴→𝒳 be deterministic, measurable mappings. If F(G(𝒙))=𝒙forΒ p𝒳-a.e. 𝒙,G(F(π’š))=π’šforΒ p𝒴-a.e.Β π’š, then G is a bijection between supp(p𝒳) and supp(p𝒴), and F=Gβˆ’1 p𝒴-almost everywhere.

Proof.

The forward cycle condition F∘G=id on supp(p𝒳) implies that G is injective on supp(p𝒳) (distinct inputs cannot map to the same output, since F would then recover both).

The backward cycle condition G∘F=id on supp(p𝒴) implies that G is surjective onto supp(p𝒴) (every π’š in the support is the image of F(π’š) under G).

Injectivity and surjectivity together give bijectivity. From F∘G=id, we have F=Gβˆ’1 on range(G)βŠ‡supp(p𝒴).

Remark 2 (Identity Loss).

In practice, an identity loss is added: β„’idt=π”Όπ’š[β€–G(π’š)βˆ’π’šβ€–1]+𝔼𝒙[β€–F(𝒙)βˆ’π’™β€–1]. This encourages G to act as an identity when applied to an image already in the target domain, preventing unnecessary colour shifts (e.g., when translating Monet β†’ photographs, a photograph should remain unchanged).

Caution.

CycleGAN assumes that the mapping between domains preserves geometric structure: a horse's outline should map to a zebra's outline. When this assumption fails, for example when translating between domains with different geometry (cats β†’ dogs), CycleGAN can produce artefacts or hallucinate structures. The cycle-consistency loss cannot prevent semantic errors, only reconstruction errors.

Progressive Growing of GANs

Generating high-resolution images (e.g., 1024Γ—1024) directly is extremely difficult: the generator must simultaneously learn coarse structure (object layout) and fine detail (skin pores, hair strands), and the discriminator must evaluate both global coherence and local texture. Progressive Growing of GANs (ProGAN) [1] addresses this by training the networks in a curriculum: start at very low resolution and gradually add layers that handle finer details.

The Progressive Training Strategy

Definition 5 (Progressive Training Schedule).

Let Gk and Dk denote the generator and discriminator at resolution stage k, where stage k operates at resolution rk=4β‹…2k (so k=0 is 4Γ—4, k=1 is 8Γ—8, etc.). Training proceeds as follows:

  1. Train (G0,D0) at 4Γ—4 until convergence.

  2. For k=1,2,…,K: enumerate

  3. Add new layers to both Gkβˆ’1 and Dkβˆ’1 to handle resolution rk.

  4. Fade in the new layers using a blending parameter α∈[0,1] that linearly increases from 0 to 1 over a fixed number of iterations.

  5. Continue training at resolution rk. enumerate

The Fade-In Mechanism

Definition 6 (Fade-In Blending).

When transitioning from resolution rkβˆ’1 to rk, the generator output is computed as (Fadein)𝒙^rk=(1βˆ’Ξ±)β‹…Upsample(𝒙^rkβˆ’1)+Ξ±β‹…NewBlock(𝒇rk), where 𝒙^rkβˆ’1 is the previous-resolution output, Upsample is nearest-neighbour upsampling followed by a 1Γ—1 convolution (the β€œtoRGB” layer from the old block), 𝒇rk is the feature map from the new convolutional block, and NewBlock includes the new toRGB layer. The blending parameter Ξ± increases linearly from 0 to 1 during the transition phase.

An analogous fade-in is applied in the discriminator, where a 1Γ—1 β€œfromRGB” convolution is blended with the output of the new higher-resolution processing block.

Proposition 4 (Smooth Transition Preserves Training Stability).

At Ξ±=0, the output 𝒙^rk=Upsample(𝒙^rkβˆ’1) is identical to the old-resolution output (upsampled), so the generator's distribution is unchanged. At Ξ±=1, the old path is fully replaced by the new block. For intermediate Ξ±, the output is a convex combination, so the distributional change is continuous. This prevents the β€œshock” that would occur if new randomly-initialised layers were suddenly activated.

Proof.

Let pΞ± denote the generator's output distribution at blending parameter Ξ±. Since is a convex combination of two continuous functions of the parameters, the mapping α↦𝒙^rk is continuous. By the continuous mapping theorem, α↦pΞ± is continuous in the weak topology on probability measures. In particular, p0=prkβˆ’1↑ (the upsampled old distribution), ensuring no discontinuity at the transition boundary.

Progressive growing of GANs. Training begins at 4Γ—4 resolution (left) and progressively adds layers to reach 1024Γ—1024 (right). G denotes generator blocks and D denotes discriminator blocks. At each transition, new layers are faded in smoothly via .

Remark 3 (Minibatch Standard Deviation).

To encourage the generator to produce diverse outputs, ProGAN appends a minibatch standard deviation layer near the end of the discriminator. For a minibatch {𝒙1,…,𝒙B}, compute Οƒ=1Bβˆ‘i=1B(𝒙iβˆ’π’™β€Ύ)2+Ο΅ (element-wise, then averaged over all dimensions to produce a single scalar), replicate it as a constant feature map, and concatenate it with the final discriminator features. If the generator produces identical images (mode collapse), Οƒβ‰ˆ0, giving the discriminator an easy signal to reject the batch.

Historical Note.

ProGAN [1] was the first GAN to produce photorealistic face images at 1024Γ—1024 resolution. It also introduced the CelebA-HQ dataset, a high-quality version of CelebA that became a standard benchmark. The progressive training idea directly inspired StyleGAN (Style-Based Generation: StyleGAN), which inherits the progressive architecture but adds a style-based generator for finer control.

Style-Based Generation: StyleGAN

StyleGAN [7] builds on ProGAN's progressive architecture but fundamentally redesigns the generator. Instead of feeding the latent code 𝒛 directly into the first layer, StyleGAN introduces a mapping network and injects style information at every resolution level through adaptive instance normalisation (AdaIN).

The Mapping Network

Definition 7 (Mapping Network).

The mapping network is a multilayer perceptron f:𝒡→𝒲 that transforms the latent code π’›βˆΌNormal⁑(0,I⁑) to an intermediate latent code π’˜=f(𝒛)βˆˆπ’². In the original StyleGAN, f consists of 8 fully-connected layers with LeakyReLU activations, and dim⁑(𝒡)=dim⁑(𝒲)=512.

Proposition 5 (Disentanglement via the Mapping Network).

The latent space 𝒡 is typically a hypersphere or Gaussian, which is a fixed geometry. The factors of variation in natural images (pose, lighting, expression, hair colour, etc.) do not respect this geometry: certain combinations may be impossible (e.g., a baby with wrinkles). A direct mapping 𝒛↦𝒙 must β€œwarp” the latent space to avoid these forbidden regions, leading to entangled representations.

The mapping network f learns a nonlinear warping π’›β†¦π’˜ such that 𝒲 is adapted to the data manifold. Forbidden regions in 𝒡 are mapped away, and the resulting 𝒲 space has a geometry where linear interpolation corresponds to semantically meaningful changes.

Adaptive Instance Normalisation

Definition 8 (Adaptive Instance Normalisation (AdaIN)).

Let 𝒇iβˆˆβ„HΓ—W⁑ be the i-th feature map in a convolutional layer and let π’˜βˆˆπ’² be the style code. A learned affine transformation A maps π’˜ to per-channel scale and bias: (Affine)(ys,i,yb,i)=Ai(π’˜),i=1,…,C, where C is the number of channels. AdaIN then normalises and re-scales each feature map: (Adain)AdaIN(𝒇i,π’˜)=ys,i𝒇iβˆ’ΞΌ(𝒇i)Οƒ(𝒇i)+Ο΅+yb,i, where ΞΌ(𝒇i) and Οƒ(𝒇i) are the spatial mean and standard deviation of 𝒇i (computed over HΓ—W), and Ο΅>0 is a small constant for numerical stability.

Remark 4 (AdaIN as Style Injection).

Instance normalisation removes the original feature statistics (mean and variance), which encode β€œstyle” information such as contrast, colour palette, and texture amplitude. AdaIN then replaces these statistics with new ones derived from π’˜. Different layers control different aspects of the image:

  • Low-resolution layers (4Γ—4 to 8Γ—8): control coarse features such as pose, face shape, presence of accessories (glasses, hats).

  • Mid-resolution layers (16Γ—16 to 32Γ—32): control facial features, hairstyle, eyes open/closed.

  • High-resolution layers (64Γ—64 to 1024Γ—1024): control colour scheme, micro-structure, skin texture, background details.

Style Mixing

Definition 9 (Style Mixing Regularisation).

During training, two latent codes 𝒛1,𝒛2 are sampled and mapped to π’˜1=f(𝒛1), π’˜2=f(𝒛2). A random crossover point k is chosen, and the generator uses π’˜1 for layers 1,…,k and π’˜2 for layers k+1,…,L. This prevents the network from assuming that adjacent layers are correlated, encouraging each layer to independently control its corresponding level of detail.

Example 3 (Style Mixing Matrix).

Consider two source latent codes π’˜A and π’˜B that produce face images A and B respectively. Injecting π’˜A at coarse layers and π’˜B at fine layers produces a face with the pose and structure of A but the colour and texture of B. Reversing the assignment gives B's structure with A's style. This decomposition is possible only because AdaIN applies style at each resolution independently.

The Truncation Trick

Definition 10 (Truncation Trick).

Let π’˜β€Ύ=𝔼𝒛[f(𝒛)] be the mean of the 𝒲 distribution. The truncated style code is (Truncation)π’˜β€²=π’˜β€Ύ+ψ(π’˜βˆ’π’˜β€Ύ), where ψ∈[0,1] is the truncation parameter. At ψ=1 (no truncation), the full diversity of the model is used. At ψ=0, every image is the β€œaverage face” G(π’˜β€Ύ). Intermediate values trade diversity for quality.

Proposition 6 (Truncation as Variance Reduction).

If π’˜βˆΌπ’©(π’˜β€Ύ,Ξ£) approximately (the distribution in 𝒲 after passing through f), then π’˜β€² from satisfies π’˜β€²βˆΌπ’©(π’˜β€Ύ,ψ2Ξ£). The variance is reduced by ψ2, concentrating samples near the mean of the learned manifold where the generator has seen the most training data and thus produces the highest quality.

Proof.

π’˜β€²βˆ’π’˜β€Ύ=ψ(π’˜βˆ’π’˜β€Ύ). Since scaling a Gaussian by ψ scales the covariance by ψ2: 𝖒ov⁑(π’˜β€²)=ψ2𝖒ov⁑(π’˜)=ψ2Ξ£.

StyleGAN generator architecture. The mapping network f transforms 𝒛 to the intermediate latent π’˜, which is injected at every resolution via AdaIN layers. Per-layer noise inputs add stochastic variation (e.g., freckles, hair placement). The synthesis network begins from a learned constant and progressively upsamples.

Insight.

StyleGAN's key insight is that style and content are best controlled at different resolutions. By injecting the latent code through AdaIN at every layer, rather than only at the input, StyleGAN gains fine-grained control: changing π’˜ at coarse layers alters pose and shape, while changing it at fine layers alters colour and micro-texture. This per-layer control is what makes style mixing and the truncation trick possible.

Semantic Image Synthesis: SPADE

In semantic image synthesis, the goal is to generate a photorealistic image from a semantic label map: a spatial map π’”βˆˆ{1,…,K}HΓ—W where each pixel is assigned a semantic class (sky, road, building, tree, etc.). GauGAN [8] solves this problem with Spatially-Adaptive Normalisation (SPADE), a normalisation layer that modulates features spatially based on the semantic layout.

Why BatchNorm Fails for Semantic Synthesis

Proposition 7 (BatchNorm Destroys Spatial Information).

Standard batch normalisation computes channel-wise statistics ΞΌc,Οƒc over the entire spatial extent and normalises: BN(𝒉c,h,w)=Ξ³c𝒉c,h,wβˆ’ΞΌcΟƒc+Ο΅+Ξ²c. The affine parameters Ξ³c,Ξ²c are spatially uniform: the same scale and shift applied everywhere. When the input is a semantic map (encoded, e.g., as a one-hot volume), the normalisation step subtracts the global mean and divides by the global standard deviation, washing out the spatial layout of the semantic classes. After a few BN layers, the generator effectively loses the input segmentation map.

Spatially-Adaptive Normalisation

Definition 11 (SPADE Layer).

Let π’‰βˆˆβ„CΓ—HΓ—W⁑ be the activation tensor at some generator layer and π’”βˆˆ{1,…,K}Hβ€²Γ—Wβ€² be the input semantic map (resized to HΓ—W if needed). The SPADE layer computes: (Spade)SPADE(𝒉,𝒔)c,h,w=Ξ³c,h,w(𝒔)𝒉c,h,wβˆ’ΞΌcΟƒc+Ο΅+Ξ²c,h,w(𝒔), where:

  • ΞΌc=1HWβˆ‘h,w𝒉c,h,w and Οƒc2=1HWβˆ‘h,w(𝒉c,h,wβˆ’ΞΌc)2 are the usual channel-wise statistics,

  • Ξ³(𝒔),Ξ²(𝒔)βˆˆβ„CΓ—HΓ—W⁑ are spatially-varying modulation parameters produced by small convolutional networks applied to the semantic map 𝒔: (Modulation)Ξ³(𝒔)=ConvΞ³(ReLU(Conv0(𝒔))),Ξ²(𝒔)=ConvΞ²(ReLU(Conv0(𝒔))), sharing the first convolution Conv0 and then branching into separate convolutions for Ξ³ and Ξ².

The crucial difference from BatchNorm and AdaIN is that Ξ³ and Ξ² vary with spatial position (h,w), determined by the semantic label at that location. A pixel labelled β€œsky” receives different modulation parameters than a pixel labelled β€œroad”, allowing the generator to synthesise appropriate textures in each region.

Theorem 2 (SPADE Generalises Conditional BatchNorm and AdaIN).

The following normalisation layers are special cases of SPADE:

  1. Batch Normalisation: set Ξ³c,h,w(𝒔)=Ξ³c and Ξ²c,h,w(𝒔)=Ξ²c (spatially constant, independent of 𝒔).

  2. Conditional BatchNorm: set Ξ³c,h,w(𝒔)=Ξ³c(y) and Ξ²c,h,w(𝒔)=Ξ²c(y) where y is a class label (spatially constant, dependent on a global condition).

  3. AdaIN: set Ξ³c,h,w(𝒔)=ys,c and Ξ²c,h,w(𝒔)=yb,c where (ys,c,yb,c) are derived from a style vector (spatially constant, per-channel modulation from a style code).

SPADE is strictly more expressive because the modulation parameters are functions of both the channel c and the spatial location (h,w), through the semantic map 𝒔.

Proof.

In each case, we verify that the restricted parameter form satisfies :

Case 1 (BN): Let Ξ³c,h,w=Ξ³c and Ξ²c,h,w=Ξ²c for all (h,w). Then reduces to standard BN with learned affine parameters.

Case 2 (Conditional BN): Let Ξ³c,h,w=Ξ³c(y) and Ξ²c,h,w=Ξ²c(y), where y is a global class label. These are spatially constant but condition-dependent, matching Conditional BN.

Case 3 (AdaIN): Let Ξ³c,h,w=ys,c(π’˜) and Ξ²c,h,w=yb,c(π’˜), where π’˜ is a style vector. The normalisation uses instance statistics (per-example rather than per-batch), and the affine parameters depend on π’˜ but not on (h,w), recovering AdaIN .

In all three cases, Ξ³ and Ξ² are constrained to be spatially uniform. SPADE allows them to vary with (h,w) through the semantic map, providing a strictly richer parameterisation.

Example 4 (Cityscapes Synthesis).

The Cityscapes dataset [2] contains paired data: semantic label maps of urban scenes and corresponding photographs. Using SPADE, a generator trained on this data can take a new label map, perhaps user-drawn, and produce a photorealistic street scene. Moving a β€œtree” label to a different location in the map causes a tree to appear in the corresponding position in the generated image, demonstrating that SPADE truly respects the spatial layout. Evaluation on Cityscapes shows significant improvements in FID and segmentation accuracy over Pix2Pix and Pix2PixHD [3].

Insight.

The evolution of normalisation in GAN generators follows a clear trajectory of increasing expressiveness: BN⏟globalβ†’Cond.Β BN⏟class-awareβ†’AdaIN⏟style-awareβ†’SPADE⏟spatially-aware. Each step adds a new axis of modulation, giving the generator finer control over what it produces and where.

Scaling and the Bigger Picture

The architectures above were designed for resolutions up to 1024Γ—1024. Scaling GANs further, to text-conditioned generation at arbitrary resolutions, requires additional innovations.

GigaGAN

GigaGAN [9] scales GAN-based text-to-image synthesis to 512px base resolution with a 1-billion-parameter generator, rivalling diffusion models in quality while retaining the fast single-pass inference speed of GANs. Key innovations include:

  1. Sample-adaptive kernel selection: convolutional kernels are dynamically chosen based on the text embedding, giving each text prompt a customised filter bank.

  2. Interleaved attention and convolution: self-attention layers (for global coherence) alternate with convolution layers (for local texture), balancing computational cost and receptive field.

  3. Multi-scale training: the generator produces images at multiple resolutions simultaneously, with separate discriminators at each scale.

Architecture Comparison

MethodConditioningPaired?Max Res.Key Innovation
cGANLabel / image / textVariesVariesCondition fed to G and D
Pix2PixInput imageYes2562PatchGAN + β„“1 loss
CycleGANNone (unpaired)No2562Cycle-consistency loss
ProGANNoneN/A10242Progressive growing + fade-in
StyleGANNone (+ truncation)N/A10242Mapping net + AdaIN
SPADESemantic mapYes5122Spatially-adaptive norm
GigaGANText embeddingN/A5122+Adaptive kernels + attention

Remark 5 (GANs and Diffusion Models).

Since 2021, diffusion models have largely overtaken GANs for image generation benchmarks, offering better mode coverage and training stability. However, GANs retain key advantages: single-pass generation (no iterative denoising), real-time inference, and a mature toolkit for image editing (latent space interpolation, style mixing). Many modern systems combine both: a diffusion model for high-quality generation with a GAN-based refiner for speed.

Key Idea.

Every GAN architecture in this chapter injects structure through one of four mechanisms:

  1. Conditioning: cGAN, Pix2Pix, GigaGAN feed side information to guide generation.

  2. Cycle-consistency: CycleGAN constrains two mappings to invert each other, supplying the structure that paired data would otherwise provide.

  3. Normalisation: StyleGAN (AdaIN) and SPADE modulate feature statistics to control style and spatial layout.

  4. Curriculum: ProGAN trains progressively from low to high resolution.

Understanding which mechanism a new architecture uses is the fastest way to categorise it and predict its strengths and limitations.

Exercises

Exercise 1 (Optimal cGAN Discriminator).

Derive the optimal discriminator Dβˆ—(𝒙,π’š) for the conditional GAN objective from first principles. Show that substituting Dβˆ— into the value function gives V(G,Dβˆ—)=π”Όπ’š[2𝖣JS⁑(pdata(β‹…|π’š)β€–pG(β‹…|π’š))]βˆ’log⁑4. Under what condition does the global optimum Vβˆ—=βˆ’log⁑4 hold?

Exercise 2 (β„“1 vs. β„“2 Reconstruction).

Consider a 1D pixel x with posterior distribution p(x|y)=12Ξ΄(xβˆ’a)+12Ξ΄(xβˆ’b) for aβ‰ b. Compute:

  1. The minimiser of 𝔼[|xβˆ’g|] (posterior median).

  2. The minimiser of 𝔼[(xβˆ’g)2] (posterior mean).

  3. Explain why the β„“2 minimiser (a+b)/2 produces a β€œblurry” result that is not a valid sample, while either β„“1 minimiser (a or b) is a valid sample.

Exercise 3 (PatchGAN Receptive Field).

A PatchGAN discriminator uses L convolutional layers, each with kernel size k and stride s. Show that the receptive field NL at the output satisfies NL=1+βˆ‘l=1L(kβˆ’1)∏j=1lβˆ’1sj. Verify this formula for the 3-layer architecture in Example Example 2 with k=4, s=2.

Exercise 4 (Cycle-Consistency and Bijectivity).

Give a concrete example of two mappings G,F that satisfy the forward cycle F(G(𝒙))=𝒙 for all 𝒙 but do not satisfy the backward cycle G(F(π’š))=π’š for all π’š. What kind of mapping is G in this case (injective, surjective, or bijective)? Why does CycleGAN need both cycles?

Exercise 5 (CycleGAN Mode Collapse).

Suppose G maps every image in 𝒳 to the same image π’š0βˆˆπ’΄. Show that the cycle-consistency loss 𝔼[β€–F(G(𝒙))βˆ’π’™β€–1] cannot be zero unless F maps π’š0 to every 𝒙 simultaneously (which is impossible for a deterministic function). Conclude that cycle-consistency prevents this form of mode collapse.

Exercise 6 (Progressive Fade-In Analysis).

Consider the fade-in formula . At the start of the transition (Ξ±=0), the new layers have random weights. Argue that the gradient of the training loss with respect to the new layer parameters is scaled by Ξ±, so the new layers receive very small gradients initially. Why is this beneficial for training stability?

Exercise 7 (AdaIN Feature Statistics).

Let π’‡βˆˆβ„HΓ—W⁑ be a feature map with mean ΞΌ and standard deviation Οƒ. After applying AdaIN(𝒇,π’˜)=ysβ‹…π’‡βˆ’ΞΌΟƒ+yb, show that the output has mean yb and standard deviation |ys|. Interpret: AdaIN replaces the feature statistics with the style-derived values (ys,yb).

Exercise 8 (Mapping Network Disentanglement).

Consider a simple 2D example where 𝒛=(z1,z2)∼Normal⁑(0,I⁑) and the data manifold is an L-shaped region: {(x1,x2):0≀x1≀1,0≀x2≀1}βˆ–{(x1,x2):x1>0.5,x2>0.5}.

Explain why a linear mapping 𝒛↦𝒙 cannot map the Gaussian 𝒛 onto this L-shaped region without β€œwasting” probability mass. Argue that a nonlinear mapping network can learn to warp the Gaussian to avoid the forbidden region, leading to better disentanglement.

Exercise 9 (Truncation and FID).

The truncation trick trades diversity for quality. Explain qualitatively why:

  1. Decreasing ψ improves the β€œquality” component of FID (generated samples are closer to real samples).

  2. Decreasing ψ worsens the β€œdiversity” component of FID (the generated distribution has lower variance than the real distribution).

  3. There exists an optimal Οˆβˆ— that minimises FID.

Exercise 10 (SPADE vs. AdaIN).

Consider a 2Γ—2 feature map π’‰βˆˆβ„1Γ—2Γ—2⁑ with a semantic map 𝒔 where the top row is β€œsky” and the bottom row is β€œgrass”. Write out explicitly the output of:

  1. AdaIN with parameters (ys,yb) derived from a global style vector.

  2. SPADE with parameters Ξ³1,1,Ξ³1,2,Ξ³2,1,Ξ³2,2 and Ξ²1,1,Ξ²1,2,Ξ²2,1,Ξ²2,2 derived from 𝒔.

Explain why SPADE can produce different textures for sky and grass pixels while AdaIN cannot.

Exercise 11 (Conditional Mode Collapse).

In a conditional GAN, mode collapse can manifest as the generator producing the same output for all noise vectors 𝒛 given a fixed condition π’š, while still producing diverse outputs across different conditions. Define the intra-class LPIPS score as S(y)=𝔼𝒛1,𝒛2[dLPIPS(G(𝒛1,y),G(𝒛2,y))], where dLPIPS is the perceptual distance. Explain why S(y)β‰ˆ0 indicates conditional mode collapse for class y, and propose a training diagnostic based on monitoring S(y) during training.

Exercise 12 (Unifying Framework).

Consider the general conditional generation framework minG⁑maxD⁑ℒadv(G,D)+Ξ»β„’recon(G). Show that:

  1. Pix2Pix uses β„’recon=𝔼[β€–G(π’š)βˆ’π’™β€–1] with paired data.

  2. CycleGAN replaces the single reconstruction loss with the cycle-consistency loss β„’cyc, enabling unpaired training.

  3. When Ξ»=0, the framework reduces to the vanilla (conditional) GAN, which has no reconstruction guarantee.

  4. When Ξ»β†’βˆž, the adversarial loss becomes irrelevant and the generator minimises reconstruction error alone, producing blurry outputs (the MMSE solution).

Conclude that Ξ» controls the reconstruction–realism trade-off, analogous to the PSNR–perceptual quality trade-off in Chapter 12.

References

  1. Progressive Growing of GANs for Improved Quality, Stability, and Variation

    Tero Karras, Timo Aila, Samuli Laine, Jaakko Lehtinen

    International Conference on Learning Representations Β· 2018

    BibTeX
    @inproceedings{karras2018progressive,
      title={Progressive Growing of {GAN}s for Improved Quality, Stability, and Variation},
      author={Karras, Tero and Aila, Timo and Laine, Samuli and Lehtinen, Jaakko},
      booktitle={International Conference on Learning Representations},
      year={2018}
    }

    Conference paper

  2. The Cityscapes Dataset for Semantic Urban Scene Understanding

    Marius Cordts, Mohamed Omran, Sebastian Ramos, Timo Rehfeld, Markus Enzweiler, Rodrigo Benenson, Uwe Franke, Stefan Roth, et al.

    Proc. of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR) Β· 2016

    BibTeX
    @inproceedings{Cordts2016Cityscapes,
    title={The Cityscapes Dataset for Semantic Urban Scene Understanding},
    author={Cordts, Marius and Omran, Mohamed and Ramos, Sebastian and Rehfeld, Timo and Enzweiler, Markus and Benenson, Rodrigo and Franke, Uwe and Roth, Stefan and Schiele, Bernt},
    booktitle={Proc. of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
    year={2016}
    }

    Conference paper

  3. High-Resolution Image Synthesis and Semantic Manipulation with Conditional GANs

    Ting-Chun Wang, Ming-Yu Liu, Jun-Yan Zhu, Andrew Tao, Jan Kautz, Bryan Catanzaro

    Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition Β· 2018

    BibTeX
    @inproceedings{wang2018highresolution,
      title={High-Resolution Image Synthesis and Semantic Manipulation with Conditional {GAN}s},
      author={Wang, Ting-Chun and Liu, Ming-Yu and Zhu, Jun-Yan and Tao, Andrew and Kautz, Jan and Catanzaro, Bryan},
      booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
      year={2018}
    }

    Conference paper

  4. Conditional Generative Adversarial Nets

    Mehdi Mirza, Simon Osindero

    arXiv:1411.1784 Β· 2014

    BibTeX
    @misc{mirza2014conditional,
          title={Conditional Generative Adversarial Nets}, 
          author={Mehdi Mirza and Simon Osindero},
          year={2014},
          eprint={1411.1784},
          archivePrefix={arXiv},
          primaryClass={cs.LG}
    }

    Reference

  5. Image-to-image translation with conditional adversarial networks

    Phillip Isola, Jun-Yan Zhu, Tinghui Zhou, Alexei A Efros

    Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 1125-1134 Β· 2017

    BibTeX
    @inproceedings{isola2017image,
      title={Image-to-image translation with conditional adversarial networks},
      author={Isola, Phillip and Zhu, Jun-Yan and Zhou, Tinghui and Efros, Alexei A},
      booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
      pages={1125--1134},
      year={2017}
    }

    Conference paper

  6. Unpaired Image-to-Image Translation Using Cycle-Consistent Adversarial Networks

    Jun-Yan Zhu, Taesung Park, Phillip Isola, Alexei A. Efros

    IEEE International Conference on Computer Vision, pp. 2223-2232 Β· 2017

    BibTeX
    @inproceedings{zhu2017unpaired,
        title = {Unpaired Image-to-Image Translation Using Cycle-Consistent Adversarial Networks},
        author = {Zhu, Jun-Yan and Park, Taesung and Isola, Phillip and Efros, Alexei A.},
        booktitle = {IEEE International Conference on Computer Vision},
        pages = {2223--2232},
        year = {2017}
    }

    Conference paper

  7. A Style-Based Generator Architecture for Generative Adversarial Networks

    Tero Karras, Samuli Laine, Timo Aila

    Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 4401-4410 Β· 2019

    BibTeX
    @inproceedings{karras2019style,
      title={A Style-Based Generator Architecture for Generative Adversarial Networks},
      author={Karras, Tero and Laine, Samuli and Aila, Timo},
      booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
      pages={4401--4410},
      year={2019}
    }

    Conference paper

  8. Semantic Image Synthesis with Spatially-Adaptive Normalization

    Taesung Park, Ming-Yu Liu, Ting-Chun Wang, Jun-Yan Zhu

    Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition Β· 2019

    BibTeX
    @inproceedings{park2019semantic,
      title={Semantic Image Synthesis with Spatially-Adaptive Normalization},
      author={Park, Taesung and Liu, Ming-Yu and Wang, Ting-Chun and Zhu, Jun-Yan},
      booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
      year={2019}
    }

    Conference paper

  9. Scaling up GANs for Text-to-Image Synthesis

    Minguk Kang, Jun-Yan Zhu, Richard Zhang, Jaesik Park, Eli Shechtman, Sylvain Paris, Taesung Park

    Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition Β· 2023

    BibTeX
    @inproceedings{kang2023scaling,
      title={Scaling up {GAN}s for Text-to-Image Synthesis},
      author={Kang, Minguk and Zhu, Jun-Yan and Zhang, Richard and Park, Jaesik and Shechtman, Eli and Paris, Sylvain and Park, Taesung},
      booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
      year={2023}
    }

    Conference paper