Heatmap-based Out-of-Distribution Detection

Julia Hornauer, Vasileios Belagiannis

Introduction

Deep neural networks (DNNs) often exhibit overconfidence when processing data outside their training distribution (Out-of-Distribution, or OOD). This behavior poses significant risks in safety-critical domains like autonomous driving or medical diagnostics. While existing OOD detection methods provide confidence scores, they typically operate as "black boxes," offering no insight into why a particular sample is flagged. This paper introduces a novel framework that not only improves detection performance but also provides human-interpretable visual explanations through heatmap generation.

Methodology

The proposed approach utilizes a fixed, pre-trained classifier augmented with a secondary decoder network. The core innovation lies in treating OOD detection as a visual explanation task.

The Heatmap Concept

The system generates a heatmap that represents the discrepancy between an input image and its closest In-Distribution (ID) counterpart. For a true ID image, the target heatmap is zero (represented as blue). For an OOD image, the heatmap highlights regions that deviate from the learned distribution.

Finding the "Closest" ID Image

To define the target heatmap for an OOD sample, the authors analyze the classifier's penultimate layer. They identify an ID sample that shares the same predicted class but has the minimum Euclidean distance in the feature space. This "closest" ID image serves as the reference for what the model "expects" to see.

Decoder and Scoring

A decoder, modeled after the DCGAN generator, is trained to reconstruct these heatmaps using the classifier's internal features and class predictions. During inference, the decoder produces a heatmap for the input. An OOD score is then derived by calculating the average of the maximum pixel values across the heatmap; a high response indicates a high likelihood of the image being OOD.

Visualizing OOD detection: (a) closest ID sample, (b) input OOD sample, and (c) the resulting heatmap highlighting out-of-place features.

Experimental Results

The method was evaluated against standard benchmarks including CIFAR-10, CIFAR-100, and Tiny ImageNet as ID datasets, with various OOD test sets like iSUN and SVHN.

Detection Performance

The heatmap-based approach significantly outperforms established baselines such as Maximum Softmax Probability (MSP), ODIN, and Energy-based scoring. On the CIFAR-10 benchmark using a ResNet18 architecture, the method reduced the False Positive Rate (FPR) at 95% True Positive Rate (TPR) to 15.37%, compared to 36.52% for the previous state-of-the-art (ReAct). AUROC scores consistently exceeded 96% for CIFAR-10 and remained robust even on more complex datasets.

Interpretability and Robustness

Qualitative analysis confirms that the heatmaps accurately highlight OOD regions (indicated by red/yellow) while remaining blank for ID samples. Furthermore, the model demonstrates intuitive sensitivity to environmental factors; for instance, images with extreme lighting or low contrast are flagged as OOD because their features become unrecognizable to the classifier.

Conclusion

By reframing OOD detection as an explanation problem, this research provides a dual benefit: state-of-the-art accuracy and transparency. The "plug-and-play" nature of the decoder allows it to be integrated with existing classifiers without retraining. Future work will focus on reducing the computational overhead of the decoder and extending the framework to more complex tasks like object detection and semantic segmentation.

Summary updated

Abstract

Our work investigates out-of-distribution (OOD) detection as a neural network output explanation problem. We learn a heatmap representation for detecting OOD images while visualizing in- and out-of-distribution image regions at the same time. Given a trained and fixed classifier, we train a decoder neural network to produce heatmaps with zero response for in-distribution samples and high response heatmaps for OOD samples, based on the classifier features and the class prediction. Our main innovation lies in the heatmap definition for an OOD sample, as the normalized difference from the closest in-distribution sample. The heatmap serves as a margin to distinguish between in- and out-of-distribution samples. Our approach generates the heatmaps not only for OOD detection, but also to indicate in- and out-of-distribution regions of the input image. In our evaluations, our approach mostly outperforms the prior work on fixed classifiers, trained on CIFAR-10, CIFAR-100 and Tiny ImageNet. The code is publicly available at: https://github.com/jhornauer/heatmap_ood.
BibTeX
@inproceedings{hornauer2022heatmap,
  author = {Julia Hornauer and Vasileios Belagiannis},
  title = {{Heatmap-based Out-of-Distribution Detection}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2022},
}
Figure