--- license: cc-by-4.0 library_name: onnx pipeline_tag: image-classification tags: [chest-x-ray, pneumonia, uncertainty, deep-ensembles, out-of-distribution, dataset-shift, model-safety, healthcare, medical-ai, pytorch, onnx] metrics: [roc_auc] --- # SecondSite: a 5-model X-ray ensemble with uncertainty, shift detection and referral A **deep ensemble of 5 ResNet18s** for paediatric pneumonia, packaged with the safety layer it was audited with: - ensemble **uncertainty** (entropy) - a **Mahalanobis shift detector** on the image features - a **refer-to-a-human** rule The audit asked: when this model moves to X-rays from another hospital, do the safeguards notice? > ⚠️ **Research model, not a medical device.** Trained and tested on public retrospective data only. Do not use it for diagnosis or treatment decisions. ▶ **Try it in your browser:** https://huggingface.co/spaces/rigel08/secondsite-xray-audit · **Code, pre-registered experiments and results:** https://github.com/rigel08/xray-safety-audit ## What the audit found - **Home hospital** (paediatric, Guangzhou): AUC 0.991. On **NIH X-rays (mostly adults)** it falls to **0.682**, and calibration error rises from 0.046 to 0.267. - Error-detection AUROC of the uncertainty signal falls from 0.824 to 0.561 under shift. - A **brightness-only** control nearly matched the shift detector (0.936 vs 0.944), so the detector mostly notices *different-looking* images. ## Files | File | What it is | |---|---| | `ensemble5_int8.onnx` | All 5 members in one graph, 8-bit (56 MB). Input `x` (batch, 3, 128, 128); outputs `member_logits` (batch, 5, 2), `features` (batch, 512) and `fmaps` | | `config.json` | Decision threshold (log-odds), temperature, entropy referral cut-off, shift cut-off, Grad-CAM weights | | `shift.f32` | Shift detector: 2 class means (512-d) and the shared precision matrix (512 × 512), float32 | | `pytorch/member_0..4.pt` | Full-precision PyTorch members for `XrayNet` / `load_model()` in the repo | | `example.py` | Runs one X-ray through the whole safety pipeline | 8-bit compression shifts probabilities by up to 0.022, but every flag and referral matched full precision in the parity test. Use the PyTorch members for exact numbers. ## Use it ```bash pip install onnxruntime huggingface_hub numpy pillow python example.py ``` ## Training data Kermany et al. 2018 paediatric chest X-rays (CC BY 4.0), 128 × 128, with 5 seeds fixed in advance. **Portfolio:** https://rigel08.github.io/portfolio-site/ · **GitHub:** https://github.com/rigel08 · **All my models and demos:** https://huggingface.co/rigel08