Skip to content
BIASED

CycleGAN: unpaired image-to-image translation

Block 1 of 8~3 min

Translation with pairs: pix2pix

So far a GAN has turned noise into images. The conditional GAN from GANs as a two-player game also took a label cc, and the previous extension, Autoencoding GANs: AAE and α-GAN, mapped images to codes and back. Now the input is an image and so is the output.

You have a thousand photos of horses and a thousand photos of zebras. You want a network that repaints a given horse as a zebra: same pose, same field, stripes added. This task is image-to-image translation. With four networks in play, we drop the parameter subscripts and write GG, FF, DXD_X, DYD_Y.

Start with the easy case, where every training example is a pair (x,y)(x, y): an edge map xx and the photo yy it was drawn from. A generator GG maps xx to an image, and a loss compares G(x)G(x) with yy.

A pixel loss alone produces blur. When several outputs are plausible for one input, the expected L2L_2 loss is minimized by their per-pixel mean, and the expected L1L_1 loss by their per-pixel median. Neither looks like any of the plausible outputs.

pix2pix (Isola et al., 2017) adds a conditional adversarial loss. Its discriminator sees the pair (x,y)(x, y) or (x,G(x))(x, G(x)) and decides whether the output is a real photo for this input:

G∗=arg⁡min⁡Gmax⁡D  LcGAN(G,D)+λ Ex,y ∥y−G(x)∥1,λ=100.G^* = \arg\min_G \max_D\; \mathcal L_{\text{cGAN}}(G, D) + \lambda\, \mathbb E_{x, y}\, \|y - G(x)\|_1 , \qquad \lambda = 100 .

Here ∥a−b∥1\|a - b\|_1 is the sum of absolute pixel differences. The adversarial term makes the output sharp, and the L1L_1 term keeps it near the true target. The discriminator is a PatchGAN: it outputs a grid of verdicts, one per overlapping image patch, and the loss averages them.

Answers are saved on the server and tied to this browser until you sign in.