Lungs Disease prediction using Medical Imaging with Implementation of VGG, Resnet and Convolutional Neural Network

Nitish Raj Pathak
Analytics Vidhya
Published in
4 min readMar 25, 2020

About

Convolutional Neural Network (CNN)

CNN is a neural network that are commonly used for image and audio recognition and classification. It is an replica of human brain that contains columns of neurons. CNN has neurons with adjustable weights and biases and unlike other neural networks. The Convolution layer helps finding and extracting features from the input data. Convolutional layers use filters, also called kernels, for this feature extracting process.

Architecture of Convolutional Neural Network.

VGG-16

VGG-16 neural network is a convolution neural network developed and trained by Visual Geometry Group(VGG) of University of Oxford. It was submitted to Large Scale Visual Recognition Challenge 2014 (ILSVRC2014) and the model achieved 92.7% top-5 test accuracy in in Imagenet Challenge 2014, ever since it has been available in various frameworks. The numerical digit is the number of layers the architecture comprises of. It has 14 million hand-annotated images of what is in the picture.

ResNet50

Resnet stands for Residual Network. The fundamental concept of resnet is Residual Learning. In residual learning, instead of trying to learn some features, we try to learn some residual. Residual is subtraction of feature learned from input of that layer. ResNet50 is a 50 layer Residual Network.

Layers of VGG and ResNet(Vgg19 and ResNet152)

Medical Imaging

Medical Imaging refers to the different types of technologies that are used to view human body for the purpose of Diagnose,medical conditions or to monitor certain part. Different types of Medical Imaging are CT scan, X-Rays, MRI etc

ImageNet

ImageNet is an image database or dataset that consists of over 14 Million images designed for Computer Vision Research(Visual Object Recognition). It contains 20,000 categories like “balloon”, “strawberry” etc. Since 2010, the ImageNet project runs an annual software contest, the ImageNet Large Scale Visual Recognition Challenge (ILSVRC). VGG and ResNet were awarded in this challenge which contributed in making them popular.

Lungs Disease Prediction

We are going to predict if the given X-ray of patient has pneumonia or not using 5856 images located in three folders train, test and Val. Pneumonia is an infectious inflammatory disease that affects the lungs typically caused by viral or bacterial infections. Pneumonia can be diagnosed by Chest X-rays. We have collection of normal and Pneumonia diagnosed X-Rays. These images have an input shape of 64x64x3: 64 wide, 64 high, with 3 color channels.We will classify images using three different types of layers: VGG-16, ResNet50 and Convolution Neural Network layer.

Lets Code

Import Libraries

Set up training and testing folders

Let’s take a look at some of the pictures

Use Image Data Generator to import images from dataset.

ImageDataGenerator helps in Image Augmentation. IMAGE_SIZE will be used in VGG, ResNet implementation to resize image

Using CNN Model

Lets build the CNN Model

Lets tell the model what cost and optimization method to use and fit the model to our training data set

Using VGG

Add Preprocessing layer infront of Vgg after Importing Vgg16 library

We use weight of imagenet

Make sure existing VGG layers are not trained and weights are not changed.

Get number of output classes

Make a flatten layer and add add last layer

len(folder) indicates how many categories i have in my output layer

Create a model and observe the model

Tell the model what cost and optimization method to use

Fit the model

Using ResNet50

Code for Resnet50 Implementation is all same to that of VGG-16. The only change you have to make is replace vgg16 by ResNet50

Fit the model

Link to Github and complete code:

https://github.com/beingnitisho7/LungsDiseasePredictionCNN_VGG_ResNet

--

--

Nitish Raj Pathak
Analytics Vidhya

A Machine Learning and Deep Learning enthusiast who is passionate about sports and Paper bill and coin collection.