Foundations to Frontier
Tests
H. Generative Models › H4 Generative Adversarial Networks

CycleGAN: unpaired image-to-image translation

Pix2Pix needs pairs of matching images, which rarely exist: there is no photo of the same scene as a Monet painting, or a SAR and an optical image taken at the same instant. CycleGAN (Zhu, Park, Isola and Efros, ICCV 2017) learns translation from two unpaired collections. It trains two generators, G from A to B and F from B to A, each with its own discriminator. A cycle-consistency loss requires F(G(a)) ≈ a and G(F(b)) ≈ b, which rules out mappings that throw information away. This page covers the objective (least-squares GAN loss, cycle and identity losses, the image history pool), its ambiguity and failure modes (geometry changes, hidden 'steganographic' information, permuted correspondences), later methods (UNIT, MUNIT, CUT) and remote-sensing and sim-to-real uses. In the exercises you build the losses and the history pool. You then translate between two unpaired 2D domains whose true map is a rotation plus a shift, known only to the evaluator. With the cycle loss, points landed 0.17–0.22 from their hidden true partners on all seeds, and every cluster went to the right place. Adversarial loss alone dropped a whole cluster on one seed (error 1.43). An identity loss, appropriate for colour-preserving tasks, pulled the mapping towards the wrong answer (error about 0.95).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Translating without a dictionary

Imagine learning to translate between two languages using only a pile of books in each, with no sentence pairs. One check helps a lot: translate a sentence there and back, and you should get the original. CycleGAN applies that check to images. A horse-to-zebra network is paired with a zebra-to-horse network, and a picture sent through both should come back unchanged. That stops the network from, say, turning every horse into the same zebra. The demo shows two unpaired domains and how far the ‘do nothing’ answer is from the true mapping.

GAN lab 2: applications and stability
Red: domain A, green: domain B (A rotated by 40° and shifted). No pairs are given; the cycle loss asks F(G(a)) ≈ a. The identity map would be off by about 1.03 at each cluster centre before the shift, which an identity loss would wrongly reward.
Why engineers care

Unpaired translation is useful wherever paired data is impossible: radar-to-optical satellite images, simulation-to-real robot camera images, day-to-night or summer-to-winter scenes for testing perception systems.

📝 Quick check (Level 0)
0/3 answered
  1. 1. CycleGAN learns from…
  2. 2. The cycle check requires…
  3. 3. CycleGAN trains how many generators?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Objective. L = L_GAN(G, D_B) + L_GAN(F, D_A) + λ L_cyc, with L_cyc = E|F(G(a)) − a|₁ + E|G(F(b)) − b|₁ and λ = 10. Least-squares GAN losses replace the log loss for stability.
  • Identity loss. For photo↔painting, an extra term λ_id = 0.5λ penalises |G(b) − b| + |F(a) − a|, so colours are preserved when the input already looks like the target domain.
  • Architecture. ResNet generator (9 residual blocks at 256², instance norm); 70 × 70 PatchGAN discriminators; a history pool of 50 past fakes for D; Adam at 2 × 10⁻⁴; 200 epochs, constant then linear decay.
  • Results. Horse↔zebra, summer↔Yosemite winter, photo↔Monet/Van Gogh, apple↔orange; on Cityscapes labels↔photos it is far better than other unpaired baselines but below paired Pix2Pix. Related at the same time: DiscoGAN and DualGAN (2017); UNIT (shared latent, 2017).
  • Limits. Shape changes fail (dog↔cat geometry); the map is not unique, since any cycle-consistent bijection that matches the distributions fits. CycleGAN can hide the information needed for reconstruction in near-invisible high-frequency signals (‘a master of steganography’, Chu et al. 2017).
  • Successors. MUNIT (2018) for multimodal output with content and style codes; CUT (Park et al. 2020), a one-sided patchwise contrastive loss, faster and without a second generator; diffusion-based unpaired translation (SDEdit 2022, DDIB 2023).
  • Applications. SAR↔optical and cross-sensor translation in remote sensing; CyCADA (Hoffman et al. 2018) for domain adaptation; RL-CycleGAN (Rao et al. 2020) for sim-to-real robot grasping.
📝 Quick check (Level 1)
0/3 answered
  1. 1. CycleGAN's cycle weight λ is…
  2. 2. A one-sided contrastive successor is…
  3. 3. CycleGAN struggles with…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Training unpaired translators

Exercise 1.

  • The cycle-consistency loss.
  • Least-squares GAN losses.
  • The identity loss.
  • The 50-image history pool.

Practice.

  • Start from the official PyTorch implementation (pytorch-CycleGAN-and-pix2pix) or from CUT for faster, one-sided training.
  • Use the identity loss only when colours or intensities should be kept (photo↔painting, sensor harmonisation). It is wrong when the mapping must change them.
  • Check the mapping, not only realism: where possible, keep a small paired validation set (or ground-control points) and measure pointwise error; good-looking outputs can still be wrong.
  • Remote sensing: co-register and normalise each sensor’s data; be wary of hallucinated features (clouds, buildings) in SAR-to-optical outputs.
  • Sim-to-real: check that downstream task performance improves (RL-CycleGAN adds a task-consistency loss).
# pip install -r requirements.txt  (github.com/junyanz/pytorch-CycleGAN-and-pix2pix)
# datasets/sar2opt/trainA (SAR tiles), trainB (optical tiles): unpaired folders
python train.py --dataroot ./datasets/sar2opt --name sar2opt --model cycle_gan \
    --lambda_A 10 --lambda_B 10 --lambda_identity 0.0 --pool_size 50 --netG resnet_9blocks
