Course contents 20 / 34

20 / 34 · GANs

StarGAN: one generator for many domains

One network that gives a face any hair colour, gender or expression: StarGAN conditions the generator on a target label, and StarGAN v2 replaces the label by a learned style code, giving many outputs per input.

On this page 12

A face dataset labels every photo with its hair colour, gender and age. You want one tool that takes any face and makes it blond, or male, or old, or all three at once. CycleGAN translates between two domains with two generators. Here every request is a different pair of domains, and a separate model per pair does not scale.

StarGAN (Choi et al., 2018) makes the target domain an input of a single generator, and a single discriminator also says which domain an image belongs to. StarGAN v2 (Choi et al., 2020) then removes CycleGAN’s other limit, one output per input, by replacing the label with a style code drawn from a learned space of styles of that domain.

Why not one CycleGAN per pair?#

A domain is a set of images that share an attribute value: blond hair, male, a happy expression. A translator between kk domains must handle every ordered pair of them, k(k−1)k(k-1) directions. CycleGAN learns the two directions of a pair together, so it needs k(k−1)/2k(k-1)/2 models and k(k−1)k(k-1) generators: 12 for four domains, 56 for the eight facial expressions of the RaFD dataset.

Each of these generators also learns from the images of two domains only, although the shape of a face or the texture of skin is shared by all of them.

StarGAN makes the target an input. Its generator takes an image xx and a target label cc and returns G(x,c)G(x, c). In training, cc is drawn at random, so one network learns every direction, and at test time any label can be requested. This is the conditional GAN with an image in place of the noise.

How the generator reads the label#

A label is a vector with ncn_c entries: binary for attributes that can occur together (on CelebA, black, blond and brown hair, male, young), one-hot for categories that exclude each other (the eight expressions of RaFD). The generator copies each entry over a constant h×wh \times w map and concatenates these maps with the three colour channels, so its first layer sees an h×w×(3+nc)h \times w \times (3 + n_c) tensor.

The rest is the CycleGAN generator at 128×128128 \times 128 with six residual blocks and instance normalization. Each label entry adds only the weights of one input channel of the first convolution; nothing else depends on the number of domains.

The discriminator: real or fake, and which domain#

The discriminator has one convolutional trunk and two heads: DsrcD_{\mathrm{src}} scores realism, and DclsD_{\mathrm{cls}} outputs one logit per label entry. The second head is the auxiliary classifier of AC-GAN (Odena, Olah and Shlens, 2017). Let c′c' be the original label of a real image xx. The classifier enters two losses:

Lclsr=Ex,c′[−log⁡Dcls(c′∣x)],Lclsf=Ex,c[−log⁡Dcls(c∣G(x,c))].\begin{aligned} \mathcal L^{r}_{\mathrm{cls}} &= \mathbb E_{x, c'}\big[-\log D_{\mathrm{cls}}(c' \mid x)\big], \\ \mathcal L^{f}_{\mathrm{cls}} &= \mathbb E_{x, c}\big[-\log D_{\mathrm{cls}}\big(c \mid G(x, c)\big)\big]. \end{aligned}

DD minimizes the first: on real images it learns their true labels. GG minimizes the second: a translated image must be classified as the target domain. The classifier is trained on real images only, so it encodes what the domains look like in the data, and the generator is rewarded for producing exactly that.

For a one-hot label, Dcls(c∣x)D_{\mathrm{cls}}(c \mid x) is a softmax probability and −log⁡-\log of it a cross-entropy. The entries of a binary attribute vector can co-occur, so each gets its own sigmoid, and the attributes are treated as independent given the image. With logits ℓi\ell_i,

Dcls(c∣x)=∏iσ(ℓi)ci(1−σ(ℓi))1−ci,D_{\mathrm{cls}}(c \mid x) = \prod_i \sigma(\ell_i)^{c_i}\big(1 - \sigma(\ell_i)\big)^{1 - c_i},

so −log⁡Dcls(c∣x)-\log D_{\mathrm{cls}}(c \mid x) is a sum of binary cross-entropies, which is what the authors’ implementation computes for CelebA.

Worked example: classifying a fake#

