AI based Covid-19 detection using X-Ray images
By: Manish Kumar
Tags: Heroku, Cnn, Covid 19, Flask

During this pandemic, we the human race has been tested thoroughly. Lot of gaps has been identified in the current medical infrastructure specially in country like India. Although now we have enough supply of testing KIT, we are still unable to deliver it to remote areas. Also, to have better result using PCR technique, we still have to send samples to some centralized hospitals which takes their own time to deliver results and hence increase the chance of fatality to the patients. The chance of transmission is also high if positive results are not delivered on time.

To address this existing medical infrastructure gap we can fallback to the existing system that we have i.e. X-Ray images.

My team has built an AI model which can detect covid-19 patient with a 96% accuracy. The MVP version of the model is being deployed and free to use for users at https://covid-detection-xray.herokuapp.com/. Users just have to upload an chest X-Ray image to know whether the patient has covid-19 symptoms or not.

Below are high level steps involved during this model building:

Covid-19 and non-covid-19 image collection Choosing appropriate Neural Network model Training the model Creating an Flask application to deploy model Deploying model on heroku

Covid-19 and non-covid-19 image collection

Non-Covid-19/Normal images are collected from kaggle.

Covid-19 X-ray images are collected and processed from a github repo.

Getting non-covid-19 images was a straight forward task but getting covid-19 images was tricky and took a little effort

Choosing appropriate Neural Network Model

We have selected CNN based model for image processing as it classifies images very effectively.

The architecture of CNNs uses many of the working principles of the animal visual system and thus they have been able to achieve extraordinary results in image-related learning tasks.

Training the model

We have used a combination of convolutional layers and max-pooling layers with dropout

CNN code below:

model = Sequential() #Layer Combination 1 model.add(Conv2D(16, kernel_size=(3,3), activation="relu", input_shape=(224,224,3))) model.add(Conv2D(16,(3,3), activation="relu")) model.add(MaxPool2D(pool_size=(2,2))) model.add(Dropout(0.25)) #Layer combination 2 model.add(Conv2D(32,(3,3), activation="relu")) model.add(MaxPool2D(pool_size=(2,2))) model.add(Dropout(0.25)) # Layer Combination 3 model.add(Conv2D(64,(3,3), activation="relu")) model.add(MaxPool2D(pool_size=(2,2))) model.add(Dropout(0.25)) #Layer Combination 4 model.add(Conv2D(128,(3,3), activation="relu")) model.add(MaxPool2D(pool_size=(2,2))) model.add(Dropout(0.25)) #layer combination 5 model.add(Flatten()) model.add(Dense(64, activation="relu")) model.add(Dropout(0.25)) model.add(Dense(1, activation="sigmoid"))

Loss function and optimizer

model.compile(loss= keras.losses.binary_crossentropy, optimizer='adam', metrics=['accuracy'])

Creating an Flask application to deploy model

We wanted to deploy our model for end users for that we have selected flask framework. Click here to check the code.

Deploying model on heroku

Heroku is a container-based cloud Platform as a Service (PaaS). Developers use Heroku to deploy, manage, and scale modern apps. Click here to check how to deploy a python application on heroku

Summary

In this article we have learned how to deploy any deep learning simple model as a web app free of cost on heroku. Although this model is specific to detecting covid-19 but similar model with some little changes in the neural network layers can be used for detecting other diseases as well using chest X-Rays.

Good luck, and thanks for reading!