Course contents 12 / 33

12 / 33 · GANs

StyleGAN: a style-based generator

How to make a GAN controllable: InfoGAN's mutual-information code, StyleGAN's mapping network, learned constant, per-layer AdaIN styles, noise inputs, style mixing, truncation in W and its two disentanglement metrics, StyleGAN2's weight demodulation, path-length and lazy regularization and skip architectures, and StyleGAN3's alias-free generator.

On this page 14

The previous note ended with GANs that produce convincing faces at 1024×10241024 \times 1024 and sharp ImageNet samples. The quality came from scale: growing the networks during training, attention, larger batches and models. Control did not come with it. Apart from a class label, the generator’s only input is one noise vector zz, nothing says what each direction of zz means, and moving zz in any direction changes many attributes of the image at once. This note follows two answers. InfoGAN (Chen et al., 2016) keeps the generator and changes the objective: part of the input must be readable back from the image. StyleGAN (Karras, Laine and Aila, 2019) keeps the objective and changes the generator: the code no longer enters at the input but sets the “style” of every layer, and a separate noise input takes care of random detail. Two follow-ups repair what StyleGAN broke: StyleGAN2 (Karras et al., 2020) removes its blob artifacts and smooths its latent space, and StyleGAN3 (Karras et al., 2021) stops fine detail from sticking to the pixel grid.

Notation. PP is the data distribution and DD the discriminator, as in the GAN note. The input latent is z∈Z=R512z \in \mathcal Z = \mathbb R^{512} with z∼N(0,I)z \sim \mathcal N(0, I). In StyleGAN, a mapping network f:Z→Wf: \mathcal Z \to \mathcal W gives the intermediate latent w=f(z)∈W=R512w = f(z) \in \mathcal W = \mathbb R^{512}, the synthesis network gg turns ww into an image, and the generator is G=g∘fG = g \circ f. A learned affine map AℓA_\ell turns ww into the style yℓ=(ys,ℓ,yb,ℓ)y_\ell = (y_{s,\ell}, y_{b,\ell}) of layer ℓ\ell: one scale and one bias per channel. In the InfoGAN part, cc is a latent code given to the generator next to zz, x=G(z,c)x = G(z, c), and qϕ(c∣x)q_\phi(c \mid x) is an auxiliary network that guesses cc from xx (called QQ in the paper; QQ is the model distribution elsewhere in the course). HH is entropy and DKLD_{\mathrm{KL}} the KL divergence, in nats.

Why z is entangled#

Take a face generator and move zz along one coordinate. A trained GAN can change several things at once: the head turns, but the face also becomes a different person, the hair changes length and the lighting moves. We would like a representation in which one direction changes one factor of variation (pose) and leaves the others (identity) alone: a disentangled one, in the sense of the β-VAE note. Nothing in the GAN objective asks for this. The discriminator judges whole images; it rewards realistic outputs, not a tidy use of zz.

There is also a structural reason, which the StyleGAN paper makes explicit (Karras, Laine and Aila, 2019, Section 4 and Figure 6). The generator maps a fixed distribution, N(0,I)\mathcal N(0, I), to the data. Every region of Z\mathcal Z is sampled, so every region must produce a realistic image, with the frequencies of the training set. Suppose two factors, masculinity and hair length, are encoded on two axes, and the training set has no long-haired men. A mapping that kept the axes straight would sample that missing corner. To avoid it, the map from Z\mathcal Z to image factors must curve so that the forbidden combination has no preimage, and a curved map means that moving along one axis of Z\mathcal Z changes both factors. With real datasets, where factors are correlated, some entanglement of Z\mathcal Z is unavoidable.

InfoGAN: a code the image must reveal#

InfoGAN splits the input into incompressible noise zz and a code c=(c1,…,cM)c = (c_1, \dots, c_M) with a factorized prior p(c)=∏ip(ci)p(c) = \prod_i p(c_i), and feeds both to the generator, x=G(z,c)x = G(z, c) (Chen et al., 2016, Section 4). A plain GAN could ignore cc: the solution pG(x∣c)=pG(x)p_G(x \mid c) = p_G(x) satisfies the discriminator just as well. InfoGAN therefore asks for high mutual information between the code and the image,

I(c;x)=H(c)−H(c∣x),H(c∣x)=−E(c,x)log⁡p(c∣x),\begin{gathered} I(c; x) = H(c) - H(c \mid x),\\ H(c \mid x) = -\mathbb E_{(c, x)} \log p(c \mid x), \end{gathered}

the drop in uncertainty about cc once the image is seen. I=0I = 0 when xx is independent of cc; it is largest when cc can be read off xx exactly. The objective adds it to the GAN game with a weight λ\lambda,

min⁡Gmax⁡D  V(D,G)−λ I(c;G(z,c)),\min_G \max_D \; V(D, G) - \lambda\, I\big(c; G(z, c)\big),

where VV is the GAN value function.

A lower bound on mutual information#

The posterior p(c∣x)p(c \mid x) of the generator is unknown, so II cannot be computed. InfoGAN bounds it with an auxiliary distribution qϕ(c∣x)q_\phi(c \mid x) (Section 5). Add and subtract log⁡qϕ\log q_\phi inside the conditional entropy:

−H(c∣x)=Ex Ec∼p(c∣x)log⁡p(c∣x)=Ex Ec∼p(c∣x)log⁡qϕ(c∣x)+Ex DKL(p(⋅∣x) ∥ qϕ(⋅∣x))≥Ex Ec∼p(c∣x)log⁡qϕ(c∣x),\begin{aligned} -H(c \mid x) &= \mathbb E_{x}\, \mathbb E_{c \sim p(c \mid x)} \log p(c \mid x)\\ &= \mathbb E_{x}\, \mathbb E_{c \sim p(c \mid x)} \log q_\phi(c \mid x)\\ &\quad + \mathbb E_x\, D_{\mathrm{KL}}\big(p(\cdot \mid x)\,\|\,q_\phi(\cdot \mid x)\big)\\ &\ge \mathbb E_{x}\, \mathbb E_{c \sim p(c \mid x)} \log q_\phi(c \mid x), \end{aligned}

because a KL divergence is non-negative. The remaining expectation is over pairs (c,x)(c, x) from the joint distribution of the generator. That joint can be sampled in the forward direction, c∼p(c)c \sim p(c), z∼p(z)z \sim p(z), x=G(z,c)x = G(z, c), without ever sampling the posterior (the paper’s Lemma 5.1 states this change of order). Adding H(c)H(c) gives the variational lower bound

