Classification of Pneumonia Using Deep Convolutional Neural Network

: Pneumonia is considered a serious and fatal disease worldwide. In fact, pneumonia can be an individual's life-endangering if not treated promptly by drugs. Therefore, the early detection of pneumonia enhances the chances of recovery, which helps reduce mortality. It is worth noting that X-rays are one of the most important diagnostic tools for diagnosing pneumonia. In fact, Chest X-ray is widely used in the diagnosis of many lung diseases (such as: Breast Cancer, Pneumonia, Tuberculosis, etc.), due to lower diagnostic costs. Indeed, the diagnoses can be subjective for many reasons for example the appearance of disease which can be unclear in chest X-ray images or can be confused with other diseases. Hence, for enhancing the level of diagnosis to guide clinicians, computer-aided diagnosis systems will be needed. In this paper, we put forward to develop a structure to classify pneumonia from chest X-ray images using a Convolutional Neural Network (CNN) and residual network architecture. Clearly, to determine if a person is infected with pneumonia or not, we used two well-known CNN pre-trained models (ResNet50 and ResNet101), with multi-class Support Vector Machine (SVM) to classify and transfer learning from the pre-trained CNN models to extract and classify features. Thus, the proposed framework takes an X-ray image size of 224 x 224 pixels as an input and gives the final prediction Normal or Pneumonia. The experimental results showed that the classification models proved to be effective, with an accuracy range of 97% to 98.3%. More precisely, the image extraction features using Resnet50 + SVM and Transfer Learning + Resnet50 methods achieve the highest performance of Accuracy of 98.3% and 97.8%, respectively.


Introduction
Pneumonia is a deadly disease that has claimed the lives of many people worldwide, within one year, about 500 million people were infected with pneumonia and about 4 million people died as a result of this disease [1].In fact, patients with pneumonia may experience some side effects, which may be, for example, a cough that produces phlegm or blood, difficulty breathing, cold, fever, shivering, fatigue, sweating, or other symptoms.Those most in danger of having pneumonia are small kids or individuals beyond 65 years old [21].It should be mentioned that in high-income countries, lower respiratory tract infections, including pneumonia, are classified as a common serious and fatal disease, especially among the elderly [2].Pneumonia develops when the lung is infected with certain viruses or bacteria, but this infectious disease can be treated with antibiotics or antiviral drugs, where a rapid diagnosis can help prevent the patient's condition from deteriorating [3].Doctors diagnose pneumonia in hospital patients by a physical examination, medical history, clinical investigations such as sputum or blood tests, chest X-rays, and other imaging techniques [22].In fact, chest X-rays are presently the best imaging tests performed for diagnosing pneumonia [4], as it is widely used in the diagnosis of many lung diseases (cancer, tuberculosis, pneumonia, etc.), due to lower diagnostic costs [5].
Recently, numerical computing has been evolved for medical image analysis [6], including machine learning and deep learning techniques [7].These technologies have helped scientists in spontaneous diagnosis through high accuracy chest X-rays images, at a level that exceeds radiologists.
It should be noted that deep learning (DL) algorithms are among the best techniques used in medical image analysis, which is a special type of artificial neural network (ANN) inspired by the human cognition system, is being investigated.Convolutional Neural Networks (CNNs) are the most favorite and popular deep learning models with superior achievements in the medical imaging domain since it provides high accuracy and impressive results compared with other models [8][9][10][11].
In machine learning, there are many techniques for feature extraction, among which we can mention the following: Histogram of Oriented Gradients (HOG) and Speeded-up Robust Features (SURF).However, these techniques face the inability to extract features accurately, which leads to a decrease in classification accuracy.Therefore, other techniques are needed to accurately extract features.
In this paper, we propose a framework for classifying pneumonia by performing chest x-ray imaging, which can help improve image quality, to be suitable for feature extraction.Therefore, we used both the convolutional neural network and the residual network to boost the accuracy and effectiveness.
The rest of this paper is organized as follows: the next Section 2 presents related works.Section 3 describes the materials and methods.In Section 4, we present the obtained results and discussion.Finally, Section 5 concludes this paper.

