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

Pix2Pix: paired image-to-image translation

Many vision tasks map one image to another: labels to photo, map to aerial view, edges to object, day to night, grayscale to colour. Pix2Pix (Isola, Zhu, Zhou and Efros, CVPR 2017) gave one recipe for all of them. A conditional GAN with a U-Net generator is judged by a PatchGAN discriminator that sees the input and output together, and the loss adds λ = 100 times an L1 term to the paired target. The L1 term gets the low frequencies right; the patch discriminator makes local texture sharp. This page covers the objective, the U-Net and PatchGAN designs and their receptive fields, why pixel losses blur, the missing diversity (the generator ignores its noise), evaluation, and successors (pix2pixHD, SPADE, BicycleGAN and diffusion-based Palette, ControlNet and InstructPix2Pix). In the exercises you build receptive fields, the best constant under L1 and L2, and the patch losses. You then train translators on a toy task where each input has two valid outputs, 70% and 30% likely. L2 alone was blurry: 39–82% of outputs fell between the two modes. A conditional GAN alone produced both modes (66–88% upper, truth 70%). Pix2Pix's cGAN + L1 was the sharpest (71–81% on a mode) and closest to the target, but it always chose the majority mode, reproducing the paper's lack of diversity.

Level 0: Foundation

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

One recipe for many picture-to-picture tasks

Turning a map into a satellite-style image, a sketch into a shoe or a black-and-white photo into colour are all the same kind of task: picture in, picture out. Pix2Pix trains a generator on example pairs. Its detective, the discriminator, looks at small patches of the output next to the input and asks whether they look real. A plain ‘match the target’ loss on its own gives blurry, washed-out results, because the network averages over every output that could be right. The detective forces crisp detail. The demo shows how big a patch the detective sees.

GAN lab 2: applications and stability
With 3 stride-2 layers and two stride-1 layers (all 4×4), each output score sees a 70×70 patch; a 256×256 input gives about a 30×30 grid of real/fake scores, averaged into the loss.
Why engineers care

Paired translation is used for map-to-aerial rendering, label-to-image synthesis for simulators, colourising archival imagery, and converting between sensors where co-registered pairs exist (for example SAR and optical acquired close in time).

📝 Quick check (Level 0)
0/3 answered
  1. 1. Pix2Pix needs…
  2. 2. A pure pixel-matching loss tends to give…
  3. 3. The Pix2Pix discriminator judges…

Level 1: Beginner

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

By hand

  • Objective. G* = arg min_G max_D L_cGAN(G, D) + λ L_L1(G), λ = 100. L_cGAN = E[log D(x, y)] + E[log(1 − D(x, G(x, z)))]; D sees the input x concatenated with a real or generated y.
  • Generator: U-Net. An encoder–decoder with skip connections between mirrored layers (Ronneberger et al. 2015), so low-level information such as edges passes straight through. Noise is given only as dropout, at training and test time. The paper notes that G learns to ignore it, so outputs are nearly deterministic.
  • Discriminator: PatchGAN. A fully convolutional D outputs a grid of real/fake scores, each for one N × N patch, averaged into the loss. The 70 × 70 version (3 stride-2 and 2 stride-1 4 × 4 convolutions) was best; 1 × 1 ‘PixelGAN’ only improves colour and 286 × 286 ‘ImageGAN’ adds parameters without gain. Treating the image as a Markov random field means L1 handles low frequencies and D handles high frequencies.
  • Training. Adam (lr 2 × 10⁻⁴, β1 = 0.5), batch size 1 to 10, D’s loss halved; tasks include facades, Cityscapes, maps ↔ aerial, edges → shoes and handbags, day → night, and colourisation.
  • Evaluation. Amazon Mechanical Turk real-versus-fake studies; FCN-score (segmentation accuracy on generated Cityscapes images); today FID, LPIPS and task-specific metrics.
  • Successors. pix2pixHD (Wang et al. 2018: 2048 × 1024, multi-scale discriminators, feature matching); SPADE/GauGAN (Park et al. 2019: spatially adaptive normalisation from label maps); BicycleGAN (Zhu et al. 2017: diverse outputs via a latent code); diffusion-based Palette (2022), ControlNet (2023) and InstructPix2Pix (2023); one-step pix2pix-turbo (2024).
📝 Quick check (Level 1)
0/3 answered
  1. 1. Pix2Pix's L1 weight λ is…
  2. 2. The best PatchGAN size in the paper was…
  3. 3. A diffusion-era successor for conditioning on edges or depth:

Level 2: Intermediate

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

Building paired translators

Exercise 1.

  • Receptive fields of convolution stacks.
  • The best constant prediction under L1 and L2.
  • The PatchGAN discriminator loss.
  • The Pix2Pix generator loss.

Practice.

  • Start from the official PyTorch code (pytorch-CycleGAN-and-pix2pix, –model pix2pix) with a U-Net generator and the 70 × 70 PatchGAN.
  • Align pairs precisely: misregistration teaches the generator to blur; co-register satellite or sensor pairs before training.
  • Tune λ: large λ gives faithful but less detailed outputs, small λ sharper but more artifacts.
  • Need diversity? Use BicycleGAN or a diffusion model; Pix2Pix’s dropout noise produces almost no variation.
  • Evaluate with the downstream task (segmentation of generated images, detection on translated images) plus FID or LPIPS, not only by eye.
# github.com/junyanz/pytorch-CycleGAN-and-pix2pix ; data folders hold side-by-side A|B pairs
python train.py --dataroot ./datasets/map2aerial --name map2aerial --model pix2pix \
    --netG unet_256 --netD basic --n_layers_D 3 --lambda_L1 100 --direction AtoB