LI(G,qϕ)=Ec∼p(c), z∼p(z)log⁡qϕ(c∣G(z,c))+H(c)≤I(c;G(z,c)),\begin{aligned} \mathcal L_I(G, q_\phi) &= \mathbb E_{c \sim p(c),\, z \sim p(z)} \log q_\phi\big(c \mid G(z, c)\big) + H(c)\\ &\le I\big(c; G(z, c)\big), \end{aligned}

which is tight when qϕq_\phi equals the posterior. The prior p(c)p(c) is fixed, so H(c)H(c) is a constant. The InfoGAN game is

min⁡G, qϕmax⁡D  V(D,G)−λ LI(G,qϕ).\min_{G,\, q_\phi} \max_D \; V(D, G) - \lambda\, \mathcal L_I(G, q_\phi) .

Maximizing LI\mathcal L_I over qϕq_\phi fits the guesser to the current generator; maximizing it over GG pushes the generator to make cc easy to guess. The trick is the one behind the ELBO: a KL divergence to an approximate posterior is dropped because it is non-negative. There it bounds a likelihood, here an information.

In practice qϕq_\phi shares all convolutional layers with the discriminator and adds one fully connected head, so the cost over a GAN is small (Section 6). For a categorical code the head is a softmax and −log⁡qϕ-\log q_\phi is a cross-entropy. For a continuous code the head outputs the mean μ(x)\mu(x) and standard deviation σ(x)\sigma(x) of a factorized Gaussian, and

log⁡qϕ(c∣x)=−(c−μ(x))22σ(x)2−ln⁡σ(x)−12ln⁡2π:\log q_\phi(c \mid x) = -\frac{(c - \mu(x))^2}{2\sigma(x)^2} - \ln \sigma(x) - \tfrac12 \ln 2\pi :

a squared error between the code and its estimate, weighted by the network’s confidence. The weight is λ=1\lambda = 1 for discrete codes; with continuous codes a smaller λ\lambda is used, because the term then involves a differential entropy and its scale differs from that of the GAN objective (Section 6).

Worked example (toy numbers). A uniform categorical code with K=10K = 10 values has H(c)=ln⁡10≈2.303H(c) = \ln 10 \approx 2.303 nats. Since log⁡qϕ≤0\log q_\phi \le 0 for a discrete distribution, LI≤ln⁡10\mathcal L_I \le \ln 10, with equality only when qϕq_\phi puts probability 1 on the true cc for every generated image: the code is then fully recoverable, and the bound equals the largest possible mutual information. For a continuous code c=0.6c = 0.6 and a guess μ=0.5\mu = 0.5, σ=0.2\sigma = 0.2, the term is −0.1250+1.6094−0.9189=0.5655-0.1250 + 1.6094 - 0.9189 = 0.5655. It is positive because a density can exceed 1; only differences of such terms matter.

What InfoGAN found#

On MNIST the code is one categorical variable with 10 values and two continuous ones uniform on [−1,1][-1, 1], next to 62 noise variables (Section 7 and Appendix C.1). The lower bound quickly reaches H(c)≈2.30H(c) \approx 2.30, while a regular GAN trained with the same auxiliary network keeps almost no information about cc in its images (Section 7.1, Figure 1). Without any label, the categorical code sorts the digits by class: matched to digit types, it classifies MNIST with a 5% error rate. One continuous code controls the rotation of the digit and the other its width, and the generator adjusts stroke thickness and style to keep the result natural; traversing the codes from −2-2 to 22, outside the training range, still gives meaningful digits (Section 7.2, Figure 2). On 3D-rendered faces, continuous codes find azimuth, elevation, lighting and the width of the face; on chairs, rotation and width; on SVHN, lighting and the context digits next to the central one; and on CelebA, with ten categorical codes of ten values each, pose, glasses, hair style and emotion (Figures 3–6).

Where InfoGAN stops#

  • The codes are chosen by hand. How many codes, of which type and with which prior is a design decision made before training: one 10-way and two continuous codes for MNIST, five continuous codes for 3D faces. Which factor each code ends up controlling is not chosen; for 3D faces and chairs, the paper shows for each factor the run, out of five, that most resembles earlier supervised results (Figures 3–4).
  • Mutual information asks for less than disentanglement. It says that cc can be read from the image. It does not say that each cic_i controls a single factor, nor that the factor is absent from zz.
  • The rest of the input stays as entangled as before. Most of the generator’s input is zz, and InfoGAN says nothing about it. The experiments use images of 28×2828 \times 28 to 64×6464 \times 64 pixels.

StyleGAN takes a different route: instead of a regularizer that asks a fixed generator to behave, it changes where and how the code enters the network.

StyleGAN: a style-based generator#

A traditional generator, such as the one of Progressive GAN, feeds the latent code through its input layer only. StyleGAN removes that input layer altogether (Karras, Laine and Aila, 2019, Section 2 and Figure 1). The code goes through a mapping network to an intermediate latent ww, ww sets the style of every convolution layer, the synthesis starts from a constant, and per-pixel noise supplies random detail. The discriminator and the loss are not changed; every change is in the generator.

Figure

The StyleGAN generator: mapping network, styles and noise

The StyleGAN generatorTop: z, the mapping network f and the code w. A horizontal bus runs from w to four A boxes, each feeding a style into its synthesis block. Middle row: the 4×4×512 constant, blocks 4×4, 8×8, 16×16, an ellipsis, block 1024² and the image x. Below every block a node B through which noise enters. Bottom inset: upsample, convolution, addition of noise, AdaIN with the style A(w).z512fMLP, 8 layersw5121A(ys, yb)AAA3const4×4×51224×42 styles8×82 styles16×162 styles1024²2 styles…ximagenoiseBnoiseBnoiseBnoiseB4inside a block, twice per resolutionupsample 2×conv3×3+B · noiseAdaINstyle A(w)then once more: conv, noise, AdaIN5The StyleGAN generatorTop: z, the mapping network f and the code w. A bus runs down from w to the A boxes on the right, each feeding a style into its synthesis block. Middle column: the constant, blocks 4×4, 8×8, 16×16, an ellipsis, 1024² and the image x. Left of every block a node B with noise. Bottom inset: upsample, convolution, addition of noise, AdaIN with the style A(w).z512fMLP, 8 layersw5121A(ys, yb)AAA3const4×4×51224×42 styles8×82 styles16×162 styles1024²2 styles⋮ximagenoiseBBBB4inside a block, ×2up 2×conv3×3+B · noiseAdaINA(w)5
Green: the input code z; blue: the intermediate code w and the feature maps; amber: learned maps; red: the image. The code z enters only the mapping network f (8 fully connected layers, 512 → 512); synthesis starts from a learned constant. The bus at the top hands the same w to every layer, but each layer has its own affine map A, so the styles differ. From below, every layer receives its own noise. The inset shows one of the two passes of a block. There are 18 synthesis layers, two per resolution from 4² to 1024²; the first three blocks and the last are drawn.
  1. Mapping network. The normalized zz passes through ff, an 8-layer MLP, and becomes w∈Ww \in \mathcal W; both have 512 dimensions.
  2. Constant input. Synthesis starts from a learned 4×4×5124 \times 4 \times 512 tensor.
  3. Styles. A learned affine map AℓA_\ell per layer turns ww into the style yℓy_\ell, which enters through AdaIN after each convolution.
  4. Noise. A learned per-channel scale BB broadcasts a single-channel Gaussian noise image to all channels; it is added after each convolution.
  5. Blocks. Two layers per resolution from 424^2 to 102421024^2, 18 in all. A block upsamples, then twice convolves, adds noise and applies AdaIN; the 4×44 \times 4 block skips the upsampling and its first convolution, acting directly on the constant. A 1×11 \times 1 convolution turns the last feature map into RGB. The generator has 26.2 million parameters, against 23.1 million for the traditional one.

