Pneumonia Diagnosis Using Transfer Learning VGG 16 Deep Learning Techniques

Khulood Nasher
6 min readAug 4, 2020

--

Source of the Photo

By: Khulood Nasher

In the previous blog, I explained how you can perform pneumonia diagnosis using deep learning CNN Classification, you can read the article here.

In this blog, I would like to dive further and explain the extra deep learning state of art’s model i.e. Transfer learning using VGG 16 pre-trained model. But before I talk about VGG16, I would like to introduce the first augmentation techniques in image classification.

Augmented Model

Augmentation Techniques

In my augmented model, I tried to use Augmentation techniques to create dummy augmented data to increase the previous model accuracy as follows:

Shearing: pulling anyone off our photo and converting a square into a rhombus

Rotation: Rotating the image

Width shift: shift the image to the right or the left

Height Shift: shifting the whole image up and down

Zooming: zoom in at any particular section of our image.

Horizontal flip: mirror image along the vertical axis

Here, I defined the parameters of image transformation

Then, I constructed the architecture of the augmented model:

And I plotted the architecture of the augmented model

And After that, I did Compiling and Optimizing my Augmented Model

Then, I performed fitting for the Augmented model with the training and Validation dataset

And I visualized the accuracy and loss of training and validation dataset

From the above plots, We can notice the overfitting between the training and validation dataset. The training accuracy was increasing until it reached its maximum around 95% before epochs=30, while the validation accuracy stays at 72% during the 30 epochs.

Also, The training loss was decreasing with epochs increased and reached its minimum of around epoch =30. Meanwhile, the validation loss was fluctuating and it reached its maximum around epoch=25.

Next, I assessed the model using confusion matrix and classification report on the test dataset

Interpreting the Results

The recall of pneumonia is high but the metrics of Normal are zero. This model is rejected.

After trying the augmented model, I tried to transfer the learning state of the art on CNN and model with VGG16.

VGG16 Model

Transfer Learning Techniques, VGG16

We used here the architecture of the conventional pre-trained model in our model. These models consist of two parts: a convolutional base and a fully connected neural network base. The convolutional base is used to identify and extract features from our images, and then the fully connected neural network base is used to classify those features.

We can add three layers to classify this dataset.

We used the convolutional base of the VGG 16 model and then we added one fully connected hidden layer and one output layer to classify features extracted from VGG 16 convolutional base.

We used a pretrained weight of ‘Imagenet’.We only want to use the convolutional part from the Imagenet model. Since convolutional bases are reusable, they are mainly used to extract features and categorize images.

So first, I defined the parameters of VGG16 image transformation:

Then, I used the weight of a pretrained model i.e.”imagenet”

And I collected the summary report of VGG16 model

Then, I added conv_base and fully connected dense and output layer

And I plotted the architecture of VGG16

Then I complied VGG 16

Then I did the fitting of training and validation dataset to VGG16 model

And I visualized the accuracy and the loss of training and validation dataset

The accuracy plot of training and validation shows that the model is doing well and there is no real discrepancy between the training and fitting during the 30 epochs. Both training and validation reach the climax of the accuracy of 97% at epoch=27. The Loss however was getting less with the increase of epochs in the training dataset but it was fluctuating in the validation dataset. The loss reached its minimum at epoch 27 at both training and validation datasets. I can see that setting the parameter at epoch =27 will give us the best metrics results.

After that, I collected the classification report and confusion matrix of VGG16

Collecting the Metrics of VGG16 and all my previous deep learning models in this blog and the previous blog from here:

Conclusion

Finally, We can say that the weight of our base model and VGG 16 are the best because the Recall was 99% in the base model but it was 75% in VGG16. However, the testing accuracy is 95% in VGG16 but it is 88% in the base model.

The base model and VGG16 are sharing the same sequence of architecture, but the number of trainable parameters in the base model is 3.5 million while the number of trainable parameters in VGG16 is 15 million. The good weight of parameters from the base model is ideal and that’s what increases the Recall metric but the transformation of the image in addition to the weight of the imagenet was also great for high accuracy. In conclusion, I recommend using my base model and VGG 16 as a reliable tool to be deployed in the medical centers for diagnosing pneumonia.

Recommendation:

Based on the accuracy of our models, I would like to recommend the following:

1- Use deep learning models for early diagnosis to limit the complications of any delay treatment,

2- Use deep learning pneumonia classification to decrease the heavy load on medical centers and particularly during weekends, holidays, and or during emergency status as it is now during COVID 19 pandemic.

3- Use deep learning in pneumonia diagnosis to test the efficiency of the health care system of the facility.

4- Apply the deep learning detection remotely as a kind of business or service with any over the sea county.

--

--

Khulood Nasher
Khulood Nasher

Written by Khulood Nasher

Data Scientist,Health Physicist, NLP Researcher, & Arabic Linguist. https://www.linkedin.com/in/khuloodnasher https:/khuloodnasher1.wixsite.com/resume

No responses yet