Related Work
To detect lung-related diseases, a chest x-ray is required to determine pulmonary problems.Many studies were conducted to detect pneumonia by performing chest X-rays, based on the CNNs, with different approaches.For example, Stephen et al. proposed a CNN model that was trained to classify Pneumonia using chest X-rays.The authors provided an accuracy of 95.31% of the proposed model [12].Chouhan et al. presented a framework to classify pneumonia using a transfer learning method with five pre-trained models, which are: AlexNet, DenseNet121, Resnet18, GoogLeNet, and Inception V3.They showed that the proposed model extended to 96.4% accuracy with a recall of 99.62% [13].Also, a study was carried out by dataset chest X-ray images, classifying images into Pneumonia, and normal.Three pre-trained models (MobileNet, Inception-V3 and Xception) were used by the approach with transfer learning, training time data was used to augment the data set, and finally, the ensemble model was produced.The authors showed that the accuracy obtained exceeds the result of previous studies [14].
Moreover, Rahman et al. use four pre-trained CNNs models to transfer learning, which are: AlexNet, ResNet 18, DenseNet 201, and SqueezeNet.The authors considered three classification schemes, and we can explain it as follows: normal and pneumonia with 98% accuracy, bacterial and viral pneumonia with an accuracy of 95%, and normal, bacterial, and viral pneumonia with an accuracy of 93.3% [15].Ayan and Ünver used the CNN Xception and Vgg16 models to diagnose pneumonia.The authors demonstrated that the used Vgg16 model outperformed the Xception model with an accuracy of 87% and 82%, respectively [16].Rajaraman et al. proposed a visualization strategy for the localization of the region of interest.They showed that the applied VGG16 model obtained an accuracy of 96.2% for disease classification and 93.6% for distinguishing between bacterial and viral pneumonia [17].
A pneumonia diagnosis system was developed using a convolutional neural network (CNN) to extract features and three different algorithms that were used in the classification stage.The InceptionV3 pre-trained CNN model was used to extract features from chest x-ray images, and then the features extracted from the (InceptionV3) training model were used to train three models of classification algorithm to predict pneumonia cases from the Kaggle dataset.The three models are Neural Network (NN), K-Nearest Neighbor (KNN), and Support Vector Machines (SVM).In this work, Neural Network NN achieved a high accuracy of 86.3% compared to SVM (84.5%) and kNN (84.3%) [23].Furthermore, a system for classifying pneumonia from chest x-rays has been proposed.The proposed method is based on the use of VGG16, VGG19, and DenseNet169 networks.The authors showed that the accuracy of the classification is highly dependent on the number of images, the accuracy of the images, and whether the X-ray image is properly classified.Furthermore, they showed that the proposed method gives relatively positive classification results with an accuracy of approximately 85% [24].

Dataset
In this paper, we used the Kaggle dataset which contains 5863 X-Ray images (JPEG).The dataset is categorized into 3 which are training, testing, and validation, each image category consists of subfolders like Normal and Pneumonia.Clearly, chest X-ray images (anterior-posterior) have been examined by the review accomplices of pediatric patients within the age group (1 to 5 years) collected from Guangzhou Women and Children Medical Center, Guangzhou, Southern China.We took all chest X-ray imaging and applied them as a major aspect of patients' normal clinical consideration [18].In Figure 1, we present a sample of a normal chest X-ray image and pneumonia.

Preprocessing
In the pre-processing stage, we resize each image to a suitable size.For each CNN Pre-trained model, the images must be resized to make them compatible with the input size (for the CNN Pre-Trained model).For the two used models (resnet50 and resent101), the images have been resized to size of 224 x 224 pixels and any grayscale images have been converted to RGB images.

Proposed Model
In Figure 2, we describe the architecture of our proposed framework.

Convolutional Neural Network
Deep residual networks (ResNets) have a specialized layer called residual blocks with shortcut connections which are followed by an FC layer at the top of the network.In addition, ResNet-50 consists of 17 residual blocks while ResNet-101 is much deeper and contains 33 residual blocks.For more details of these network architectures, the reader is invited to consult the papers by He et al. [19], Szegedy et al. [20].

Extract Image Features Using a Pre-trained Network
In this method, we first loaded the pre-trained networks, and then extracted the image features from specified layers.Next, we train the SVM classifier using the features extracted from the layers.Finally, we tested the SVM model using the features extracted from the images that have been tested.
Transfer learning using a pre-trained network.
In this method, we have done the following: 1) we loaded the pre-trained networks (resent50 and resent101), 2) we replaced the final layers with new adapted layers for the new dataset, 3) then, classes numbers were specified (in this study 2-class) in training images, 4) finally, we trained the network and tested the trained network by classifying test images.

