Detecting COVID-19 in X-ray Images Using VGG16 CNN Model
Objective : Detect COVID-19 from X-ray images.
Convolution Neural Network (CNN):
Deep Learning is becoming a very popular subset of machine learning due to its high level of performance across many types of data. A great way to use deep learning to classify images is to build a convolutional neural network (CNN). The Keras library in Python makes it pretty simple to build a CNN.
Computers see images using pixels. Pixels in images are usually related. For example, a certain group of pixels may signify an edge in an image or some other pattern. Convolutions use this to help identify images.
A convolution multiplies a matrix of pixels with a filter matrix or ‘kernel’ and sums up the multiplication values. Then the convolution slides over to the next pixel and repeats the same process until all the image pixels have been covered. This process is visualized below. (For an introduction to deep learning and neural networks, you can refer to my deep learning article here).
VGGNet :
When?
- International Year of Family Farming and Crystallography
- First Robotic Landing on Comet
- Year of Robin Williams’ death
Why? VGGNet was born out of the need to reduce the # of parameters in the CONV layers and improve on training time.
What? There are multiple variants of VGGNet (VGG16, VGG19 etc.) which differ only in the total number of layers in the network. The structural details of a VGG16 network has been shown below.
VGG16 has a total of 138 million parameters. The important point to note here is that all the conv kernels are of size 3x3 and maxpool kernels are of size 2x2 with stride of two.
How? The idea behind having fixed size kernels is that all the variable size convolutional kernels used in Alexnet (11x11, 5x5, 3x3) can be replicated by making use of multiple 3x3 kernels as building blocks. The replication is in terms of the receptive field covered by the kernels.
Let’s consider the following example. Say we have an input layer of size 5x5x1. Implementing a conv layer with kernel size of 5x5 and stride one will result and output feature map of 1x1. The same output feature map can be obtained by implementing two 3x3 conv layers with stride of 1 as shown below
Now let’s look at the number of variables needed to be trained. For a 5x5 conv layer filter the number of variables is 25. On the other hand, two conv layers of kernel size 3x3 have a total of 3x3x2=18 variables (a reduction of 28%).
Similarly, the effect of one 7x7 (11x11) conv layer can be achieved by implementing three (five) 3x3 conv layer with stride of one. This reduces the number of trainable variables by 44.9% (62.8%). Reduced number of trainable variables means faster learning and more robust to overfitting.
Dataset :
Dataset has only 50 x-ray images. 25 X-ray images has COVID-19 +ve and 25 X-ray images has COVID-19 -ve.
Model Architecture:
Procedure :
Load VGG16 pre-defined model and remove the fully connected layer from the model.Later construct the head of the model that will be placed on top of the base model(VGG16).And below is the final model,
Results :
This model has given 95% training accuracy and 100% validation accuracy. Because the current mode has trained very very less data (40 images) and validate on just 10 images.If we use more data on same model then results will good.
Source Code :
Go to my github repository to get source code of this case study. https://github.com/sanjeevpalla/COVID-19-Detection