H2ST: Hierarchical Two-Sample Tests for Continual Out-of-Distribution Detection

Yuhang Liu, Wenjie Zhao, Yunhui Guo

Introduction

In the evolving field of Task Incremental Learning (TIL), models are typically evaluated in "closed-world" environments where they only encounter data from previously learned tasks. However, real-world applications, such as autonomous driving or robotics, operate in an "open-world." In these scenarios, a model must not only classify known tasks but also identify Out-of-Distribution (OOD) samples—data that does not belong to any previously seen category.

Existing OOD detection methods struggle with three primary challenges in continual learning: threshold sensitivity, where manually tuning a score-based threshold is impractical in non-stationary streams; model dependence, where poor classification performance degrades OOD detection; and a lack of task identity, as standard methods often fail to specify which learned task an in-distribution (ID) sample belongs to.

The H2ST Framework

To address these hurdles, we introduce H2ST (Hierarchical Two-Sample Tests). This framework shifts OOD detection from simple score-based thresholding to a robust statistical hypothesis testing paradigm.

The H2ST framework uses a cascaded hierarchy of two-sample tests to identify task-id and detect OOD samples.

Hierarchical Architecture and Early-Exit

Instead of a monolithic classifier, H2ST employs a cascade of task-specific binary classifiers. As a new sample enters the system, it traverses this hierarchy. If a classifier identifies the sample as belonging to its specific task, the process triggers an early-exit, and the sample is passed to that task's inference head. If the sample passes through all $T$ layers without being matched, it is definitively labeled as OOD. This hierarchical approach significantly improves efficiency; on average, a sample only requires $(T+1)/2$ tests.

Feature-Level Statistical Testing

H2ST performs tests on intermediate feature maps rather than final logits. High-level semantic representations are often more stable than classification layers, making the system more resilient to "catastrophic forgetting." For each task, a small binary classifier—the Classifier Two-Sample Test (C2ST)—is trained to distinguish between "source" samples (from a memory buffer) and new incoming data. Decisions are made using the Clopper-Pearson (CP) interval, providing a statistically grounded, threshold-free deployment.

Experimental Evaluation

We evaluated H2ST across diverse benchmarks, including MNIST, SVHN, CIFAR-10, CIFAR-100, and real-world datasets like CoRe50 and Stream-51. The experiments utilized a "6k-2k-2k" configuration, simulating an open-world stream where incremental task learning is interspersed with OOD detection rounds.

Performance and Efficiency

H2ST demonstrates a significant performance leap over traditional baselines such as Maximum Softmax Probability (MSP), Energy-based models, and ODIN.

H2ST consistently outperforms existing OOD methods in both F1 score and Task Accuracy (TA) across various datasets.

As shown in the results, H2ST achieves an average F1 score of approximately 92% on CIFAR-10, nearly 30 percentage points higher than the next best method (MORE). Crucially, H2ST provides a massive boost in Task Accuracy (TA)—the ability to correctly identify the task-id of an ID sample—reaching ~90% where others hover around 20%.

Beyond accuracy, H2ST is computationally efficient. In a 9-task setup, it processed inputs in 16.7ms, compared to 22.0ms for a non-hierarchical C2ST approach, validating the benefits of the early-exit strategy.

Conclusion

H2ST offers a robust, threshold-free solution for open-world continual learning. By decoupling OOD detection from classification performance and utilizing a hierarchical statistical testing structure, it provides superior detection and task identification. While the method currently relies on a memory buffer for source samples, its compatibility with standard continual learning strategies like Experience Replay (ER) makes it a versatile tool for real-world deployment. Future work will focus on further reducing the overhead of online binary classifier updates and optimizing the task order within the hierarchy.

Summary updated

BibTeX
@inproceedings{liu2025h,
  author = {Yuhang Liu and Wenjie Zhao and Yunhui Guo},
  title = {{H2ST: Hierarchical Two-Sample Tests for Continual Out-of-Distribution Detection}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2025},
  doi = {10.1109/cvpr52734.2025.01436},
}
Figure