Commit ·
7673fac
0
Parent(s):
Initial model upload
Browse files- .gitattributes +1 -0
- LICENSE +25 -0
- README.md +142 -0
- config.json +53 -0
- pytorch_model.safetensors +3 -0
- training_history.png +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
---
|
| 3 |
+
|
| 4 |
+
```text
|
| 5 |
+
MIT License
|
| 6 |
+
|
| 7 |
+
Copyright (c) 2025 OM KUMAR
|
| 8 |
+
|
| 9 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 10 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 11 |
+
in the Software without restriction, including without limitation the rights
|
| 12 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 13 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 14 |
+
furnished to do so, subject to the following conditions:
|
| 15 |
+
|
| 16 |
+
The above copyright notice and this permission notice shall be included in all
|
| 17 |
+
copies or substantial portions of the Software.
|
| 18 |
+
|
| 19 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 20 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 21 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 22 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 23 |
+
LIABILITY, WHETHER IN AN ACTION O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| 3 |
+
tags:
|
| 4 |
+
- vision
|
| 5 |
+
- densenet
|
| 6 |
+
- densenet121
|
| 7 |
+
- chexpert
|
| 8 |
+
- chest-xray
|
| 9 |
+
- multi-label
|
| 10 |
+
- classification
|
| 11 |
+
- safetensors
|
| 12 |
+
- pytorch
|
| 13 |
+
license: mit
|
| 14 |
+
pipeline_tag: image-classification
|
| 15 |
+
author: Om Kumar (@itsomk)
|
| 16 |
+
---
|
| 17 |
+
# DenseNet121 CheXpert Multi-label (chexpert-densenet121-v1)
|
| 18 |
+
|
| 19 |
+
## Model Description
|
| 20 |
+
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.
|
| 21 |
+
It predicts the presence of the following 14 labels (order preserved):
|
| 22 |
+
|
| 23 |
+
- No Finding
|
| 24 |
+
- Enlarged Cardiomediastinum
|
| 25 |
+
- Cardiomegaly
|
| 26 |
+
- Lung Opacity
|
| 27 |
+
- Lung Lesion
|
| 28 |
+
- Edema
|
| 29 |
+
- Consolidation
|
| 30 |
+
- Pneumonia
|
| 31 |
+
- Atelectasis
|
| 32 |
+
- Pneumothorax
|
| 33 |
+
- Pleural Effusion
|
| 34 |
+
- Pleural Other
|
| 35 |
+
- Fracture
|
| 36 |
+
- Support Devices
|
| 37 |
+
|
| 38 |
+
**Author:** Om Kumar (Hugging Face: [@itsomk](https://huggingface.co/itsomk))
|
| 39 |
+
|
| 40 |
+
**Model files included:**
|
| 41 |
+
- `chexpert_pytorch.safetensors` — model weights saved with `safetensors`
|
| 42 |
+
- `config.json` — minimal config (backbone, num_labels, transforms)
|
| 43 |
+
- `training_history.png` — training curves
|
| 44 |
+
|
| 45 |
+
> ⚠️ **Important:** This model is provided **for research and educational purposes only**. Not for clinical use.
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
## Intended Use
|
| 50 |
+
- Research in medical imaging and multi-label classification
|
| 51 |
+
- Educational use and reproducible baseline for further fine-tuning or adaptation
|
| 52 |
+
- NOT intended for clinical diagnosis or patient care. Use with caution; validate thoroughly before any downstream application.
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
## Training Summary
|
| 57 |
+
- **Backbone:** DenseNet-121 (PyTorch `torchvision.models.densenet121`)
|
| 58 |
+
- **Dataset:** CheXpert v1.0 (Stanford)
|
| 59 |
+
- **Uncertainty handling:** U-Zeros (replace -1 with 0)
|
| 60 |
+
- **Image size:** 224 × 224
|
| 61 |
+
- **Epochs:** 20
|
| 62 |
+
- **Batch size:** 32
|
| 63 |
+
- **Optimizer:** Adam (lr=1e-4, weight_decay=1e-4)
|
| 64 |
+
- **Loss:** BCEWithLogitsLoss with per-class pos_weight
|
| 65 |
+
- **Best validation mean AUC:** **0.8176**
|
| 66 |
+
|
| 67 |
+
### Per-class AUC (validation)
|
| 68 |
+
- No Finding : 0.8762
|
| 69 |
+
- Enlarged Cardiomediastinum : 0.5959
|
| 70 |
+
- Cardiomegaly : 0.8165
|
| 71 |
+
- Lung Opacity : 0.8083
|
| 72 |
+
- Lung Lesion : 0.8230
|
| 73 |
+
- Edema : 0.8779
|
| 74 |
+
- Consolidation : 0.8527
|
| 75 |
+
- Pneumonia : 0.7559
|
| 76 |
+
- Atelectasis : 0.7117
|
| 77 |
+
- Pneumothorax : 0.8546
|
| 78 |
+
- Pleural Effusion : 0.9021
|
| 79 |
+
- Pleural Other : 0.9157
|
| 80 |
+
- Fracture : 0.7936
|
| 81 |
+
- Support Devices : 0.8622
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## Quick Usage (local safetensors)
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
|
| 89 |
+
import torch
|
| 90 |
+
from torchvision import models, transforms
|
| 91 |
+
from safetensors.torch import load_file
|
| 92 |
+
from huggingface_hub import hf_hub_download
|
| 93 |
+
from PIL import Image
|
| 94 |
+
|
| 95 |
+
REPO_ID = "itsomk/chexpert-densenet121"
|
| 96 |
+
FILENAME = "pytorch_model.safetensors"
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
local_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class DenseNet121_CheXpert(torch.nn.Module):
|
| 103 |
+
def __init__(self, num_labels=14, pretrained=False):
|
| 104 |
+
super().__init__()
|
| 105 |
+
self.densenet = models.densenet121(pretrained=pretrained)
|
| 106 |
+
num_features = self.densenet.classifier.in_features
|
| 107 |
+
self.densenet.classifier = torch.nn.Linear(num_features, num_labels)
|
| 108 |
+
def forward(self, x):
|
| 109 |
+
return self.densenet(x)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
state = load_file(local_path)
|
| 113 |
+
|
| 114 |
+
model = DenseNet121_CheXpert(num_labels=14, pretrained=False)
|
| 115 |
+
|
| 116 |
+
model.load_state_dict(state, strict=False)
|
| 117 |
+
model.eval()
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
preprocess = transforms.Compose([
|
| 121 |
+
transforms.Resize((224, 224)),
|
| 122 |
+
transforms.ToTensor(),
|
| 123 |
+
transforms.Normalize(mean=[0.485,0.456,0.406], std=[0.229,0.224,0.225])
|
| 124 |
+
])
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
labels = [
|
| 128 |
+
"No Finding","Enlarged Cardiomediastinum","Cardiomegaly","Lung Opacity",
|
| 129 |
+
"Lung Lesion","Edema","Consolidation","Pneumonia","Atelectasis",
|
| 130 |
+
"Pneumothorax","Pleural Effusion","Pleural Other","Fracture","Support Devices"
|
| 131 |
+
]
|
| 132 |
+
|
| 133 |
+
# inference
|
| 134 |
+
img = Image.open("path/to/xray.jpg").convert("RGB")
|
| 135 |
+
x = preprocess(img).unsqueeze(0)
|
| 136 |
+
with torch.no_grad():
|
| 137 |
+
logits = model(x)
|
| 138 |
+
probs = torch.sigmoid(logits).squeeze().tolist()
|
| 139 |
+
|
| 140 |
+
results = {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 141 |
+
print(results)
|
| 142 |
+
|
config.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "densenet",
|
| 3 |
+
"architectures": ["DenseNet121"],
|
| 4 |
+
"num_labels": 14,
|
| 5 |
+
"labels": [
|
| 6 |
+
"No Finding",
|
| 7 |
+
"Enlarged Cardiomediastinum",
|
| 8 |
+
"Cardiomegaly",
|
| 9 |
+
"Lung Opacity",
|
| 10 |
+
"Lung Lesion",
|
| 11 |
+
"Edema",
|
| 12 |
+
"Consolidation",
|
| 13 |
+
"Pneumonia",
|
| 14 |
+
"Atelectasis",
|
| 15 |
+
"Pneumothorax",
|
| 16 |
+
"Pleural Effusion",
|
| 17 |
+
"Pleural Other",
|
| 18 |
+
"Fracture",
|
| 19 |
+
"Support Devices"
|
| 20 |
+
],
|
| 21 |
+
"id2label": {
|
| 22 |
+
"0": "No Finding",
|
| 23 |
+
"1": "Enlarged Cardiomediastinum",
|
| 24 |
+
"2": "Cardiomegaly",
|
| 25 |
+
"3": "Lung Opacity",
|
| 26 |
+
"4": "Lung Lesion",
|
| 27 |
+
"5": "Edema",
|
| 28 |
+
"6": "Consolidation",
|
| 29 |
+
"7": "Pneumonia",
|
| 30 |
+
"8": "Atelectasis",
|
| 31 |
+
"9": "Pneumothorax",
|
| 32 |
+
"10": "Pleural Effusion",
|
| 33 |
+
"11": "Pleural Other",
|
| 34 |
+
"12": "Fracture",
|
| 35 |
+
"13": "Support Devices"
|
| 36 |
+
},
|
| 37 |
+
"label2id": {
|
| 38 |
+
"No Finding": 0,
|
| 39 |
+
"Enlarged Cardiomediastinum": 1,
|
| 40 |
+
"Cardiomegaly": 2,
|
| 41 |
+
"Lung Opacity": 3,
|
| 42 |
+
"Lung Lesion": 4,
|
| 43 |
+
"Edema": 5,
|
| 44 |
+
"Consolidation": 6,
|
| 45 |
+
"Pneumonia": 7,
|
| 46 |
+
"Atelectasis": 8,
|
| 47 |
+
"Pneumothorax": 9,
|
| 48 |
+
"Pleural Effusion": 10,
|
| 49 |
+
"Pleural Other": 11,
|
| 50 |
+
"Fracture": 12,
|
| 51 |
+
"Support Devices": 13
|
| 52 |
+
}
|
| 53 |
+
}
|
pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f6fa96434c2b4822b0e1f6c3ea4f236466788e49749c05fd5c30a83a263450f2
|
| 3 |
+
size 28298128
|
training_history.png
ADDED
|