NCDD: Nearest Centroid Distance Deficit for Out-Of-Distribution Detection in Gastrointestinal Vision

Sandesh Pokhrel, Sanjay Bhandari, Sharib Ali, Tryphon Lambrou, Anh Nguyen, Yash Raj Shrestha, Angus Watson, Danail Stoyanov, Prashnna K. Gyawali, Binod BhattaraiarXiv 2024 · DOI · arXiv

Introduction

Deep learning models are increasingly deployed in gastrointestinal (GI) endoscopy to identify anatomical landmarks like the pylorus or cecum. However, these models often suffer from a "reliability gap": they tend to be overconfident when encountering out-of-distribution (OOD) images, such as rare diseases or novel pathologies not seen during training. In clinical settings, misidentifying a rare tumor as a healthy landmark is a critical failure.

This challenge is exacerbated by the visual similarity between healthy landmarks and certain pathologies in the latent feature space. Unlike natural images where classes are distinct (e.g., cats vs. tractors), a "healthy Z-line" and "esophagitis" may appear very similar, creating "near-OOD" cases where standard confidence-based detection methods fail.

The NCDD Method

To address this, we introduce Nearest Centroid Distance Deficit (NCDD), a post-hoc distance-based OOD detection framework. NCDD operates on pre-trained classifiers without requiring retraining, making it highly versatile.

Overview of the proposed OOD detection pipeline using the NCDD score.

The method follows a three-step process:

  1. Centroid Estimation: Calculate the mean feature vector (centroid) for each In-Distribution (ID) class using the training set.
  2. Distance Calculation: For a test image, extract its feature vector $z$ and determine the Euclidean distance to the nearest centroid ($D_{\mu n}$) and the sum of distances to all other centroids ($D_{\mu m}$).
  3. Scoring: The NCDD score is defined as $NCDD = \alpha \cdot D_{\mu m} - \beta \cdot D_{\mu n}$.

The weights $\alpha$ and $\beta$ are dynamically scaled by the logarithm of the L1-norm of the feature vector, enhancing sensitivity to feature magnitude and helping distinguish subtle anomalies.

The Equidistance Hypothesis

The core intuition behind NCDD is that OOD samples in GI vision lack the "clustering effect" seen in ID data. While an ID sample is "pulled" toward its specific class centroid during training, an OOD sample remains relatively equidistant or scattered across the embedding space.

Visualization of the embedding space showing the distance relationships between ID and OOD samples.

By leveraging information from both the nearest and non-nearest centroids, NCDD captures the "deficit" in clustering that characterizes OOD samples. ID samples typically have a large deficit (close to one, far from others), whereas OOD samples have a lower score due to their neutral positioning relative to all centroids.

Experimental Evaluation

The method was evaluated on two primary benchmarks:

  • Kvasirv2: 8,000 images with healthy landmarks as ID and pathologies (Polyps, Ulcerative Colitis, Esophagitis) as OOD.
  • Gastrovision: A complex dataset with 27 categories, using 11 normal classes as ID and 16 pathological/intervention classes as OOD.

NCDD consistently outperformed state-of-the-art (SOTA) methods like MSP, ODIN, and Energy-based scores across various architectures, including ResNet-18, ViT, and MLP-Mixer. On the Gastrovision dataset with a ResNet-18 backbone, NCDD achieved an AUC of 79.1%, surpassing ODIN (74.12%). Furthermore, it significantly reduced the False Positive Rate (FPR95); for instance, using a ViT model on Kvasirv2, NCDD reached an FPR95 of 22.94%, compared to 38.44% for KNN-OOD.

Conclusion and Future Work

NCDD provides a robust, architecture-agnostic solution for identifying unknown pathologies in GI vision. While the method currently relies on hyperparameters tuned via synthetic OOD data, future work will focus on refining these parameters for clinical environments. Integrating NCDD into "human-in-the-loop" systems could allow AI to flag uncertain cases for immediate specialist review during live endoscopies, bridging the reliability gap in medical AI.

Summary updated

Abstract

The integration of deep learning tools in gastrointestinal vision holds the potential for significant advancements in diagnosis, treatment, and overall patient care. A major challenge, however, is these tools' tendency to make overconfident predictions, even when encountering unseen or newly emerging disease patterns, undermining their reliability. We address this critical issue of reliability by framing it as an out-of-distribution (OOD) detection problem, where previously unseen and emerging diseases are identified as OOD examples. However, gastrointestinal images pose a unique challenge due to the overlapping feature representations between in- Distribution (ID) and OOD examples. Existing approaches often overlook this characteristic, as they are primarily developed for natural image datasets, where feature distinctions are more apparent. Despite the overlap, we hypothesize that the features of an in-distribution example will cluster closer to the centroids of their ground truth class, resulting in a shorter distance to the nearest centroid. In contrast, OOD examples maintain an equal distance from all class centroids. Based on this observation, we propose a novel nearest-centroid distance deficit (NCCD) score in the feature space for gastrointestinal OOD detection. Evaluations across multiple deep learning architectures and two publicly available benchmarks, Kvasir2 and Gastrovision, demonstrate the effectiveness of our approach compared to several state-of-the-art methods. The code and implementation details are publicly available at: https://github.com/bhattarailab/NCDD
BibTeX
@misc{pokhrel2024ncdd,
  author = {Sandesh Pokhrel and Sanjay Bhandari and Sharib Ali and Tryphon Lambrou and Anh Nguyen and Yash Raj Shrestha and Angus Watson and Danail Stoyanov and Prashnna K. Gyawali and Binod Bhattarai},
  title = {{NCDD: Nearest Centroid Distance Deficit for Out-Of-Distribution Detection in Gastrointestinal Vision}},
  year = {2024},
  eprint = {2412.01590},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.01590},
}
Figure