A DenseNet-121 model fine-tuned to detect 14 thoracic abnormalities from frontal-view chest X-rays, trained on the NIH ChestX-ray14 dataset.
⚠️ Not a clinical or diagnostic tool. This model was built for research/educational purposes, trained on NLP-derived (not radiologist-adjudicated) labels, and has not been validated for any clinical use. Do not use it to inform real medical decisions.
Code, training notebook, and full writeup: GitHub repo
torchvision.models.densenet121), with the original classifier replaced by a single linear layer outputting 14 independent sigmoid logits (multi-label, not multi-class).Atelectasis, Cardiomegaly, Consolidation, Edema, Effusion, Emphysema, Fibrosis, Hernia, Infiltration, Mass, Nodule, Pleural_Thickening, Pneumonia, Pneumothorax
Each label is an independent binary prediction — an image can be positive for multiple findings at once.
Intended for: research, education, and as a reference implementation for multi-label medical image classification (transfer learning, class-imbalance handling, multi-GPU training).
Not intended for: clinical diagnosis, triage, or any use where a real patient's care would be affected by the model's output.
NIH ChestX-ray14 — 112,120 frontal-view chest X-rays from 30,805 patients, with labels extracted via NLP from radiology reports (not individually verified by radiologists per image — a known limitation of this dataset).
lr=1e-3).lr=1e-5, classifier head lr=1e-4), AdamW optimizer (weight_decay=1e-4), early stopping on validation Macro AUROC (patience = 5).pos_weight (handles class imbalance) with focal modulation (γ=2.0, focuses gradient on hard examples).torch.amp), multi-GPU (DataParallel, 2× T4).Full training code: GitHub repo
Evaluated once on the held-out NIH test set. Precision/Recall/F1 use per-class thresholds tuned to maximize F1 on the validation set (not the test set), applied unchanged at test time.
| Class | AUROC | Precision | Recall | F1 | AUPRC | Prevalence |
|---|---|---|---|---|---|---|
| Atelectasis | 0.7357 | 0.2527 | 0.5965 | 0.3550 | 0.2936 | 0.1281 |
| Cardiomegaly | 0.8626 | 0.3303 | 0.4060 | 0.3642 | 0.2950 | 0.0418 |
| Consolidation | 0.7048 | 0.1314 | 0.5383 | 0.2113 | 0.1340 | 0.0709 |
| Edema | 0.8277 | 0.1540 | 0.4151 | 0.2246 | 0.1445 | 0.0361 |
| Effusion | 0.7949 | 0.3706 | 0.7005 | 0.4848 | 0.4469 | 0.1820 |
| Emphysema | 0.8604 | 0.2974 | 0.4465 | 0.3570 | 0.2877 | 0.0427 |
| Fibrosis | 0.7779 | 0.0906 | 0.1149 | 0.1013 | 0.0636 | 0.0170 |
| Hernia | 0.8907 | 0.7500 | 0.1744 | 0.2830 | 0.2950 | 0.0034 |
| Infiltration | 0.6795 | 0.3044 | 0.8084 | 0.4423 | 0.3736 | 0.2388 |
| Mass | 0.7469 | 0.2223 | 0.3484 | 0.2715 | 0.2069 | 0.0683 |
| Nodule | 0.7081 | 0.2188 | 0.2502 | 0.2334 | 0.1813 | 0.0634 |
| Pleural_Thickening | 0.7336 | 0.1207 | 0.3963 | 0.1850 | 0.1105 | 0.0447 |
| Pneumonia | 0.6703 | 0.0603 | 0.0937 | 0.0734 | 0.0416 | 0.0217 |
| Pneumothorax | 0.8321 | 0.4035 | 0.4473 | 0.4243 | 0.3663 | 0.1041 |
| Macro | 0.7732 | 0.2648 | 0.4098 | 0.2865 | 0.2315 | — |
Macro AUROC: 0.7732 · Macro AUPRC: 0.2315 · Macro F1: 0.2865
AUPRC is low relative to AUROC for rare findings (e.g. Hernia, Pneumonia) because AUPRC's baseline for a random classifier equals class prevalence — not a sign of a broken model, just an expected property of imbalanced multi-label evaluation. Full results, including a fixed-0.5-threshold comparison, are in the GitHub repo.
from huggingface_hub import hf_hub_download
import torch
from torchvision.models import densenet121
from torch import nn
# Download the checkpoint
checkpoint_path = hf_hub_download(
repo_id="AbdelMoety1/nih-chest-xray-densenet121",
filename="NIH Chest X-Ray model.pt"
)
checkpoint = torch.load(checkpoint_path, map_location="cpu")
# Rebuild the architecture and load weights
LABELS = [
"Atelectasis", "Cardiomegaly", "Consolidation", "Edema", "Effusion",
"Emphysema", "Fibrosis", "Hernia", "Infiltration", "Mass", "Nodule",
"Pleural_Thickening", "Pneumonia", "Pneumothorax"
]
model = densenet121(weights=None)
model.classifier = nn.Linear(model.classifier.in_features, len(LABELS))
model.load_state_dict(checkpoint["model_state_dict"])
model.eval()
# Inference (expects a 224x224 ImageNet-normalized tensor, batch dim included)
with torch.no_grad():
logits = model(image_tensor)
probs = torch.sigmoid(logits) # one probability per label in LABELS
Preprocessing (resize, normalization) and the full evaluation pipeline are in the linked GitHub repo.
DataParallel (not DistributedDataParallel) was used for training; no test-time augmentation or ensembling was applied.Please cite the original dataset if you use this model:
Wang X, Peng Y, Lu L, Lu Z, Bagheri M, Summers RM. ChestX-ray8: Hospital-scale Chest
X-ray Database and Benchmarks on Weakly-Supervised Classification and Localization of
Common Thorax Diseases. CVPR 2017.
MIT — see LICENSE in the GitHub repo. This license covers the code and model weights only; the NIH ChestX-ray14 dataset has its own usage terms.