Simple Algorithm
Deep Learning · Emergence · 26 min

Style-Based Generators

StyleGAN’s mapping network, style modulation and controllable synthesis.

Between 2017 and 2021 one research group rebuilt the GAN generator four times. Each rebuild fixed a specific, visible defect: training that fell apart at high resolution, entangled controls, water-droplet blobs, and textures glued to the screen while faces moved. Following the fixes is a tour of what a generator's architecture actually controls.

What you’ll learn

  • Explain progressive growing and StyleGAN's mapping network, style modulation, constant input, noise inputs and style mixing.
  • Prove that AdaIN overrides each channel's statistics, derive StyleGAN2's weight demodulation, and explain path-length regularization.
  • Explain texture sticking as an aliasing problem and how StyleGAN3 treats feature maps as bandlimited continuous signals.
  • Analyze the truncation trick as a fidelity–diversity trade-off, and place GANs among generative models as of the mid-2020s.

From progressive growing to styles

Progressive growing (Karras, Aila, Laine & Lehtinen, 2018) attacked the instability of high-resolution GANs by not starting at high resolution. Generator and discriminator begin at 4×44\times4; new layers for 8×88\times8, then 16×1616\times16 and onward are added during training, each faded in by blending its output with an upsampled copy of the previous resolution as a weight α\alpha rises from 0 to 1. The networks learn coarse structure first and refine it, and the paper reached 1024×10241024\times1024 faces on a new high-quality version of the CelebA dataset. It also introduced a minibatch standard-deviation feature that lets the discriminator see how varied a batch is (a cheap defense against collapse), an equalized learning rate that rescales each layer's weights at runtime by its He initialization constant, and pixelwise feature normalization in the generator.

StyleGAN (Karras, Laine & Aila, 2019) kept the discriminator and the progressive schedule but redesigned how the latent enters the generator.

Style mixing exploits the localization. During training a fraction of images are generated from two latents: w1\mathbf w_1 drives the layers before a random crossover point and w2\mathbf w_2 the layers after it, which discourages the network from assuming adjacent styles are correlated. At inference, copying the coarse styles (424^2 to 828^2) from one face transfers pose, face shape and eyeglasses; the middle styles (16216^2 to 32232^2) carry smaller facial features and hair style; the fine styles carry the color scheme and microstructure. The noise inputs take over truly stochastic detail, such as the exact placement of hairs and freckles, so the latent need not encode it.

Why a mapping network? Z\mathcal Z must follow a fixed distribution, so if some combination of factors is rare or missing in the data (say, long hair on a particular face shape), the generator must warp Z\mathcal Z to avoid producing it. W\mathcal W is not tied to any fixed distribution, so the mapping can absorb that warping and leave W\mathcal W closer to linear in the factors of variation. Karras et al. introduced two measures to test the claim on their new FFHQ dataset of 70,000 faces at 1024×10241024\times1024:

  • Perceptual path length (PPL): subdivide interpolation paths into steps of size ϵ=10−4\epsilon=10^{-4} and average the perceptual distance (a weighted difference of VGG16 features) between images at the ends of each step, scaled by 1/ϵ21/\epsilon^2. Paths use slerp in Z\mathcal Z and plain interpolation in W\mathcal W. A short path means no abrupt changes along the way.
  • Linear separability: label 200,000 generated images with classifiers for 40 CelebA attributes, keep the more confidently labeled half, fit a linear SVM per attribute in latent space, and report exp⁡(∑iH(Yi∣Xi))\exp\big(\sum_iH(Y_i\mid X_i)\big), the conditional entropy of the true labels given the SVM's side. Lower means the attributes are more linearly separable.

On both measures W\mathcal W beat Z\mathcal Z substantially.

Check your understanding

You generate two faces, A and B, and build a third by taking the styles for the 4×44\times4 and 8×88\times8 layers from B and all other styles from A. What do you expect?

  1. B's colors and skin texture on A's face shape and pose
  2. An average of the two faces at every scale
  3. B's pose, face shape and eyeglasses, with A's finer features, colors and texture
  4. A face identical to A, since only two layers changed
Show the answer

C. B's pose, face shape and eyeglasses, with A's finer features, colors and texture

The coarse layers decide large-scale structure, and AdaIN resets channel statistics at every layer, so B's coarse styles fix the layout that A's finer styles then render. This is style mixing as reported by Karras, Laine & Aila (2019).

StyleGAN2: demodulation and smooth latents

Most StyleGAN images contain a faint blob, like a water droplet, visible in the feature maps from about 64×6464\times64 upward. Karras et al. (2020) traced it to AdaIN itself. Normalizing each feature map separately discards the relative magnitudes of features, and the generator learns to sneak magnitude information past the normalization by creating a strong localized spike that dominates the statistics. Remove the normalization and the droplets disappear, but the styles need some normalization to stay in range. StyleGAN2 normalizes the weights instead, based on the statistics the activations are expected to have.

