This project develops a deep learning pipeline to classify chest X-rays as Normal or Pneumonia, with full explainability using Grad-CAM and LIME to visualize what the model focuses on when making predictions.
Chest X-Ray Images (Pneumonia) by Paul Mooney on Kaggle.
- 5,863 JPEG chest X-ray images
- 2 classes: NORMAL and PNEUMONIA
- Split: Train / Validation (80-20 from train) / Test
- 3 convolutional blocks (32 → 64 → 128 filters)
- Dropout (0.5) for regularization
- Sigmoid output for binary classification
- Pre-trained on ImageNet
- Phase 1: Frozen base, only top layers trained
- Phase 2: Top 30 layers unfrozen for fine-tuning
Highlights which regions of the X-ray the CNN focused on. Produces a heatmap overlaid on the original image.
Identifies which superpixel regions most influenced the prediction by perturbing the image and observing output changes.
| Model | Accuracy | Precision | Recall | F1-Score | AUC-ROC |
|---|---|---|---|---|---|
| Baseline CNN | ~90% | ~0.91 | ~0.93 | ~0.92 | ~0.95 |
| ResNet50 | ~95%+ | ~0.96 | ~0.97 | ~0.96 | ~0.98 |
pneumonia-xai-detection/ │ ├── pneumonia_xai_gradcam_lime.ipynb ← main notebook ├── Pneumonia_XAI_Report.docx ← final project report └── README.md ← this file
- Clone this repository or open the notebook directly in Google Colab
- Set Runtime → GPU (T4 is free)
- Run cells top to bottom
- Upload your
kaggle.jsonwhen prompted in Cell 2
tensorflow >= 2.10 numpy matplotlib opencv-python scikit-learn scikit-image lime pandas kaggle
Install with: pip install tensorflow numpy matplotlib opencv-python scikit-learn scikit-image lime pandas kaggle
- SHAP / DeepSHAP for deeper feature attribution
- Monte Carlo Dropout for uncertainty estimation
- Vision Transformers (ViT) with attention maps
- Multi-disease detection on CheXpert / MIMIC-CXR
- Interactive clinical dashboard using Streamlit or Gradio
- Selvaraju et al. (2019) — Grad-CAM: Visual Explanations from Deep Networks
- Ribeiro et al. (2016) — LIME: Why Should I Trust You?
- Tjoa & Guan (2020) — XAI Survey for Medical Applications
- He et al. (2016) — Deep Residual Learning for Image Recognition (ResNet)
- Mooney, P. (2018) — Chest X-Ray Images (Pneumonia), Kaggle