Performance Measures
This phase aims to evaluate and compare the performance of different pre-trained models using four performance measures, which are accuracy, sensitivity, Specificity and F1 score, which were calculated as in as in Eq. 1, as in Eq. 2, as in Eq. 3, and as in Eq. 4.
In fact, the performance of the classification model is described through a confusion matrix as shown in Figure 3.It should be noted that TP represents the number of true positive and denote the number of people who have pneumonia according to the model, TN represents true negative and denote the number of people who are normal and categorized as normal according to the model, FN represents false negative and denotes the number of people who are actually with pneumonia but categorized as normal according to the model, and FP represents false positive to the number of people who are normal but categorized as pneumonia, according to the model.The accuracy is the actual number of correctly calculated predicted labels as in Eq. 1.

Accouracy TP TN TP TN FP FN
The proportion of actual positive samples that correctly is given by sensitivity measures, and can be calculated as in Eq. 2.

TP Sensitivity TP FN
Furthermore, in this study, we will be focusing on specificity as measures the proportion of identified negative samples, in which the percentage of normal images is correctly classified as normal, and can be calculated as in Eq. 3.

TN Specificity
TN FP = + In addition, F1-score measures the average F1-score through different class labels that can be calculated as in Eq. 4.

Results and Discussion
The main goal of our proposed framework is the adequate diagnosis of pneumonia from chest X-ray images.Therefore, all the models that we explained above were prepared and trained separately.Then, we conducted training and testing using a Windows platform computer with an Intel Core i5-CPU @ 2.7 GHz configuration with 8 GB of RAM.
Performance measurements for all proposed methods (Resnet50 + SVM, Transfer learning + Resnet50, Resnet101 + SVM and Transfer learning + Resnet101) are presented in Table 1.We can see that the Resnet50 + SVM achieved a better F-score and accuracy.In Figure 8, the comparative performance of the classification accuracy of our models on pre-trained CNNs is presented.We can see that for all the proposed models, Resnet50 + SVM produces the highest accuracy, the classification accuracy was 98.3%.In general, we can also see that the image extraction features using Resnet50 + SVM and Transfer Learning + Resnet50 methods achieve the highest performance of Accuracy of 98.3% and 97.8%, respectively.Also, Resnet50 + SVM and Transfer Learning + Resnet50 methods achieve the highest performance of F1-score of 98.2%% and 97.4%, respectively, (see Figure 9), which outperformed the methods of Resnet101 + SVM and Transfer Learning + Resnet101.From the presented state-of-the-art and our results, we can conclude that there are several studies were conducted to detect pneumonia by performing chest X-rays images, based on the CNNs, with different approaches, either by transferring learning or building a model from scratch.Moreover, many results have been presented and evaluated.In this paper, we suggest a novel framework for classifying pneumonia from chest X-ray images using pre-trained CNN models (ResNet50 and ResNet101).It is worth mentioning that, to the best of our knowledge, the best model achieves an Accuracy of 98% [15], while our experimental results showed that our proposed methods reached an accuracy range of 97% to 98.3%.So, the results of our study are the best achieved so far.

Conclusion
This paper provides a framework for classifying pneumonia from chest X-ray images using pre-trained CNN models.We implemented two pre-trained CNN models (ResNet50 and ResNet101) for feature extraction and a SVM for classification and transfer learning from pre-trained CNN models to extract and classify features.The experimental results showed that the features of image extraction using a pre-trained network method have outperformed the transfer-learning method in terms of accuracy.In fact, the Resent50 + SVM model is more accurate compared to the other models.

Figure 1 .
Figure 1.Shows a sample of a Normal chest X-ray image and a Pneumonia chest X-ray image.

, 6 ,
and 7 show the confusion matrix of pneumonia for two classes.

Figure 8 .
Figure 8.Comparison of Accuracy results for the proposed methods.

Figure 9 .
Figure 9.Comparison of F1-score results for the proposed methods.

Table 1 .
Comparison of the results with approaches in metric measurements.