DenseNet121 CheXpert Multi-label (chexpert-densenet121-v1)
Model Description
This model is a fine-tuned DenseNet-121 (PyTorch) for multi-label classification of chest X-rays, trained on the Stanford CheXpert v1.0 dataset.
It predicts the presence of the following 14 labels (order preserved):
- No Finding
- Enlarged Cardiomediastinum
- Cardiomegaly
- Lung Opacity
- Lung Lesion
- Edema
- Consolidation
- Pneumonia
- Atelectasis
- Pneumothorax
- Pleural Effusion
- Pleural Other
- Fracture
- Support Devices
Author: Om Kumar (Hugging Face: @itsomk)
Model files included:
chexpert_pytorch.safetensors
โ model weights saved withsafetensors
config.json
โ minimal config (backbone, num_labels, transforms)training_history.png
โ training curves
โ ๏ธ Important: This model is provided for research and educational purposes only. Not for clinical use.
Intended Use
- Research in medical imaging and multi-label classification
- Educational use and reproducible baseline for further fine-tuning or adaptation
- NOT intended for clinical diagnosis or patient care. Use with caution; validate thoroughly before any downstream application.
Training Summary
- Backbone: DenseNet-121 (PyTorch
torchvision.models.densenet121
) - Dataset: CheXpert v1.0 (Stanford)
- Uncertainty handling: U-Zeros (replace -1 with 0)
- Image size: 224 ร 224
- Epochs: 20
- Batch size: 32
- Optimizer: Adam (lr=1e-4, weight_decay=1e-4)
- Loss: BCEWithLogitsLoss with per-class pos_weight
- Best validation mean AUC: 0.8176
Per-class AUC (validation)
- No Finding : 0.8762
- Enlarged Cardiomediastinum : 0.5959
- Cardiomegaly : 0.8165
- Lung Opacity : 0.8083
- Lung Lesion : 0.8230
- Edema : 0.8779
- Consolidation : 0.8527
- Pneumonia : 0.7559
- Atelectasis : 0.7117
- Pneumothorax : 0.8546
- Pleural Effusion : 0.9021
- Pleural Other : 0.9157
- Fracture : 0.7936
- Support Devices : 0.8622
Quick Usage (local safetensors)
import torch
from torchvision import models, transforms
from safetensors.torch import load_file
from huggingface_hub import hf_hub_download
from PIL import Image
REPO_ID = "itsomk/chexpert-densenet121"
FILENAME = "pytorch_model.safetensors"
local_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
class DenseNet121_CheXpert(torch.nn.Module):
def __init__(self, num_labels=14, pretrained=False):
super().__init__()
self.densenet = models.densenet121(pretrained=pretrained)
num_features = self.densenet.classifier.in_features
self.densenet.classifier = torch.nn.Linear(num_features, num_labels)
def forward(self, x):
return self.densenet(x)
state = load_file(local_path)
model = DenseNet121_CheXpert(num_labels=14, pretrained=False)
model.load_state_dict(state, strict=False)
model.eval()
preprocess = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485,0.456,0.406], std=[0.229,0.224,0.225])
])
labels = [
"No Finding","Enlarged Cardiomediastinum","Cardiomegaly","Lung Opacity",
"Lung Lesion","Edema","Consolidation","Pneumonia","Atelectasis",
"Pneumothorax","Pleural Effusion","Pleural Other","Fracture","Support Devices"
]
# inference
img = Image.open("path/to/xray.jpg").convert("RGB")
x = preprocess(img).unsqueeze(0)
with torch.no_grad():
logits = model(x)
probs = torch.sigmoid(logits).squeeze().tolist()
results = {labels[i]: float(probs[i]) for i in range(len(labels))}
print(results)
- Downloads last month
- 15