Chest X-ray image analysis and classification for COVID-19 pneumonia detection using Deep CNN
By: Syyam Noor
Tags: Coronavirus, Convolutional Network, Data Science, Covid 19, Deep Learning

Coronavirus or COVID-19 is considered an irresistible and dangerous pneumonia type infection until ongoing time. Novel coronavirus or SARS-COV-2 strain is responsible for COVID-19 and it has already shown the deadly nature of the respiratory disease by threatening the health of millions of lives across the globe. A clinical report uncovers that a COVID-19 tainted individual may encounter a dry cough, muscle torment, cerebral pain, fever, and sore throat. Most people who get COVID-19 have mild or moderate symptoms like coughing, a fever, and shortness of breath. But some who catch the new coronavirus get severe pneumonia in both lungs. At the same time, it affects the lungs badly with virus infection. So, the lung can be a prominent internal organ to diagnose the symptoms of COVID-19 infection using an X-Ray of the chest. I developed a new diagnosis platform using a deep convolutional neural network (CNN) that is able to assist radiologists with diagnosis by distinguishing COVID-19 pneumonia from non-COVID-19 pneumonia in patients based on chest X-ray classification and analysis.

In this work, I have taken the chest x-ray scans for covid-19 affected patients as well as healthy patients. After cleaning up the images and applying data augmentation, I have used LeNet architecture — straightforward and small, (in terms of memory footprint).

With this approach, the proposed model exhibits a higher classification accuracy of around 95.53% for X-Ray images with precision, recall, and f1-accuracy of 96% (Weighted avg.). The evaluation has been done on publicly available datasets containing both chest X-Ray

Preparing the data

The first and most significant step in any AI task is to set up the dataset. For many scientists and industry practitioners, the process of gathering, cleaning, labeling, and storing the data into a usable digital format represents the lion’s share of the work. Errors introduced during this step will cause the learning algorithm to learn incorrect patterns. As they say: shit in, shit out.

The dataset used in this project is collected from the below sources.

1 Dataset

2 Kaggle for more images of Normal Cases

Once I have the dataset, I have to format it appropriately for my neural network. I resized all the images to 50*50 and converted them into grayscale images. I am using 2/3 of the data for training and the remaining of the data for testing later in the blog post.

Here’s the graphical representation of how the looks like:

The LeNet architecture

The LeNet architecture consists of two sets of convolutional, activation, and pooling layers, followed by a fully-connected layer, activation, another fully-connected, and finally a softmax classifier.

Now, coming onto the juicy part of any machine learning application, that is building a NN. The LeNet architecture is an excellent “first architecture” for Convolutional Neural Networks. LeNet is small and easy to understand — yet large enough to provide interesting results. Designing a NN architecture is fun and also a pain in the clit sometimes as no one knows the answer to these 3 questions:

How many layers are there? How many nodes are there in each of those layers? What activation function is used at each of those layers?

Instead of explaining the number of convolution filters per layer, the size of the filters themselves, and the number of fully-connected nodes right now, I’m going to save this discussion until the next section of the blog post where the source code will serve as an aid in the explanation.

Implementation

I implemented the LeNet architecture with python and Keras (Keras is built on top of TensorFlow, which makes it a wrapper for deep learning purposes).

Note: The original LeNet architecture used TANH activation functions rather than RELU. The reason why I used RELU here is that it tends to give much better classification accuracy due to a number of nice, desirable properties. And I am using sigmoid instead of softmax in the last layer as I am dealing with a binary classification problem.

Now the model is ready to load the dataset and so I partition the dataset into the training and testing sets:

The next step is to categorize my labels into binary so they can be used with the binary cross-entropy loss function. I’m training my network using RMSProp Optimizer with a learning rate of 0.0001. Binary cross-entropy is used as my loss function, a fairly standard choice when working with binary datasets. The model is then compiled and loaded into memory.

Training the network is accomplished by making a call to the .fit method of the instantiated model. I allowed the network to train for 25 epochs (indicating that the network will “see” each of the training examples a total of 25 times to learn distinguishing filters for both the classes).

I then evaluate the network on the testing data and display the results to the terminal.

Experimental Results

Let’s visualize the progress of all metrics throughout the total epochs lifetime.

Accuracy and loss of training ad validation sets.

The accuracy we are getting on the Test dataset is almost around 95%. Let’s predict the test dataset and look at some of the performance measurement metrics in detail to evaluate our model.

Classification Report

Confusion Matrix

The confusion matrix of my model is given below: