An end-to-end deep learning application for detecting Pneumonia from chest X-ray images using a fine-tuned ResNet18 model. The project demonstrates the complete machine learning workflow—from data preprocessing and model training to evaluation and deployment through a Streamlit web application.
Pneumonia is a potentially life-threatening lung infection where early diagnosis is critical. This project leverages transfer learning to classify chest X-ray images into one of two categories:
- ✅ Normal
- 🦠 Pneumonia
The primary objective is to build an accurate and user-friendly diagnostic assistance tool while showcasing an end-to-end machine learning pipeline.
- Deep learning–based binary image classification
- Transfer learning with pretrained ResNet18
- Interactive web interface built with Streamlit
- Real-time inference on uploaded X-ray images
- Clean and modular project structure
- Easy-to-understand training and evaluation scripts
- Base Model: ResNet18 (ImageNet pretrained)
- Framework: PyTorch
- Transfer Learning: Fine-tuned final classification layer
- Output Classes: Normal, Pneumonia
- Loss Function: CrossEntropyLoss
- Optimizer: Adam
| Metric | Score |
|---|---|
| Accuracy | ~95% |
| Pneumonia Recall | ~96% |
| False Negatives | 32 |
Note: In medical image classification, Recall is often more important than overall accuracy because missing a pneumonia case (false negative) can have serious clinical consequences.
pneumonia-detection/
│
├── app.py # Streamlit application
├── src/
│ ├── data_loader.py
│ ├── model.py
│ ├── train.py
│ └── evaluate.py
│
├── requirements.txt
├── README.md
└── screenshot.png
Clone the repository:
git clone https://github.com/Abhhiiissshhek/pneumonia-detection.git
cd pneumonia-detectionCreate a virtual environment (recommended):
python -m venv .venvActivate the environment:
.venv\Scripts\activatesource .venv/bin/activateInstall dependencies:
pip install -r requirements.txtRun the application:
streamlit run app.pyThis project uses the Chest X-ray Pneumonia Dataset available on Kaggle.
The dataset is not included in this repository due to its size and licensing restrictions.
To train the model from scratch or fine-tune the network:
python src/train.pyAfter training, save the model weights and use them with the Streamlit application for inference.
Model evaluation includes:
- Accuracy
- Recall
- Confusion Matrix
- Classification Metrics
The evaluation script can be executed using:
python src/evaluate.py- The trained
.pthmodel file is not included because it exceeds GitHub's file size limit. - You can reproduce the model by training it using the provided scripts.
- Confidence score for predictions
- Grad-CAM visualizations for model explainability
- Docker support
- Cloud deployment
- Model comparison (ResNet, EfficientNet, DenseNet)
- Improved recall with advanced augmentation techniques
- Continuous Integration (GitHub Actions)
- Python
- PyTorch
- TorchVision
- Streamlit
- NumPy
- Pillow
- Matplotlib
Through this project, I gained hands-on experience with:
- Transfer Learning
- Medical Image Classification
- Deep Learning using PyTorch
- Model Evaluation and Performance Analysis
- Building production-ready ML applications with Streamlit
- End-to-end machine learning workflows
Abhishek Prajapati
- GitHub: https://github.com/Abhhiiissshhek
- LinkedIn: https://www.linkedin.com/in/abhishekprajapati-ml
If you found this project useful, consider giving the repository a star. Feedback, suggestions, and contributions are always welcome.