Use an original synthetic tile with four independent binary attributes: striped, bright, wide and tilted. The requested label is c=(1,0,1,0)c=(1,0,1,0) and the example logits are (0.8,−0.3,1.1,0.4)(0.8,-0.3,1.1,0.4). No image dataset or trained classifier supplies these values. Each attribute contributes −[cilog⁡σ(ℓi)+(1−ci)log⁡(1−σ(ℓi))]-\big[c_i\log\sigma(\ell_i)+(1-c_i)\log(1-\sigma(\ell_i))\big]:

stripedbrightwidetilted
target cic_i1010
logit ℓi\ell_i0.8−0.31.10.4
σ(ℓi)\sigma(\ell_i)0.6900.4260.7500.599
loss term0.3710.5540.2870.913

The sum is approximately 2.126=−log⁡0.1192.126=-\log 0.119. The largest contribution is “tilted”: the target is zero, but its predicted probability exceeds one half. Changing the striped and wide logits to −0.8-0.8 and −1.1-1.1 raises the loss by 0.8+1.1=1.90.8+1.1=1.9, to about 4.0264.026. The logit gradient is σ(ℓi)−ci\sigma(\ell_i)-c_i; during a generator update it propagates through the fixed classifier into GG. It rewards matching the target label, but says nothing by itself about preserving the input’s content.

Adversarial loss and the way back#

For the realism head, StarGAN uses the WGAN-GP objective, with DsrcD_{\mathrm{src}} a critic with a real-valued output:

Ladv=Ex[Dsrc(x)]−Ex,c[Dsrc(G(x,c))]−λgp Ex^[(∥∇x^Dsrc(x^)∥2−1)2],\begin{aligned} \mathcal L_{\mathrm{adv}} = {}& \mathbb E_x\big[D_{\mathrm{src}}(x)\big] - \mathbb E_{x, c}\big[D_{\mathrm{src}}(G(x, c))\big] \\ &- \lambda_{\mathrm{gp}}\, \mathbb E_{\hat x}\Big[\big(\|\nabla_{\hat x} D_{\mathrm{src}}(\hat x)\|_2 - 1\big)^2\Big], \end{aligned}

where x^\hat x is drawn on segments between real and translated images and λgp=10\lambda_{\mathrm{gp}} = 10. The discriminator maximizes Ladv\mathcal L_{\mathrm{adv}}, with the generated images detached for that update. The generator minimizes only −Ex,cDsrc(G(x,c))-\mathbb E_{x,c}D_{\mathrm{src}}(G(x,c)); the gradient penalty is a discriminator regularizer and is not differentiated through GG.

Neither the adversarial nor the classification objective explicitly compares the translated image with its input: any realistic image of domain cc satisfies both, whatever xx was. This is CycleGAN’s problem with the adversarial loss alone, and StarGAN uses the same remedy, a cycle-consistency loss:

Lrec=Ex,c,c′ ∥x−G(G(x,c), c′)∥1.\mathcal L_{\mathrm{rec}} = \mathbb E_{x, c, c'}\, \big\|x - G\big(G(x, c),\, c'\big)\big\|_1 .

The way back is the same generator with the original label c′c'. Inverting a translation is just another translation, so no second network is needed.

The full objective#

Each player has its own classification term, so the two minimize different objectives:

LD=−Ladv+λcls Lclsr,LG=−Ex,cDsrc(G(x,c))+λcls Lclsf+λrec Lrec,\begin{aligned} \mathcal L_D &= -\mathcal L_{\mathrm{adv}} + \lambda_{\mathrm{cls}}\, \mathcal L^{r}_{\mathrm{cls}}, \\ \mathcal L_G &= -\mathbb E_{x,c}D_{\mathrm{src}}(G(x,c)) + \lambda_{\mathrm{cls}}\, \mathcal L^{f}_{\mathrm{cls}} + \lambda_{\mathrm{rec}}\, \mathcal L_{\mathrm{rec}}, \end{aligned}

with λcls=1\lambda_{\mathrm{cls}} = 1 and λrec=10\lambda_{\mathrm{rec}} = 10 in all experiments. Training uses Adam with an initial learning rate 10−410^{-4}, five critic updates per generator update as in WGAN-GP, and batches of 16. The authors’ implementation draws target labels by shuffling the labels of the batch, so every requested label is a combination that occurs in the data.

Figure

One StarGAN training step: translate, fool D, return

The data flow of StarGANTop row: x, the generator G with the target label c below it, the fake G(x, c), G again with the original label c′, the reconstruction and a dashed reconstruction arrow back to x. Below, the discriminator D twice: under x for the real image and under the fake.xreal, label c′G1010target c(tiled, concatenated)G(x, c)fake in domain cDDsrc: score ↑ (for G)Dcls → cG0101original c′G(G(x, c), c′)reconstructionrec: ‖x − G(G(x, c), c′)‖₁DDsrc: x ↑, fake ↓, + GPDcls(x) → c′1234The data flow of StarGANTop to bottom: x, the generator G with the target label c, the fake G(x, c), G again with the original label c′ and the reconstruction; a dashed arrow leads from the reconstruction back to x. On the right, the discriminator D for x and for the fake.xreal, c′G1010target cG(x, c)fake, cDDsrc: score ↑Dcls → cG0101original c′G(G(x, c), c′)reconstructionrec: ‖x − G(G(x, c), c′)‖₁DDsrc: x ↑, fake ↓Dcls(x) → c′1234
Synthetic RGB tile with four attributes: c′ = (0, 1, 0, 1), target c = (1, 0, 1, 0). G receives 7 channels: the image and label maps. The classifier directs translation; applying G again checks the cycle. This is a computation schematic, not a trained-network result.

Training on several datasets: the mask vector#

CelebA labels hair colour, gender and age; RaFD (4,824 images of 67 people) labels expressions. A model trained on both could give CelebA faces the expressions learned from RaFD. The obstacle is the reconstruction loss: it needs the full original label c′c', and each dataset knows only its own part of it.

StarGAN appends a mask vector mm, a one-hot vector over the nn datasets that says which part of the label is known, and sets the unknown parts to zero:

c~=[ c1,…,cn,m ].\tilde c = [\,c_1, \dots, c_n, m\,].

For CelebA and RaFD the unified label has 5+8+2=155 + 8 + 2 = 15 entries. A blond young woman from CelebA is (0,1,0,0,1∣0,…,0∣1,0)(0, 1, 0, 0, 1 \mid 0, \dots, 0 \mid 1, 0); the request “make her happy” is (0,0,0,0,0∣(0, 0, 0, 0, 0 \mid one-hot for happy ∣0,1)\mid 0, 1). The classifier predicts all 5+8=135 + 8 = 13 labels, but on a batch from one dataset only the outputs for that dataset’s labels enter Lclsr\mathcal L^{r}_{\mathrm{cls}} and Lclsf\mathcal L^{f}_{\mathrm{cls}}, and training alternates between the datasets.

The model learns to read the mask. Given an expression label with the wrong mask [1,0][1, 0], it ignores the expression, reads the all-zero CelebA part as “not young”, and ages the face (Choi et al., 2018, Figure 7).

One output per image and domain#

Sharing helps: a model for two RaFD expressions sees about 1,000 images, StarGAN about 4,000. An expression classifier that errs on 0.45% of real test images errs on 2.12% of StarGAN’s translations and 5.99% of CycleGAN’s (Choi et al., 2018, Table 3).

But G(x,c)G(x, c) is a function: the same image and label always give the same translation. A domain contains many appearances. “Female” covers every hairstyle and every kind of makeup, and StarGAN picks one of them for each input. On CelebA-HQ it changes the gender of a face only locally, mostly by applying makeup (Choi et al., 2020).

The obvious fix is to give the generator noise as well. In the reported StarGAN v2 ablation, the authors tried it: feed a latent code zz to GG next to the domain and ask an encoder to recover it from the output. The outputs became varied, but the codes had no way to separate domains, the authors conjecture that this favoured domain-shared variations, such as colour, over domain-specific variations, such as hairstyle. The fix that worked maps the noise to a style of a particular domain first.

StarGAN v2: a style code instead of a label#

The v2 explanation and local schematic below adapt the method described by Yunjey Choi, Youngjung Uh, Jaejun Yoo and Jung-Woo Ha in StarGAN v2, arXiv v2, licensed CC BY 4.0. Wording, organization and diagram layout are changed; see the scoped attribution. The article license does not license the separately distributed code, models or images used as training data.

