yashk2000 / covid-detection

Covid19 detection using xray images of patients.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detecting covid-19 using Xray images

Collecting data

This repository contains a database of COVID-19 cases with chest X-ray or CT images as well as MERS, SARS, and ARDS. Clone this repository in order to proceed with building the dataset.

Using the metadata.csv, extract all images which are covid-positive using the build_dataset.py script.

python build_dataset.py -m <path to the cloned dataset folder> -o <path to where you want the output stored>

Next inorder to get some xrays of healthy patients/covid-negetive patients, we can randomly take images from the Kaggle chest xray dataset. To prevent class imbalance, keep the number of images of covid-positive and covid-negetive same. Store this in a folder called normal in your dataset.

The dataset should have a structure like the one in this repo.

My dataset consists of 68 covid-positive images and 70 normal images.

Training the model

The model is trained using VGGNet which is pre-trained on the imagenet dataset. To train obtain a model and save it, run the trainModel.py script.

python trainModel.py -d <path to dataset>

This will save the model in the same folder as the script as a file, [model.h5](https://github.com/yashk2000/covid-detection/blob/master/model.h5). A plot showing accuracy and loss curves will also be generated.

plot

This is the plot generated while I was training my model.

Classifying more images using the trained model

Now using the model obtained by running the above script, we can classify our own images as covid-positive or covid-negetive. To do this, run the detectCovid.py script.

python detectCovid.py -i <path to input image> -m <path to the trained model>

This will give an output with image labeled as covid-positive or covid-negetive.

Sample Output

There are a few sample images in the test-data folder.

For exmaple, for the image covid1.jpeg, which is covid-positive, I got the following output:

python detectCovid.py -i test-data/covid1.jpeg -m model.h5

Screenshot from 2020-03-21 00-48-17

For the image normal1.jpeg, which is covid-negetive, I got the following output:

python3 detectCovid.py -i test-data/normal1.jpeg -m model.h5

Screenshot from 2020-03-21 00-51-53

Cheers to this blog post by Adrian Rosebrock which was an invaluable resource.

About

Covid19 detection using xray images of patients.


Languages

Language:Python 100.0%