The mapping network and the space W#

The argument of the first section applies to Z\mathcal Z because Z\mathcal Z has a fixed distribution that must match the data. W\mathcal W has no such constraint. Its sampling density is whatever ff makes of N(0,I)\mathcal N(0, I), so ff can absorb the curving that the data force and leave W\mathcal W closer to straight axes: in the example above, the missing combination can simply be a region of W\mathcal W that ff never reaches. The authors argue that training pushes in this direction, because it should be easier for the synthesis network to generate realistic images from a disentangled representation than from an entangled one (Section 4). It is a hypothesis, tested below with two metrics.

The mapping network is trained with a learning rate 100 times lower than the rest, because deeper mapping networks were unstable at high learning rates (Appendix C). Its depth matters. On FFHQ, a style-based generator without a mapping network, driven directly by zz, reaches FID 5.06; with an 8-layer one, 4.40. Adding an 8-layer mapping network in front of a traditional generator also improves its FID, from 5.25 to 4.87, and makes the intermediate space far better separable than its input space (Table 4; the separability score is defined below).

A learned constant instead of an input layer#

After the mapping network and AdaIN were added, the network no longer benefited from receiving the code at its first layer. StyleGAN therefore starts synthesis from a learned 4×4×5124 \times 4 \times 512 constant, initialized to ones (Section 2.1 and Appendix C), and the image depends on ww only through the styles. This step left FID about the same on FFHQ and improved it on CelebA-HQ (configurations C and D in the table below), and it makes the role of the styles clean: all image content is set by them and by the noise.

Styles through AdaIN#

Each style y=(ys,yb)=Aℓ(w)y = (y_s, y_b) = A_\ell(w) controls the layer through adaptive instance normalization, defined for channel ii of a feature map xx as (Section 2, Eq. 1)

AdaIN(xi,y)=ys,i xi−μ(xi)σ(xi)+yb,i,\mathrm{AdaIN}(x_i, y) = y_{s,i}\,\frac{x_i - \mu(x_i)}{\sigma(x_i)} + y_{b,i},

where μ(xi)\mu(x_i) and σ(xi)\sigma(x_i) are the mean and standard deviation of channel ii over its spatial positions, as in instance normalization. AdaIN, with a worked example, is in the StarGAN note, where StarGAN v2 injects its style code the same way. The style has two numbers per channel, so its dimension is twice the number of feature maps of the layer, and the biases of ysy_s start at one (Appendix C).

Why styles act locally follows from the normalization. AdaIN first sets every channel to zero mean and unit variance, and only then applies the new scale and bias. The statistics that a style imposes therefore do not survive the next AdaIN, which normalizes them away again. Each style controls one convolution, until the next AdaIN overrides it (Section 3). The style is also spatially invariant: one scale and one bias for a whole feature map. It changes what the next convolution emphasizes everywhere at once, which suits global aspects such as pose, lighting and the overall look.

Noise for stochastic detail#

Much of a portrait is random in a harmless way: the exact placement of hairs, stubble, freckles and pores can be redrawn without changing how we perceive the face. A traditional generator has to produce such variation from its input, which costs capacity and often shows as repeated patterns. StyleGAN gives each layer a fresh single-channel image of uncorrelated Gaussian noise, scaled per channel by learned factors (BB in the figure) and added after the convolution, before the nonlinearity (Section 2 and Figure 1).

The network learns to use the two inputs for different things without being told (Sections 3.2–3.3). Redrawing the noise for a fixed ww leaves identity and pose intact and moves hairs, parts of the silhouette and the background; noise only in the coarse layers (424^2 to 32232^2) gives large-scale curls, noise only in the fine layers (64264^2 to 102421024^2) fine curls and skin pores, and no noise at all gives a featureless, painterly look (Figures 4–5). The style scales whole feature maps, so it is the natural channel for global decisions; the noise is independent at every pixel, and controlling pose through it would give spatially inconsistent images, which the discriminator penalizes.

Style mixing: coarse, middle and fine styles#

Every layer receives its own style, so nothing forces them all to come from the same ww. Style mixing runs two codes z1,z2z_1, z_2 through the mapping network and uses w1w_1 for the layers before a crossover point and w2w_2 after it. During training, StyleGAN does this for a fixed share of the images, with a random crossover, as a regularizer: it prevents the network from assuming that adjacent styles are correlated (Section 3.1). The effect shows when several codes are mixed at test time. FID on FFHQ with 1 to 4 random codes and random crossovers (Table 2):

Mixing during training1 code2 codes3 codes4 codes
0% (configuration E)4.428.2212.8817.41
50%4.416.108.7111.61
90% (configuration F)4.405.116.889.03
100%4.835.176.638.40

At 90% the single-code quality is unchanged and the network tolerates mixing far better. Mixing two faces shows what each group of layers controls (Figure 3):

  • coarse styles (424^2 to 828^2): pose, general hair style, face shape and eyeglasses;
  • middle styles (16216^2 to 32232^2): smaller facial features, hair style, eyes open or closed;
  • fine styles (64264^2 to 102421024^2): mainly the colour scheme and microstructure.

The coarse layers decide the layout, the fine ones the texture. The separation is a property of the trained network, not of a label: on LSUN bedrooms the coarse styles set the camera viewpoint, the middle ones the furniture and the fine ones colours and materials (Appendix E). Feeding a separate code to every layer defines the extended space W+\mathcal W^+, which the drag-editing note uses for editing.

Truncation in W#

