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.
The method follows a three-step process:
- Centroid Estimation: Calculate the mean feature vector (centroid) for each In-Distribution (ID) class using the training set.
- 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}$).
- 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.
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