Four networks#

From here on, yy is the original domain of xx, y~\tilde y a target domain, z∼N(0,I)z \sim \mathcal N(0, I) a latent code in R16\mathbb R^{16} and s∈R64s \in \mathbb R^{64} a style code. StarGAN v2 has four networks.

The generator G(x,s)G(x, s) translates xx to an image with the style ss. It receives no domain label, because the style code already belongs to a domain. The mapping network FF turns a latent code into a style code of a chosen domain, s=Fy~(z)s = F_{\tilde y}(z): an MLP with four shared layers and a branch of four more for each domain. The style encoder EE reads the style of an image of domain yy, s=Ey(x)s = E_y(x), with a shared trunk and one output head per domain. The discriminator DD has one output head per domain.

Latent-guided translation samples zz and uses s=Fy~(z)s = F_{\tilde y}(z), so varying zz can produce different outputs; the losses below encourage the model to use that variation. Reference-guided translation uses s=Ey~(xref)s = E_{\tilde y}(x_{\mathrm{ref}}) for a real image xrefx_{\mathrm{ref}} of the target domain, and the output takes on its style.

How the style enters#

The style enters through adaptive instance normalization, as in StyleGAN: each channel is normalized over its positions, then scaled and shifted by numbers computed from ss. The official implementation writes the scale as 1+γ(s)1 + \gamma(s), so a zero style map starts as plain instance normalization (Clova AI Research, 2020). The downsampling blocks use plain instance normalization; the last two bottleneck blocks and all upsampling blocks use AdaIN.

This is where StarGAN’s padding problem disappears. StarGAN’s label entered before normalization and relied on a boundary-induced spatial variation. The style acts after the normalization, which therefore cannot remove it.

One discriminator head per domain#

StarGAN v2’s discriminator asks one question per domain: is this a real image of domain yy? Each head DyD_y is a binary real-versus-fake classifier, and there is no classification loss. The authors report that this multi-task discriminator (Mescheder, Geiger and Nowozin, 2018; Liu et al., 2019) lets the generator change the global structure of an image, where the auxiliary classifier led to local edits.

Losses#

Draw a target domain y~\tilde y and a latent code zz, and let s=Fy~(z)s = F_{\tilde y}(z). The head of the target domain judges the translation:

Ladv=Ex,y[log⁡Dy(x)]+Ex,y~,z[log⁡(1−Dy~(G(x,s)))],\begin{aligned} \mathcal L_{\mathrm{adv}} = {}& \mathbb E_{x, y}\big[\log D_y(x)\big] \\ &+ \mathbb E_{x, \tilde y, z}\big[\log\big(1 - D_{\tilde y}(G(x, s))\big)\big], \end{aligned}

where DyD_y is a probability, a sigmoid of the head’s logit. In practice the generator uses the non-saturating loss −log⁡Dy~(G(x,s))-\log D_{\tilde y}(G(x, s)).

Three more terms tie the output to the style and to the input. Style reconstruction asks the style encoder to read ss back from the output, penalizing GG when it ignores distinct styles. This term alone does not prevent the mapping network from collapsing different latent codes to one style. Style diversification draws a second code s2=Fy~(z2)s_2 = F_{\tilde y}(z_2) and rewards the generator for a second output that differs from the first. The cycle returns to xx with the input’s own estimated style s^=Ey(x)\hat s = E_y(x):

Lsty=E ∥s−Ey~(G(x,s))∥1,Lds=E ∥G(x,s)−G(x,s2)∥1,Lcyc=E ∥x−G(G(x,s), s^)∥1.\begin{aligned} \mathcal L_{\mathrm{sty}} &= \mathbb E\, \big\|s - E_{\tilde y}\big(G(x, s)\big)\big\|_1, \\ \mathcal L_{\mathrm{ds}} &= \mathbb E\, \big\|G(x, s) - G(x, s_2)\big\|_1, \\ \mathcal L_{\mathrm{cyc}} &= \mathbb E\, \big\|x - G\big(G(x, s),\, \hat s\big)\big\|_1 . \end{aligned}