Regions of low data density are hard to learn for any generative model, and sampling only from the well-learned centre of the latent space improves average quality at the cost of variety. StyleGAN does this in W\mathcal W (Appendix B). Compute the centre of mass wˉ=Ez∼p(z)f(z)\bar w = \mathbb E_{z \sim p(z)} f(z) and move each sample toward it:

w′=wˉ+ψ (w−wˉ),ψ<1.w' = \bar w + \psi\,(w - \bar w), \qquad \psi < 1 .

ψ\psi multiplies every deviation from wˉ\bar w: at ψ=0.7\psi = 0.7 each ww keeps 70% of its distance from the centre, and the squared distance 49%. It is a shrink, not a rejection. At ψ=0\psi = 0 every sample becomes the “mean face” of FFHQ, which looks similar for all trained networks; negative ψ\psi gives an “anti-face”, in which viewpoint, glasses, age, colouring, hair length and often gender flip (Figure 8). The truncation trick of BigGAN acts on zz, and Brock et al. found that only some networks tolerate it, even with orthogonal regularization; truncation in W\mathcal W works reliably without changes to the loss (Appendix B). Because each layer has its own style, truncation can also be applied to the coarse layers only, leaving the fine detail untouched: the uncurated samples of the paper use ψ=0.7\psi = 0.7 for 424^2 to 32232^2 (Figure 2). All FIDs are computed without truncation.

Results on FFHQ#

The paper also introduces FFHQ (Flickr-Faces-HQ): 70,000 face images at 1024×10241024 \times 1024, crawled from Flickr under permissive licenses, automatically aligned and cropped, with much more variation in age, ethnicity, background and accessories than CelebA-HQ (Appendix A). FID, lower is better, computed against 50,000 images drawn from the training set and reported at its lowest value during training (Table 1):

ConfigurationCelebA-HQFFHQ
A. Progressive GAN baseline7.798.04
B. + bilinear resampling, longer training, tuning6.115.25
C. + mapping network and styles5.344.85
D. + learned constant, no input layer5.074.88
E. + noise inputs5.064.42
F. + mixing regularization5.174.40

On FFHQ, configurations B–F use the non-saturating loss with the R1 penalty (γ=10\gamma = 10), and CelebA-HQ uses WGAN-GP. From the improved traditional baseline B to the style-based E, FID drops by 15.8% on FFHQ and 17.2% on CelebA-HQ. Training took about a week on eight Tesla V100 GPUs (Appendix C). On LSUN, FID was 2.65 for bedrooms at 2562256^2, 3.27 for cars at 512×384512 \times 384 and 8.53 for cats at 2562256^2 (Figures 10–12).

Measuring disentanglement without an encoder#

Existing disentanglement metrics need an encoder from images to latent codes, which a GAN does not have. StyleGAN proposes two that need neither an encoder nor known factors of variation (Section 4).

Perceptual path length#

If a latent space is entangled, interpolating between two codes can produce features that are absent at both ends, a sign of a curved path through image space. Perceptual path length (PPL) measures how much the image changes along small steps of an interpolation, with the LPIPS distance dd. In Z\mathcal Z, with slerp because zz is Gaussian (Section 4.1, Eq. 2),

lZ=E[1ε2 d(G(slerp(z1,z2;t)),G(slerp(z1,z2;t+ε)))],\begin{aligned} l_{\mathcal Z} = \mathbb E\Big[\frac{1}{\varepsilon^2}\, d\big(&G(\mathrm{slerp}(z_1, z_2; t)),\\ &G(\mathrm{slerp}(z_1, z_2; t + \varepsilon))\big)\Big], \end{aligned}

with z1,z2∼p(z)z_1, z_2 \sim p(z), t∼U(0,1)t \sim U(0, 1) and ε=10−4\varepsilon = 10^{-4}. In W\mathcal W the vectors are not normalized, so the interpolation is linear (Eq. 3):

lW=E[1ε2 d(g(lerp(f(z1),f(z2);t)),g(lerp(f(z1),f(z2);t+ε)))].\begin{aligned} l_{\mathcal W} = \mathbb E\Big[\frac{1}{\varepsilon^2}\, d\big(&g(\mathrm{lerp}(f(z_1), f(z_2); t)),\\ &g(\mathrm{lerp}(f(z_1), f(z_2); t + \varepsilon))\big)\Big]. \end{aligned}

LPIPS is a squared distance, so for a smooth path d≈ε2×d \approx \varepsilon^2 \times (squared speed of the image along the path), and dividing by ε2\varepsilon^2 leaves the mean squared perceptual speed. The expectation uses 100,000 samples, and the images are cropped to the face. A short path in W\mathcal W can be unfair to Z\mathcal Z: if W\mathcal W is a flattened version of Z\mathcal Z, a straight line between two reachable points of W\mathcal W can pass through regions that ff never produces and that gg renders badly. The paper therefore also reports the endpoint version, t∈{0,1}t \in \{0, 1\}, which only compares images near codes that ff actually produces.

Linear separability#

If a latent space is disentangled, a binary attribute such as gender should be separable by a hyperplane (Section 4.2). The test: train 40 classifiers for the 40 CelebA attributes on CelebA-HQ; generate 200,000 images; classify each and keep the more confident half, 100,000 labelled codes per attribute; fit a linear SVM that predicts the label from the code (zz or ww); and compute the conditional entropy H(Y∣X)H(Y \mid X) of the classifier’s label YY given the side of the hyperplane XX. The score is exp⁡(∑i=140H(Yi∣Xi))\exp\big(\sum_{i=1}^{40} H(Y_i \mid X_i)\big). It equals 1 when every attribute is perfectly predicted by a hyperplane and grows with the information the hyperplanes miss; lower is better.

Both metrics on FFHQ, lower is better (Tables 3 and 4):

GeneratorSpacePPL, fullPPL, endSeparability
traditional (B)Z\mathcal Z412.0415.310.78
style-based, no noise (D)W\mathcal W446.2376.63.61
+ noise inputs (E)W\mathcal W200.5160.63.54
+ mixing 90% (F)W\mathcal W234.0195.93.79
traditional + 8-layer mappingZ\mathcal Z896.2902.0170.29
traditional + 8-layer mappingW\mathcal W324.5212.26.52

W\mathcal W is consistently better separable than Z\mathcal Z, and its paths are shorter. The traditional generator with a mapping network is the clearest case: its intermediate space is easy to separate (6.52), while its input space becomes much worse (170.29), which supports the claim that the input space of a GAN can be arbitrarily entangled. Mixing regularization costs some path length and separability; the authors suggest that it makes it harder for W\mathcal W to encode factors that span several scales. They also note that PPL slowly rises late in training while FID keeps falling (Appendix D): quality was bought partly with entanglement.

