A deep learning project that classifies chest X-ray images into Normal and Pneumonia using PyTorch and Transfer Learning.
- Project Overview
- Features
- Dataset
- Technologies Used
- Model Architecture
- Results
- Installation
- Project Structure
- Future Improvements
- Author
- License
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.
- 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)
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.pngOr 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.
The dataset consists of chest X-ray images categorized into:
- Normal
- Pneumonia
Google Drive:
https://drive.google.com/file/d/1d6G2RkXVNnMBJTO-QWCx6QZ2bMElMqgu/view
After downloading, extract the dataset into the dataset/ folder.
- Python
- PyTorch
- Torchvision
- NumPy
- Matplotlib
- Pillow
- Scikit-learn
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)
The trained model successfully classifies chest X-ray images into Normal and Pneumonia categories.
Evaluation metrics and visualizations will be added in future updates.
Clone the repository
git clone https://github.com/badivana/Chest-X-Ray-Classification.git
cd Chest-X-Ray-ClassificationInstall dependencies
pip install -r requirements.txtChest-X-Ray-Classification/
├── README.md
├── requirements.txt
├── LICENSE
├── train_model.ipynb
├── best_model.pth
├── dataset/
├── images/
└── src/
- Deploy using Streamlit
- Multi-class disease classification
- Vision Transformer implementation
- ✅ Explainable AI using Grad-CAM
- Docker support
Prajwal B T
Information Science & Engineering
NMAM Institute of Technology
GitHub: https://github.com/badivana
This project is licensed under the MIT License.