python test.py --dataroot ./datasets/sar2opt --name sar2opt --model cycle_gan
🐍 Exercise 1: CycleGAN losses and the history pool
Implement the cycle and identity losses, the least-squares GAN losses and the image history pool.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Use the identity loss when…
  2. 2. A small paired validation set lets you…
  3. 3. The history pool feeds D…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

What the cycle loss guarantees. If F(G(a)) = a for all a, then G is injective: two inputs cannot map to the same output. Together with the adversarial loss, which makes G(A) distributed like B, G is a measure-preserving bijection between the domains. It does not identify which bijection: any rearrangement within B that preserves the distribution, composed with the true map, is equally cycle-consistent.

What breaks the tie. In practice, the architecture’s inductive bias picks the solution: residual generators and convolutions prefer simple, local, near-identity changes. In the exercise, residual generators that start near the identity found the true map, a 40° rotation plus shift, rather than a permuted one.

Identity loss as a prior. Adding |G(b) − b| says the map should be the identity on inputs that already look like B. This is right when domains share a colour space and only style differs, and wrong when the true map moves everything, as here.

Hidden information. Because the cycle loss needs F to undo G exactly, G may encode details of a in tiny high-frequency perturbations of G(a). The output looks right but carries a hidden code: a reason to distrust pixel-level outputs of unpaired translators in measurement tasks.

📝 Quick check (Level 3)
0/3 answered
  1. 1. F(G(a)) = a for all a implies G is…
  2. 2. The cycle loss alone does not decide…
  3. 3. CycleGAN can hide reconstruction information in…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Does the cycle loss recover the true mapping between unpaired domains, and when does an identity loss hurt?

History.

  • J.-Y. Zhu, T. Park, P. Isola and A. Efros, “Unpaired image-to-image translation using cycle-consistent adversarial networks” (ICCV 2017).
  • T. Kim et al., DiscoGAN (2017); Z. Yi et al., DualGAN (2017); M.-Y. Liu et al., UNIT (2017).
  • T. Park et al., “Contrastive learning for unpaired image-to-image translation” (CUT, 2020).

Exercise 2. Unpaired domains with a hidden answer.

  • Domains: A has three 2D clusters (weights 0.5, 0.3, 0.2, sd 0.25) at the corners of a triangle of radius 1.5. B = T(A), where T rotates by 40° and shifts by (0.5, 0). Training draws A and B independently, so there are no pairs. T is used only to score.
  • Models: residual generators x + MLP(x) (2 → 32 → 32 → 2, starting near the identity); two discriminators; non-saturating GAN loss; Adam; 380 steps.
  • Variants: adversarial only; + cycle loss (λ = 10, L1); + cycle + identity loss (weight 5).
  • Metrics: point error |G(a) − T(a)|; share mapped to the correct target cluster; share landing near any B cluster; cycle error |F(G(a)) − a|.
seed 0 point error correct cluster near a B cluster cycle error
adversarial only 1.43 0.515 0.994 3.186
+ cycle 0.222 1.0 0.935 0.038
+ cycle + identity 0.959 0.929 0.374 0.013
identity map (no training) 0.981
  • Adversarial loss alone failed badly on seed 0: all samples landed near B clusters (0.994), but cluster shares were 0.808, 0.192 and 0 instead of 0.5, 0.3 and 0.2. Two clusters were merged into one and a whole cluster was dropped, a many-to-one map that only a cycle loss forbids.
  • On seeds 1 and 2, adversarial loss alone did reasonably (point error 0.195 and 0.248, against 0.168 and 0.175 with the cycle loss). The near-identity residual generator did much of the work. The cycle loss mainly removed the catastrophic case and cut cycle error by about 10× (0.338 → 0.037).
  • The identity loss hurt on every seed (0.959, 0.966, 0.925). It pulled G towards the identity map (error 0.98), and only 36–37% of outputs landed near a B cluster. It is a prior for colour preservation, not a general regulariser.
  • Caveat: 2D toy with a simple true map. Real image translation is far less identifiable, and nothing in this setup tests steganography or geometry changes.
🐍 Exercise 2 (research): does the cycle loss recover the true mapping between unpaired domains, and when does an identity loss hurt?
Train a CycleGAN between two unpaired 2D domains with a hidden true map; compare adversarial-only, cycle-consistent and identity-regularised variants by their pointwise error against the hidden map.

Unpaired translation in AI, robotics and aerospace

  • SAR ↔ optical: translating radar images into optical-looking ones aids interpretation and cloud gap-filling, but invented features (roads, roofs) are a known risk; validate against co-registered pairs where they exist.
  • Sim-to-real: RL-CycleGAN and similar methods make simulated camera images look real for robot grasping and drone navigation policies.
  • Domain adaptation: CyCADA-style pixel-level adaptation transfers detectors between sensors, seasons and regions.

References

  1. J.-Y. Zhu, T. Park, P. Isola and A. A. Efros (2017). “Unpaired image-to-image translation using cycle-consistent adversarial networks.” ICCV.
  2. C. Chu, A. Zhmoginov and M. Sandler (2017). “CycleGAN, a master of steganography.” NeurIPS Workshop.
  3. T. Park, A. A. Efros, R. Zhang and J.-Y. Zhu (2020). “Contrastive learning for unpaired image-to-image translation.” ECCV.
  4. J. Hoffman et al. (2018). “CyCADA: cycle-consistent adversarial domain adaptation.” ICML.
  5. K. Rao et al. (2020). “RL-CycleGAN: reinforcement learning aware simulation-to-real.” CVPR.