StyleGAN2: removing the artifacts#

StyleGAN images often contain a characteristic blob that resembles a water droplet, and moving features such as teeth sometimes stay fixed in place. StyleGAN2 traces the first to AdaIN and the second to progressive growing, and adds a regularizer that makes the generator smoother (Karras et al., 2020). It focuses all analysis on W\mathcal W, the space that matters to the synthesis network.

Droplets and the normalization in AdaIN#

The droplet appears around 64×6464 \times 64, is present in all feature maps even when hard to see in the final image, and grows stronger at higher resolutions (Section 2, Figure 1). StyleGAN2’s hypothesis: AdaIN normalizes the mean and variance of each feature map separately, which destroys any information carried by the magnitudes of the features relative to each other. The generator sneaks this signal-strength information past the normalization by creating a strong, localized spike that dominates the statistics; with the spike in place it can scale the signal elsewhere as it likes. The hypothesis is supported by an experiment: when the normalization step is removed, the droplets disappear completely. In the rare cases (perhaps 0.1% of images) where the droplet is missing, the image is severely corrupted (Figure 15).

Worked example (toy numbers). A feature map of 16 positions carries a pattern of ±a\pm a on 15 of them (8 positive, 7 negative) and a spike SS at the 16th. After instance normalization the amplitude of the pattern is 1.035 for S=0S = 0, whatever aa is: the normalization discards the scale that the previous layers chose. With a spike it depends on the ratio S/aS/a; for a=1a = 1: 0.737 for S=4S = 4, 0.386 for S=10S = 10 and 0.103 for S=40S = 40, while the spike itself becomes a large value (3.85 at S=40S = 40) at its own position. The spike works as a volume knob that the normalization cannot remove.

StyleGAN2 first simplifies the block (Section 2.1, Figure 2). AdaIN is split into its two parts, normalization and modulation. The bias and the noise are moved out of the part of the network where a style is active, so that their effect no longer scales with the style; normalization and modulation then act on the standard deviation alone, without the mean; and the bias, noise and normalization of the constant input are removed. The block that remains is modulation, convolution, normalization, and the normalization can now be replaced.

Weight modulation and demodulation#

Write wijkw_{ijk} for the weight of a convolution from input channel ii to output channel jj at kernel position kk, and sis_i for the style’s scale of input channel ii (in this section ww with three indices is a weight, not the latent). The derivation takes three steps (Section 2.2, Eqs. 1–3).

Step 1: modulation as a weight change. Scaling input channel ii by sis_i and then convolving is the same as convolving with scaled weights, because a convolution is linear in each input channel:

wijk′=si wijk.w'_{ijk} = s_i\, w_{ijk} .

Step 2: the output scale. Assume the input activations are independent random variables with unit standard deviation. Output jj at one position is ∑i,kwijk′ xi,k\sum_{i,k} w'_{ijk}\, x_{i,k}, a sum of independent terms, and the variance of such a sum is the sum of the variances, ∑i,kwijk′2⋅1\sum_{i,k} w'^2_{ijk} \cdot 1. Its standard deviation is the L2L_2 norm of the weights of output channel jj:

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

Step 3: demodulation. Instance normalization aims to remove the effect of ss from the output statistics. Dividing output jj by σj\sigma_j does this directly, and the division can again be folded into the weights, with a small ϵ\epsilon for numerical safety:

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

The whole style block is now one convolution whose weights depend on the style. The normalization is computed from the weights, not from the feature maps, so a spike in the data no longer changes how the data are scaled, and the droplet loses its purpose. The price is that demodulation rests on a statistical assumption about the inputs rather than on their actual content; the authors call it weaker than instance normalization. Similar variance arguments are used in weight initialization, and the computation is the one of weight normalization. The weights differ for every sample in a minibatch, which standard convolution routines do not support; the implementation reshapes the minibatch into one sample with NN groups and uses grouped convolutions (Appendix B). The activation functions are scaled so that they keep the expected signal variance.

Worked example (toy numbers). One output channel of a 1×11 \times 1 convolution with two inputs has weights w=(0.6,0.8)w = (0.6, 0.8), so unit-variance independent inputs give an output of variance 0.36+0.64=10.36 + 0.64 = 1. A style s=(3,0.5)s = (3, 0.5) gives w′=(1.8,0.4)w' = (1.8, 0.4) and an output variance of 3.24+0.16=3.43.24 + 0.16 = 3.4. Demodulation divides by σ=3.4=1.844\sigma = \sqrt{3.4} = 1.844: w′′=(0.976,0.217)w'' = (0.976, 0.217), and the variance is 0.953+0.047=10.953 + 0.047 = 1 again. The style still decides the mix, the first input now carries 95% of the variance instead of 36%, but not the overall scale. If the two inputs were correlated with coefficient 0.5, the same weights would give 1+2⋅0.5⋅0.976⋅0.217=1.211 + 2 \cdot 0.5 \cdot 0.976 \cdot 0.217 = 1.21: the assumption matters. The figure repeats the experiment on a toy 3×33 \times 3 convolution with six random styles.

Figure

Demodulation restores unit output variance

Output standard deviations of a modulated convolutionFor six samples, three columns of dots on a logarithmic axis from 0.5 to 20. Amber dots spread from 1.4 to 14.9, blue dots sit on the dashed line at 1, hollow dots range from 0.65 to 1.2.0.51251020output std (log scale)sample 1sample 2sample 3sample 4sample 5sample 6modulation onlydemodulated, i.i.d. inputdemodulated, smooth inputOutput standard deviations of a modulated convolutionFor six samples, three columns of dots on a logarithmic axis from 0.5 to 20. Amber dots spread from 1.4 to 14.9, blue dots sit on the dashed line at 1, hollow dots range from 0.65 to 1.2.0.51251020output std (log scale)123456modulation onlydemodulated, i.i.d. inputdemodulated, smooth inputsample
A toy 3×3 convolution with 8 input and 8 output channels, weights from N(0, 1/72), input maps of 26×26 independent standard normals (outputs 24×24). Each of six samples has its own style vector, s_i = exp(1.5 n_i) with standard normal n_i. For every sample the dots show the standard deviations of all 8 output channels. Amber: modulation alone, w′ = s_i w: from 1.4 to 14.9, different for every sample and channel. They agree with the prediction σ_j = (Σ w′²)^½ to within 7%. Blue: after demodulation, w″ = w′/σ_j: from 0.93 to 1.05; what remains is the sampling error of a standard deviation over 576 positions. Hollow: the same demodulated weights with a spatially correlated input (a 3×3 sum divided by 3: variance 1, neighbour correlation 2/3): from 0.65 to 1.20. Demodulation relies on the assumption of independent unit-variance inputs and is as exact as that assumption. Toy numbers.

