Unmasking Anomalies in Road-Scene Segmentation

Shyam Nandan Rai, Fabio Cermelli, Dario Fontanel, Carlo Masone, Barbara Caputo

TL;DR

Mask2Anomaly shifts the paradigm of anomaly segmentation for self-driving cars from a noisy per-pixel classification approach to a mask-based classification framework. By introducing global masked attention, mask contrastive learning, and a panoptic-driven refinement mask, it slashes false positive rates by 60% while setting a new state-of-the-art on standard benchmarks.

What Problem Does This Paper Address?

For autonomous vehicles to operate safely, they must detect unexpected objects on the road—such as a fallen box, a lost piece of cargo, or an animal—that were never seen during training. This task is known as anomaly segmentation.

Traditionally, this problem is treated as a per-pixel classification task, where models assign an anomaly score to every single pixel independently. However, ignoring the surrounding context leads to severe pixel-level noise, blurry object boundaries, and a massive number of false positives.

Recent advances in computer vision have introduced mask-transformers (like Mask2Former), which group pixels into coherent "object masks" before classifying them. While this sounds perfect for capturing anomalies as whole entities, naively applying anomaly detection to mask-transformers fails. This is because their standard attention mechanisms are designed to focus exclusively on predicted foreground regions, effectively blinding the model to anomalies that appear in the background.

Figure 1: Per-pixel vs per-mask Anomaly Segmenta- tion: Dense Hybrid [22], the state-of-the-art method for AS based on per-pixel classification can detect the anoma- lies, but it produces many false positives. Anomaly seg- mentation can be cast as a mask classification problem, but naively using MSP [25] on top of Mask2Former [12] does not produce good results. Our Mask2Anomaly ex- ploits mask-transformers properties to refine the classifi- cation of anomalies, drastically reducing false positives. fpixel and fmask denotes per-pixel, and per-mask architec- ture. Anomalies in the output image are represented in red.

Methods

The authors introduce Mask2Anomaly, a novel framework that successfully adapts mask-classification architectures for anomaly segmentation through three key technical innovations:

  1. Global Masked Attention (GMA): Standard masked attention restricts the model's focus to foreground regions to speed up training convergence. GMA remedies this "blind spot" by adding a parallel attention branch that explicitly targets background regions, ensuring the model can detect anomalies anywhere in the scene.
  2. Mask Contrastive Learning: To ensure a clean mathematical separation between known classes and anomalies, the authors implement a contrastive loss function. During training, out-of-distribution (OOD) objects from an auxiliary dataset are digitally pasted onto the training images. The model is then trained to maximize the score margin between these outlier masks and known in-distribution classes.
  3. Refinement Mask ($R_M$): This inference-time technique leverages panoptic segmentation principles, which divide a scene into "things" (countable objects like cars or pedestrians) and "stuff" (amorphous regions like sky, buildings, or sidewalks). Since road anomalies are physically distinct objects ("things") usually located on the drivable surface, this module filters out false positives by zeroing out anomaly scores in "stuff" regions (except for the road itself).
Figure 2: Mask2Anomaly Overview. Mask2Anomaly meta-architecture consists of an encoder, a pixel decoder, and a trans- former decoder. We propose global mask attention (Sec. 3.2) that independently distributes the attention between foreground and background. V, K, and Q are Value, Key, and Query. ϕ is image features. ϕi, ϕi+1, ϕi+2 are upsampled image features at multiple scales. Mask contrastive Loss LCL (Sec. 3.3) utilizes outlier masks to maximize the separation between anomalies and known classes. During anomaly inference, we utilize refinement mask RM (Sec. 3.4) to minimize false positives.

Datasets

  • In-Distribution Training: Cityscapes (urban street scenes).
  • Outlier Supervision: MS-COCO (used to extract random objects and paste them onto Cityscapes images to simulate anomalies during training).
  • Evaluation Benchmarks: Road Anomaly, Fishyscapes (FS Static and FS Lost & Found), and Segment Me If You Can (SMIYC-RA21 and SMIYC-RO21).

Key Insights and Ideas

  • Objectness as an Anomaly Prior: Shifting from pixels to masks forces the model to reason about objects as unified entities. This structural constraint inherently suppresses pixel-level noise and yields much cleaner anomaly boundaries.
  • The Attention Double-Edged Sword: Restricting attention to foreground masks is a powerful optimization for closed-set semantic segmentation, but it acts as a structural blindfold for open-set anomaly detection. Retaining background context is essential for safety-critical applications.
  • Panoptic Heuristics: The semantic distinction between "things" and "stuff" serves as an elegant, training-free prior to eliminate edge-case false positives (such as false anomalies triggered by lighting changes on buildings or sky boundaries).
Figure 4: Mask Refinement Illustration: To obtain the refined prediction, we multiply the prediction map with a refinement mask that is built by assigning zero anomaly scores for pixels that are categorized as “stuff”, except for the “road”. The refinement eliminates many false positives at the boundary of objects and in the background. The re- gion to be masked is white in the refinement mask.

Key Results

  • Dramatic False Positive Reduction: On average across all benchmarks, Mask2Anomaly reduces the False Positive Rate ($\text{FPR}_{95}$) by 60% compared to the previous state-of-the-art.
  • Precision Improvements: The model improves the average Area under the Precision-Recall Curve ($\text{AuPRC}$) by 20%.
  • Architectural Efficiency: When paired with a standard ResNet-50 backbone, Mask2Anomaly outperforms vanilla Mask2Former variations that use much larger, computationally heavy transformer backbones (like Swin-S), while requiring only 30% of the trainable parameters (23M vs 69M).

Limitations and Future Work

Despite its strong performance, the authors note a few remaining challenges:

  • Tiny Objects: Mask2Anomaly still struggles to accurately segment very small anomalous objects located far down the road.
  • Road Surface Irregularities: The model occasionally suffers from false positives when encountering structural road hazards, such as potholes, mistakenly segmenting them as distinct anomalous objects rather than road textures.

Future directions will likely explore multi-scale feature refinements to better capture minute objects and methods to distinguish between road damage and physical obstacles.

Summary updated

Abstract

Anomaly segmentation is a critical task for driving applications, and it is approached traditionally as a per-pixel classification problem. However, reasoning individually about each pixel without considering their contextual semantics results in high uncertainty around the objects' boundaries and numerous false positives. We propose a paradigm change by shifting from a per-pixel classification to a mask classification. Our mask-based method, Mask2Anomaly, demonstrates the feasibility of integrating an anomaly detection method in a mask-classification architecture. Mask2Anomaly includes several technical novelties that are designed to improve the detection of anomalies in masks: i) a global masked attention module to focus individually on the foreground and background regions; ii) a mask contrastive learning that maximizes the margin between an anomaly and known classes; and iii) a mask refinement solution to reduce false positives. Mask2Anomaly achieves new state-of-the-art results across a range of benchmarks, both in the per-pixel and component-level evaluations. In particular, Mask2Anomaly reduces the average false positives rate by 60% wrt the previous state-of-the-art. Github page: https://github.com/shyam671/Mask2Anomaly-Unmasking-Anomalies-in-Road-Scene-Segmentation.
BibTeX
@inproceedings{rai2023unmasking,
  author = {Shyam Nandan Rai and Fabio Cermelli and Dario Fontanel and Carlo Masone and Barbara Caputo},
  title = {{Unmasking Anomalies in Road-Scene Segmentation}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
}
Figure