DerivationWeight modulation and demodulation
  1. wijk′=si⋅wijkw'_{ijk}=s_i\cdot w_{ijk}

    Fold the style into the convolution: scale the weights reading input map ii by its style sis_i. Here jj indexes output maps and kk the kernel's spatial taps:

  2. σj=∑i,kwijk′2\sigma_j=\sqrt{\textstyle\sum_{i,k}{w'_{ijk}}^2}

    Assume the input activations are independent with unit standard deviation. Output jj at a position is ∑i,kwijk′xi,k\sum_{i,k}w'_{ijk}x_{i,k}, a sum of independent terms, so its variance is the sum of squared weights:

  3. wijk′′=wijk′∑i,kwijk′2+ϵw''_{ijk}=\frac{w'_{ijk}}{\sqrt{\sum_{i,k}{w'_{ijk}}^2+\epsilon}}

    Divide each output map's weights by that standard deviation, with a small ϵ\epsilon for numerical safety, to restore unit variance:

  4. Unlike AdaIN this uses no statistics of the actual feature maps, only of the weights and styles, so it cannot erase information the generator carries in magnitudes, and there is no incentive to create spikes. It is also cheap: modulation and demodulation act on the kernel, implemented as a grouped convolution with one kernel per example.

Predict before you look

One output map of a 3×33\times3 convolution reads 4 input maps; every weight is 0.10.1 and every style is si=1s_i=1. With independent unit-variance inputs, what is the output's standard deviation before demodulation?

Show the answer

0.6

There are 4×9=364\times9=36 weights, so σj=36×0.01=0.36=0.6\sigma_j=\sqrt{36\times0.01}=\sqrt{0.36}=0.6. Demodulation divides those weights by 0.60.6, restoring unit variance. Doubling one style sis_i raises its 9 weights' contribution fourfold, and demodulation renormalizes the whole output, so styles change the mix of inputs, not the overall scale.

Path-length regularization. Karras et al. found that lower PPL correlated with images that looked better, and argued that a well-conditioned map from W\mathcal W to images, where a fixed-size step in w\mathbf w changes the image by a fixed amount in every direction, should help. With JwJ_{\mathbf w} the Jacobian of the generator at w\mathbf w and y∼N(0,I)\mathbf y\sim\mathcal N(\mathbf 0,I) a random image, they penalize

Ew,y(∥Jw⊤y∥2−a)2,\E_{\mathbf w,\mathbf y}\big(\norm{J_{\mathbf w}^\top\mathbf y}_2-a\big)^2,