The new design removes the droplets while keeping full control through styles. FID is almost unchanged, 4.40 to 4.39 on FFHQ, but precision falls from 0.721 to 0.702 and recall rises from 0.399 to 0.425 (Table 1, rows A and B; see precision and recall). The authors consider this shift desirable, since recall can be traded back for precision with truncation but not the other way round.

Path-length regularization#

FID and precision and recall have a blind spot. StyleGAN2 shows pairs of LSUN models with the same FID and similar precision and recall whose images differ clearly in quality, and the difference is captured by PPL: on LSUN Cat, StyleGAN at FID 8.53 has PPL 924, and an early snapshot of StyleGAN2 at the same FID has PPL 387 and produces cat-shaped objects more often (Section 3, Figures 4–5 and 13). Images with low per-image PPL tend to look good, those with high PPL worse. The authors’ hypothesis: as the discriminator penalizes broken images, the easiest way for the generator to improve is to stretch the regions of the latent space that give good images, which squeezes the bad ones into small regions of rapid change. Minimizing PPL itself would push toward a degenerate generator with zero recall, so they regularize something weaker: that a fixed-size step in W\mathcal W gives a fixed-size change in the image, whatever the step’s direction (Section 3.2).

The local behaviour of gg at ww is captured by its Jacobian Jw=∂g(w)/∂wJ_w = \partial g(w) / \partial w. The regularizer is (Eq. 4)

Lpl=Ew, y∼N(0,I)(∥Jw⊤y∥2−a)2,\mathcal L_{\mathrm{pl}} = \mathbb E_{w,\, y \sim \mathcal N(0, I)} \big(\lVert J_w^\top y \rVert_2 - a\big)^2 ,

where yy is a random image with normally distributed pixels, w=f(z)w = f(z) with z∼N(0,I)z \sim \mathcal N(0, I), and aa is a running average of ∥Jw⊤y∥2\lVert J_w^\top y \rVert_2 (decay 0.99), so the network chooses the global scale itself. The Jacobian is never formed. By the chain rule, the gradient of the scalar g(w)⋅yg(w) \cdot y with respect to ww is Jw⊤yJ_w^\top y, so a single backward pass gives Jw⊤y=∇w(g(w)⋅y)J_w^\top y = \nabla_w \big(g(w) \cdot y\big).

Why does this favour an even mapping? Write the singular value decomposition Jw⊤=UΣV⊤J_w^\top = U \Sigma V^\top with singular values σ1,…,σL\sigma_1, \dots, \sigma_L (L=512L = 512, the dimension of W\mathcal W). A standard normal yy is unchanged in distribution by the rotation V⊤V^\top, the components beyond the first LL are multiplied by zero, and UU does not change lengths, so ∥Jw⊤y∥\lVert J_w^\top y\rVert is distributed as (∑i=1Lσi2y~i2)1/2\big(\sum_{i=1}^{L} \sigma_i^2 \tilde y_i^2\big)^{1/2} with independent standard normal y~i\tilde y_i. With aa at the mean length, the penalty is the variance of this length. The sum Q=∑iσi2y~i2Q = \sum_i \sigma_i^2 \tilde y_i^2 has mean ∑iσi2\sum_i \sigma_i^2 and variance 2∑iσi42\sum_i \sigma_i^4, and for large LL the variance of Q\sqrt Q is approximately Var⁡Q/(4 EQ)=∑iσi4/(2∑iσi2)\operatorname{Var} Q / (4\,\mathbb E Q) = \sum_i \sigma_i^4 / \big(2\sum_i \sigma_i^2\big). For a fixed ∑iσi2\sum_i \sigma_i^2, the Cauchy–Schwarz inequality (∑iσi2)2≤L∑iσi4\big(\sum_i \sigma_i^2\big)^2 \le L \sum_i \sigma_i^4 makes this smallest when all σi\sigma_i are equal: a Jacobian that is orthogonal up to a global scale, which preserves lengths and squeezes no direction. The paper reaches the same conclusion with a concentration argument (Appendix C). Toy numbers: with L=512L = 512 and ∑iσi2=512\sum_i \sigma_i^2 = 512, equal singular values give a variance of 0.50; half of them three times larger than the other half give 0.82 (0.81 in a Monte Carlo run with 20,000 draws). Spectral normalization, by contrast, constrains only the largest singular value (see the WGAN note); adding it to the generator, with or instead of these changes, always worsened FID (Section 3.2 and Appendix E). The term is weighted by γpl=ln⁡2/(r2(ln⁡r−ln⁡2))\gamma_{\mathrm{pl}} = \ln 2 / \big(r^2 (\ln r - \ln 2)\big) for output resolution rr, a choice that worked across all datasets (Appendix B).

With the regularizer, models behave more reliably, the generator becomes easier to invert, and the distribution of per-image PPL tightens without its mode going to zero. On FFHQ, PPL falls from 158.0 to 122.5 while FID barely moves, 4.38 to 4.34; on LSUN Car, FID rises from 2.83 to 3.43, which points to a trade-off between FID and PPL on less structured datasets (Table 1, rows C and D).

Lazy regularization#

The R1 penalty and the path-length term need extra backward passes. StyleGAN2 computes them less often than the main loss: once every k=16k = 16 minibatches for the discriminator and k=8k = 8 for the generator, in a separate pass (Section 3.1 and Appendix B). The term is multiplied by kk to keep the size of its gradients, and because kk main steps are now followed by one regularization step, Adam’s learning rate and decay rates are adjusted with c=k/(k+1)c = k/(k+1): λ′=cλ\lambda' = c\lambda, β1′=β1 c\beta_1' = \beta_1^{\,c}, β2′=β2 c\beta_2' = \beta_2^{\,c}. Running R1 once every 16 minibatches did no harm, FID 4.39 to 4.38 on FFHQ (Table 1, row C). With weight demodulation, lazy regularization and code optimizations, training at 102421024^2 rose from 37 to 61 images per second on eight V100 GPUs (Section 6).

Without progressive growing#

Progressive growing, the training scheme StyleGAN inherited from Progressive GAN, gives StyleGAN a strong location preference for details: when a face turns, the teeth or the eyes can stay aligned with the camera and then jump to the next preferred position (Section 4, Figure 6). The authors’ explanation: during growing, each resolution serves for a while as the output resolution, so it is pushed to produce maximal-frequency detail; the trained network keeps excessively high frequencies in its intermediate layers, which compromises shift invariance (Figure 16).

