/Pneumonia-Detection-using-Deep-Learning

Detecting pneumonia from chest radiographs using deep learning with the PyTorch framework. Faster RCNN ResNet50 backbone.

Primary LanguagePythonMIT LicenseMIT

Pneumonia Detection using Deep Learning (PyTorch)

Try the live demo here => https://pneumonia-detection-dl.herokuapp.com/

About the Project

This project aims to detect pneumonia from chest radio graph images. This project uses data from the RSNA Pneumonia Detection Challenge. The results and evaluation metric plots presented here also uses the same metric as was in the competition.

Feel free to improve upon the project by using the TRAINING Kaggle notebook and TEST Kaggle notebook.

Framework Used

This project used the PyTorch deep learning framework. Use PyTorch version >= 1.4 to reproduce the results.

Get the Data

Get the competition data from here.

Project Structure

The following is the directory structure of the project. You will be able to directly

───faster_rcnn_resnet_final_project
│   │   dataset.py
│   │   dcm_to_jpg.py
│   │   engine..py
│   │   fasterrcnn_resnet50_fpn.pth
│   │   loss.png
│   │   model.py
│   │   precision.png
│   │   README.md
│   │   submission.csv
│   │   test.py
│   │   train.py
├───input
│   │   stage_2_detailed_class_info.csv
│   │   stage_2_sample_submission.csv
│   │   stage_2_train_labels.csv
│   ├───images
│   ├───samples
├───test_predictions
  • faster_rcnn_resnet_final_project: This contains all the files including the python scripts that you see in this repository.
  • input : This contains the training images in JPG format in the images folder and test images in the samples folder.
  • test_predictions will contain all the predicted bounding box results on the test images after you run test.py

Run the Detection API on Your LocalHost

  • I have made this really simple.

  1. Clone this repository to your local disk.
  2. Run the requirements.txt file using pip install -r requirements.txt.
  3. Run the app.py script using python app.py.
  4. Open 127.0.0.1:12000 in your browser.
  5. Choose a lung x-ray image from your disk and click on the Predict button.

Training and Testing

  • First run dcm_to_jpg.py to convert all the DICOM images to JPG images and save them in the inout/images folder. Change the paths according to your need if want to structure your project differently.
  • Then run train.py to train a Faster RCNN ResNet50 backbone model on the data. I have trained the model for 30 epochs to obtain the results. You may train for longer if you want to.
  • Finally run test.py to predict on the test images present in the input/samples folder.

If You Want to Directly Predict on the Test Images, Then Download the Weights from THIS KAGGLE NOTEBOOK.

You will also find the test notebook here.

Results

  • The following the private and public leaderboard score as per the competition metric of Average Precision.

    Private Leaderboard Public Leaderboard
    Average Precision 0.12993 0.11904
  • Validation Precision Plot

  • Loss Plot

  • Detection on a Test Image

References