Skip to content

A computer vision (CV) application that performs real-time classification of chest X-rays to detect pneumonia using TorchXRayVision. The model accurately distinguishes between normal and pneumonia cases, aiding healthcare professionals in early diagnosis and treatment.

Notifications You must be signed in to change notification settings

Muhammad-Talha4k/Pneumonia-Detection-using-torch-xray-vision

Repository files navigation

Chest X-Ray Pneumonia Detection App

Overview

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.

Live App

App Demo

demo.mp4

Sample Chest X-Ray Images from Dataset

Below are sample images from the dataset, showing Normal and Pneumonia .

Normal Normal Normal Normal Normal
Normal Normal Normal Normal Normal
Pneumonia Pneumonia Pneumonia Pneumonia Pneumonia
Pneumonia Pneumonia Pneumonia Pneumonia Pneumonia

Features

  • 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.

Project Structure

├── images
 └── normal & pneumonia images
├── README.md
├── app.py
├── pneumonia_detection.ipynb
├── best_pneumonia_model.pth
├── Demo.mp4
└── requirements.txt

Workflow

  1. Data Preparation

    • Collect chest X-ray images (Normal and Pneumonia) from public datasets ( Kaggle’s pneumonia dataset).
    • Splited into training, testing and validation sets.
  2. 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.
  3. Web App

    • The Streamlit app loads the fine-tuned model.
    • Users upload chest X-ray images, and the model outputs predictions in real time.
  4. Model Deployment

    • The trained model is hosted on Streamlit Cloud.
    • Real-time predictions are made available through the web interface.

Installation

To run this project locally, follow these steps:

  1. Clone the repository:
    git clone https://github.com/Muhammad-Talha4k/Pneumonia-Detection-using-torch-xray-vision.git
  2. Prerequisites:
  • Python 3.8+
  • (Optional) GPU for faster inference or training
  • Packages: TorchXRayVision, PyTorch, Streamlit, and others listed in requirements.txt
  1. Install the required dependencies:
    pip install -r requirements.txt

Usage

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.

Contributing

Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Acknowledgements

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.

About

A computer vision (CV) application that performs real-time classification of chest X-rays to detect pneumonia using TorchXRayVision. The model accurately distinguishes between normal and pneumonia cases, aiding healthcare professionals in early diagnosis and treatment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published