StyleGAN2 keeps the goal of growing, low resolutions first and fine detail later, without changing the network during training. It compares three generators and three discriminators trained without growing (Section 4.1, Figure 7): the original feedforward networks; skip connections, where the generator upsamples and sums RGB outputs from every resolution and the discriminator receives a downsampled image at every resolution; and residual networks, whose two branches are added and multiplied by 1/21/\sqrt2 to keep the variance. FID and PPL on FFHQ (Table 2):

Generator / discriminatororiginalinput skipsresidual
original4.32 / 2654.18 / 2353.58 / 269
output skips4.33 / 1693.77 / 1273.31 / 125
residual4.35 / 2033.96 / 2293.79 / 243

Skip connections in the generator improve PPL strongly, and a residual discriminator improves FID. StyleGAN2 uses a skip generator and a residual discriminator. Measuring how much each resolution contributes to the summed output then shows the generator behaving like progressive growing on its own: low resolutions dominate early, higher ones later. But the 102421024^2 layers never took over, and the images looked like sharpened 5122512^2 images. Doubling the feature maps of the 64264^2 to 102421024^2 layers of both networks fixed this, at 22% and 21% more parameters for the generator and the discriminator (Section 4.2, Figure 8).

Results#

FFHQ at 1024×10241024 \times 1024; FID and PPL lower is better, precision and recall higher is better (Table 1):

ConfigurationFIDPPLPrecisionRecall
A. StyleGAN4.40212.10.7210.399
B. + weight demodulation4.39175.40.7020.425
C. + lazy regularization4.38158.00.7190.427
D. + path-length regularization4.34122.50.7150.418
E. + no growing, new G and D3.31124.50.7050.449
F. + large networks (StyleGAN2)2.84145.00.6890.492
A with large networks3.98199.20.7160.422

FID falls by 35.5%, from 4.40 to 2.84, and recall rises from 0.399 to 0.492. The last row shows that capacity alone does not explain the gain. PPL here is the endpoint version in W\mathcal W computed on whole images, without the face crop of the StyleGAN paper, so it is not directly comparable with the earlier table. On LSUN, FID improves from 3.27 to 2.32 for cars, 8.53 to 6.93 for cats, 4.21 to 3.86 for churches and 3.83 to 3.43 for horses, and PPL falls by about half or more in all four (Tables 1 and 3).

StyleGAN3: details glued to the pixel grid#

StyleGAN2 still has a defect that shows in motion. In a latent interpolation, coarse features move, but fine detail such as hair or fur stays fixed in pixel coordinates, as if glued to the screen rather than to the surface of the face: texture sticking (Karras et al., 2021, Section 1, Figure 1). The network has access to unintended positional references: image borders, per-pixel noise inputs, positional encodings, and aliasing, the faint after-images of the pixel grid left by non-ideal upsampling filters (nearest, bilinear, strided convolutions) and by pointwise nonlinearities such as ReLU. The network amplifies even slight aliasing and combines it across scales into texture motifs fixed in screen coordinates.

StyleGAN3 treats every feature map as a continuous, bandlimited signal that the pixel grid merely represents, as in the Nyquist–Shannon sampling theorem (Section 2). A layer is then equivariant to a translation or rotation if it commutes with it in the continuous domain, and it must not create frequencies that the output grid cannot represent. Convolution is fine. Upsampling must use a close approximation of the ideal low-pass filter: a windowed sinc with a Kaiser window, since common filters attenuate aliases far too little, and filters with over 100 dB attenuation turn out to be needed. A pointwise nonlinearity can create arbitrarily high frequencies, so it is applied at twice the resolution and low-pass filtered back down, in a custom CUDA kernel (Sections 2.1 and 3.2). The generator also replaces the learned constant with Fourier features that can be translated and rotated exactly, removes the noise inputs, keeps a 10-pixel margin around the canvas instead of relying on padding, and sets the cutoff of each of its 14 layers separately. The rotation-equivariant version StyleGAN3-R uses 1×11 \times 1 convolutions and radially symmetric filters; the translation-equivariant one is StyleGAN3-T. Equivariance is measured as a PSNR in decibels between the output for a transformed input and the transformed output (EQ-T for translation, EQ-R for rotation, Eq. 3).

On unaligned FFHQ at 102421024^2 (Figure 5), StyleGAN2 reaches FID 3.79 with EQ-T 15.89 dB, StyleGAN3-T 3.67 with 61.69 dB, and StyleGAN3-R 3.66 with 64.78 dB and an EQ-R of 47.64 dB, against 10.79 for StyleGAN2. On aligned FFHQ the FIDs are 2.70, 2.79 and 3.07. The baseline in this comparison is a StyleGAN2 with Fourier features, not the exact configuration F above. The FID stays level with StyleGAN2 while the internal representation changes completely; the gain is the motion, which matters for video and animation. The price is compute: on FFHQ, 1106 GPU hours for StyleGAN2, 1576 (+42%) for StyleGAN3-T and 2248 (+103%) for StyleGAN3-R.

Editing real images#

Everything above controls images that the generator itself produced from a known ww. To edit a photograph, we first need a ww whose image reproduces it: GAN inversion, an optimization over the latent, possibly per layer in W+\mathcal W^+, explained with its distortion–editability trade-off in the drag-editing note. StyleGAN2’s own projector optimizes ww and the noise maps under LPIPS, with ramped-down noise added to ww and a regularizer that keeps the noise maps from carrying coherent signal; it stays in W\mathcal W rather than W+\mathcal W^+, because the extended space can reproduce arbitrary images that the generator could never have produced (Section 5). The path-length regularized generator is much easier to invert: images generated by StyleGAN2 project back almost perfectly, which makes it possible to attribute a generated image to the network that made it, while projections of real training images show clear differences (Section 5.1, Figures 9–10).

What changed#

Traditional generatorInfoGANStyleGANStyleGAN2StyleGAN3
Where the code entersfirst layerfirst layer, as (z,c)(z, c)every layer, as styles from w=f(z)w = f(z)every layer, as weight modulationevery layer, as weight modulation
Source of controlnoneMI term with an auxiliary networkarchitecture: mapping network, styles, noisethe samethe same
Normalization in the generatorbatch or pixel normbatch normAdaINdemodulation of the weightsdemodulation, filtered resampling
Random detailfrom zzfrom zzper-pixel noiseper-pixel noisenoise removed
Training scheduleprogressive growing (Progressive GAN)fixed networkprogressive growingskip G, residual D, no growingno growing
Known artifact addressed–trivial use of the codeentanglement of Z\mathcal Zdroplets, phase artifactstexture sticking