StarGAN’s way back used the original label c′c', which says only which domain to return to. Here the return must restore the particular appearance of the input. The generator, mapping network and style encoder play against the discriminator:

min⁡G,F,E  max⁡D    Ladv+λsty Lsty−λds Lds+λcyc Lcyc,\begin{aligned} \min_{G, F, E}\; \max_D\;\; & \mathcal L_{\mathrm{adv}} + \lambda_{\mathrm{sty}}\, \mathcal L_{\mathrm{sty}} \\ & - \lambda_{\mathrm{ds}}\, \mathcal L_{\mathrm{ds}} + \lambda_{\mathrm{cyc}}\, \mathcal L_{\mathrm{cyc}}, \end{aligned}

with λsty=λcyc=1\lambda_{\mathrm{sty}} = \lambda_{\mathrm{cyc}} = 1 and λds=1\lambda_{\mathrm{ds}} = 1 on CelebA-HQ, 2 on the animal-face dataset AFHQ. The diversity term is maximized. On an unconstrained output space it can grow without bound; even with bounded pixels it can reward unrealistic differences. The authors linearly decay its weight to zero during training to stabilize the competing objectives; this is a training choice, not a proof of stability. The same objective is also trained with reference-guided styles in place of Fy~(z)F_{\tilde y}(z).

Figure

One StarGAN v2 training step: a style, a translation and three checks

The data flow of StarGAN v2Row 1: z, the mapping network F, the style code s and the discriminator head D_ỹ. Row 2: x, the generator G, the output G(x, s), the style encoder E and the recovered style. Row 3: the input style ŝ = E_y(x), G again and the reconstruction. Row 4: a second code s₂, G and a second output, with a dashed double arrow to the first output.xdomain ynew: a style code replaces the labelzFbranch ỹs = Fỹ(z)AdaINGG(x, s)Dỹreal imageof domain ỹ?EEỹ(G(x, s))style: ‖s − Eỹ(G(x, s))‖₁Eŝ = Ey(x)GG(G(x, s), ŝ)cycle: ‖x − G(G(x, s), ŝ)‖₁s₂ = Fỹ(z₂)xGG(x, s₂)diversity ↑: ‖G(x, s) − G(x, s₂)‖₁12345The data flow of StarGAN v2Top to bottom: z, F and the style code s; x, G, the output G(x, s) and the head D_ỹ; the style encoder E and the recovered style; the input style ŝ, G and the reconstruction; a second code s₂, G and a second output.xdomain ynewzFbranch ỹs = Fỹ(z)AdaINGG(x, s)Dỹreal for ỹ?EEỹ(G(x, s))style: ‖s − Eỹ(G(x, s))‖₁ŝ = Ey(x)G(x, s)GG(G(x, s), ŝ)cycle: ‖x − G(G(x, s), ŝ)‖₁s₂ = Fỹ(z₂)xGG(x, s₂)G(x, s)diversity ↑: ‖G(x, s) − G(x, s₂)‖₁12345
Local schematic after Choi et al. (2020), CC BY 4.0; layout changed. F maps 16-dimensional z to a 64-dimensional style. E checks style, the cycle checks input recovery, and a second code tests output variation. These objectives encourage the desired behaviour without guaranteeing it.

R1: a penalty on real images only#

StarGAN used WGAN-GP. StarGAN v2 uses the non-saturating loss and adds the R1 penalty of Mescheder, Geiger and Nowozin (2018) to the discriminator’s loss:

R1=γ2 Ex∼P ∥∇xD(x)∥22,R_1 = \frac{\gamma}{2}\, \mathbb E_{x \sim P}\, \big\|\nabla_x D(x)\big\|_2^2 ,

with γ=1\gamma = 1, where D(x)D(x) is the discriminator’s logit and PP the data. The penalty acts on real images only and pulls the gradient towards zero, where WGAN-GP pulls it towards norm 1 on interpolates. A linear logit D(x)=w⊤xD(x) = w^\top x with w=(0.6,−0.8,0)w = (0.6, -0.8, 0) shows the difference: ∥w∥2=1\|w\|_2 = 1, so the WGAN-GP penalty is 0, while R1 is 12∥w∥22=0.5\tfrac12\|w\|_2^2 = 0.5. R1 asks for a discriminator that is flat on the data.

