Foundations to Frontier
Tests
G. Computer Vision and Remote Sensing › G2 Core Vision Tasks

Semantic segmentation: FCN, U-Net, DeepLab

Semantic segmentation labels every pixel with a class, such as road, building, vegetation or water, without separating individual objects. FCN, U-Net and DeepLab (Section E10) are its classic architectures; this page is about the task. It covers the problem setup and its label conventions (void pixels, class lists), the benchmark datasets (PASCAL VOC, Cityscapes, ADE20K, LoveDA), the metrics (pixel accuracy, mIoU and how it is accumulated, Dice, boundary measures), a practical pipeline with tiling, losses for rare classes and sliding-window inference, and the failure modes: thin and rare classes, boundaries and domain shift. In the exercises you implement the confusion matrix with an ignore label and show that dataset-level and per-image mIoU differ on the same predictions. You then segment synthetic 4-band land-cover scenes with thin roads. A per-pixel classifier reached 0.892 pixel accuracy but road IoU 0.050. Adding 5 × 5 context raised mIoU from 0.670 to 0.820, and class weighting raised road IoU from 0.460 to 0.555 at a small cost in pixel accuracy.

Level 0: Foundation

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

A label for every pixel

Semantic segmentation colours in a picture: every pixel gets a class such as road, field, forest or water. It answers what is where, at the finest level, but it does not count things: three touching buildings become one blob of building pixels. Good scores are harder than they look. If most of the image is field, a model that ignores the thin roads still gets most pixels right. The demo shows how pixel accuracy, IoU and Dice react as a predicted region slides away from the true one.

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

Land-cover maps from Sentinel-2, flood extents from radar, drivable space for rovers and cars, and cloud masks for every optical satellite product are all semantic segmentation.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Semantic segmentation assigns a class to…
  2. 2. Two touching buildings in a semantic map are…
  3. 3. Pixel accuracy is dominated by…

Level 1: Beginner

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

By hand

  • Output. A label map the size of the image (logits are usually predicted at 1/4 to 1/8 resolution and upsampled). Pixels labelled void or unlabelled (index 255 by convention) are ignored in the loss and the metrics.
  • Datasets. PASCAL VOC 2012 (20 classes plus background); Cityscapes (Cordts et al. 2016; 5000 finely annotated street scenes, 19 evaluation classes); ADE20K (Zhou et al. 2017; 150 classes); COCO-Stuff; for Earth observation DeepGlobe (2018), LoveDA (Wang et al. 2021) and OpenEarthMap (2023).
  • Metrics. Pixel accuracy; IoU per class = TP/(TP + FP + FN); mIoU, normally from one confusion matrix accumulated over the whole test set (per-image averaging gives different numbers); frequency-weighted IoU; Dice = 2|A∩B|/(|A| + |B|), common in medical imaging; Boundary IoU (Cheng et al. 2021) for edge quality.
  • Architectures (E10). FCN (2015), U-Net (2015), DeepLab v3+ (2018), PSPNet (2017); transformer-based SegFormer (Xie et al. 2021), UPerNet with Swin or ConvNeXt backbones, and Mask2Former (2022), which also does instance and panoptic segmentation.
  • Failure modes. Thin and rare classes (roads, power lines, poles); boundaries, where labels themselves are uncertain; domain shift across cities, seasons and sensors (synthetic GTA5 to real Cityscapes is a standard adaptation benchmark).
📝 Quick check (Level 1)
0/3 answered
  1. 1. Void pixels (label 255) are…
  2. 2. Standard mIoU accumulates the confusion matrix over…
  3. 3. Dice is related to IoU J by…

Level 2: Intermediate

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

A segmentation pipeline for large images

Exercise 1.

  • A confusion matrix that skips void pixels.
  • Per-class IoU and dataset-level mIoU.
  • Per-image mIoU, to see how much the accumulation choice matters.

Practice.

  • Labels. Fix the class list and the void policy first; label boundaries consistently; for satellite data, check the label date against the image date.
  • Training crops. Train on random crops (512 × 512 is common) with flips, rotations and scale jitter; sample crops so rare classes appear.
  • Losses for rare and thin classes. Weighted cross-entropy (inverse or median frequency), Dice or Lovász-softmax (Berman et al. 2018), or online hard example mining.
  • Inference on large images. Sliding windows with overlap, averaging logits in the overlaps (or keeping only window centres) to avoid seams; optional flip and multi-scale test-time augmentation.
  • Evaluate per class and on held-out regions or cities; report mIoU, per-class IoU and the rare classes that matter to the user.
  • Tools. segmentation_models_pytorch, MMSegmentation, Hugging Face SegFormer and Mask2Former; TorchGeo for geospatial data.
import segmentation_models_pytorch as smp, torch
model = smp.Unet("resnet34", encoder_weights="imagenet", in_channels=4, classes=4)    # 4 bands, 4 classes
w = torch.tensor([0.5, 0.6, 0.8, 3.0])                                              # median-frequency style weights
ce = torch.nn.CrossEntropyLoss(weight=w, ignore_index=255)
dice = smp.losses.DiceLoss("multiclass", ignore_index=255)
loss = ce(model(x), y) + dice(model(x), y)
# inference on a large scene: overlapping windows, average the logits
from torchgeo.samplers import GridGeoSampler   # or a simple loop over window origins with stride < window
🐍 Exercise 1: confusion matrix, IoU and mIoU
Build a confusion matrix that ignores void pixels, compute per-class IoU, and compare dataset-level with per-image mIoU.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A loss that helps thin, rare classes:
  2. 2. Seams between inference windows are avoided by…
  3. 3. For geospatial segmentation data loading, a common library is…

Level 3: Advanced

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

Theory

