ShortcutCheck: paediatric pneumonia X-ray classifier (and how it cheats)

A ResNet18 that scores a paediatric chest X-ray for pneumonia vs normal. It reaches 0.991 ROC-AUC (5-seed mean, 624 test images). The project's real finding is what it relies on: greying out only the image border cuts specificity from 0.93 to 0.11–0.36 in every seed, so the model uses information outside the lungs.

⚠️ 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, including the border test: https://huggingface.co/spaces/rigel08/shortcutcheck-pneumonia · Code and results: https://github.com/rigel08/pneumonia-xray-classifier

Files

File What it is
model_fp16.onnx ONNX model, 16-bit weights (22 MB). Input x (batch, 3, 224, 224); outputs logit and layer4 (for Grad-CAM)
model.pt PyTorch checkpoint (16-bit model_state, plus arch, image_size, threshold) for build_model() in the repo
config.json Preprocessing and decision threshold
*.png Two test images (PneumoniaMNIST, CC BY 4.0)
example.py Scores both images, with and without the border greyed out

Use it

pip install onnxruntime huggingface_hub numpy pillow
python example.py
import json, numpy as np, onnxruntime as ort
from PIL import Image
from huggingface_hub import hf_hub_download

repo = "rigel08/shortcutcheck-pneumonia"
cfg = json.load(open(hf_hub_download(repo, "config.json")))
sess = ort.InferenceSession(hf_hub_download(repo, "model_fp16.onnx"))
g = np.asarray(Image.open("xray.png").convert("L").resize((224, 224)), np.float32) / 255
x = np.stack([(g - m) / s for m, s in zip(cfg["imagenet_mean"], cfg["imagenet_std"])])[None].astype(np.float32)
p = 1 / (1 + np.exp(-sess.run(["logit"], {"x": x})[0][0, 0]))
print("pneumonia probability", p, "FLAG" if p >= cfg["threshold"] else "")

Training data

PneumoniaMNIST / Kermany et al. 2018 paediatric chest X-rays (Guangzhou), at 224 × 224. All images come from one hospital.

Limitations

  • Children aged 1–5 from one hospital. On adult X-rays from elsewhere a sister model fell from 0.991 to 0.682 AUC (see SecondSite).
  • The model uses cues outside the lungs, which is the project's point. Don't trust its score without the border test.

Portfolio: https://rigel08.github.io/portfolio-site/ · GitHub: https://github.com/rigel08 · All my models and demos: https://huggingface.co/rigel08

Downloads last month
17
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Space using rigel08/shortcutcheck-pneumonia 1