Why flat? Mescheder et al. answer with the smallest possible GAN, the Dirac-GAN. The data are a point mass at 0, the generator is a point mass at θ\theta, and the discriminator’s logit is D(x)=ψxD(x) = \psi x. With f(t)=log⁡σ(t)f(t) = \log \sigma(t), the value is V=f(0)+f(−ψθ)V = f(0) + f(-\psi\theta): the real point scores f(D(0))f(D(0)) and the fake one f(−D(θ))f(-D(\theta)). The discriminator maximizes V−γ2ψ2V - \tfrac\gamma2 \psi^2, the R1 penalty being γ2ψ2\tfrac\gamma2\psi^2 because ∇xD=ψ\nabla_x D = \psi; the generator minimizes VV. Gradient ascent and descent in continuous time, linearized at the equilibrium θ=ψ=0\theta = \psi = 0 with a=f′(0)=12a = f'(0) = \tfrac12, give

θ˙=−∂θV=a ψ,ψ˙=∂ψV−γψ=−a θ−γψ,ddt(θ2+ψ2)=2θθ˙+2ψψ˙=−2γψ2.\begin{aligned} \dot\theta &= -\partial_\theta V = a\,\psi, \\ \dot\psi &= \partial_\psi V - \gamma\psi = -a\,\theta - \gamma\psi, \\ \tfrac{d}{dt}\big(\theta^2 + \psi^2\big) &= 2\theta\dot\theta + 2\psi\dot\psi = -2\gamma\psi^2 . \end{aligned}

Without the penalty, γ=0\gamma = 0, the distance to the equilibrium is conserved: the two players circle it forever. With γ>0\gamma > 0 it shrinks. The eigenvalues of this linear system solve λ2+γλ+a2=0\lambda^2 + \gamma\lambda + a^2 = 0, so for γ=1\gamma = 1 both equal −12-\tfrac12 and the players approach the equilibrium at the rate e−t/2e^{-t/2}, up to a linear factor. This calculation concerns the local linearized continuous-time system, not a general neural training trajectory. Their Theorem 4.1 proves local convergence of simultaneous and alternating updates under assumptions I–III: a realizable equilibrium, a discriminator zero in a neighbourhood of the data support, regular parameterization manifolds and nondegeneracy/expressivity conditions, with sufficiently small learning rates. It is not a global convergence guarantee for StarGAN v2.

How translation models are measured#

The comparisons of StarGAN v2 follow a fixed protocol (Choi et al., 2020, Appendix C). For realism, every test image of a source domain is translated to a target domain with 10 random latent codes, and the FID between these translations and the training images of the target domain is computed and averaged over pairs of domains. For diversity, the LPIPS distances between the (102)=45\binom{10}{2} = 45 pairs of outputs of each test image are averaged.

Selected rows from the authors’ Table 1, with abbreviated labels, under CC BY 4.0: the CelebA-HQ ablation compares successive changes. These are published research measurements, not results of our synthetic practice.

ConfigurationFIDLPIPS
A. StarGAN98.4–
C. + multi-task DD, R1, AdaIN80.5–
D. + latent code fed to GG32.30.312
E. + mapping network and style code17.10.405
F. + style diversification: StarGAN v213.70.452

The authors attribute the C-to-D gap to the number of output samples: D supplies ten outputs per input where C supplies one. That comparison mixes a model change with sample-size bias in FID. Equal output counts in D, E and F make the comparison more informative, but a lower FID is still a distributional score, not proof of better input-preserving translations; empirical FID is not guaranteed to decrease in every larger finite sample. For reference, the FID between the training and the test images of CelebA-HQ is 14.8, and StarGAN v2 lies below it; with a small test set, that number is no floor.

Neither score looks at the input: a generator that ignores xx and draws good faces scores well. A fair report adds domain accuracy, as in StarGAN’s RaFD experiment, and a check that pose and identity survive.

Where it breaks#

