You are on page 1of 5

" Detecting Pneumonia from X ray images using Transfer Learning "

My project work was on detecting pneumonia from x-ray images

As we know pneumonia a lung infection affects normal functioning of the lungs.

More than 1 million cases are reported every year and it affects under developed nations the most.

A general physician recommends x-ray image to be conducted to examine the condition and take
further action.

However there is a severe shortage of experts in under developed nations, therefore a low cost
method to diagnose pneumonia is needed. Thus, computer aided diagnosis systems could become
viable tools or addressing these issue.

In my project I used transfer learning technique wherein I used 2 existing architectures namely
inception model and densenet121 with pretrained weights on IMAGENET dataset.

Effectiveness of using pretrained models in medical image analysis is an area under research.

To study this effects I considered 2 configurations wherein in 1 configuration used pretrained


weights and in other configuration is initialized the above models with random weights. All layers of
the existing model are then set as non-trainable. The last 6 layers are then removed.

The reason for choosing pretrained weights is that, it’s computationally inexpensive and performs
better than training from scratch.

Transfer learning has become most popular method of choice for the implementation of medical
image analysis because this approach requires less computational power.

Transfer learning: It is a practice of employing the structure and corresponding weights of pre-
trained models for tasks and datasets for which they have not been originally designed.

The opposite of transfer learning is training from scratch, i.e. model weights are randomly initialized.

For example, Stephen et al. constructed their own convolutional neural network (CNN) model that
achieved high classification accuracy for pneumonia on chest x-ray images [7]. Its crucial drawback is
its high development cost, making it a hurdle for deployment.

Therefore, whether deep transfer learning is generally more effective compared to training from
scratch in the medical setting is still subject to research.

The objective of this study is to investigate the use of deep transfer learning to classify pneumonia
among chest X-ray images. Experimental results demonstrated that, with small training epochs, deep
transfer learning can bring performance advantages over training from scratch. two models,
Inception V3 and DensetNet121, were trained separately with 20 epochs using deep transfer
learning and from scratch.

Dataset :

University of California San Diego Chest X-ray having 5,606 images which is of 4 GB size. out of which
number of normal images is 3500 and of pneumonia is 2000. Training 80 % and Validation 20%
Data augmentation allows us to improve the diversity of the given data for training without the
burden of collecting more data. Some of the data augmentation techniques are cropping, padding,
zooming, flipping, etc. As the size of the dataset is fairly small some of these techniques we utilized
to improve the veracity of the data and are shown in Table III. Random rotation- Input images were
rotated by 10 degree. Random Horizontal Flip- Some input images were randomly flipped with a
probability of 0.5. Random grayscale- Some input images were converted to grayscale with a
probability of 0.1. Random affine- affinity is used to preserve the lines with a probability of 0.05.

Methodology :

The idea of transfer learning is to finetune existing models which have been pre-trained on other
datasets for the specific classification tasks. This approach makes the training task less
computationally expensive, since salient features of a chest X-ray image have already been learned
by the model.

Architecture :

A model architecture for deep transfer learning, with two configurations, is explored for pneumonia
classification. An illustration of the model architecture, with two configurations, is depicted in Fig. 2.

1) Layer 0 - Existing model: An existing model is obtained with either Configuration A - initialized
with random weights or Configuration B - initialized with ImageNet weights. All layers of the existing
model are then set as non-trainable. The last 5 layers are then removed.

2) Layer 1 - Global Average Pooling (GAP): Following [13], a GAP layer is added to connect to the
existing model.

3) Layer 2 - Dropout Layer: To reduce over-fitting, a dropout layer is added [14]. The dropout
parameter is set as 0.2, i.e., 20% of the inputs would be randomly set as zeroes.

4) Layer 3 - Dense Layer: A dense layer is added with 512 neurons (relu activation). To reduce over-
fitting, following [15], a L2 regularization factor of 0.0005 is added.

5) Layer 4 - Dropout Layer: To reduce over-fitting, a dropout layer is added [14]. The dropout
parameter is set as 0.2, i.e., 20% of the inputs would be randomly set as zeroes.

