Semantic Segmentation

Machine Learning
Introduced by
Long, J., Shelhamer, E., & Darrell, T.
Year
2015
Type
Dense prediction / pixel-wise classification
Family
Deep learning / NLP / CV

What does it do?

Semantic segmentation assigns a class label to every pixel in an image, producing a dense, category-annotated map of the scene.

Unlike object detection, which outputs bounding boxes, it delineates the spatial extent of each class. This makes it useful where region boundaries matter, such as medical image analysis, autonomous driving, and satellite mapping.

The intuition behind the method

Think of semantic segmentation as colouring a photograph by category: every road pixel receives one colour, every sky pixel another, and every pedestrian pixel a third. The network makes these per-pixel decisions by first compressing the image into an abstract feature representation and then expanding it back to full resolution. The output says which exact pixels belong to a class, not only that a class is somewhere in the image. This is more informative than a bounding box, but it also requires per-pixel training labels and more compute.

History

Semantic segmentation as an end-to-end deep-learning task was advanced by Long, Shelhamer, and Darrell's fully convolutional network (2015), which replaced fully connected classification layers with convolutions so that images of arbitrary size could be mapped to dense outputs. DeepLab (Chen et al.) highlighted atrous convolution as a tool for dense prediction, and introduced atrous spatial pyramid pooling and fully connected CRF refinement to improve boundary localisation. U-Net, an encoder-decoder with skip connections widely used in biomedical imaging, is another influential design. Transformer-based architectures have since been proposed for dense prediction as well.

When to use it

Use semantic segmentation when you need to know where each class occurs at pixel level: organ or lesion delineation in medical images, road, lane, and obstacle mapping for driving, land-cover classification in remote sensing, and defect localisation in inspection. Do not use it when a bounding box is enough, when per-pixel masks are unavailable or too costly to produce, or when you must count or separate individual objects of the same class, which requires instance segmentation. Also reconsider it when GPU memory and compute cannot support the encoder-decoder at the required resolution.

Limitations and considerations

  • Training requires large numbers of pixel-level annotations, which are far more expensive to produce than image-level or bounding-box labels.
  • The output does not separate instances: adjacent objects of the same class merge into one region.
  • Pooling and downsampling give the network invariance but reduce localisation accuracy, as Chen et al. note; boundaries remain the weak point without refinement such as a fully connected CRF.
  • Memory use grows with input resolution, which limits full-resolution inference on edge devices.
  • Classes with few training pixels are learned poorly unless class weighting, oversampling, or a similar remedy is applied.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The fully convolutional design, as introduced by Long et al., accepts inputs of arbitrary size and returns an output of matching spatial size in a single forward pass.
  • Skip connections combine coarse, semantically rich deep features with fine, shallow appearance features, which is why the boundaries of predicted regions can be sharper than those from a coarse map alone.
  • Atrous (dilated) convolution, as described by Chen et al., enlarges the field of view for context without adding parameters or computation, so it can be used with high-resolution feature maps.
  • Because the whole image is labelled in one pass, inference cost is shared across all pixels once the model is trained.
  • The same encoder-decoder pattern applies across image types, including natural photographs, medical scans, and satellite imagery, provided per-pixel labels exist.

Applications

  • Medical image analysis: organ, lesion, and tumour delineation in CT, MRI, and pathology slides.
  • Autonomous driving: road, lane, vehicle, and pedestrian scene parsing.
  • Satellite and aerial remote sensing: land-use and land-cover classification.
  • Industrial quality control: localisation of defects on manufactured surfaces.
  • Augmented reality: scene understanding for object placement and occlusion handling.
  • Agricultural monitoring: crop type mapping and disease region identification from drone imagery.

How it works

How it works

1

A convolutional encoder, typically a pre-trained backbone such as ResNet or EfficientNet, processes the input through successive convolution and pooling layers. Spatial resolution falls as the feature maps become more abstract and capture semantic content at several scales.

2