Diversity scores count artifacts as diversity. Against two-domain models trained once per pair of domains, StarGAN v2 has the lowest FID on AFHQ, 16.2 against 41.5 for MUNIT. Yet MUNIT’s LPIPS, 0.511, is higher than StarGAN v2’s 0.450 (Table 2). The authors conjecture that spurious artifacts in MUNIT’s outputs explain this: two outputs that differ by artifacts are far apart in LPIPS, and the score reads that as variety.

The published StarGAN v2 setup assigns each training image one domain index, because FyF_y, EyE_y and DyD_y are heads indexed by it. Overlapping attributes are not interchangeable with that single categorical index: one CelebA face is male, young and smiling at once, so directly treating its 40 attributes as 40 mutually exclusive domains would discard this overlap. A usable partition takes one binary attribute, mutually exclusive values of one attribute, or the products of a few attributes, such as male or female times young or old. The mask vector, which joined datasets with different label sets, has no counterpart.

What changed#

CycleGANStarGANStarGAN v2
Networks for kk domainsk(k−1)k(k-1) generators and discriminatorsone GG, one DDone each of GG, FF, EE, DD
Conditionnonetarget label, tiled and concatenatedstyle code through AdaIN
Discriminatorone per domaincritic and domain classifierone real/fake head per domain
Tie to the inputtwo cycles, identity losscycle with the original labelcycle with the input’s style
Outputs per input and targetoneonemany
Labelstwo unlabelled collectionsany combination of attributesone domain per image

What you should remember#

  • One G(x,c)G(x, c) replaces k(k−1)k(k-1) pairwise generators and learns from all domains.
  • DD classifies real images; GG must make fakes it assigns to the target; the way back is G(G(x,c),c′)G(G(x, c), c').
  • A mask vector marks which dataset’s labels are known, so one model trains on several datasets.
  • StarGAN v2: a style Fy~(z)F_{\tilde y}(z) or Ey~(xref)E_{\tilde y}(x_{\mathrm{ref}}) enters through AdaIN; style, diversity and cycle losses.
  • R1 penalizes ∥∇xD∥2\|\nabla_x D\|^2 on real data; local convergence results require the stated equilibrium and regularity assumptions.
  • FID depends on sample count; diversity scores can reward artifacts.

Notebook#

Run python3 scripts/notes/generative-practice.py stargan. The synthetic diagnostic represents an object by three coordinates: two preserve its content, and the third stores a domain offset plus style. Domain offsets are −2 and 2; style lies between −0.4 and 0.4. Three content points are authored directly in the script. There are no faces, overlapping attribute labels or model checkpoints.

  • Translate from the negative to the positive domain while retaining the first two coordinates; restore the original domain and style. The saved output has zero content and cycle error, with 100% target-domain accuracy on these three constructed points.
  • Apply the identity map instead. It also has zero cycle error, but 0% target-domain accuracy. Cycle consistency alone cannot tell whether a translation happened.
  • Supply styles −0.4 and 0.4 to the same target domain. The style coordinate changes by 0.8. A map that ignores the supplied style has separation zero. These checks distinguish content preservation, domain control and style diversity. The transformation is analytic; no StarGAN networks or perceptual-quality metric are trained or evaluated.

The example, script and observations were newly authored for this course with Codex assistance; the numerical results are from the linked run. A separate standard-library verifier recomputes the four-attribute classifier example, the padding/normalization mechanism and the local linearized R1 dynamics; its saved results are also reproducible without downloads.

Next#

StarGAN v2 gives many styles across many domains with one generator, but it is one route among several. The next note follows the others: splitting every image into content and style (MUNIT), dropping the cycle in favour of a contrastive loss between patches (CUT), generating a photograph from a label map (SPADE), and adding plausible detail to a small image (SRGAN).

Where to see the images#

These models are best judged by their samples; figure numbers refer to the linked arXiv versions.

  • StarGAN (Choi et al., 2018; arXiv v3): CelebA faces given RaFD expressions in Figure 1; single and multiple attribute transfer in Figure 4; RaFD expressions in Figure 5; repository.
  • StarGAN v2 (Choi et al., 2020; arXiv v2): diverse outputs on CelebA-HQ and AFHQ in Figure 1; reference-guided synthesis in Figure 4; comparisons with the baselines in Figures 5 and 6; repository.

References#