{'fraction_non_alphanumeric': 0.029399802451920285, 'fraction_numerical': 0.012375806170472372, 'mean_word_length': 4.731601731601732, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A deep learning approach for detecting pneumonia in chest X-rays

Pneumonia causes the death of many children every year and constitutes a certain proportion of the world population. Chest X-rays are primarily used to diagnose this disease, but even for a trained radiologist, chest X-rays are not easy to interpret. In this study, a model for pneumonia detection trained on digital chest X-ray images is presented to assist radiologists in their decision-making processes. The study is carried out on the Phyton platform by using deep learning models, which have been widely preferred recently. In this study, a deep learning framework for pneumonia classification with four different CNN models is proposed. Three of them are pre-trained models, MobileNet, ResNet and AlexNet and the other is the recommended CNN Model. These models are evaluated by comparing them with each other according to their performance. The experimental performance of the proposed deep learning framework is evaluated on the basis of precision, recall and F1-score. The models achieved accuracy values of 93%, 97%, 97% and 86%, respectively. It is clear that the proposed ResNet model achieves the highest results compared to the others.


Introduction
Infectious diseases are one of the most important factors that threaten human health from past to present. Pneumonia comes first among the infectious diseases [1]. Pneumonia is defined as lung inflammation that occurs as a result of the effects of living things such as viruses and bacteria on the microscopic air sacs [2], [3]. Every year, approximately 7% of the world population is affected by pneumonia, and approximately 4 million of these affected patients die [8]. Early diagnosis is very important in such diseases [4]. Typical symptoms include chest pain, shortness of breath, cough etc. takes place. Diagnostic tools include sputum culture and chest X-ray images [5].
Artificial intelligence, which has become popular in recent years, tries to make computers more useful by trying to understand the nature of human intelligence. Machine learning and deep learning, which are sub-branches of artificial intelligence used in many fields, also promise to help experts in the early diagnosis of diseases. CNN-based deep networks have been developed differently by researchers and these networks have been applied to classification, segmentation, object detection and localization, especially in computer vision [6]- [8]. Also, besides computer vision problems, CNNs are used for breast cancer detection [9], brain tumour segmentation [10], Alzheimer's disease diagnosis, skin lesion classification [11], [12] etc. Successful results have been observed by using it in the solution of medical problems.
The following tests can be performed for the diagnosis of pneumonia: Chest X-ray, Lung CT, Chest ultrasound, Lung needle biopsy Chest MRI [5]. Currently, a chest X-ray is one of the best methods for detecting pneumonia [6]. X-ray imaging is preferred over CT imaging, as CT imaging typically takes significantly more time than X-ray imaging, and many undeveloped areas lack adequate high-quality CT scanners. In contrast, X-rays are the most widely available diagnostic imaging technique. When the studies in the literature are examined, there are many studies, especially in the detection of pneumonia.
In the study given in [13], Kieu et al. used multiple CNN constructs to detect abnormal (abnormal) rib cage images. In this method, a rib cage image is divided into three parts as right, left and whole and used as inputs for different ESA models. Then the result of the CNN models is combined with the Fusion method. The applicability of the proposed multiple CNN method is shown with the result of 96% obtained as a result of the study.
In [14], Ivo M. Baltruschat et al., performed the classification of 14 different diseases in 112120 lung X-ray images provided by The National Institutes of Health (NIH) Clinical Center with different hyper parameters of the ResNet50 and Resnet38 models. ResNet38 and ResNet101 also conducted similar studies. Baltruschat has shown that ResNet models get the best results with ResNet38.
In [15], O'Quinn et al. They carried out their studies using 5659 images in DICOM format to detect pneumonia disease. In this study, 70% of the dataset is used for training and the rest for testing. By using the AlexNet deep learning network in learning transfer, 76% recognition success is achieved in this method. In [16], Wang et al. developed a deep CNN method and presented a study for the detection of 14 thoracic cage diseases called Thorax-Net. In this method, it is included in the classification and attention section. A result has been obtained by using the outputs of these two sections with Thorax-Net. They have shown that with the Thorax-net architecture, the area below the average ROC per class reached 0.7876.
In [17], Hammoudi et al. They have worked on deep learning models that could be used to diagnose pneumonia using radiographic images to assist healthcare professionals. ResNet34, ResNet50 and DenseNet169 have used different deep learning methods (Inception ResNetV2-RNN) such as VGG-19 and dual usage model. They attempted to classify X-ray images of the rib cage as viral pneumonia, bacterial pneumonia, and normal, and obtained different results for each model used.
The aim of this study is to provide radiologists and medical professionals with a low-cost software tool to review their interpretation of the disease in the diagnostic process and identify other potential findings that may be overlooked, using deep learning methods that have achieved great success in medical image classification of pneumonia, a disease for which early diagnosis is very important. Also, in many developing countries, people's access to radiologists is limited due to the high cost. With this software, healthcare professionals will be able to help interpret X-ray images. For this purpose, rib cage X-ray images shared on Kaggle, a community of online data scientists and machine learning practitioners, are used. In this dataset, there are a total of 5840 X-ray images, consisting of two classes, Normal and Pneumonia.
In this article, a study about the deep learning methods used in the field of health and the classification of pneumonia, which is the aim of this study in the literature, is presented.

Dataset
X-rays in datasets are labeled by their respective clinicians. The dimensions of the tagged view counts of the data set are specified in the method section. In this study, the publicly available Chest X-ray Images (Pneumonia) dataset is used. The dataset is compiled into two subfolders containing pneumonia and normal chest X-ray images, respectively. The total number of data is 5840, with 1575 normal and 4265 pneumonia cases. In Figure  1, there are images of pneumonia and normal classes from the database. For this study, a dataset containing X-ray images of the thorax shared on the Kaggle platform is used. Among these images, low quality or unreadable ones are eliminated, and the remaining images are rated by three experts in order to be used in artificial intelligence studies. Example X-ray images of pneumonia disease are shown in Figure 1.

Deep Learning
The term deep learning refers to multi-layer artificial neural networks (ANNs). Recently, deep learning has become one of the most powerful tools in the literature because it can process large amounts of data [18]. Convolutional Neural Networks (CNN) are one of the most well-known deep learning networks. Significant successes have been achieved in studies such as voice recognition, image processing and pattern recognition using CNN. CNN is a deep neural network in which feature extraction is performed by applying the convolution operation to at least one of its layers. One of the reasons why CNN is frequently used in studies is that it handles the features in the image independently of the location.

Convolutional Neural Network
In this section, some of the most well-known CNN models used in similar studies are discussed in order to compare the results of the study.

Input layer
The input layer forms the first layer of the CNN. In the input layer, the input data is given raw to the network. In order for the computer to understand the input (image), the pixels of the input are converted into numerical data. The size of the image in the input layer in a used network is important. Large input sizes will cause a lot of memory usage and increase the number of parameters, which may slow down the network, but may yield better results as more attributes can be extracted.
In addition, since the number of parameters will decrease with small input sizes, the network may give faster results, but the performance of the network may decrease as the feature extraction is less [19].

Convolution layer
The convolution layer is also known as the feature extraction layer because the features of the image supplied to the network are extracted in this layer. The feature map of the image is created by using various filters (kernel) in the convolution layer [3]. The filters used can be of different sizes such as 2×2, 3×3, 5×5. With these filters, the convolution process is applied to the image. The coefficients of the filters change with each learning iteration in the training set during the training of the CNNs to determine which regions of the data are important in determining the attributes of the network [19].

The pooling layer
The pooling or pooling layer is generally used in CNNs to reduce the number of parameters and the computational load. It reduces the input size for the next convolution layer without affecting the depth. That is, while the height and width values of the input data decrease after pooling, the depth, that is, the number of channels, does not change. In general, two different pooling layers can be mentioned.

Activation layer
The activation layer comes after the convolution layer. Generally, this non-linear layer is used to adjust and limit the output produced [18]. The purpose of use of this layer is to reduce the negative values in the linear network formed after the convolution layer to zero, to put the network into a non-linear form and to enable the network to learn faster. It is also called the activation function. There are many different activation functions such as tanh, sigmoid, ELU, but ReLU is the most widely used.

Fully connected layer
After the successive layers of convolution, ReLU, and pooling in an CNN comes the full link layer. For the full link layer, the feature map is converted to a 1D feature vector, this is called flattening [20]. This layer is called the full link layer because it is connected to all areas of the previous layer and it is shown in Figure 3. The full link layer is used to classify images in different categories.

Convolutional Neural Network Models
In this section, some of the most well-known CNN models used in similar studies are discussed in order to compare the results of the studies. These architectures are deep learning models delivered with pre-trained weights on the ImageNet dataset. These models can be used for operations such as prediction, feature extraction and classification. A pre-trained image classification model that has learned to extract powerful and informative features from images can be taken and used as a starting point for learning a new task. Applications are made for three pre-trained models to be used for image classification. In this part, Alexnet, ResNet50 Architecture and MobileNet architecture are used.  The accuracy given in Equation 1 is a measure of how well the learning model is [21]; Accuracy, = + + + + (1) Equation 2, True Positive Rate (Recall, (TPR)) is a measure that defines how many of the positive predictions are true [21].
Recall, = + (2) Equation 3, Precision positive predictive value (PPV) is a measure that defines how many of the positive predictions are correct [21].

Results and Discussion
Google Colaboratory workspace is used to diagnose pneumonia from X-ray images. Colab is a free Python development environment based on the Jupyter notebook and cloud environment. Classification for pneumonia diagnosis from X-ray images is performed using the Python programming language. Python is a programming language with both practical and easy documentation used by many researchers working with machine learning and data science. Many libraries have been developed thanks to the work in the field of deep learning. These libraries provide convenience for the easy implementation of algorithms. Libraries used within the scope of the study are NumPy and Matplotlib.

Datasets and their application to the model
CNN models take inputs of fixed size and calculate parameters accordingly. After reading the X-ray images in the dataset, they are resized to 512 x 512 to minimize the loss of details in the images. For training and testing, the data set is randomly divided into 80% (training) and 20% (testing). Of the total of 5840 data sets, 4672 are used for training and 1168 for testing.

Network Architecture
In this section, the proposed CNN model is classified with the X-ray dataset and its performance is observed. Machine Learning algorithms create a mathematical model that associates the data in the data set with its labels. Thus, when an image is given to the model, it tries to determine which class the image belongs to. The model to be recommended is Keras' Sequential model. The training of the CNN model consisting of Sequential Convolution (CONV2D) and MaxPooling layers is carried out with the X-ray dataset. The layers of the proposed model are listed below.

Fig. 5. The used Model
The 'Adam' algorithm, which is thought to give good results in image data training, is used as the optimization algorithm, which has a great effect on model performance. The initial learning rate is very important for education. If it is selected large, it may cause it to skip the global minimum, or if it is selected too small, it may get stuck in local minimums and cannot reach the global minimum. Considering these issues, the learning rate is determined as 0.0001. The performance metric accuracy is selected.
In the designed model, the training data is trained 10 times (epoch) in 30 mini-batches (small groups). Then, testing is carried out in 15 mini-batches with the trained model test data. In the test of the model, an accuracy rate of 93% is obtained. The estimated results in classification are given in Figure 6 in the confusion matrix. The difference in the number of data between the two classes in the training data may affect the model performance. The class with more numbers can suppress the other class. In the training data we used in the study, the normal class consists of 1260 and pneumonia class 3412 samples. In this case, it is not appropriate to only take accuracy as a performance metric. Apart from accuracy, performance metrics such as precision, recall, and F1-score should also be considered. These metrics are included in the classification report given in Figure 7. The data set is also trained with pre-trained CNN models and their performance is observed. The pre-trained MobileNet, ResNet and AlexNet models are trained with the preprocessed dataset, respectively. According to classification report, 99%, 99% and 96% training accuracy is obtained from the models trained 10 times in 35 mini-batches, respectively. Trained models are tested with test data in 35 mini-batches. In the testing of the models, 97%, 97% and 86% accuracy rates are obtained. The predicted results in classification are given in each model's own confusion matrix and classification report given below Figures 8,9 and 10.

Conclusions and Recommendations
The presence of specialist radiologists is the most important requirement to accurately diagnose pneumonia disease. This study primarily aims to improve medical competence in areas where radiologists are still limited and to facilitate early diagnosis of pneumonia in order to prevent negative consequences (death etc.). Developing algorithms in this area can be highly beneficial for providing better healthcare. At this point, different models such as the proposed CNN model and pre-trained MobileNet, ResNet and AlexNet are used to evaluate chest images of pneumonia patients. The use of these models on X-ray pictures, in particular, has generated promising results. Such a finding is particularly important in that X-ray images are easily accessible and cost-effective. In this paper, four distinct CNN models are proposed as part of a deep learning framework for pneumonia classification. Three of them are pre-trained models, MobileNet, ResNet and AlexNet and the other is the recommended CNN Model. These models are evaluated by comparing them with each other according to their performance. The experimental performance of the proposed deep learning framework is evaluated on the basis of precision, recall and f1-score. The models achieved accuracy values of 93%, 97%, 97% and 86%, respectively. It is clear that the used ResNet model achieves the highest results compared to the others.