This project is a computer vision (CV) application that leverages deep learning to classify chest X-ray images as either normal or indicative of pneumonia. It utilizes a pretrained DenseNet model (from TorchXRayVision), fine-tuned on a pneumonia dataset to improve diagnostic accuracy. The application is deployed using Streamlit, providing an interactive and user-friendly web interface for real-time medical image analysis.
- Check out the deployed app here: Pneumonia Detection Live App
demo.mp4
Below are sample images from the dataset, showing Normal and Pneumonia .
Normal | Normal | Normal | Normal | Normal |
---|---|---|---|---|
Pneumonia | Pneumonia | Pneumonia | Pneumonia | Pneumonia |
---|---|---|---|---|
- AI-Powered Classification: Upload a chest X-ray image (PNG/JPG/JPEG) and receive an immediate prediction (Normal or Pneumonia).
- Pretrained + Fine-Tuned Model: Uses a DenseNet model pretrained on large chest X-ray datasets, then fine-tuned for pneumonia detection.
- Interactive Web Interface: A Streamlit-based web app for quick and intuitive usage.
- Real-Time Predictions: Get immediate diagnostic feedback after uploading an image.
├── images
└── normal & pneumonia images
├── README.md
├── app.py
├── pneumonia_detection.ipynb
├── best_pneumonia_model.pth
├── Demo.mp4
└── requirements.txt
-
Data Preparation
- Collect chest X-ray images (Normal and Pneumonia) from public datasets ( Kaggle’s pneumonia dataset).
- Splited into training, testing and validation sets.
-
Model Training
- Fine-tuned a DenseNet model densenet121-res224-all (pretrained on large-scale chest X-ray data) on the pneumonia dataset.
- Saved the trained weights for inference as best_pneumonia_model.pth.
-
Web App
- The Streamlit app loads the fine-tuned model.
- Users upload chest X-ray images, and the model outputs predictions in real time.
-
Model Deployment
- The trained model is hosted on Streamlit Cloud.
- Real-time predictions are made available through the web interface.
To run this project locally, follow these steps:
- Clone the repository:
git clone https://github.com/Muhammad-Talha4k/Pneumonia-Detection-using-torch-xray-vision.git
- Prerequisites:
Python 3.8+
(Optional) GPU for faster inference or training
Packages: TorchXRayVision, PyTorch, Streamlit, and others listed in requirements.txt
- Install the required dependencies:
pip install -r requirements.txt
Once the app is running, you can:
- Upload a Chest X-ray: Upload your chest X-ray image (PNG/JPG/JPEG)
- The model will classify the image as Normal or Pneumonia.
- The app displays the uploaded image along with a zoomed-in version.
- A clear label (NORMAL or PNEUMONIA) is shown based on the prediction.
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request.
This project is licensed under the MIT License.
TorchXRayVision: This project uses the DenseNet model implementation from TorchXRayVision, which provides state-of-the-art pretrained models for chest X-ray analysis.
Kaggle Pneumonia Dataset: The pneumonia dataset used for fine-tuning was sourced from Kaggle’s chest X-ray pneumonia dataset.
Special thanks to the contributors of the Torch XRAY-Vision library and kaggle for the dataset.