python test.py --dataroot ./datasets/map2aerial --name map2aerial --model pix2pix --direction AtoB
🐍 Exercise 1: receptive fields and Pix2Pix losses
Compute receptive fields, the L1 and L2 optimal constants for a two-mode target, the PatchGAN loss and the Pix2Pix generator loss.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Misaligned training pairs make the generator…
  2. 2. For diverse outputs use…
  3. 3. The 70 × 70 PatchGAN uses how many stride-2 layers?

Level 3: Advanced

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

Theory

Why pixel losses blur. For an input with several valid outputs, the constant minimising E‖ŷ − y‖² is the conditional mean, which can lie between the modes: an average of plausible images, which is blurry. The L1 minimiser is the conditional median, per pixel. It is sharper when one mode dominates, but it still never produces the minority outcome.

What the conditional discriminator adds. D(x, y) can reject outputs that are off the data manifold for that input, including in-between averages. So the adversarial term rewards outputs on a valid mode. Adding L1 then pulls them towards the single most likely mode: sharp, faithful, but not diverse.

PatchGAN as a texture model. Averaging patch scores assumes pixels more than one patch apart are independent given the input, a Markov random field. That is enough to enforce local texture and sharpness, while L1 constrains global structure. It also makes D fully convolutional, so it runs on any image size.

Receptive field. Going backwards through layers with kernel k and stride s: r ← (r − 1)s + k. For 4 × 4 kernels with strides 2, 2, 2, 1, 1 this gives 70.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The L2-optimal output for a two-mode target is…
  2. 2. The L1-optimal output is…
  3. 3. PatchGAN assumes distant pixels are…

Level 4: Expert

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

On an ambiguous translation task, what do L2, L1, a conditional GAN and Pix2Pix’s combination produce?

History.

  • P. Isola, J.-Y. Zhu, T. Zhou and A. Efros, “Image-to-image translation with conditional adversarial networks” (CVPR 2017).
  • J.-Y. Zhu et al., BicycleGAN (2017); T.-C. Wang et al., pix2pixHD (2018); T. Park et al., SPADE (2019).
  • C. Saharia et al., Palette (2022); L. Zhang et al., ControlNet (2023); T. Brooks et al., InstructPix2Pix (2023).

Exercise 2. A one-pixel ‘image’ translation with an ambiguous target.

  • Data: input x ~ U(−1, 1); target y = sin(πx) + 0.6 with probability 0.7, or sin(πx) − 0.6 with probability 0.3, plus noise of sd 0.05.
  • Models: G(x, z) with 2-dimensional noise, 32-32 hidden; conditional D(x, y); Adam; 800 steps (400 for the pixel-loss-only models).
  • Metrics: sharp = share within 0.15 of a valid mode; blurry = share closer to the midline than 0.3; upper share = share of sharp outputs in the upper mode (truth 0.7); L1 to the paired target.
seed 0 sharp blurry upper share L1 to target
L2 only 0.282 0.385 1.0 0.476
L1 only 0.5 0.085 1.0 0.493
cGAN only 0.264 0.154 0.657 0.805
cGAN + 1 · L1 0.412 0.271 0.926 0.527
cGAN + 10 · L1 0.714 0.037 1.0 0.428
  • Pixel losses behaved as theory says: L2 put 39%, 82% and 60% of outputs in the blurry zone on seeds 0, 1 and 2; L1 chose the majority mode (upper share 1.0, 1.0, 0.995).
  • The conditional GAN alone was the only diverse model: upper share 0.657, 0.805 and 0.884 against the true 0.7. But it was less sharp (0.264, 0.388, 0.428) after 800 steps.
  • cGAN + L1 (Pix2Pix) was the sharpest and closest to the target (sharp 0.714, 0.813, 0.72; L1 0.428, 0.395, 0.426, near the deterministic floor of about 0.39). It never produced the minority mode: the diversity loss reported in the paper.
  • A small L1 weight (1) did not combine the benefits: it was less sharp than weight 10 and already almost always picked the majority mode.
  • Caveat: a scalar toy, so it says nothing about the PatchGAN or U-Net. Weight 10 here plays the role of Pix2Pix’s 100, which multiplies a per-pixel mean.
🐍 Exercise 2 (research): on an ambiguous translation task, what do L2, L1, a conditional GAN and Pix2Pix's combination produce?
Train L2, L1, conditional-GAN and cGAN + L1 translators on a task with two valid outputs per input; measure sharpness, blur, diversity and L1 error.

Paired translation in AI, robotics and aerospace

  • Maps ↔ aerial imagery: the original Pix2Pix demo; today used for synthetic aerial views from vector maps in flight simulators and for map extraction from imagery.
  • Sensor-to-sensor translation: SAR → optical and thermal → visible with co-registered pairs. Remember that the output is the most likely appearance, not a measurement.
  • Label → image for simulation: SPADE/GauGAN and ControlNet turn semantic layouts from a simulator into realistic images to train perception models.

References

  1. P. Isola, J.-Y. Zhu, T. Zhou and A. A. Efros (2017). “Image-to-image translation with conditional adversarial networks.” CVPR.
  2. O. Ronneberger, P. Fischer and T. Brox (2015). “U-Net: convolutional networks for biomedical image segmentation.” MICCAI.
  3. T.-C. Wang et al. (2018). “High-resolution image synthesis and semantic manipulation with conditional GANs.” CVPR.
  4. J.-Y. Zhu et al. (2017). “Toward multimodal image-to-image translation.” NeurIPS.
  5. L. Zhang, A. Rao and M. Agrawala (2023). “Adding conditional control to text-to-image diffusion models.” ICCV.