Chest X-ray 14 Findings: DenseNet121 with calibrated probabilities (ONNX)
A DenseNet121 (ImageNet-pretrained, fine-tuned) that gives a probability for each of the 14 findings of NIH ChestX-ray14 on a frontal chest X-ray, with class activation maps. Per-class Platt calibration, fitted on the validation set, turns the raw scores into probabilities that match how often each finding occurs.
Research use only. Not a medical device. The outputs are model scores against labels mined from radiology reports. They are not diagnoses and must not be used for patient care.
- Paper: Class Weights Miscalibrate Chest X-ray Classifiers by a Predictable Amount (Zenodo, doi:10.5281/zenodo.23840865)
- Software (code, notebooks, results): doi:10.5281/zenodo.23065563 Β· github.com/MHKhan50/lung-disease-classification
- Live demo (runs in the browser): MHkhan50/chest-xray-14-findings
- Author: Muzammal Hussain (ORCID 0009-0001-2570-5686)
Which checkpoint
Three DenseNet121 seeds were trained. This is seed 2, the one with the highest validation mean AUROC (0.831); it was chosen on validation, not on test.
Results on the official test set (25,596 images, patient-wise split)
| Value | |
|---|---|
| Mean AUROC over 14 findings | 0.803 (95% patient-level bootstrap interval 0.797 to 0.808) |
| Mean ECE, raw β calibrated | 0.261 β 0.011 |
| Mean Brier score, raw β calibrated | 0.174 β 0.058 |
Per-finding AUROC: Atelectasis 0.759, Cardiomegaly 0.874, Effusion 0.822, Infiltration 0.692, Mass 0.807, Nodule 0.745, Pneumonia 0.703, Pneumothorax 0.857, Consolidation 0.733, Edema 0.835, Emphysema 0.918, Fibrosis 0.812, Pleural thickening 0.771, Hernia 0.911.
Files and use
chest_xray_densenet121.onnx: inputimage, float32[1, 3, 224, 224](grayscale image repeated on three channels, bilinear resize to 224 Γ 224, scaled to 0β1, ImageNet mean and std). Outputsprobs(14 raw sigmoid probabilities) andcams(class activation maps).platt_params.json: per-class calibrationp_cal = sigmoid(a Β· logit(p_raw) + b), fitted on the 8,805 validation images.
import json, numpy as np, onnxruntime as ort
from huggingface_hub import hf_hub_download
repo = "MHkhan50/chestxray14-densenet121-calibrated"
session = ort.InferenceSession(hf_hub_download(repo, "chest_xray_densenet121.onnx"))
platt = json.load(open(hf_hub_download(repo, "platt_params.json")))["labels"]
x = np.zeros((1, 3, 224, 224), dtype=np.float32) # preprocessed as described above
probs, cams = session.run(["probs", "cams"], {"image": x})
p = np.clip(probs[0], 1e-6, 1 - 1e-6)
logit = np.log(p / (1 - p))
calibrated = {c["label"]: float(1 / (1 + np.exp(-(c["a"] * z + c["b"])))) for c, z in zip(platt, logit)}
In the browser demo the ONNX model gives the same probabilities as the PyTorch model within 0.2 percentage points on the three example images.
Training data and procedure
NIH ChestX-ray14 (Wang et al., 2017), official patient-wise split: 77,719 training, 8,805 validation and 25,596 test images, no patient in two splits. ImageNet-pretrained DenseNet121, 224 Γ 224 grayscale input, horizontal flips, AdamW (learning rate 1e-4), batch 128, class-weighted binary cross-entropy, early stopping on validation mean AUROC. Kaggle T4 GPU.
Limitations
- Labels were mined from report text by NLP and are sometimes wrong.
- One dataset from one hospital system; no external validation.
- The test set is "sicker" than the validation set (62% against 43% of images with a finding). Pneumothorax ends up under-predicted after calibration (mean 0.065 against a prevalence of 0.104). Any other site would need to recalibrate on its own patients.
- Weakest findings: infiltration (0.692) and pneumonia (0.703).
Citation
@misc{hussain2026chestxray,
author = {Hussain, Muzammal},
title = {{Class Weights Miscalibrate Chest X-ray Classifiers by a Predictable Amount}},
year = {2026},
publisher = {Zenodo},
doi = {10.5281/zenodo.23840865},
url = {https://doi.org/10.5281/zenodo.23840865}
}
Please also cite the dataset: Wang, X., Peng, Y., Lu, L., Lu, Z., Bagheri, M. and Summers, R. M. (2017). ChestX-ray8: Hospital-scale chest X-ray database and benchmarks on weakly-supervised classification and localization of common thorax diseases. CVPR.