Foundations to Frontier
Tests
E. Deep Learning › E10 Segmentation Architectures

U-Net

U-Net (Ronneberger, Fischer and Brox, 2015) is a symmetric encoder–decoder for segmentation. A contracting path captures context, an expanding path upsamples step by step, and skip connections concatenate encoder features into the decoder at every scale. Trained from very few images with heavy elastic augmentation and a weighted loss that emphasises the borders between touching objects, it won the 2015 ISBI cell-tracking challenge by a large margin. It became the standard architecture for biomedical and many other segmentation tasks, and the backbone of diffusion models. This page covers the architecture, valid convolutions and tiling, augmentation and the weight map. In the exercises you compute U-Net's sizes, then show its border term raises the loss weight on the thin gaps between touching cells from 4% to 25%.

Level 0: Foundation

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

Down to understand, up to draw, with bridges in between

U-Net has the shape of a U. The left side shrinks the image step by step, learning what is in it. The right side grows it back to full size to draw the outline of each object. Bridges carry the fine detail from each step on the left straight across to the matching step on the right, so edges stay sharp. It learns well from only a few dozen labelled images, which made it the workhorse of medical image analysis.

Segmentation lab
pixel accuracy 0.893 · IoU 0.509 · Dice 0.675 (blue: correct, red: false positive, yellow: missed)
Segmentation labels every pixel. Coarse score maps lose boundaries when upsampled; skip connections from finer layers (FCN, U-Net) and dilated convolutions (DeepLab) recover detail. Judge masks by IoU or Dice, not pixel accuracy, which background inflates.
Why engineers care

U-Net-style networks segment cells, organs, roads, buildings, crops and craters. The same architecture is the denoising network inside diffusion image generators.

📝 Quick check (Level 0)
0/3 answered
  1. 1. U-Net's left side…
  2. 2. The bridges carry…
  3. 3. U-Net is known for working with…

Level 1: Beginner

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

By hand

  • Architecture:
    • four down-steps of two 3 × 3 unpadded convolutions with ReLU and 2 × 2 max pooling, with channels 64, 128, 256, 512;
    • a bottom of 1,024 channels;
    • four up-steps of a 2 × 2 up-convolution, concatenation with the cropped encoder map, and two 3 × 3 convolutions;
    • a final 1 × 1 convolution to the classes.
  • Valid convolutions: each unpadded 3 × 3 convolution removes 2 pixels. A 572 × 572 input tile gives a 388 × 388 output; the first skip crops 88 pixels from each side (568 → 392).
  • Overlap-tile strategy: segment large images tile by tile with overlapping inputs, mirroring at image borders. A 1,000 × 1,000 image needs 3 × 3 = 9 output tiles of 388.
  • Weight map: w(x) = w_c(x) + w₀·exp(−(d₁(x) + d₂(x))²/2σ²), with d₁ and d₂ the distances to the nearest two cells, w₀ = 10 and σ ≈ 5 pixels.
  • Dice: 2TP/(2TP + FP + FN); with TP = 30, FP = 10 and FN = 20 it is 60/90 ≈ 0.667.
📝 Quick check (Level 1)
0/3 answered
  1. 1. U-Net output for a 572 × 572 input:
  2. 2. Channels at U-Net's bottom:
  3. 3. The weight map's w₀:

Level 2: Intermediate

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

U-Net in code

Exercise 1.

  • Following the unpadded convolutions and poolings gave 388 × 388 output for a 572 × 572 tile and an 88-pixel crop for the first skip.
  • The channels doubled from 64 to 1,024.

Practice.

  • Modern U-Nets usually use padded convolutions (output size = input size), BatchNorm or GroupNorm, and pretrained encoders (segmentation_models_pytorch provides many).
  • Loss: cross-entropy plus Dice handles class imbalance; the original weight map helps separate touching instances.
  • Augmentation: elastic deformations, rotations, flips and intensity changes are crucial with few training images.
  • nnU-Net configures U-Nets automatically from the dataset and is a strong baseline across medical segmentation tasks.