Context versus detail. A pixel’s own value is often ambiguous (a road and bare soil can have almost the same spectrum), and context from its neighbourhood resolves it. But context averages over neighbours, which blurs boundaries and erases structures thinner than the context window. Encoder–decoder designs with skip connections (U-Net, DeepLab v3+) exist to get both: deep, wide-context features and full-resolution detail.

Why accuracy misleads. Pixel accuracy weights classes by area. A class covering 9% of pixels can be missed completely while accuracy stays above 0.9. mIoU weights every class equally, so a missed class costs 1/K of the score.

How mIoU is accumulated. Dataset-level mIoU sums TP, FP and FN over all images before dividing: large images and frequent classes dominate each class’s IoU. Per-image mIoU averages image scores, counting classes absent from an image differently. The two can differ by tens of points; papers almost always report the dataset-level version.

Class weighting. Reweighting the loss by inverse class frequency moves the decision boundary towards rare classes: more of them are found (higher recall) at the price of false positives in common classes, so rare-class IoU usually rises while pixel accuracy falls slightly.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Context blurs…
  2. 2. Missing one of K classes completely costs mIoU…
  3. 3. Class weighting usually trades…

Level 4: Expert

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

What do pixel values, spatial context and class weighting each contribute to segmenting thin, rare classes?

History.

  • J. Long, E. Shelhamer and T. Darrell, “Fully convolutional networks for semantic segmentation” (2015).
  • O. Ronneberger, P. Fischer and T. Brox, “U-Net” (2015).
  • L.-C. Chen et al., “Encoder-decoder with atrous separable convolution for semantic image segmentation” (2018): DeepLab v3+.

Exercise 2. Synthetic 64 × 64 land-cover scenes with 4 spectral bands (blue, green, red, near infrared).

  • Classes: smooth regions of water, vegetation and bare soil, crossed by three straight roads 1–2 pixels wide (8.7% of pixels) whose spectrum is close to bare soil; Gaussian sensor noise.
  • Model: softmax regression (a linear 1 × 1 ‘network’) trained on 6000 sampled pixels from 6 scenes, tested on 6 new scenes.
  • Features: the pixel’s 4 bands; its 5 × 5 neighbourhood mean (context only); both; both with inverse-frequency class weights.
  • Boundary accuracy: accuracy on pixels within one pixel of a class change (49% of pixels, mostly along roads).
features pixel accuracy mIoU road IoU boundary accuracy
pixel only 0.892 0.670 0.050 0.811
5 × 5 context only 0.876 0.675 0.191 0.748
pixel + context 0.946 0.820 0.460 0.892
pixel + context, class-weighted 0.939 0.833 0.555 0.891
  • Pixel accuracy hid the failure: 0.892 with roads essentially never found (IoU 0.050), because roads look like soil pixel by pixel.
  • Context alone helped roads but hurt boundaries: averaging over 5 × 5 suppressed noise along the roads (IoU 0.191) but blurred every edge (boundary accuracy 0.811 to 0.748).
  • Pixel plus context won clearly (mIoU 0.820): the linear analogue of an encoder–decoder with skip connections.
  • Class weighting raised road IoU by 0.095 and mIoU by 0.013 while pixel accuracy fell by 0.007; a good trade when roads are the point.
  • Seeds 1 and 2: pixel + context mIoU 0.831 and 0.825; weighted road IoU 0.567 and 0.554; pixel-only road IoU 0.105 and 0.081.
  • Caveat: a linear model with hand-built context; deep networks learn their context, but the same accuracy-versus-mIoU and context-versus-boundary effects appear in them.
🐍 Exercise 2 (research): what do pixel values, spatial context and class weighting each contribute to segmenting thin, rare classes?
Segment synthetic land-cover scenes with pixel, context and combined features, with and without class weighting, and compare pixel accuracy, mIoU, road IoU and boundary accuracy.

Semantic segmentation in AI, robotics and aerospace

  • Earth observation: land-cover mapping (ESA WorldCover 2020–2021 at 10 m), flood and burn-scar mapping from Sentinel-1 and Sentinel-2, cloud and shadow masks (G5).
  • Planetary robotics: terrain classification for Mars rovers, for example the AI4Mars dataset (2021) of crowd-labelled Curiosity and Perseverance images (soil, bedrock, sand, big rock).
  • Driving and drones: drivable-area and lane segmentation at video rate, typically with BiSeNet or SegFormer variants.

References

  1. J. Long, E. Shelhamer and T. Darrell (2015). “Fully convolutional networks for semantic segmentation.” CVPR.
  2. O. Ronneberger, P. Fischer and T. Brox (2015). “U-Net: convolutional networks for biomedical image segmentation.” MICCAI.
  3. L.-C. Chen, Y. Zhu, G. Papandreou, F. Schroff and H. Adam (2018). “Encoder-decoder with atrous separable convolution for semantic image segmentation.” ECCV.
  4. M. Cordts et al. (2016). “The Cityscapes dataset for semantic urban scene understanding.” CVPR.
  5. B. Zhou et al. (2017). “Scene parsing through ADE20K dataset.” CVPR.
  6. E. Xie et al. (2021). “SegFormer: simple and efficient design for semantic segmentation with transformers.” NeurIPS.
  7. M. Berman, A. Rannen Triki and M. Blaschko (2018). “The Lovász-softmax loss.” CVPR.
  8. B. Cheng, R. Girshick, P. Dollár, A. Berg and A. Kirillov (2021). “Boundary IoU: improving object-centric image segmentation evaluation.” CVPR.
  9. J. Wang et al. (2021). “LoveDA: a remote sensing land-cover dataset for domain adaptive semantic segmentation.” NeurIPS Datasets and Benchmarks.