Skip to content

mandanajignesh-byte/Chest-X-ray-Classifier-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🫁 CheXNet: Chest X-Ray Disease Classifier

Live Demo Dataset Model

DenseNet-121 trained on 112,120 chest X-rays to detect 14 diseases — with Grad-CAM visualization showing exactly where the model looks.

🚀 Live Demo

Try it here → huggingface.co/spaces/Jignesh2619/chestxray-classifier

Upload any chest X-ray and get:

  • Top 3 disease predictions with confidence scores
  • Grad-CAM heatmap showing which lung regions influenced the prediction

📊 Results

Metric Value
Mean AUC (14 classes) 0.7630
Best class — Hernia 0.8986
Best class — Emphysema 0.8507
Best class — Cardiomegaly 0.8244
Training epochs 10 (5 frozen + 5 fine-tune)
Dataset size 112,120 images

🏗️ Architecture

  • Backbone: DenseNet-121 pretrained on ImageNet
  • Classifier: Custom linear head → 14 disease classes
  • Loss: Weighted Binary Cross-Entropy (handles class imbalance)
  • Evaluation: Per-class AUROC
  • Visualization: Grad-CAM on features.denseblock4

Training Pipeline

Phase 1: Frozen backbone → train classifier head (5 epochs, lr=1e-3)
         Loss: 1.1192 → 1.0378

Phase 2: Full fine-tune (5 epochs, lr=1e-5)
         Loss: 0.9640 → 0.7391

🦠 14 Disease Classes

Atelectasis · Cardiomegaly · Consolidation · Edema · Effusion · Emphysema · Fibrosis · Hernia · Infiltration · Mass · Nodule · Pleural Thickening · Pneumonia · Pneumothorax


🔬 What Makes This Better Than the Original CheXNet Paper

Feature CheXNet (Stanford 2017) This Project
Architecture DenseNet-121 DenseNet-121
Dataset NIH ChestX-ray14 NIH ChestX-ray14
Class imbalance handling Standard BCE ✅ Weighted BCE
Grad-CAM visualization
Live deployment ✅ HuggingFace Spaces
Patient-level data split ✅ No data leakage

📁 Repository Structure

chest-x-ray.ipynb     — Full training pipeline (data → model → eval → Grad-CAM)
app.py                — Gradio demo (HuggingFace Spaces)
requirements.txt      — Dependencies

🛠️ Key Implementation Details

Class Imbalance: NIH dataset has severe imbalance (e.g. Hernia: 227 samples vs Infiltration: 19,894). Computed per-class weights inversely proportional to frequency and applied to BCE loss.

No Data Leakage: Used official NIH patient-level train/test split. Images from the same patient never appear in both train and test sets.

Grad-CAM: Hooked into features.denseblock4 — the last dense block before Global Average Pooling. Gradients of the target class score with respect to feature maps are used to weight the spatial activations, producing a heatmap of the most influential regions.


📦 Run Locally

pip install torch torchvision gradio opencv-python matplotlib
python app.py

📚 References


Built as part of a 30-day ML sprint — Day 12/13

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors