Detecting COVID-19 using Deep Learning
By: Daksh Trehan
Tags: Deep Learning, Machine Learning, Artificial Intelligence, Covid 19, Data Science

Detecting COVID-19 using Deep Learning

A practical approach to help medical practitioners helping us in the battle against COVID-19

“Coronavirus disease 2019 (COVID-19) is a highly infectious disease caused by severe acute respiratory syndrome coronavirus 2".

“The disease first originated in December 2019 from Wuhan, China and since then it has spread globally across the world affecting more than 200 countries. The impact is such that the World Health Organization(WHO) has declared the ongoing pandemic of COVID-19 a Public Health Emergency of International Concern.”

As of 29th April, there is a total of 31,30,191 cases with 2,17,674 deaths in more than 200 countries across the world. (Source: Bing COVID-19 tracker).

So, in this particular scenario, one primary thing that needs to be done and has already started in the majority of the countries is Manual testing, so that the true situation can be understood and appropriate decisions can be taken.

But the drawbacks of manual testing includes sparse availability of testing kits, costly and inefficient blood tests; a blood test takes around 5–6 hours to generate the result.

So, the idea is to overcome these circumstances using the Deep Learning technique for better and efficient treatment. Since the disease is highly contagious therefore as early as we generate the results the fewer cases in the city that’s why we can use Convolution Neural Network to get our job done.

Can you distinguish between both X-rays if they haven’t been labeled? I bet you can’t, but a CNN can.

The problem is a binary classification problem where we classify Normal vs COVID-19 cases.

There are several pros and cons of using Deep Learning to tackle such kinds of situations:

Pros: More time saving; less expensive; easy to operate Cons: Practically we need ~100% accuracy as we can’t wrongly identify the patients as it might lead to further spread of disease which is highly discouraged.

But still, this model can return good accuracies and can further can be enhanced.

Data Preparation

Machine Learning needs a lot of data to train; the data we need for this type of problem is chest X-Ray for both COVID affected and fit patients.

Dr.Joseph Paul Cohen recently open-sourced a database containing chest X-ray images of patients suffering from the COVID-19 disease. The dataset used is an open-source dataset which consists of COVID-19 images from publicly available research, as well as lung images with different pneumonia-causing diseases such as SARS, Streptococcus, and Pneumocystis. I have also used the Kaggle’s Chest X-ray competitions dataset to extract X-rays of healthy patients and have sampled 100 images to have a balance with the COVID-19 available images.

So, the dataset consists of COVID-19 X-ray scan images. It turns out that the most frequently used view is the Posteroanterior view and I have considered the COVID-19 PA view X-ray scans for my analysis.

To stratify our data we will take an equal number of images and will blend them and later will divide into test and train data.

Model Deployment

Since we have already prepared the data which is the most tedious part of this project, let’s move to the next step here we will create a deep learning model that is going to learn the difference between normal X-Ray and COVID-19 affected X-Ray.

I assume you all know the basics of CNN architecture if not I highly recommend you follow:- Basics of CNN

Model Architecture

I tend to have 3 hidden layers, you can experiment with more or fewer layers that is up to you. I am going to mimic the traditional route of increasing the neurons, as the more we go deep inside the layer, the more features are learnt.

I’m going to have (224,224,3) input neurons that are we are resizing our data to 224*224 with 3 channels as it is considered to be the ideal size.

At last, I am going to flatten our features and will use sigmoid as activation function as we are having binary classification problem, and thus our output will only contain one cell, adam as optimizer works pretty well with sigmoid hence compiling the model with them in addition to cross binary entropy.

Parameters

You might be wondering why I didn’t directly deploy VGG16 or any predefined model but for that, you must know the architecture of VGG16, it contains roughly around 140million parameters, on the other hand, our model includes around 5.7million parameters, so it is better and more optimal to use customized model rather than training for hours on transfer learning especially for small datasets like this.

Training Data

Since we’ve already defined our model the next task we are left with is training our data on the defined model.

I tried training the data without performing shearing, zooming and horizontal shifts so the accuracy I got was around 50% which is pretty low for real-time projects like this.