with aa a running average of the observed lengths. Since Ey∥Jw⊤y∥2=∥Jw∥F2\E_{\mathbf y}\norm{J_{\mathbf w}^\top\mathbf y}^2=\norm{J_{\mathbf w}}_F^2, the penalty asks for the same overall gain everywhere, and in high dimensions it is minimized when JwJ_{\mathbf w} is orthogonal up to a global scale at every w\mathbf w. It cannot be pushed to zero PPL, which would mean a constant generator; Karras et al. note that minimizing PPL directly leads to a degenerate solution with zero recall. The penalty is computed only every few minibatches (lazy regularization: every 16 for the discriminator's R1R_1 penalty, every 8 for the path-length term), at little cost in quality.

StyleGAN2 also dropped progressive growing, whose intermediate resolutions produced phase artifacts: details such as teeth and eyes that stayed fixed on screen as the face turned, then jumped. A generator with skip connections that sum RGB outputs from every resolution, and a residual discriminator, learn coarse-to-fine without changing the network's topology during training.

StyleGAN3: aliasing and texture sticking

Animate a StyleGAN2 face by interpolating its latent, and fine details such as hair and stubble appear glued to the screen while the face moves underneath them: texture sticking. The generator is using absolute pixel coordinates, which it should have no access to. Karras et al. (2021) located the leaks: image borders, per-pixel noise inputs, positional encodings and, above all, aliasing from imperfect upsampling filters and from pointwise nonlinearities applied on the pixel grid. Aliasing in convolution layers is introduced in Convolution, Pooling & Receptive Fields.

Alias-free GAN (StyleGAN3) treats every feature map as the samples of a bandlimited continuous signal and requires each layer to be a well-defined operation on the continuous signal, which then makes it equivariant to translations (and optionally rotations) in the continuous domain:

  • Convolutions and up/downsampling are already fine if their filters are proper low-pass filters; StyleGAN3 uses Kaiser-windowed sinc filters, with cutoffs that rise gradually through the layers.
  • Pointwise nonlinearities are the problem. A ReLU applied to a smooth signal creates sharp kinks, whose spectrum extends to arbitrarily high frequencies; on a discrete grid those frequencies alias. StyleGAN3 temporarily upsamples by 2×2\times, applies the nonlinearity at the higher rate, low-pass filters, and downsamples back.
  • No absolute positions. The learned constant input becomes Fourier features, which can be translated and rotated exactly; per-pixel noise inputs are removed; borders are handled by computing on a margin around the visible image.

The translation-equivariant StyleGAN3-T keeps 3×33\times3 convolutions; StyleGAN3-R also becomes equivariant to rotations by using 1×11\times1 convolutions and radially symmetric (jinc-based) filters. Equivariance is measured as the PSNR, in decibels, between "transform the input, then generate" and "generate, then transform the output". FID stayed comparable to StyleGAN2 (3.67 for StyleGAN3-T and 3.66 for -R against 3.79 on unaligned FFHQ at 102421024^2), while the motion became natural: textures now move with the surfaces they belong to.

Think first StyleGAN2 is trained only on still images and is scored only on still images. Why should anyone care that it is not equivariant?

Because the latent space is used to animate and edit: interpolation videos, pose changes, and any downstream use that moves content in the image. Sticking textures are invisible in single frames and glaring in motion. More fundamentally, a network that exploits absolute pixel coordinates has learned something false about images, that content depends on where the frame is, which also limits how well its internal representations transfer.

Truncation, and where GANs stand

Every GAN has rare latents that produce poor samples. The truncation trick trades diversity for fidelity by avoiding them. BigGAN (Brock, Donahue & Simonyan, 2019), trained on ImageNet at a then-unprecedented scale (batch size up to 2,048), sampled z\mathbf z from a truncated normal, resampling any coordinate whose magnitude exceeds a threshold. Lowering the threshold raised the Inception Score, a fidelity measure, while variety fell, until FID, which also penalizes lost diversity, got worse. Not every generator tolerates truncated inputs, so BigGAN added an orthogonality penalty Rβ(W)=β∥W⊤W⊙(1−I)∥F2R_\beta(W)=\beta\norm{W^\top W\odot(\mathbf 1-I)}_F^2 with β=10−4\beta=10^{-4}, which pushes filters toward orthogonality without constraining their norms; it raised the share of models amenable to truncation from 16% to 60%.

StyleGAN truncates in W\mathcal W instead, pulling each latent toward the average:

w′=wˉ+ψ(w−wˉ),wˉ=Ez[f(z)],0≤ψ≤1.\mathbf w'=\bar{\mathbf w}+\psi(\mathbf w-\bar{\mathbf w}),\qquad\bar{\mathbf w}=\E_{\mathbf z}\big[f(\mathbf z)\big],\qquad0\le\psi\le1.

At ψ=1\psi=1 nothing changes; at ψ=0\psi=0 every sample is the "average face"; in between, samples become more typical and less varied. Applying it only to the coarse layers keeps fine-detail variety. In the language of Evaluating Generative Models, truncation raises precision and lowers recall.

Where GANs stand. Diffusion models overtook GANs in image quality around 2021 (Dhariwal & Nichol, 2021) and, by the mid-2020s, dominate image and video generation. GANs keep three niches:

  • One-step generation. A generator samples in a single forward pass. GigaGAN (Kang et al., 2023) scaled a GAN to text-to-image synthesis and generates a 512×512512\times512 image in about 0.13 seconds; StyleGAN-XL (Sauer, Schwarz & Geiger, 2022) reached 102421024^2 on ImageNet; and R3GAN (Huang, Gokaslan, Kuleshov & Tompkin, 2024) showed that a regularized relativistic loss lets a modernized, trick-free architecture beat StyleGAN2 on several datasets.
  • Adversarial losses as components. The discriminators of VQGAN-style tokenizers, latent-diffusion autoencoders, super-resolution models and neural audio codecs, and the adversarial term in diffusion distillation such as ADD (Sauer et al., 2024), which samples large image models in 1 to 4 steps (see Few-Step Generation).
  • Small data and editing. Adaptive discriminator augmentation (Karras et al., 2020) trains StyleGAN-quality models from a few thousand images, and StyleGAN latent spaces remain a laboratory for inversion and editing.

Key takeaways

  • Progressive growing trained GANs coarse to fine; StyleGAN then fed the latent through a mapping network to W\mathcal W and injected it as per-layer styles via AdaIN, starting from a learned constant, with per-pixel noise for stochastic detail.
  • AdaIN resets each channel's mean and standard deviation, so styles act at the scale of their layer, which is what style mixing exploits; PPL and linear separability showed W\mathcal W smoother and more linear than Z\mathcal Z.
  • StyleGAN2 replaced AdaIN by weight demodulation wijk′′=wijk′/∑i,kwijk′2+ϵw''_{ijk}=w'_{ijk}/\sqrt{\sum_{i,k}{w'_{ijk}}^2+\epsilon}, which removed droplet artifacts, and added path-length regularization and skip/residual architectures without progressive growing.
  • StyleGAN3 traced texture sticking to aliasing and positional leaks, and made the generator equivariant by treating feature maps as bandlimited signals and filtering around every nonlinearity.
  • Truncation (ψ<1\psi<1 in W\mathcal W, or truncated normals in BigGAN) trades diversity for fidelity. As of the mid-2020s GANs matter mainly for one-step generation, as adversarial losses inside other systems, and for small-data training and editing.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Why does StyleGAN map z∼N(0,I)\mathbf z\sim\mathcal N(\mathbf 0,I) through an 8-layer MLP to w\mathbf w instead of feeding z\mathbf z to the synthesis network?

  1. To make sampling faster
  2. To reduce the latent dimension
  3. Because w\mathbf w must follow a Gaussian distribution
  4. Because W\mathcal W is not tied to a fixed distribution, so the mapping can absorb the warping that data statistics demand and leave W\mathcal W closer to linear in the factors of variation
