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.

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: input image, float32 [1, 3, 224, 224] (grayscale image repeated on three channels, bilinear resize to 224 Γ— 224, scaled to 0–1, ImageNet mean and std). Outputs probs (14 raw sigmoid probabilities) and cams (class activation maps).
  • platt_params.json: per-class calibration p_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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support