Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Pneumonia Detection Using Explainable Deep Learning (Grad-CAM & LIME)

Python TensorFlow License


Overview

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.


Dataset

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

Models

1. Baseline Custom CNN

  • 3 convolutional blocks (32 → 64 → 128 filters)
  • Dropout (0.5) for regularization
  • Sigmoid output for binary classification

2. ResNet50 Transfer Learning

  • Pre-trained on ImageNet
  • Phase 1: Frozen base, only top layers trained
  • Phase 2: Top 30 layers unfrozen for fine-tuning

Explainability Methods

Grad-CAM

Highlights which regions of the X-ray the CNN focused on. Produces a heatmap overlaid on the original image.

LIME

Identifies which superpixel regions most influenced the prediction by perturbing the image and observing output changes.


Results

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

Project Structure

pneumonia-xai-detection/ │ ├── pneumonia_xai_gradcam_lime.ipynb ← main notebook ├── Pneumonia_XAI_Report.docx ← final project report └── README.md ← this file


How to Run

  1. Clone this repository or open the notebook directly in Google Colab
  2. Set Runtime → GPU (T4 is free)
  3. Run cells top to bottom
  4. Upload your kaggle.json when prompted in Cell 2

Requirements

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


Future Work

  • 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

References

  1. Selvaraju et al. (2019) — Grad-CAM: Visual Explanations from Deep Networks
  2. Ribeiro et al. (2016) — LIME: Why Should I Trust You?
  3. Tjoa & Guan (2020) — XAI Survey for Medical Applications
  4. He et al. (2016) — Deep Residual Learning for Image Recognition (ResNet)
  5. Mooney, P. (2018) — Chest X-Ray Images (Pneumonia), Kaggle

Releases

Packages

Contributors

Languages