A decoder recovers spatial resolution, for example through transposed convolution or bilinear upsampling. Designs such as U-Net add skip connections from encoder layers, and DeepLab uses atrous convolutions to keep a larger field of view at higher resolution. The ratio between input and feature-map resolution, often called the output stride, is a design choice: a smaller stride preserves more spatial detail at the cost of higher compute and memory, and atrous convolution allows this resolution to be controlled without losing context. The decoder combines low-level spatial detail with high-level semantic features to produce a full-resolution feature volume.

3

A 1x1 convolution maps the final feature volume to a score map of shape H x W x C, where C is the number of classes. A softmax converts the scores to per-pixel class probabilities, and the argmax gives the predicted label for each pixel.

Formula
\hat{y}_{i} = \arg\max_{c} p(c \mid x_{i})
4

Training minimises the pixel-wise cross-entropy shown in the formula, summed over all N pixels and C classes. The formula is the unweighted form. In practice a per-class weight, often inverse to class frequency, is commonly multiplied into the inner sum to counter the imbalance between background pixels and rare classes such as tumours or pedestrians.

Formula
\mathcal{L} = -\frac{1}{N}\sum_{i=1}^{N}\sum_{c=1}^{C} y_{ic}\log p_{ic}
5

Parameters are updated by backpropagation through the full encoder-decoder pipeline. Common practice includes starting from a pre-trained encoder, using a poly learning-rate schedule, mixed-precision training, and data augmentation such as random crop, flip, and colour jitter to regularise the dense prediction head.

Common pitfalls

  • Reporting only pixel accuracy. On imbalanced data a model can score well by predicting the dominant classes, so per-class IoU and mean IoU (mIoU) should be reported alongside it.
  • Ignoring class imbalance in the loss. Without class weighting or a rebalancing loss such as focal loss, predictions for rare classes tend to be suppressed, and their IoU stays low even when overall accuracy looks acceptable.
  • Running the model at a resolution different from training without recalibration or fine-tuning, which typically degrades boundary quality.
  • Training the full encoder-decoder from scratch on a small set of annotated masks, where a pre-trained encoder usually gives more stable results.
  • Choosing semantic segmentation for a task that needs counting or separating individual objects; that task calls for instance segmentation.

Frequently asked questions

What is the difference between semantic segmentation and instance segmentation?

Semantic segmentation assigns one class label per pixel but does not separate objects of the same class, so all cars share one label. Instance segmentation gives each individual object its own mask, which is needed for counting or tracking distinct objects.

What evaluation metric should I report?

Report per-class IoU and mean Intersection-over-Union (mIoU). For class c, IoU is TP_c / (TP_c + FP_c + FN_c), the overlap between predicted and ground-truth pixels of that class divided by their union. mIoU is the mean of these values over all classes, computed on held-out test images. Pixel accuracy alone can be misleading when classes are imbalanced, because a model that largely ignores rare classes can still score well on it.

How much labelled data do I need?

The requirement depends on the number of classes, how visually varied the domain is, and whether the encoder is pre-trained. A pre-trained encoder generally reduces the number of annotated masks needed compared with training from scratch. A learning curve from a pilot annotation set is a practical way to estimate the need for your own data. Weakly or semi-supervised methods can supplement pixel labels when annotation is the bottleneck.

Which architecture should I start with?

For limited GPU memory, U-Net-style encoder-decoders are a common starting point, especially for medical images. For large-scale scene parsing with modern hardware, SegFormer or DeepLab v3+ with a pre-trained backbone is often considered for the accuracy-to-compute trade-off. The choice should be checked against your own data and hardware.

Can semantic segmentation run in real time?

Lightweight designs such as ERFNet, BiSeNet, and MobileNet-based decoders are built for speed. Whether a given model reaches real-time frame rates depends on the input size and the hardware, so speed must be measured on the target deployment device.

Related methods

Sources

  1. Long, J., Shelhamer, E., & Darrell, T. (2015). Fully convolutional networks for semantic segmentation. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 3431–3440.

    Open DOI reference
  2. Chen, L.-C., Papandreou, G., Kokkinos, I., Murphy, K., & Yuille, A. L. (2018). DeepLab: Semantic image segmentation with deep convolutional nets, atrous convolution, and fully connected CRFs. IEEE Transactions on Pattern Analysis and Machine Intelligence, 40(4), 834–848.

    Open DOI reference