CycleGAN

CycleGAN (Zhu, Park, Isola, Efros, ICCV 2017), nicknamed “there and back aGAN”, translates between two image domains and . It learns from unpaired collections. Examples are horse photos and zebra photos, or photographs and Monet paintings. No image in has a known partner in .

It trains two generators, and , and two discriminators. separates real images from translations , and separates real images from translations . Each generator and discriminator play the GAN game. In the lecture’s convention, where outputs the probability of fake,

and has the same form with and swapped. The cycle-consistency loss asks that a round trip return the starting image, in both directions:

Here is drawn from collection , from collection , and sums absolute pixel differences. The full objective is

with in the paper. The adversarial terms make translations look like the target domain. The cycle term makes them keep the content of the input, because must hold enough information to rebuild .

CycleGAN works best for changes of appearance. The lecture shows collection style transfer from photos to Monet, Van Gogh, Cezanne and Ukiyo-e, and horse to zebra. It also shows Grand Theft Auto frames turned into real street scenes and back, and a shallower depth of field. Changes of shape are hard. When aligned pairs exist, 8.4. Pix2Pix with its L1 term to the ground truth is the more accurate choice.

Discriminator Convention

The CycleGAN paper writes the adversarial loss with as the probability of real: . Replacing by gives the lecture’s form above. The game and its solution are the same.

Intuition

Pix2pix measures error against the true output, and unpaired data has no true output. The adversarial loss alone only asks that look like some zebra. A generator could ignore its input, paint the same convincing zebra for every horse, and still fool . CycleGAN adds a check that needs no ground truth. Translate a horse into a zebra and back again. If the result differs from the original horse, the zebra lost information about its input. The lecture illustrates this with translation between English and French: a sentence translated into French and back should match the original.

The name comes from this round trip, , which closes a cycle. The figure shows the two mappings with their discriminators on the left and the two cycles on the right.

\usepackage{tikz}
\begin{document}
\definecolor{gmap}{HTML}{2F80ED}
\definecolor{fmap}{HTML}{D9483B}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[>=latex, dom/.style={draw, thick, minimum width=1.3cm, minimum height=1.3cm}, img/.style={draw, minimum width=1.2cm, minimum height=0.9cm}]
\node[dom] (X) at (0,0) {$X$};
\node[dom] (Y) at (4,0) {$Y$};
\draw[->, thick, gmap] (X.north east) to[bend left=30] node[above] {$G: X \to Y$} (Y.north west);
\draw[->, thick, fmap] (Y.south west) to[bend left=30] node[below] {$F: Y \to X$} (X.south east);
\node (DX) at (0,-2.2) {$D_X$};
\node (DY) at (4,-2.2) {$D_Y$};
\draw[->, thick, mid] (X) -- (DX);
\draw[->, thick, mid] (Y) -- (DY);
\node[mid, align=center] at (0,-2.9) {\small is it a real $x$\\ \small or an $F(y)$?};
\node[mid, align=center] at (4,-2.9) {\small is it a real $y$\\ \small or a $G(x)$?};
\node[img] (x) at (7,0.9) {$x$};
\node[img, gmap] (gx) at (9,0.9) {$G(x)$};
\node[img, fmap] (fgx) at (11,0.9) {$F(G(x))$};
\draw[->, thick, gmap] (x) -- node[above] {$G$} (gx);
\draw[->, thick, fmap] (gx) -- node[above] {$F$} (fgx);
\draw[<->, dashed, mid] (x.south) to[bend right=25] node[below, black] {$\|F(G(x)) - x\|_1$} (fgx.south);
\node[img] (y) at (7,-2.0) {$y$};
\node[img, fmap] (fy) at (9,-2.0) {$F(y)$};
\node[img, gmap] (gfy) at (11,-2.0) {$G(F(y))$};
\draw[->, thick, fmap] (y) -- node[above] {$F$} (fy);
\draw[->, thick, gmap] (fy) -- node[above] {$G$} (gfy);
\draw[<->, dashed, mid] (y.south) to[bend right=25] node[below, black] {$\|G(F(y)) - y\|_1$} (gfy.south);
\end{tikzpicture}
\end{document}

Properties

(Cycle Prevents Collapse) A generator that sends two inputs to the same output pays a cycle loss at least as large as the distance between the inputs.

Suppose . Then returns a single image for both, and the triangle inequality for the L1 norm gives

Mapping many inputs to one output is the GAN failure called mode collapse. The adversarial loss cannot see it when the shared output looks real. The cycle term makes it expensive, which pushes toward a mapping that can invert.

(Cycle Is Not Meaning) A zero cycle loss shows only that undoes , and many such pairs are not the intended translation.

Any invertible with has zero cycle loss. The adversarial terms narrow the choice to invertible maps that turn the horse collection into something distributed like the zebra collection. Many such maps exist, for example ones that swap which horse becomes which zebra. In practice the generators are convolutional networks that change images locally. The maps they learn tend to keep pose and layout and change texture and color, which matches the intended translation for horse to zebra.

(Appearance Over Geometry) CycleGAN succeeds at changes of texture and color and often fails when shapes must change.

Horse to zebra, photo to painting and game graphics to real streets all keep the outline of every object. A change that needs new shapes, such as turning a cat into a dog, gives weak results. The lecture’s failure case is a photo of a man riding a horse. The model paints zebra stripes on the rider as well. The horse photos used for training contained no riders, so the model never learned to leave a rider alone.

(Both Cycles Needed) The backward cycle constrains what does to real images of .

The forward cycle only tests images that start in . Without the backward term, only the adversarial loss of constrains on real zebras. The paper’s ablations report that keeping a single cycle direction often leads to unstable training and collapse in the unconstrained direction. With both terms, and become close to inverses on both collections.

Examples

(Easy) A Day-to-Night Toy

Treat a tiny daytime image as four pixel intensities, , and a tiny night image as . The generator darkens a day image. Compare two backward generators, and .

(Medium) What Collapse Costs

Two day images are and . A collapsed generator sends every day image to the same uniform dark gray image . In this toy the real night images are dark gray, so cannot reject .