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ainty-estimation
|
| 8 |
+
- out-of-distribution-detection
|
| 9 |
+
- biomedical-imaging
|
| 10 |
+
- digital-pathology
|
| 11 |
+
- histopathology
|
| 12 |
+
- model-calibration
|
| 13 |
+
- reliable-ai
|
| 14 |
+
datasets:
|
| 15 |
+
- acevedo2020
|
| 16 |
+
- jung2022
|
| 17 |
+
- tang2019
|
| 18 |
+
- wong2022
|
| 19 |
+
- kather2016
|
| 20 |
+
- kather2018
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# SNGP Models for Uncertainty-Aware Biomedical Image Classification
|
| 24 |
+
|
| 25 |
+
## Model Details
|
| 26 |
+
|
| 27 |
+
### Model Description
|
| 28 |
+
|
| 29 |
+
This repository contains trained Spectral-normalized Neural Gaussian Process (SNGP) models for uncertainty-aware image classification in biomedical imaging tasks, including white blood cells, amyloid plaques, and colorectal histopathology.
|
| 30 |
+
|
| 31 |
+
SNGP augments standard deep neural networks by applying spectral normalization and replacing the final dense layer with a Gaussian process layer, enabling improved uncertainty estimation and out-of-distribution (OOD) detection with a single forward pass.
|
| 32 |
+
|
| 33 |
+
- **Developed by:** Uma Meleti, Jeffrey J. Nirschl
|
| 34 |
+
- **Affiliation:** University of Wisconsin-Madison
|
| 35 |
+
- **Model type:** Convolutional neural network (ResNet18 backbone) with SNGP head
|
| 36 |
+
- **License:** MIT
|
| 37 |
+
- **Paper:** https://arxiv.org/abs/2602.02370
|
| 38 |
+
- **Repository:** [https://github.com/nirschl-lab/sngp_core]
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## Uses
|
| 43 |
+
|
| 44 |
+
### Direct Use
|
| 45 |
+
- Image classification in biomedical imaging datasets
|
| 46 |
+
- Estimation of predictive uncertainty via entropy/logit-based measures
|
| 47 |
+
- Detection of out-of-distribution (OOD) samples in medical imaging workflows
|
| 48 |
+
|
| 49 |
+
### Downstream Use
|
| 50 |
+
- Integration into clinical decision-support pipelines (research only)
|
| 51 |
+
- Benchmarking uncertainty estimation methods (SNGP vs MC Dropout vs deterministic)
|
| 52 |
+
- Domain shift detection across institutions or datasets
|
| 53 |
+
|
| 54 |
+
### Out-of-Scope Use
|
| 55 |
+
- Clinical diagnosis without expert oversight
|
| 56 |
+
- Deployment in safety-critical settings without validation
|
| 57 |
+
- Use on imaging modalities or domains not represented in training data
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## Bias, Risks, and Limitations
|
| 62 |
+
|
| 63 |
+
### Limitations
|
| 64 |
+
- Performance depends on dataset domain similarity (scanner, staining, preprocessing)
|
| 65 |
+
- OOD detection is not guaranteed to capture all distribution shifts
|
| 66 |
+
- Models trained on limited public datasets; may not generalize to all populations
|
| 67 |
+
|
| 68 |
+
### Risks
|
| 69 |
+
- Misinterpretation of uncertainty estimates as calibrated probabilities
|
| 70 |
+
- False confidence on near-OOD samples
|
| 71 |
+
- Dataset-specific biases (e.g., acquisition site, staining protocols)
|
| 72 |
+
|
| 73 |
+
### Recommendations
|
| 74 |
+
- Always use with human-in-the-loop (e.g., pathologist review)
|
| 75 |
+
- Validate on local institutional data before deployment
|
| 76 |
+
- Use uncertainty thresholds conservatively for rejection
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## How to Get Started with the Model
|
| 81 |
+
Load pretrained SNGP models from the Hugging Face Hub using the provided inference utilities.
|
| 82 |
+
|
| 83 |
+
### Installation
|
| 84 |
+
#### Clone repo and install
|
| 85 |
+
```bash
|
| 86 |
+
# Clone repository
|
| 87 |
+
git clone <repository-url>
|
| 88 |
+
cd sngp_core
|
| 89 |
+
|
| 90 |
+
# Install uv
|
| 91 |
+
curl -Ls https://astral.sh/uv/install.sh | sh
|
| 92 |
+
|
| 93 |
+
# Install dependencies
|
| 94 |
+
uv sync
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
#### Python API
|
| 98 |
+
SNGP Inference with uncertainty quantification
|
| 99 |
+
```python
|
| 100 |
+
import torch
|
| 101 |
+
from scripts.example_inference import quick_sngp_inference
|
| 102 |
+
|
| 103 |
+
# Create input batch [batch_size, channels, height, width]
|
| 104 |
+
batch = torch.randn(4, 3, 224, 224)
|
| 105 |
+
|
| 106 |
+
# Load model from Hugging Face Hub and run inference
|
| 107 |
+
results = quick_sngp_inference(
|
| 108 |
+
"wong_sngp_resnet18",
|
| 109 |
+
batch,
|
| 110 |
+
device="cuda" # or "cpu"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# Outputs:
|
| 114 |
+
# - results["logits"]: Raw model outputs
|
| 115 |
+
# - results["predictions"]: Predicted class indices
|
| 116 |
+
# - results["confidence"]: Prediction confidence scores
|
| 117 |
+
# - results["variance"]: Uncertainty estimates
|
| 118 |
+
# - results["probabilities"]: Class probabilities
|
| 119 |
+
|
| 120 |
+
print(f"Predictions: {results['predictions'].tolist()}")
|
| 121 |
+
print(f"Confidence: {results['confidence'].tolist()}")
|
| 122 |
+
print(f"Uncertainty (variance): {results['variance'].tolist()}")
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
#### Baseline inforerence (deterministic)
|
| 126 |
+
```python
|
| 127 |
+
import torch
|
| 128 |
+
from scripts.example_inference import quick_baseline_inference
|
| 129 |
+
|
| 130 |
+
batch = torch.randn(4, 3, 224, 224)
|
| 131 |
+
|
| 132 |
+
results = quick_baseline_inference(
|
| 133 |
+
"wong_baseline_resnet18",
|
| 134 |
+
batch,
|
| 135 |
+
device="cuda" # or "cpu"
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
print(f"Predictions: {results['predictions'].tolist()}")
|
| 139 |
+
print(f"Confidence: {results['confidence'].tolist()}")
|
| 140 |
+
```
|