Beyond CycleGAN: MUNIT, CUT and SPADE
Other ways to keep a translation faithful to its input: content and style instead of a cycle (MUNIT), a contrastive loss between patches (CUT), a segmentation mask inside every normalization layer (SPADE), and super-resolution, where the best answer by pixels is a blurry average (SRGAN).
Content and style
StarGAN v2 gave one input many outputs (see StarGAN: one generator for many domains). A style code entered the generator through AdaIN, and a cycle carried the image back with its own style. Three requests are still open. Translate without a second pass through a cycle. Render a photo from a map of labels, "sky here, road there". Make a small image sharp at four times the size. This topic covers one answer to each, and starts with an older route to many outputs.
MUNIT (Huang et al., 2018) assumes that an image is made from two codes. The content code is shared by both domains: the spatial structure, such as a cat's pose and layout. The style code belongs to domain : the rendering, such as fur and colour. Here is content, not StarGAN's label.
Each domain gets a content encoder , a style encoder and a decoder . To translate from domain 1 to domain 2, keep the content and swap the decoder:
A new gives a new output. Taking from a real image of the second domain gives example-guided translation: the output copies the style of the example.
The shapes of the two codes do much of the separating. For a image, the content is a feature map computed with instance normalization. That normalization removes each channel's mean and spread, statistics that carry much of the style. The style is a vector of just 8 numbers from global average pooling, so it has no layout at all. The decoder injects it through AdaIN, as in StyleGAN: a style-based generator, with the scales and shifts computed from by a small MLP.
Reconstruction instead of a cycle
MUNIT trains its encoders and decoders to be inverses in both directions. Take a real , its content and a random style . Three losses tie everything together:
The same three terms run with the domains swapped. Least-squares adversarial losses make translations look like real images of the target domain. The weights are for the image terms and for the content and style terms.
Image reconstruction makes each pair an autoencoder of its own domain. Content reconstruction ties the output to the input: the target domain's encoder must read back from the translation. Style reconstruction forces the decoder to use . Without it, a decoder learns to ignore a random input, as the pix2pix generator ignored its noise.
Why not simply add CycleGAN's cycle? Huang et al. (2018, Proposition 5) show that it fights the randomness. Suppose translation is random in both directions, its outputs look like the other domain, and both cycles hold exactly: every translation of , translated back, returns , and every translation of , translated back, returns . Let and be two translations of one input . By the forward cycle, every way back from lands on . Now apply the backward cycle to and see what it demands of .
The two cycles together leave each input a single translation: CycleGAN's one output per input, now as a theorem. MUNIT keeps a weaker cycle instead. Translate with a random , then translate back with the original's own style , and you get . This style-augmented cycle holds at the optimum of the three reconstruction losses. StarGAN v2's cycle with the input's style is the same idea.
One ablation is a warning about measuring "many outputs". Without image reconstruction, outputs of the same input differ about twice as much as MUNIT's, by a learned perceptual distance (LPIPS, which the course defines later). Human raters prefer them in only 6% of comparisons. Artifacts make outputs differ, and a diversity score counts them. A diversity number means something only next to a quality number.
A contrastive loss instead of a cycle
The cycle assumes that the two domains correspond one to one, and many do not: a horse can become many zebras, and a photo holds more than its label map. It also costs a second generator and a second discriminator, which exist only to check the first. CUT (Park et al., 2020) keeps a single generator, , and asks for a different tie. A patch of the output should tell us which patch of the input it came from. A zebra's forehead should point back to the horse's forehead, and to nothing else in the photo.
The tool is InfoNCE (van den Oord, Li and Vinyals, 2018). It turns "is related to ?" into a classification. A query , its positive and negatives are unit vectors, and a softmax over their dot products must pick the positive:
This is the cross-entropy of an -way classification with temperature ; CUT uses .
Why does a low loss mean that the output remembers the input? If the candidates carried no information about the query, the positive would be as likely as any negative. The best classifier could then give it only , and the loss would sit at the chance level . Van den Oord et al. turn this into a bound on the mutual information, the KL divergence between the joint distribution of and and the product of their marginals: . A loss far below chance requires dependence.
The temperature decides how much small differences count. Let a query have cosine with its positive and , and with three negatives. With the positive gets probability , a loss of , close to chance, . With the gap of to the nearest negative becomes in the logits. The positive gets , and the loss falls to . A small temperature makes the loss sensitive to small differences, and the hardest negative dominates the gradient.
PatchNCE: each patch finds its source
CUT applies InfoNCE to patches at several scales. The encoder half of the generator, , computes a stack of feature maps; each position of the map at layer describes a patch of the input, and deeper layers describe larger patches. CUT takes layers, from the pixels to the fifth residual block. A small two-layer MLP per layer maps each feature vector to a unit vector.
The same encoder embeds the input and the output: and . At random positions per layer, the output feature is the query, the input feature at the same position is the positive, and the input features at the other 255 positions, , are the negatives:
The negatives come from the same image. A zebra leg in the output must be closer to the horse leg at that position than to the horse's back, the sky or the grass of the same photo. Negatives from other images worked worse: the encoder then has to tell images apart by things the translation does not care about, such as white against brown horses. An output that kept no trace of its input would score about per query. And the encoder learns what "corresponding" means across domains, shapes and parts rather than texture, so stripes themselves cost nothing.
The generator and the MLPs minimize the adversarial loss plus PatchNCE with weight on the pairs and weight on the pairs for real target images , a contrastive version of CycleGAN's identity loss. On horse → zebra, FID (a distance between image distributions that the course defines later; lower is better) falls from 77.2 for CycleGAN to 45.5, at 0.24 s per iteration instead of 0.40 (Park et al., 2020).
Without a cycle, CUT is free to change more of the image, and it uses that freedom to match the target's statistics. Zebras cover 36.8% of the pixels of the training zebra photos and horses 17.9% of the horse photos. CUT's zebras cover 30.8%, CycleGAN's 19.1%. That helps cat → dog, which needs a change of shape, and hurts when stripes grow onto the background.
Label maps and normalization
Semantic image synthesis turns a segmentation mask , a class label for every pixel, into a photo. Training data are pairs of a photo and its mask, so the problem is supervised, as for pix2pix. Two things are new. Street-scene masks come at . And a mask is mostly large uniform regions, which the normalization layers of a standard generator erase.
pix2pixHD (Wang et al., 2018a) handles the resolution. Its generator works coarse to fine, and three identical PatchGANs judge the image downsampled by 1, 2 and 4: the same window covers a wider region of a coarser image, so one discriminator judges global layout and another fine detail. The generator must also match the discriminators' internal features on the real photo and on its synthesis, a feature-matching loss that needs the pairs.
Now the erasing. pix2pixHD feeds the one-hot mask to its first layer and follows every convolution with instance normalization, which subtracts each channel's mean over positions and divides by its standard deviation. Take a mask with one label everywhere. A convolution of a constant is a constant (away from the borders, and everywhere with reflection padding): channel holds one value at every position, its standard deviation is , and normalization returns
whatever the label was. An all-grass mask and an all-sky mask give the same activations.
Two labels fare little better. Let sky cover a fraction of the pixels and grass the rest, and let a convolution give a channel the values . The channel's mean and standard deviation are
For , normalization gives on the sky and on the grass, for the weights , or alike. The layout survives: where the boundary runs and which region is larger. Which labels they were, and how different, is gone. Feeding the mask again at every layer does not help, since each copy is convolved and normalized in turn.
SPADE: the mask after the normalization
SPADE (spatially-adaptive denormalization; Park et al., 2019) lets the mask in after the normalization, where nothing can remove it. A layer's activations are normalized without learned parameters, with the per-channel mean and standard deviation . Then maps computed from the mask scale and shift them, position by position:
Compare the three relatives. Batch normalization learns one and one per channel. AdaIN computes and from a style vector, still one number per channel. SPADE's scale and shift have spatial dimensions: a different value at every pixel, set by the labels around it. A small convolutional network computes them from the mask, resized to the layer's resolution: a convolution with ReLU, then two convolutions, one for and one for .
A toy layer shows the arithmetic. One channel on a map has and . The mask network gives the sky , and the grass , . A sky pixel with is normalized to and leaves the layer as .
A uniform mask now gives a uniform but label-specific and , so sky and grass differ. Since the mask enters every layer, the generator needs no encoder for it: it upsamples a random vector through residual blocks with SPADE, and that vector makes the synthesis multimodal.
The ablation isolates the idea. With the same decoder, a segmentation network run on the generated COCO-Stuff photos agrees with the input masks at a mean IoU of 35.2 with SPADE and 31.9 with the mask concatenated at every layer (Park et al., 2019). What matters is where the mask enters.
Super-resolution: the average is blurry
Super-resolution recovers a high-resolution image from a downsampled , usually four times along each side, so 16 pixels per input pixel. Pairs are free: downsample any photo. The difficulty is the loss. One small image fits many large ones, which differ exactly in the fine texture that downsampling removed.
The output with the smallest expected squared error is the conditional mean, , and its error is the total conditional variance . The standard score, PSNR, is decibels, so it is maximized by the same mean. When plausible answers differ in texture, their mean is a smooth image that matches none of them. This is the VAE's blur again (see Latent variables and the ELBO).
Even a perfect generator cannot win on this score. Let be a sample from the true conditional distribution, independent of given . Write both as deviations from ; the cross term vanishes, because the deviations are independent with mean zero:
An ideal sampler has twice the MSE of the mean, on any data. In a toy, four stripe patterns shifted by 0 to 3 pixels all shrink to the same flat grey input: their mean, a flat grey, has MSE , and a sharp stripe sample has .
SRGAN (Ledig et al., 2017) replaces the squared error by a perceptual loss: a squared error between feature maps of a pretrained VGG19 network, plus times the non-saturating adversarial loss. Deep features tolerate texture that differs in detail, and the discriminator pushes the output towards natural images, where an average of textures does not lie. On the BSD100 test set at , raters scored images from 1 to 5:
| bicubic | MSE-trained network | SRGAN | original | |
|---|---|---|---|---|
| PSNR, dB | 25.94 | 27.58 | 25.16 | ∞ |
| mean opinion score | 1.47 | 2.29 | 3.56 | 4.46 |
ESRGAN (Wang et al., 2018b) refines each part: a deeper generator without batch normalization, VGG features taken before the ReLU, a relativistic discriminator that asks whether a real image looks more real than the fakes on average, and blending of the weights of a PSNR-trained and a GAN-trained network to trade one for the other. The added texture is plausible but invented. That is fine for a holiday photo and wrong wherever details are evidence, as in medical images.
What keeps the output faithful
The translation models of this extension differ mostly in what keeps the output faithful to its input:
| Model | Input → output | Tie to the input | Data | Outputs |
|---|---|---|---|---|
| pix2pix | image → image | to the target | paired | one |
| CycleGAN | image → image | cycle through a second generator | unpaired | one |
| StarGAN v2 | image + style → image | cycle with the input's style | unpaired, labelled | many |
| MUNIT | image + style → image | content and style reconstruction | unpaired | many |
| CUT | image → image | PatchNCE between patches | unpaired | one |
| SPADE | label map → photo | mask in every normalization layer | paired | many |
| SRGAN | small → large image | VGG features of the target | paired | one |
Every unpaired model here needed an extra loss to make its input recoverable from its output, because its generators are not invertible. Cycles, reconstructions and contrastive patches are all ways of buying back that lost information. And no GAN, of any architecture, can say how likely an image is.
A generator that is invertible by construction would settle both. Its inverse is exact, so a cycle through it costs nothing and holds by design, and the change of variables turns it into an exact density. That is where the main line resumes: The change of variables, normalizing flows.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.