Skip to content

Paired image translation and super-resolution: Pix2Pix, SRGAN, ESRGAN

Conditional GANs that turn one image into another from aligned pairs, perceptual losses that make upscaled images look sharp, and why sharp is not the same as true.

Advanced ~14 min8 steps

What runs in CodeSplash

You will be able to

  • Describe Pix2Pix's generator, patch discriminator and L1 term
  • Explain why an L1 or L2 loss alone gives blurry outputs
  • Compare pixel, perceptual and adversarial losses in super-resolution
  • Say when an upscaled image must not be used as evidence

Read first

01

One image in, another out

Read

Many tasks turn one image into another of the same scene: a map into an aerial photo, a sketch into a shoe, a day photo into night, a small image into a large one. With aligned pairs of inputs and outputs, this is supervised learning with an image as the label.

The obvious loss, pixel-by-pixel difference to the target, has a flaw. When several outputs are plausible (where exactly does each brick edge go?), the average of them minimizes the error, and the average of many sharp images is a blurry one.

02

Pix2Pix: a GAN with a condition

Read
Reference · VIS023 · Explained herePix2Pix conditional image-to-image translationPix2Pix learns a mapping between aligned source and target images with conditional adversarial training and a reconstruction term.

Pix2PixPix2Pix (paired image translation)A conditional GAN trained on aligned input–output image pairs, with an L1 loss that keeps outputs close to the target. adds a discriminator that sees the input together with either the real output or the generated one, and learns to tell them apart. The generator, a U-NetU-NetAn encoder–decoder CNN for per-pixel labels: the decoder upsamples and concatenates the encoder's maps of the same size., must fool it while also staying close to the target in L1 distance, weighted by λ = 100.

In the program the discriminator's loss is 0.634 and the generator's adversarial loss 1.132; the L1 distance of 0.1125 times 100 brings the generator's total to 12.38. The L1 term anchors the content; the adversarial term supplies sharpness.

03

Judge patches, not whole images

Read

Pix2Pix's discriminator, called PatchGAN, gives a real-or-fake score for each small patch instead of one for the image, then averages them. The L1 term already gets the overall layout right, so the discriminator only needs to judge local texture, and a patch-sized network has far fewer weights.

Everything depends on aligned pairs. Shift the targets by a few pixels and L1 pulls toward blur again; with no pairs at all, cycle-consistent methods train two translators that must undo each other instead.

04

Super-resolution: invent the missing detail

Read
Reference · VIS024 · Explained hereSRGAN / ESRGAN perceptual super-resolution familySRGAN and its ESRGAN successor combine adversarial and perceptual learning for image super-resolution. They are grouped as one related family here: ESRGAN changes the generator, discriminator objective and perceptual…

Super-resolutionSuper-resolutionProducing a larger image from a smaller one. Detail the input never held is invented, plausibly but not truthfully. enlarges an image. The small input lacks the fine detail, so any sharp output invents it. SRGAN combines three losses: pixel difference, a perceptual lossPerceptual lossComparing two images through a pretrained network's features instead of pixel by pixel, so textures count more than exact values. comparing pretrained-network features, and an adversarial loss. ESRGAN deepened the generator and used a relativistic discriminator, which asks whether real images look more real than generated ones on average.

The program's weighted total of 0.050 combines a pixel loss of 0.087, a toy feature loss of 0.036 and a relativistic generator loss of 2.56, each with its own weight.

05

Sharp or close?

Predict

Predict first

Two upscalers enlarge the same photo. One, trained on pixel loss, looks soft; the other, a GAN, looks crisp. Which usually scores higher PSNR against the true large image?

The sharp GAN outputThe blurry pixel-loss outputThey tie
Reveal

The blurry one. PSNR rewards being close on average, and averaging over possible details is closest. The crisp output places invented edges a little off, and each misplaced edge costs more than blur. This is the perception–distortion trade-off.

06

Plausible is not true

Read

A super-resolved license plate, face or tumor margin shows what such images usually look like, not what was there. Don't use upscaled or translated images as evidence, and don't measure objects in them. For display, say an image was enhanced and keep the original.

07

Check: translation and super-resolution

Checkpoint

Check yourself

Why does Pix2Pix keep an L1 term next to the adversarial loss?

Show the answer

Answer: a

The condition and the L1 term tie the output to this input's target. The discriminator adds the sharpness L1 can't.

Check yourself

You have photos of summer and winter landscapes, but never the same place in both seasons. Can you train Pix2Pix?

Show the answer

Answer: b

Without pairs there is no target for the L1 term. Cycle-consistent training replaces it with "translate there and back".

Check yourself

What does a PatchGAN discriminator score?

Show the answer

Answer: a

Local realism is the discriminator's job; the L1 term handles the overall layout.

Check yourself

What does a perceptual loss compare?

Show the answer

Answer: b

Feature distances care about textures and edges rather than exact values, so they penalize blur more than pixel losses do.

Check yourself

A GAN upscaler makes a blurry security frame's license plate readable. What can you conclude about the plate?

Show the answer

Answer: b

Detail missing from the input can't be recovered, only imagined. Never treat super-resolved detail as evidence.

Check yourself

What does ESRGAN's relativistic discriminator estimate?

Show the answer

Answer: a

Comparing against the other kind's average gives the generator useful gradients from both real and fake images.

08

Recap

Recap
  • Pixel losses alone average over plausible outputs and blur; an adversarial term adds sharpness.
  • Pix2Pix: a U-Net generator, a patch discriminator that sees the input, and L1 to aligned targets.
  • SRGAN and ESRGAN mix pixel, perceptual and adversarial losses; crisp outputs score lower PSNR than soft ones.
  • Generated detail is plausible, not true: never use it as evidence.

Concepts in this lesson