Show the answer

D. Because W\mathcal W is not tied to a fixed distribution, so the mapping can absorb the warping that data statistics demand and leave W\mathcal W closer to linear in the factors of variation

Z\mathcal Z is forced to be Gaussian, so a generator fed z\mathbf z directly must curve it to avoid generating rare or absent factor combinations. The learned mapping lets W\mathcal W take whatever shape suits the synthesis network, and PPL and linear separability were both better in W\mathcal W.

Question 2

What does StyleGAN2's demodulation normalize, and why does that remove the droplet artifacts?

  1. The activations of each feature map, using their measured mean and variance, exactly as AdaIN does
  2. The modulated weights of each output map, by the standard deviation the output would have for independent unit-variance inputs; no measured activation statistics are discarded, so there is no reason to create spikes
  3. The generator's output image, by clipping it to a valid range
  4. The latent w\mathbf w, by projecting it onto the unit sphere
Show the answer

B. The modulated weights of each output map, by the standard deviation the output would have for independent unit-variance inputs; no measured activation statistics are discarded, so there is no reason to create spikes

Dividing wijk′w'_{ijk} by ∑i,kwijk′2+ϵ\sqrt{\sum_{i,k}{w'_{ijk}}^2+\epsilon} fixes the expected output scale using only weights and styles. AdaIN's per-map normalization of actual activations was what the droplets were exploiting.

Question 3

You lower StyleGAN's truncation parameter ψ\psi from 11 to 0.50.5. What happens?

  1. Samples become more typical and individually cleaner, but less varied: fidelity up, diversity down
  2. Samples become more varied, because latents are spread further from the mean
  3. Nothing, because truncation only affects training
  4. The generator must be retrained for the new ψ\psi
Show the answer

A. Samples become more typical and individually cleaner, but less varied: fidelity up, diversity down

w′=wˉ+ψ(w−wˉ)\mathbf w'=\bar{\mathbf w}+\psi(\mathbf w-\bar{\mathbf w}) pulls every latent halfway toward the average, away from the rare regions that produce poor samples. In precision–recall terms, precision rises and recall falls; at ψ=0\psi=0 every sample is the same average face.

Question 4

What did StyleGAN3 identify as the main cause of texture sticking?

  1. Too few latent dimensions to describe motion
  2. Mode collapse of the generator
  3. Aliasing and other unintended positional references, such as image borders and per-pixel noise, that let the network tie details to pixel coordinates
  4. The truncation trick
Show the answer

C. Aliasing and other unintended positional references, such as image borders and per-pixel noise, that let the network tie details to pixel coordinates

Imperfect resampling filters and pointwise nonlinearities on the pixel grid create aliased frequencies that depend on the grid's position. StyleGAN3 treats feature maps as bandlimited continuous signals, filters around every nonlinearity, and removes absolute-position inputs.

Further reading

  • T. Karras, T. Aila, S. Laine & J. Lehtinen, "Progressive growing of GANs for improved quality, stability, and variation," ICLR (2018).
  • T. Karras, S. Laine & T. Aila, "A style-based generator architecture for generative adversarial networks," CVPR (2019).
  • T. Karras, S. Laine, M. Aittala, J. Hellsten, J. Lehtinen & T. Aila, "Analyzing and improving the image quality of StyleGAN," CVPR (2020).
  • T. Karras, M. Aittala, S. Laine, E. Härkönen, J. Hellsten, J. Lehtinen & T. Aila, "Alias-free generative adversarial networks," NeurIPS (2021).
  • A. Brock, J. Donahue & K. Simonyan, "Large scale GAN training for high fidelity natural image synthesis," ICLR (2019).