Out-of-Distribution Detection in Gastrointestinal Vision by Estimating Nearest Centroid Distance Deficit

Sandesh Pokhrel, Sanjay Bhandari, Sharib Ali, Tryphon Lambrou, Anh Nguyen, Yash Raj Shrestha, Angus Watson, Danail Stoyanov, Prashnna K. Gyawali, Binod BhattaraiMIUA 2025

TL;DR

This paper introduces NCDD, a novel method for Out-of-Distribution (OOD) detection in gastrointestinal (GI) imaging. By analyzing how well image features cluster around known disease categories, NCDD effectively flags unseen or rare abnormalities, enhancing the reliability of AI in medical diagnostics. This approach is crucial for building trustworthy AI systems that can assist clinicians in identifying potentially life-threatening conditions.

What Problem Does This Paper Address?

Deep learning models have shown immense promise in analyzing gastrointestinal (GI) images for diagnosis and treatment. However, a significant challenge is their tendency to make overconfident predictions, even when encountering novel or rare disease patterns they haven't been explicitly trained on. This "out-of-distribution" (OOD) problem undermines their reliability in real-world clinical settings. Existing OOD detection methods, often developed for natural images, struggle with GI images due to overlapping feature representations between normal (in-distribution, ID) and abnormal (OOD) cases. This makes it difficult for AI to distinguish between subtle variations of known conditions and entirely new pathologies, posing a risk to patient care.

Methods

The core of this paper is the Nearest Centroid Distance Deficit (NCDD) score. The authors hypothesize that features from in-distribution (ID) examples will cluster tightly around their respective class centroids, while out-of-distribution (OOD) examples will be more scattered and equidistant from all centroids.

Here's how NCDD works:

  1. Feature Extraction: A standard deep learning model (e.g., ResNet, ViT) is trained on a classification task using only normal GI anatomical landmarks (ID classes). The penultimate layer's feature representations are extracted.
  2. Centroid Estimation: For each ID class, a centroid is calculated by averaging the feature vectors of all training samples belonging to that class.
  3. Distance Calculation: For a given test image, its feature vector is extracted. The Euclidean distance to each class centroid is computed.
  4. Nearest Centroid Distance ($D_{\mu\eta}$): The shortest distance from the test sample's feature vector to any of the ID class centroids.
  5. Non-Nearest Centroid Distance ($D_{\mu m}$): The sum of distances from the test sample's feature vector to all other (non-nearest) ID class centroids.
  6. NCDD Score: A novel score is calculated as: $NCDD = \alpha \cdot D_{\mu m} - \beta \cdot D_{\mu \eta}$. The parameters $\alpha$ and $\beta$ are dynamically determined using the L1-norm of the feature vector, inspired by prior work on OOD detection. This score aims to capture the "deficit" in distance to the nearest centroid relative to the distances to other centroids.
  7. OOD Decision: If the NCDD score falls below a learned threshold, the image is classified as OOD; otherwise, it's classified as ID.

This method is post-hoc, meaning it can be applied to any pre-trained classification model without retraining.

Datasets

The authors evaluated their NCDD method on two publicly available gastrointestinal endoscopy datasets:

  • Kvasirv2 [18]: Contains 8 categories, including normal anatomical landmarks (Z-line, Pylorus, Cecum) and various pathological findings (Esophagitis, Polyps, Ulcerative Colitis, etc.). The normal landmarks were designated as ID classes, and the pathologies as OOD.
  • Gastrovision [38]: A larger dataset with 27 categories, including normal findings, anatomical landmarks (11 classes), and pathological findings/therapeutic interventions (16 classes). Similar to Kvasirv2, normal findings and landmarks were used as ID classes, and the rest as OOD.

They also generated synthetic validation OOD data for hyperparameter tuning.

Key Insights and Ideas

  • GI Images are Tricky for OOD: Unlike natural images where OOD examples often look distinctly "out of place," GI abnormalities can sometimes share feature similarities with normal anatomy, making them "near-OOD" cases. This necessitates a more nuanced approach than simply looking at the closest cluster.
  • Centroid Distance is Key, But Not Enough: While ID samples tend to be closer to their class centroids, relying solely on this distance can be insufficient for near-OOD cases. The NCDD score's innovation lies in considering both the distance to the nearest centroid and the sum of distances to non-nearest centroids.
  • "Deficit" Captures Nuance: The NCDD score's formulation ($ \alpha \cdot D_{\mu m} - \beta \cdot D_{\mu \eta}$) is designed to penalize samples that are far from all centroids, which is characteristic of OOD data, while also accounting for how close they are to the "expected" ID clusters.
  • Model-Agnostic and Post-Hoc: The fact that NCDD can be applied to any pre-trained classification model makes it highly practical and adaptable for existing AI systems in medical imaging.

Key Results

The NCDD method demonstrated superior performance compared to several state-of-the-art OOD detection methods (MSP, ODIN, Energy, Entropy, MaxLogit, KNN, Neco, FDBD) across both Kvasirv2 and Gastrovision datasets.

  • AUC and FPR95: NCDD consistently achieved high AUC (Area Under the Curve) and low FPR95 (False Positive Rate at 95% True Positive Rate) scores across various backbone architectures (ResNet-18, ViT, DeiT, MLP-Mixer). For example, on the Kvasirv2 dataset with ResNet-18, NCDD achieved an AUC of 85.68% and an FPR95 of 30.86%, outperforming most other methods.
  • Qualitative Improvements: Visualizations showed that NCDD was more effective at correctly identifying challenging OOD examples (like Polyps) that other methods often misclassified as ID. It also showed improved distinction for classes with significant feature overlap with ID classes (e.g., Esophagitis vs. Normal Z-line).

Limitations and Future Work

  • Hyperparameter Tuning: The $\alpha$ and $\beta$ parameters in the NCDD score are hyperparameters that require tuning, though the authors provide a method for this.
  • Reliance on Classification Model: The performance of NCDD is dependent on the quality of the feature representations learned by the underlying classification model.
  • Future Work: The authors suggest that their method shows tremendous potential for flagging abnormalities in endoscopy images, an area that has been relatively unexplored for OOD detection. They highlight its ease of integration and its ability to support expert intervention, making it a promising step towards more trustworthy AI in medical diagnostics. The potential for integrating NCDD into fully autonomous AI systems is also an avenue for future research.

Summary updated

BibTeX
@inproceedings{pokhrel2025out,
  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 = {{Out-of-Distribution Detection in Gastrointestinal Vision by Estimating Nearest Centroid Distance Deficit}},
  booktitle = {MIUA},
  year = {2025},
  doi = {10.1007/978-3-031-98691-8\_14},
}
Figure