19 / 34 · GANs
CycleGAN: unpaired image-to-image translation
Learn what marginal matching, cycle reconstruction and identity regularization constrain, and test their limits on an exact finite translation problem.
On this page 10
An image translator should change a rendering while preserving the useful structure of its input. Two folders of examples tell us what each rendering looks like. They do not necessarily tell us which outputs belong to which inputs. The previous model reconstructed images through latent codes; now the intermediate representation must itself resemble an image from another domain.
CycleGAN couples two translators with reconstruction losses (Zhu et al., 2017). Following a translation by its reverse should recover the input. That gives a testable constraint, while leaving an important ambiguity: several reversible correspondences may fit the same two collections.
Paired translation: pix2pix#
With aligned pairs , a supervised translator has direct evidence about the desired correspondence. A conditional discriminator sees or ; it can inspect whether the generated output fits this input. A reconstruction term supplies another signal:
The pix2pix objective combines this term with a conditional adversarial objective (Isola et al., 2017, Section 3.1). Its generator uses an encoder–decoder with skip connections. The discriminator evaluates overlapping patches of the concatenated input and output.
Why combine the terms? For a genuinely ambiguous conditional target, squared error selects its conditional mean, while absolute error selects a conditional median in each output coordinate; see conditional expectation. These point predictions can average incompatible structures. An adversarial signal assesses the distribution of generated structure. Neither loss guarantees a sharp and correct result under finite capacity or unsuccessful optimization.
A shuffled target is no longer the paired target. Training on independently shuffled while keeping the same reconstruction term asks the network to fit an unrelated conditional distribution. Removing the pairing changes the information available to the objective.
Without pairs, the adversarial loss is not enough#
Write for the two data distributions and . A discriminator that sees only the output constrains the pushforward distribution , defined as the distribution of when . It does not observe the input–output joint distribution. In the idealized comparison, two maps with the same pushforward receive the same marginal evidence.
Consider an original finite example. Both collections are uniform over four scalar codes:
Every permutation of the four target codes gives the exact target marginal. There are such maps. We specify one reference correspondence solely for evaluation: in the listed input order, its outputs are . These pair labels are withheld from the marginal-matching criterion.
The increasing assignment has the same target frequencies as the reference assignment. Its mean absolute deviation from the reference is
The scalar codes are explicit synthetic data, not image features or measurements from an experiment. They separate distribution matching from correspondence without relying on an image discriminator’s imperfections.
Two reversible maps with identical marginals
A deterministic constant map cannot match this four-point uniform marginal. Conversely, a stochastic translator that independently samples a target code matches it while discarding the input. We must distinguish an optimum of the marginal criterion from mode collapse caused by imperfect optimization.
Cycle consistency#
Introduce the reverse translator . The standard reconstruction penalty is
For every permutation above, choose its inverse. Both cycles then have zero error. Consequently all 24 correspondences survive, including the assignment with reference error 13. Cycle consistency preserves recoverable information; reference correspondence needs additional evidence or assumptions.
The injectivity argument is precise. If on a set, two different points in that set cannot have the same output: applying would have to return both. A zero expected nonnegative loss gives the equality almost surely, rather than at every arbitrary point outside the data distribution. On our finite support every point has positive probability, so the equality holds at all four points.
A small nonzero loss is weaker. Map the two equally likely inputs and to one code and reconstruct zero. The mean absolute cycle error is only , although the map is noninjective. A finite penalty therefore does not turn an arbitrary neural network into an exactly invertible map.
Forward reconstruction alone constrains only on outputs reached by . The reverse cycle also checks real target inputs. Under exact surjectivity onto a finite support the second equality can follow from the first, but finite-data neural training does not supply that assumption. The original paper tests the practical contribution of both directions in its ablations.
Identity loss#
If the input representations have compatible shapes, we can also feed a target-domain example into its own translator. The identity penalty is
The CycleGAN paper uses this additional regularizer to encourage preservation of color composition in selected applications (Section 5.2). It is a soft preference on those supplied inputs. Its benefit depends on whether “already in the target domain” should mean “leave unchanged” for the task.
It still does not identify our reference permutation. The two scalar supports are disjoint. Extend any cross-domain permutation by setting on the four target points and on the four source points. Every one of the 24 choices now has exact marginal matching, zero cycles and zero identity loss. These are explicitly defined lookup functions; smoothness and architectural restrictions could alter which extensions are feasible.
One observed reference pair leaves permutations; two leave ; three determine the fourth and leave one. This count makes the value of additional information concrete. A small number of reliable anchors can resolve an ambiguity that simply increasing the cycle coefficient cannot.
The full objective#
The log-discriminator formulation is a minimax game. The least-squares implementation uses separate minimization losses for discriminator and generator. Keeping these forms separate avoids reversing a training direction.
Let be a real-valued score with target 1 for real data and 0 for translated data. One consistent convention is
The analogous losses train and the reverse translator. With nonnegative regularization weights, the generators minimize
Each discriminator minimizes its own loss, with generated images detached from the generator for that update. During the generator update the discriminator parameters stay fixed, but differentiation must pass through its input to the generator. Detaching that input would remove the adversarial generator gradient.
The two regularizers compare different inputs. The cycle compares an original with its round trip. Identity compares a target-domain input with the output of the target-domain translator. They cannot be substituted for each other by using the same tensor in both losses.
How many correspondences remain after anchors
The networks#
The original CycleGAN uses a residual generator with downsampling, residual blocks and upsampling, and instance normalization. Residual parameterization makes some small changes easy to represent. It does not guarantee minimal changes in pixels, geometry or semantic attributes. Which solution training selects also depends on data, optimization and the other losses.
A PatchGAN produces a grid of scores. For the pinned implementation’s NLayerDiscriminator(n_layers=3), five convolution kernels have size 4 and strides ; track the convolutional footprint and spacing from :
With padding 1 at each convolution, a 256-pixel side becomes 128, 64, 32, 31 and finally 30 positions. The nominal footprint is 70 pixels, and adjacent scores overlap. Instance normalization additionally couples spatial positions through image-wide statistics, so 70 is not a strict dependency boundary for the full normalized network. A local-score architecture also does not certify global arrangement.
Loss reduction matters. For two illustrative scores and real target 1, squaring the average error gives , whereas averaging the squared errors gives . In general, with population variance over patches,
Expand ; the cross term sums to zero. Averaging scores before the loss removes this variance penalty and allows different patches to compensate for one another.
Training#
Training alternates generator and discriminator updates. Batches from the two domains need not be aligned, but both cycles must use the translated output of their actual starting input. Reconstruction against a random example from the same domain tests the wrong relationship.
The original method uses least-squares adversarial losses and a history buffer of generated images. Historical fakes change the discriminator’s training distribution and can reduce rapid chasing of the current generator. A buffer is a training heuristic, not a convergence proof or necessarily the most recent contiguous window of samples.
For one score , the derivative of with respect to is . The parameter gradient also contains the discriminator and generator Jacobians. A nonzero score derivative alone cannot guarantee a useful nonzero parameter gradient.
Record loss reductions and relative weights along with optimizer settings; see Adam. For a fixed supplied gradient history with zero initial moments, multiplying every gradient by a positive constant scales Adam’s first moment linearly and its second moment quadratically. Their normalized ratio cancels that scale when the stabilizer is zero and the denominator is nonzero; a nonzero stabilizer or changing only some loss terms changes the conclusion. Halving a displayed loss is not a general promise to halve the parameter step. Our finite computations below do not simulate Adam or claim neural training stability.
Results#
The exact finite calculation has three distinct outcomes. Marginal matching accepts all 24 permutations. Adding inverse cycles and the defined identity extensions still accepts all 24. Adding three specific correspondence anchors leaves one. These results follow from exhaustive enumeration, not a trained model or an image-quality benchmark.
For real images, evaluate appearance and input fidelity separately. Realistic target texture can coexist with an incorrect object layout. Reconstruction error measures the round trip and can miss an unwanted intermediate transformation. Reference pairs used only for evaluation, when available, provide information that unpaired losses do not observe.
Zhu et al. report both perceptual realism and downstream semantic evaluations, plus loss ablations (Sections 5.1–5.2). Those experiments are evidence about their settings, not universal guarantees for new image collections. Their article and project page provide the visual results; no source images or measured image-model outputs are redistributed here.
Where it breaks#
A deterministic cycle assumes enough information can survive the intermediate representation. Our four source codes cannot be reconstructed exactly through only two possible target codes: at least two source points share an output. This restricted alphabet also cannot match the original four-point target marginal. Enumerating the 16 binary assignments and choosing a median reconstruction for each group gives the best possible mean absolute error .
One optimum groups together and together. Their within-group absolute errors sum to , and dividing by four gives . Restricting the inverse to source values does not worsen the optimum: for absolute error a finite group’s median can be chosen from the group. The executable calculation considers all assignments and all such reconstruction choices. With just one intermediate code the optimum becomes .
Neural image outputs have more room than a two-code alphabet. A model may compromise between matching the target, reconstructing its input and satisfying its architecture; it may also encode details in features that the discriminator scarcely checks. Chu, Zhmoginov and Sandler documented hidden information and corruption-sensitive reconstruction in trained CycleGANs. This is an observed failure mode, not a theorem that every unpaired model must hide information.
There is a second limitation even with enough capacity: a deterministic translator supplies one output per input. Tasks with several appropriate outputs require an explicit way to represent that conditional diversity. Independent models for every pair of domains also grow quadratically in the number of domains.
What changed#
| Information or constraint | Paired translation | Unpaired cycle translation |
|---|---|---|
| Correspondence evidence | observed input–target pairs | separate domain collections |
| Discriminator input | source and target candidate | candidate in one domain |
| Reconstruction target | aligned output | starting input after a round trip |
| Remaining ambiguity | capacity, noise and conditional diversity | these issues plus correspondence ambiguity |
The cycle recovers some structure that a marginal loss omits, while anchors or explicit assumptions still carry the meaning of the correspondence.
What you should remember#
- Matching a target marginal does not determine the input–output joint distribution.
- Exact forward reconstruction implies injectivity on the set where it holds; small loss does not.
- Identity regularization is a soft target-domain preference and can leave several correspondences valid.
- Least-squares discriminator and generator losses are separately minimized.
- Small cycle error is compatible with incorrect semantic translation or fragile information storage.
- Evaluate the intermediate output, not only its reconstruction.
Executable experiment#
The optional standard-library executable cases use only the explicit scalar supports above. Their saved exact results are the data used by both figures.
- Enumerating every target permutation gives 24 exact marginal/cycle/identity solutions; successive reference anchors leave 24, 6, 2, 1, 1.
- Enumerating the two-code bottleneck gives reconstruction error ; one code gives .
- Fraction arithmetic separates the two patch-loss reductions, and , and verifies the noninjective small-cycle example. A convolution calculation checks the nominal footprint and output sizes.
The script has been executed with saved outputs. It downloads no dataset or model and does not train CycleGAN.
Next#
A separate two-way translator for every unordered pair among domains requires models. This is the naive pairwise design, not a lower bound on all architectures. StarGAN instead gives one translator a target-domain condition, sharing parameters and training evidence across domains.
Where to see the images#
The authors’ CycleGAN project and pix2pix project link visual examples and limitations. Viewing them is separate from the synthetic practice. Their linked datasets, models and images have their own terms; this page does not redistribute them.
References#
-
Jun-Yan Zhu, Taesung Park, Phillip Isola, Alexei A. Efros. Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks. ICCV, 2017. Sections 3–4, 5.1–5.2, 6 and Appendix 7: objectives, architecture, evaluation, identity term and limits.
-
Phillip Isola, Jun-Yan Zhu, Tinghui Zhou, Alexei A. Efros. Image-to-Image Translation with Conditional Adversarial Networks. CVPR, 2017. Sections 3.1–3.3 and Appendix 6.1: paired objective, U-Net, PatchGAN and stochasticity.
-
Xudong Mao, Qing Li, Haoran Xie, Raymond Y. K. Lau, Zhen Wang, Stephen Paul Smolley. Least Squares Generative Adversarial Networks. ICCV, 2017. Section 3.2: separate least-squares objectives.
-
Casey Chu, Andrey Zhmoginov, Mark Sandler. CycleGAN, a Master of Steganography. NIPS Workshop on Machine Deception, 2017. Sections 2–3: observed information hiding and corruption sensitivity.
-
Jun-Yan Zhu, Taesung Park and contributors. PyTorch CycleGAN and pix2pix network definitions, revision
2a7afba.NLayerDiscriminatorandget_norm_layer: convolution sizes/strides and instance-normalization scope. Referenced for these implementation facts; no source code, weights or data are imported.