import segmentation_models_pytorch as smp
model = smp.Unet(encoder_name="resnet34", encoder_weights="imagenet", classes=1)   # padded U-Net, pretrained encoder
loss = smp.losses.DiceLoss("binary") + nn.BCEWithLogitsLoss()
🐍 Exercise 1: U-Net's sizes
Track tile sizes through U-Net's unpadded convolutions, the skip crop, and the channel widths.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A self-configuring U-Net framework:
  2. 2. Key augmentation in U-Net:
  3. 3. Modern U-Nets usually use…

Level 3: Advanced

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

Theory

Why concatenation skips. FCN added coarse and fine predictions. U-Net concatenates fine encoder features into the decoder at every scale, so the decoder can combine high-resolution detail with context and learn how. The symmetric multi-step upsampling gives precise boundaries.

Learning from few images. The EM data had only 30 training images. Elastic deformations simulate the natural variability of tissue, and the fully convolutional design turns each image into many overlapping training patches. Together these made U-Net data-efficient.

Separating touching objects. Adjacent cells are separated by thin background lines that cover a tiny fraction of pixels. An unweighted loss barely penalises missing them, which merges cells. The border term raises the weight of those gaps. In exercise 2 their share of the loss weight grew from 4% to 25%, so the network must get them right.

Results.

  • On the ISBI 2015 cell-tracking challenge, U-Net reached IoU 92.0% (PhC-U373) and 77.5% (DIC-HeLa), against 83% and 46% for the next best.
  • It segmented a 512 × 512 image in under a second on a 2015 GPU.
📝 Quick check (Level 3)
0/3 answered
  1. 1. U-Net merges encoder features by…
  2. 2. EM training images used:
  3. 3. The weight map helps…

Level 4: Expert

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

How much does the border weight focus the loss?

History.

  • O. Ronneberger, P. Fischer and T. Brox (2015) introduced U-Net at MICCAI. It won the ISBI 2015 cell-tracking challenge and the EM segmentation challenge.
  • F. Isensee et al. (2021) introduced nnU-Net.
  • U-Nets became the denoisers of diffusion models (J. Ho et al., 2020; R. Rombach et al., 2022).

Exercise 2. This is a calculation, not a training run. Four 64 × 64 images each contain 7 touching cells separated by thin gaps. We compute U-Net’s weight map for several w₀ (σ = 5) and measure the share of the total loss weight on gap pixels: background within 3 pixels of two different cells.

w₀ share of loss weight on gap pixels (gaps are 4.8% of the image)
0 (class balancing only) 0.039
5 0.170
10 0.246
20 0.330
  • Without the border term the gaps are nearly invisible to the loss. Class balancing even lowers their share below their 4.8% area, because it up-weights foreground.
  • With the default w₀ = 10 they carry a quarter of the weight, five times their area, so merging two cells costs much more.
  • This is the mechanism, not the outcome. The paper showed the weighted loss gives better separation; whether it helps on other data depends on how often objects touch.
🐍 Exercise 2 (research): how much does the border weight focus the loss?
Compute U-Net's border weight map on images of touching cells and measure the share of loss weight on the gaps between them.

U-Net in AI, robotics and aerospace

  • Medical imaging: organ, tumour and cell segmentation, often with nnU-Net.
  • Earth observation: building footprints, roads, field boundaries and craters from satellite and planetary imagery.
  • Generative models: U-Net denoisers in diffusion models generate and edit images, including synthetic training data for robotics.

References

  1. O. Ronneberger, P. Fischer, T. Brox (2015). “U-Net: convolutional networks for biomedical image segmentation.” Proc. MICCAI.
  2. F. Isensee, P. F. Jaeger, S. A. A. Kohl, J. Petersen, K. H. Maier-Hein (2021). “nnU-Net: a self-configuring method for deep learning-based biomedical image segmentation.” Nature Methods 18.
  3. J. Ho, A. Jain, P. Abbeel (2020). “Denoising diffusion probabilistic models.” Advances in NeurIPS.