Limitations#

  • No encoder. A StyleGAN maps codes to images only. Editing a real photo needs an inversion by optimization or a separately trained encoder, and what lies outside the generator’s range cannot be reached.
  • Disentanglement is encouraged, not guaranteed. The mapping network gives the generator room to straighten W\mathcal W, but nothing forces it. The metrics improve without reaching their ideal values, the separability score of W\mathcal W is 3.79 against a floor of 1, and PPL rises again late in training.
  • The coarse, middle and fine split is found, not specified. Which attributes end up in which layers depends on the data and the training run, and some factors, like hair style, are spread over several groups.
  • Demodulation is approximate. It equalizes output variance only under its statistical assumption, and needs grouped convolutions with per-sample weights.
  • Trade-offs remain. Path-length regularization can cost FID on less structured datasets, truncation trades variety for quality, and the rotation-equivariant StyleGAN3-R needs about twice the GPU hours of StyleGAN2.
  • One kind of object per model. The results of all three StyleGAN papers are on collections of a single kind of object, such as faces, cars, cats, bedrooms or beaches, often aligned. FFHQ is aligned and cropped; StyleGAN3 created unaligned versions of FFHQ and MetFaces to test equivariance.

Summary#

  • A GAN’s input zz follows a fixed distribution that must cover the data, so missing combinations of factors force a curved, entangled map from Z\mathcal Z to images.
  • InfoGAN adds a code cc and maximizes a variational lower bound Elog⁡qϕ(c∣G(z,c))+H(c)\mathbb E \log q_\phi(c \mid G(z, c)) + H(c) on the mutual information between cc and the image; on MNIST it finds digit class, rotation and width without labels, but the codes are designed by hand and the rest of zz stays entangled.
  • StyleGAN maps zz through an 8-layer MLP to ww, starts synthesis from a learned constant, injects ww through a per-layer affine map and AdaIN, adds per-pixel noise for stochastic detail, and regularizes with style mixing. Coarse styles carry pose and shape, middle ones facial features, fine ones colour and microstructure; truncation shrinks ww toward wˉ\bar w.
  • Perceptual path length and linear separability measure disentanglement without an encoder; both favour W\mathcal W over Z\mathcal Z.
  • StyleGAN2 replaces AdaIN’s data-dependent normalization by weight modulation w′=siww' = s_i w and demodulation w′′=w′/∥wj′∥2w'' = w' / \lVert w'_{j} \rVert_2, which removes the droplets; adds path-length regularization that favours an orthogonal Jacobian; computes regularizers lazily; and replaces progressive growing with a skip generator and a residual discriminator. FFHQ FID falls from 4.40 to 2.84.
  • StyleGAN3 removes aliasing by treating feature maps as continuous signals, which ends texture sticking at the same FID.

Code#

A modulated convolution with per-sample weights, run as one grouped convolution, and a numerical check of the identity behind the path-length regularizer. It runs in about a second on a CPU.

import torch
import torch.nn.functional as F

torch.manual_seed(0)

# 1. A modulated 3x3 convolution with per-sample weights, run as one grouped convolution.
N, C, k, H = 4, 64, 3, 32                       # 4 samples, 64 channels in and out
x = torch.randn(N, C, H, H)                     # i.i.d. unit-variance inputs
w = torch.randn(C, C, k, k) / (C * k * k) ** 0.5
s = torch.exp(1.5 * torch.randn(N, C))          # one style vector per sample
wm = w[None] * s[:, None, :, None, None]        # modulate: (N, C_out, C_in, k, k)
wd = wm * (wm.pow(2).sum([2, 3, 4], keepdim=True) + 1e-8).rsqrt()   # demodulate

def conv(weights):
    y = F.conv2d(x.reshape(1, N * C, H, H), weights.reshape(N * C, C, k, k), groups=N)
    return y.reshape(N, C, H - 2, H - 2)

for name, wt in [("modulated", wm), ("demodulated", wd)]:
    sd = conv(wt).std(dim=(2, 3))               # std of every output channel of every sample
    print(f"{name:12s} std of channels: min {sd.min():.2f}, max {sd.max():.2f}")
# modulated    std of channels: min 3.31, max 6.62
# demodulated  std of channels: min 0.92, max 1.06

# 2. The path-length trick: J^T y equals the gradient of g(w) . y with respect to w.
g = torch.nn.Sequential(torch.nn.Linear(8, 32), torch.nn.LeakyReLU(0.2), torch.nn.Linear(32, 100))
wv = torch.randn(8, requires_grad=True)
y = torch.randn(100)                            # a random "image" direction
J = torch.autograd.functional.jacobian(g, wv)   # 100 x 8
(grad,) = torch.autograd.grad(g(wv) @ y, wv)
print("max |J^T y - grad| =", f"{(J.T @ y - grad).abs().max():.1e}")
# max |J^T y - grad| = 3.6e-07   (float32 rounding)

Next#

StyleGAN controls what it generates: coarse and fine styles, a truncation knob, directions in W\mathcal W. It still has no way back from an image to its code. Inversion is an optimization run separately for every photograph, and nothing in training ensures that a real image has a good code at all. The next note gives a GAN an encoder, trained together with the generator: adversarial autoencoders and α-GAN.

Where to see the images#

These models are best judged by their samples. Each line says where to find them; figure numbers refer to the linked arXiv version.

  • InfoGAN (Chen et al., 2016; arXiv v1): one latent code varied at a time on MNIST in Figure 2 (digit class, rotation, width), on 3D faces in Figure 3, 3D chairs in Figure 4, SVHN in Figure 5 and CelebA in Figure 6.
  • StyleGAN (Karras, Laine and Aila, 2019; arXiv v3): uncurated FFHQ faces in Figure 2; style mixing in Figure 3; stochastic variation from the noise inputs in Figures 4 and 5; the truncation trick in Figure 8; uncurated LSUN bedrooms, cars and cats in Figures 10–12; repository with the result video.
  • StyleGAN2 (Karras et al., 2020; arXiv v2): droplet artifacts in Figure 1 and their removal by demodulation in Figure 3; phase artifacts of progressive growing in Figure 6; hand-picked samples in Figure 11 and uncurated samples for every dataset in Figure 12; repository with the result video and example images.
  • StyleGAN3 (Karras et al., 2021; arXiv v4): texture sticking in Figure 1; internal feature maps of StyleGAN2 and StyleGAN3 in Figure 6; uncurated samples for FFHQ-U, MetFaces-U, AFHQv2 and Beaches in Figures 7–10; project page with videos. Texture sticking shows only in motion, so the videos say more than the figures.

References#