6) Layer 5 - Classification Layer: For the binary classification of pneumonia, a dense layer with 1
neuron (sigmoid activation) is added.

Dropout is a regularization technique used to drop or ignore some of the neurons while training and
the weights of such neurons are not trained, which can be viewed as adding noise to the input.
Dropout helps in avoiding the model overfitting the data. For this study, a dropout rate of 0.5 was
considered.
Precision :

Precision is the ratio between the True Positives and all the Positives. For our problem statement,
that would be the measure of patients that we correctly identify having a pneumonia out of all the
patients actually having it

Precision also gives us a measure of the relevant data points. It is important that we don’t start
treating a patient who actually doesn’t have a pneumonia ailment, but our model predicted as
having it.

Recall :

The recall is the measure of our model correctly identifying True Positives. Thus, for all the patients
who actually have heart disease, recall tells us how many we correctly identified as having a heart
disease.

Recall also gives a measure of how accurately our model is able to identify the relevant data. We
refer to it as Sensitivity or True Positive Rate. What if a patient has heart disease, but there is no
treatment given to him/her because our model predicted so? That is a situation we would like to
avoid!
1. What does a CNN network consist of?

Convolution neural network (CNN’s) is a deep learning algorithm that consists of


convolution layers that are responsible for extracting features maps from the image using
different numbers of kernels. Then there come pooling layers that reduce these dimensions.
There are again different types of pooling layers that are max pooling and average pooling
layers. Also, the network comprises more such layers like dropouts and dense layers. The
below image shows an example of the CNN network.

2. What is BatchNormalization? Where is it used?

Batch normalization is a layer that allows every layer of the network to do learning more
independently. It is used to normalize the output of the previous layers. The activations scale
the input layer in normalization. Using batch normalization learning becomes efficient also it
can be used as regularization to avoid overfitting of the model. The layer is added to the
sequential model to standardize the input or the outputs. It can be used at several points in
between the layers of the model. It is often placed just after defining the sequential model and
after the convolution and pooling layers. The below code shows how to define the
BatchNormalization layer for the classification of handwritten digits. We will first import the
required libraries and the dataset. Use the below code for the same. 

3. What are Dropouts? Where are they used?

Dropouts are the regularization technique that is used to prevent overfitting in the model.
Dropouts are added to randomly switching some percentage of neurons of the network. When
the neurons are switched off the incoming and outgoing connection to those neurons is also
switched off. This is done to enhance the learning of the model. Dropouts are usually advised
not to use after the convolution layers, they are mostly used after the dense layers of the
network. It is always good to only switch off the neurons to 50%. If we switched off more
than 50% then there can be chances when the model leaning would be poor and the
predictions will not be good.  Let us see how we can make use of dropouts and how to define
them while building a CNN model. We will use the same MNIST data for the same. 

Max pooling :is a sample-based discretization process. The objective is to down-sample an


input representation (image, hidden-layer output matrix, etc.), reducing it’s dimensionality
and allowing for assumptions to be made about features contained in the sub-regions binned.

Batch Normalization: normalization (shifting inputs to zero-mean and unit variance) is often
used as a pre-processing step to make the data comparable across features. This therefore
leads to higher learning rate and better speed.

To learn more about Batch Normalization, take a look at:


https://www.quora.com/Why-does-batch-normalization-help 166

Drop out: Its a regularization function that reduces/prevents overfitting, by normalizing some
pixels to 0.

Conclusion:
In this study, we explored the use of deep transfer learning to classify pneumonia in chest X-
ray images. In our experiments, three models, namely ResNet-50,Inception V3 and
DensetNet121, were trained separately with 20 epochs using deep transfer learning and from
scratch. Transfer learning achieved better results than training from scratch, an effect that
may be generally expected but needs verification in medical domains. It has thus been
demonstrated that with a small number of training epochs, transfer learning can bring
performance advantages over training from scratch, when we are dealing with vision-based
diagnostic cases such as pneumonia. The results support the effectiveness of transfer learning,
providing a low-cost development option for systems based on deep learning for faster and
more efficient clinical deployment.

You might also like