Skip to main content
Semantic Segmentation

Semantic Segmentation

From Classification to Segmentation

Segmentation is classification taken to its extreme: instead of assigning one label to the entire image, you assign a label to every single pixel. This is the foundation for applications like self-driving cars (is this pixel road, sidewalk, or pedestrian?), medical imaging (is this pixel tumor or healthy tissue?), and satellite analysis (is this pixel forest, water, or urban?).
Segmentation models are memory-hungry because they must maintain spatial resolution throughout the network (unlike classification models that aggressively pool). A single 512x512 input with a U-Net encoder can easily consume 8+ GB of GPU memory during training. If you hit OOM errors, reducing input resolution (e.g., from 512 to 256) has a much larger impact than reducing batch size because activation memory scales quadratically with spatial dimensions.

Fully Convolutional Networks (FCN)

The foundation of modern segmentation. Before FCN, people would apply classifiers to each pixel independently (or to sliding windows), which was absurdly slow. FCN’s breakthrough was realizing that you can replace the fully connected layers at the end of a classification network with convolutional layers, turning the entire network into a spatial-in, spatial-out function that processes the whole image in one forward pass:

U-Net

The most influential segmentation architecture, especially in medical imaging where labeled data is scarce. The name comes from its U-shaped architecture: the left side encodes (compresses) the input, the bottom is the bottleneck, and the right side decodes (expands) back to full resolution. The critical innovation is the skip connections that bridge corresponding encoder and decoder layers, allowing the decoder to use fine-grained spatial details from the encoder that would otherwise be lost during downsampling. Think of it like making a summary (encoding) and then expanding it back into a full essay (decoding) — without the skip connections, you would lose all the specific details. With them, the decoder can say “I know the big picture from the bottleneck features, and here are the precise boundaries from the encoder.”

DeepLab Series

DeepLab takes a different approach from the encoder-decoder style: instead of downsampling and then upsampling, use dilated (atrous) convolutions to maintain resolution while still capturing large-scale context. This avoids the information loss from repeated pooling.

Atrous (Dilated) Convolutions


Transformer-Based Segmentation

Transformers have entered segmentation with force. Their key advantage: global receptive field from layer 1. A CNN needs many layers of convolutions to “see” the full image, but a transformer’s self-attention can relate any two pixels in a single layer. This makes transformers particularly good at capturing long-range dependencies (e.g., understanding that a road continues behind a building).
Transformer-based segmentation models are significantly more data-hungry than CNN-based ones. A U-Net can achieve strong results on datasets as small as 30 images (with heavy augmentation). SegFormer or SETR typically require pretraining on ImageNet-21k and fine-tuning on thousands of labeled segmentation images. If your dataset is small (under 1,000 annotated images), a pretrained U-Net or DeepLabV3+ with a ResNet backbone is almost always the better choice.

SETR (Segmentation Transformer)


Instance & Panoptic Segmentation


Loss Functions


Exercises

Create a loss that focuses on boundaries:
Implement test-time augmentation for segmentation:
  • Inference at multiple scales
  • Flip augmentation
  • Ensemble predictions
Add Conditional Random Field refinement:

What’s Next?

Hyperparameter Tuning

Systematic optimization with Optuna and Ray Tune

Reproducibility

Experiment tracking and reproducible research