Deep Unsupervised Learning

Pix2Pix Image Translation

Pix2PixU-NetPatchGANcGAN
Pix2Pix Image Translation
Problem

Given a structural edge sketch of a shoe, can a model synthesize a plausible RGB shoe image that respects the input geometry? This is paired image-to-image translation: every edge map has a corresponding real photo, and the model must learn a conditional mapping without blurring fine structure into mush.

Dataset

Edge2Shoes dataset (balraj98/edges2shoes via Kaggle): 49,825 training pairs and 200 validation pairs. Each image is a side-by-side pair—left half is the edge sketch (input), right half is the RGB shoe (target). Resized to 128×128, converted to tensor, and normalized to [-1, 1] with mean=std=0.5.

Approach

Classic Pix2Pix setup. The generator is a U-Net with six encoder downsampling blocks (3→64→128→256→512→512→512), six decoder upsampling blocks with skip connections, LeakyReLU in the encoder, BatchNorm + ReLU in the decoder, and Dropout(0.5) in the first two decoder layers. Output passes through Tanh. The discriminator is a PatchGAN: it receives the concatenated edge + shoe tensor (6 channels) and outputs a 14×14 grid of real/fake predictions, encouraging high-frequency realism locally rather than a single global score.

Training

Batch size 16, 5 epochs (~3,100 steps). Generator Adam lr=0.0002; discriminator Adam lr=0.0001 (lower so D does not overpower G). β1=0.5, β2=0.999. Generator loss = BCEWithLogits adversarial loss + 100 × L1 pixel loss. Conv weights initialized N(0, 0.02); BatchNorm weights N(1, 0.02). Generator: 29.2M params; discriminator: 2.8M params.

My Work
  • Built EdgeShoeDataset that splits each paired JPG into edge (left) and shoe (right) tensors
  • Implemented the full U-Net generator with encoder–decoder skip connections
  • Implemented PatchGAN discriminator with reflect padding and patch-level outputs
  • Ran alternating generator/discriminator updates with separate learning rates
  • Visualized 10 validation triplets: edge input → generated shoe → ground truth
Evaluation
  • 10 validation-set triplets: edge sketch → generated shoe → ground truth
  • Qualitative check of edge adherence, texture, and colour on held-out pairs
Pix2Pix validation translation examples part 1
Validation triplets 1–5: edge → generated → ground truth
Pix2Pix validation translation examples part 2
Validation triplets 6–10: edge → generated → ground truth
Results
  • Final epoch 5, step 3100 — D loss: 0.550, G loss: 13.46 (GAN: 1.01, L1: 0.125)
  • Qualitative: generated shoes follow edge structure with plausible texture and colour
  • L1 term anchors global layout; PatchGAN sharpens local high-frequency detail
Pix2Pix generator and discriminator loss curves
Generator and discriminator loss over training
Takeaway

Paired translation works remarkably well when alignment is free: the L1 loss prevents the generator from ignoring the input structure, while PatchGAN supplies the texture sharpness a plain L1 model would smooth away. Watching edge strokes turn into recognizable shoes made the conditional GAN objective click in a way theory alone did not.

Work completed during Oxford summer coursework. This page shows only my own implementations and outputs; course materials are not redistributed.