Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python PyTorch License Status

🩺 Chest X-Ray Pneumonia Detection using Deep Learning

A deep learning project that classifies chest X-ray images into Normal and Pneumonia using PyTorch and Transfer Learning.

📑 Table of Contents

  • Project Overview
  • Features
  • Dataset
  • Technologies Used
  • Model Architecture
  • Results
  • Installation
  • Project Structure
  • Future Improvements
  • Author
  • License

📌 Project Overview

Pneumonia is a serious lung infection that can be detected through chest X-ray images. Manual diagnosis can be time-consuming and depends on the expertise of radiologists.

This project uses a deep learning model based on PyTorch and Transfer Learning to automatically classify chest X-ray images into:

  • Normal
  • Pneumonia

The objective is to demonstrate how convolutional neural networks can assist in medical image classification.

✨ Features

  • Data preprocessing and augmentation
  • Transfer Learning using ResNet50
  • Binary classification (Normal vs Pneumonia)
  • Model training and validation
  • Performance evaluation
  • Prediction on new chest X-ray images
  • Explainable AI with Grad-CAM (heatmaps of the regions influencing each prediction)

🔍 Explainability (Grad-CAM)

Grad-CAM produces a heatmap over the last convolutional layer showing which regions of the X-ray drove the prediction — useful for sanity-checking that the model looks at the lungs rather than artifacts.

Run it on any image from the command line:

python scr/gradcam.py --image path/to/xray.jpeg --model best_model.pth --output cam.png

Or use it from Python:

from scr.gradcam import load_model, run_gradcam

model = load_model("best_model.pth")
overlay, pred_idx, probs, cam = run_gradcam(model, "xray.jpeg")

A ready-to-run Grad-CAM cell is also included at the end of train_model.ipynb.

📂 Dataset

The dataset consists of chest X-ray images categorized into:

  • Normal
  • Pneumonia

Dataset Source

Google Drive:

https://drive.google.com/file/d/1d6G2RkXVNnMBJTO-QWCx6QZ2bMElMqgu/view

After downloading, extract the dataset into the dataset/ folder.

🛠 Technologies Used

  • Python
  • PyTorch
  • Torchvision
  • NumPy
  • Matplotlib
  • Pillow
  • Scikit-learn

🧠 Model Architecture

This project uses a custom Convolutional Neural Network (CNN) designed for chest X-ray image classification.

Architecture:

Input Image (1 × 224 × 224) ↓ Conv2D (16 filters) + BatchNorm + ReLU + MaxPool ↓ Conv2D (32 filters) + BatchNorm + ReLU + MaxPool ↓ Conv2D (64 filters) + BatchNorm + ReLU + MaxPool ↓ Conv2D (128 filters) + BatchNorm + ReLU + MaxPool ↓ Conv2D (256 filters) + BatchNorm + ReLU + MaxPool ↓ Flatten ↓ Fully Connected (1024) ↓ Fully Connected (256) ↓ Fully Connected (128) ↓ Output Layer (2 classes: NORMAL / PNEUMONIA)

📈 Results

The trained model successfully classifies chest X-ray images into Normal and Pneumonia categories.

Evaluation metrics and visualizations will be added in future updates.

🚀 Installation

Clone the repository

git clone https://github.com/badivana/Chest-X-Ray-Classification.git

cd Chest-X-Ray-Classification

Install dependencies

pip install -r requirements.txt

📁 Project Structure

Chest-X-Ray-Classification/

├── README.md

├── requirements.txt

├── LICENSE

├── train_model.ipynb

├── best_model.pth

├── dataset/

├── images/

└── src/

🚀 Future Improvements

  • Deploy using Streamlit
  • Multi-class disease classification
  • Vision Transformer implementation
  • ✅ Explainable AI using Grad-CAM
  • Docker support

👨‍💻 Author

Prajwal B T

Information Science & Engineering

NMAM Institute of Technology

GitHub: https://github.com/badivana

📄 License

This project is licensed under the MIT License.

About

Deep Learning project for Chest X-Ray Pneumonia Classification using PyTorch and Transfer Learning.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages