Uncertainty-Aware Image Classification In Biomedical Imaging Using Spectral-normalized Neural Gaussian Processes
Paper • 2602.02370 • Published
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.
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.
Load pretrained SNGP models from the Hugging Face Hub using the provided inference utilities.
# Clone repository
git clone https://github.com/nirschl-lab/sngp_core
cd sngp_core
# Install uv
curl -Ls https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync
SNGP Inference with uncertainty quantification
import torch
from scripts.example_inference import quick_sngp_inference
# Create input batch [batch_size, channels, height, width]
batch = torch.randn(4, 3, 224, 224)
# Load model from Hugging Face Hub and run inference
results = quick_sngp_inference(
"wong_sngp_resnet18",
batch,
device="cuda" # or "cpu"
)
# Outputs:
# - results["logits"]: Raw model outputs
# - results["predictions"]: Predicted class indices
# - results["confidence"]: Prediction confidence scores
# - results["variance"]: Uncertainty estimates
# - results["probabilities"]: Class probabilities
print(f"Predictions: {results['predictions'].tolist()}")
print(f"Confidence: {results['confidence'].tolist()}")
print(f"Uncertainty (variance): {results['variance'].tolist()}")
import torch
from scripts.example_inference import quick_baseline_inference
batch = torch.randn(4, 3, 224, 224)
results = quick_baseline_inference(
"wong_baseline_resnet18",
batch,
device="cuda" # or "cpu"
)
print(f"Predictions: {results['predictions'].tolist()}")
print(f"Confidence: {results['confidence'].tolist()}")