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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
- healthcare-ai
|
| 18 |
- computer-vision
|
| 19 |
- image-classification
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# Multi-Label Chest X-Ray Classifier
|
| 23 |
+
|
| 24 |
+
**ResNet-50 | PyTorch | NIH ChestX-ray14 | Grad-CAM**
|
| 25 |
+
|
| 26 |
+
An end-to-end medical computer vision project using an ImageNet-pretrained ResNet-50 to classify 14 thoracic conditions from chest X-ray images. The model was trained on the NIH ChestX-ray14 dataset with patient-level data splitting, class-weighted binary cross-entropy, and experiment tracking through Weights & Biases.
|
| 27 |
+
|
| 28 |
+
**Held-Out Test Mean ROC-AUC: 0.823**
|
| 29 |
+
|
| 30 |
+
[Live Interactive Demo](https://huggingface.co/spaces/Samer17/chest-xray-classifier-demo) | [GitHub Repository](https://github.com/Samer-4/COGS-181-DL-Final-Project) | [Training Experiment](https://wandb.ai/sam-ahmed1703-uc-san-diego/chest-xray-classification/runs/68h5gmia)
|
| 31 |
+
|
| 32 |
+
## Model Overview
|
| 33 |
+
|
| 34 |
+
| Property | Description |
|
| 35 |
+
|---|---|
|
| 36 |
+
| Architecture | ResNet-50 with custom classification head |
|
| 37 |
+
| Framework | PyTorch |
|
| 38 |
+
| Initialization | ImageNet-pretrained weights |
|
| 39 |
+
| Task | Multi-label image classification |
|
| 40 |
+
| Dataset | NIH ChestX-ray14 |
|
| 41 |
+
| Dataset Size | 112,120 images from 30,805 patients |
|
| 42 |
+
| Output Classes | 14 thoracic conditions |
|
| 43 |
+
| Input Resolution | 224 × 224 |
|
| 44 |
+
| Loss Function | Class-weighted BCEWithLogitsLoss |
|
| 45 |
+
| Optimizer | Adam |
|
| 46 |
+
| Training Hardware | NVIDIA Tesla T4 |
|
| 47 |
+
| Test Mean ROC-AUC | **0.823** |
|
| 48 |
+
| Model Selection | Best validation ROC-AUC, epoch 7 |
|
| 49 |
+
|
| 50 |
+
## Supported Conditions
|
| 51 |
+
|
| 52 |
+
The model generates independent prediction scores for 14 thoracic conditions:
|
| 53 |
+
|
| 54 |
+
1. Atelectasis
|
| 55 |
+
2. Cardiomegaly
|
| 56 |
+
3. Effusion
|
| 57 |
+
4. Infiltration
|
| 58 |
+
5. Mass
|
| 59 |
+
6. Nodule
|
| 60 |
+
7. Pneumonia
|
| 61 |
+
8. Pneumothorax
|
| 62 |
+
9. Consolidation
|
| 63 |
+
10. Edema
|
| 64 |
+
11. Emphysema
|
| 65 |
+
12. Fibrosis
|
| 66 |
+
13. Pleural Thickening
|
| 67 |
+
14. Hernia
|
| 68 |
+
|
| 69 |
+
Because this is a multi-label classification task, multiple conditions may be associated with the same X-ray.
|
| 70 |
+
|
| 71 |
+
The model produces 14 logits, converted into scores using the sigmoid function. These scores are not clinically calibrated probabilities.
|
| 72 |
+
|
| 73 |
+
## Model Architecture
|
| 74 |
+
|
| 75 |
+
The classifier uses an ImageNet-pretrained ResNet-50 backbone with a custom classification head.
|
| 76 |
+
|
| 77 |
+
```text
|
| 78 |
+
Chest X-Ray (224 × 224 × 3)
|
| 79 |
+
|
|
| 80 |
+
ResNet-50 Backbone
|
| 81 |
+
|
|
| 82 |
+
2048-D Feature Vector
|
| 83 |
+
|
|
| 84 |
+
Linear(2048, 512)
|
| 85 |
+
|
|
| 86 |
+
ReLU
|
| 87 |
+
|
|
| 88 |
+
Dropout(0.3)
|
| 89 |
+
|
|
| 90 |
+
Linear(512, 14)
|
| 91 |
+
|
|
| 92 |
+
14 Output Logits
|
| 93 |
+
|
|
| 94 |
+
Sigmoid (Inference)
|
| 95 |
+
|
|
| 96 |
+
14 Prediction Scores
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
The model is implemented in PyTorch using the custom `ChestXRayNet` class.
|
| 100 |
+
|
| 101 |
+
## Dataset and Preprocessing
|
| 102 |
+
|
| 103 |
+
The model was trained on the NIH ChestX-ray14 dataset, containing 112,120 frontal chest X-ray images from 30,805 patients.
|
| 104 |
+
|
| 105 |
+
Preprocessing includes:
|
| 106 |
+
|
| 107 |
+
- RGB image conversion
|
| 108 |
+
- Resizing to 224 × 224 pixels
|
| 109 |
+
- ImageNet mean and standard deviation normalization
|
| 110 |
+
- Training-time horizontal flipping, brightness/contrast adjustments, and geometric augmentation
|
| 111 |
+
|
| 112 |
+
### Patient-Level Data Splitting
|
| 113 |
+
|
| 114 |
+
To prevent patient-level data leakage, the dataset was split by patient identifier rather than by individual image.
|
| 115 |
+
|
| 116 |
+
| Split | Images | Patients |
|
| 117 |
+
|---|---:|---:|
|
| 118 |
+
| Training | 78,566 | 21,563 |
|
| 119 |
+
| Validation | 17,063 | 4,621 |
|
| 120 |
+
| Test | 16,491 | 4,621 |
|
| 121 |
+
| **Total** | **112,120** | **30,805** |
|
| 122 |
+
|
| 123 |
+
The split uses a 70/15/15 patient-level allocation with random seed 42 and zero patient overlap across partitions.
|
| 124 |
+
|
| 125 |
+
Images labeled `No Finding` were retained as negative examples for all 14 conditions.
|
| 126 |
+
|
| 127 |
+
## Training Methodology
|
| 128 |
+
|
| 129 |
+
Training was performed on Kaggle using an NVIDIA Tesla T4 GPU.
|
| 130 |
+
|
| 131 |
+
| Hyperparameter | Value |
|
| 132 |
+
|---|---|
|
| 133 |
+
| Epochs | 10 |
|
| 134 |
+
| Batch Size | 32 |
|
| 135 |
+
| Learning Rate | 0.0001 |
|
| 136 |
+
| Optimizer | Adam |
|
| 137 |
+
| Loss | Weighted BCEWithLogitsLoss |
|
| 138 |
+
| Input Size | 224 × 224 |
|
| 139 |
+
| Dropout | 0.3 |
|
| 140 |
+
| Checkpoint Selection | Highest validation mean ROC-AUC |
|
| 141 |
+
|
| 142 |
+
### Class Imbalance Handling
|
| 143 |
+
|
| 144 |
+
The NIH ChestX-ray14 dataset contains substantial label imbalance, particularly for rare conditions such as Hernia and Pneumonia.
|
| 145 |
+
|
| 146 |
+
To address this, positive class weights were calculated from the training set:
|
| 147 |
+
|
| 148 |
+
`positive_weight = negative_samples / positive_samples`
|
| 149 |
+
|
| 150 |
+
These weights were incorporated into `BCEWithLogitsLoss` to increase the contribution of positive examples from underrepresented classes.
|
| 151 |
+
|
| 152 |
+
Training and validation metrics were tracked using Weights & Biases.
|
| 153 |
+
|
| 154 |
+
## Evaluation Results
|
| 155 |
+
|
| 156 |
+
The best checkpoint was selected at epoch 7 using validation mean ROC-AUC.
|
| 157 |
+
|
| 158 |
+
- **Best Validation Mean ROC-AUC:** 0.8315
|
| 159 |
+
- **Held-Out Test Mean ROC-AUC:** 0.8225
|
| 160 |
+
- **Test Images:** 16,491
|
| 161 |
+
- **Test Patients:** 4,621
|
| 162 |
+
|
| 163 |
+
### Per-Class Test ROC-AUC
|
| 164 |
+
|
| 165 |
+
| Condition | ROC-AUC |
|
| 166 |
+
|---|---:|
|
| 167 |
+
| Atelectasis | 0.7935 |
|
| 168 |
+
| Cardiomegaly | 0.8962 |
|
| 169 |
+
| Effusion | 0.8719 |
|
| 170 |
+
| Infiltration | 0.6960 |
|
| 171 |
+
| Mass | 0.8045 |
|
| 172 |
+
| Nodule | 0.7422 |
|
| 173 |
+
| Pneumonia | 0.7380 |
|
| 174 |
+
| Pneumothorax | 0.8775 |
|
| 175 |
+
| Consolidation | 0.7913 |
|
| 176 |
+
| Edema | 0.8926 |
|
| 177 |
+
| Emphysema | 0.9268 |
|
| 178 |
+
| Fibrosis | 0.7957 |
|
| 179 |
+
| Pleural Thickening | 0.7947 |
|
| 180 |
+
| Hernia | 0.8949 |
|
| 181 |
+
| **Mean** | **0.8225** |
|
| 182 |
+
|
| 183 |
+
ROC-AUC measures the model's ability to distinguish positive and negative examples across classification thresholds. It does not establish clinical diagnostic accuracy, calibration, sensitivity, or specificity at a particular operating threshold.
|
| 184 |
+
|
| 185 |
+
## Model Inference
|
| 186 |
+
|
| 187 |
+
The trained model checkpoint is available in this repository as `best_model.pth`.
|
| 188 |
+
|
| 189 |
+
Inference requires the matching `ChestXRayNet` architecture and preprocessing pipeline.
|
| 190 |
+
|
| 191 |
+
For an interactive inference experience, visit the [Hugging Face Space](https://huggingface.co/spaces/Samer17/chest-xray-classifier-demo).
|
| 192 |
+
|
| 193 |
+
The deployed application allows users to:
|
| 194 |
+
|
| 195 |
+
- Upload a chest X-ray image
|
| 196 |
+
- Generate prediction scores for all 14 conditions
|
| 197 |
+
- View conditions ranked by model score
|
| 198 |
+
- Generate a Grad-CAM heatmap for the highest-scoring condition
|
| 199 |
+
- Visualize the heatmap overlaid on the original image
|
| 200 |
+
|
| 201 |
+
## Model Interpretability
|
| 202 |
+
|
| 203 |
+
Grad-CAM (Gradient-weighted Class Activation Mapping) is integrated into the model to visualize image regions contributing to a selected class output.
|
| 204 |
+
|
| 205 |
+
The implementation uses gradients and activations from the final ResNet-50 convolutional block to generate spatial heatmaps.
|
| 206 |
+
|
| 207 |
+
Grad-CAM visualizations are interpretability aids, not validated medical localization results. Highlighted regions do not necessarily correspond to clinically confirmed pathology.
|
| 208 |
+
|
| 209 |
+
## Intended Use
|
| 210 |
+
|
| 211 |
+
This model is intended for:
|
| 212 |
+
|
| 213 |
+
- Educational and research exploration of medical computer vision
|
| 214 |
+
- Multi-label classification experimentation
|
| 215 |
+
- Transfer learning and class imbalance studies
|
| 216 |
+
- Model interpretability demonstrations
|
| 217 |
+
- Machine learning engineering portfolio evaluation
|
| 218 |
+
|
| 219 |
+
## Limitations and Ethical Considerations
|
| 220 |
+
|
| 221 |
+
- The model was evaluated on a held-out partition of NIH ChestX-ray14, not an independent external clinical dataset.
|
| 222 |
+
- NIH ChestX-ray14 labels are derived from radiology reports and may contain annotation noise.
|
| 223 |
+
- Performance may vary across hospitals, imaging equipment, patient populations, and acquisition conditions.
|
| 224 |
+
- Rare conditions have relatively few positive examples, limiting the stability of their performance estimates.
|
| 225 |
+
- Model scores have not been clinically calibrated.
|
| 226 |
+
- No prospective clinical evaluation or regulatory validation has been performed.
|
| 227 |
+
- Grad-CAM heatmaps should not be interpreted as definitive pathology localization.
|
| 228 |
+
- The model should not be used for diagnosis, treatment decisions, or autonomous medical screening.
|
| 229 |
+
|
| 230 |
+
**This model is a research and educational prototype, not a clinically validated medical device.**
|
| 231 |
+
|
| 232 |
+
## Project Resources
|
| 233 |
+
|
| 234 |
+
- [Interactive Hugging Face Demo](https://huggingface.co/spaces/Samer17/chest-xray-classifier-demo)
|
| 235 |
+
- [Source Code and Training Pipeline](https://github.com/Samer-4/COGS-181-DL-Final-Project)
|
| 236 |
+
- [Weights & Biases Training Run](https://wandb.ai/sam-ahmed1703-uc-san-diego/chest-xray-classification/runs/68h5gmia)
|
| 237 |
+
|
| 238 |
+
## Author
|
| 239 |
+
|
| 240 |
+
**Samer Ahmed**
|
| 241 |
+
|
| 242 |
+
Developed as a medical computer vision and deep learning engineering project.
|