Pneumonia represents a life-endangering and deadly disease that results from a viral or bacterial infection in the human lungs. The earlier pneumonia’s diagnosing is an essential aspect in the processes of successful treatment. Recently, the developed methods of deep learning that include several layers of processing to comprehend the stratified data representation have obtained the best results in various domains, especially in the identification and classification of human diseases. Therefore, for improving the systems’ performance for detecting pneumonia disease, there is a requirement for implementing automatic models based on deep learning models that have the ability to diagnose the images of chest X-rays and to facilitate the detection process of pneumonia novices and experts. A convolutional neural network (CNN) model is developed in this paper for detecting pneumonia via utilizing the images of chest X-rays. The proposed framework encompasses two main stages: the stage of image preprocessing and the stage of extracting features and image classification. The proposed CNN model provides high results of precision, recall, F1-score, and accuracy by 98%, 98%, 97%, and 99.82%, respectively. Regarding the obtained results, the proposed CNN model-based pneumonia detection has achieved a better result of consistency and accuracy, and it has outperformed the other pretrained deep learning models such as residual networks (ResNet 50) and VGG16. Furthermore, it exceeds the recently existing models presented in the literature. Thus, the significant performance of the proposed CNN model-based pneumonia detection in all measures of performance can provide effective services of patient care and decrease the rates of mortality.

1. Introduction

Pneumonia represents inflammation of lung parenchyma that can result from chemical and physical factors, immunologic injury, pathogenic microorganisms, and other improper pharmaceuticals [1]. Pneumonia can be categorized into noninfectious and infectious relying on various pathogeneses in which noninfectious pneumonia can be categorized into aspiration pneumonia and immune-related pneumonia, while infectious pneumonia can be categorized into the virus, bacteria, chlamydial, mycoplasmas, etc. [2]. The accelerated detection of pneumonia and the subsequent implementation of proper medicine can assist considerably to avoid patients’ condition deterioration that ultimately may lead to death [3].

In the last decades, various technologies have appeared like genomics and imaging that offer a complicated and enormous amount of health care data [4]. Chest X-ray images represent the preferable technology in diagnosis pneumonia; however, these images are somewhat not obvious and sometimes misclassified to benign abnormalities or other diseases by the expert radiologists, which lead to giving the wrong medicine to the patients and consequently worsening the patients’ condition [5]. There is a requirement for an automatic and intelligent model to assist radiologists in diagnosing various kinds of pneumonia from the images of chest X-rays [6].

Deep learning represents a subdomain of machine learning regarding algorithms motivated via the structure and function of the brain [7]. The recently developed algorithms of deep learning promote the quantification, identification, and classification of patterns within medical images. Deep learning algorithms are capable of learning features simply from data, rather than hand-designing features depending on field-specific knowledge. The recently utilized model of developed deep learning is the convolutional neural network (CNN). This model of layers works on processing images and coming up with extracting low levels of features (like edges) within images. The layers of CNN can successfully capture the temporal and spatial dependencies in images with the assistance of filters. In contrary to the layers of normal feed-forward, the CNN layers include considerably fewer parameters and utilized a technique of weight sharing, consequently, decreasing the effort of computation. Thus, this developed model helps medical practitioners in diagnosing and classifying specific medical conditions effectively [8].

The main contribution of this work is to provide an effective deep learning framework for detecting pneumonia using the images of chest X-rays with a balanced performance in accuracy and complexity terms, furthermore providing medical and radiologist experts with a lower cost tool. The attended objectives are as follows: (i)Firstly, applying CNN model to detect pneumonia from the images of chest X-rays as feature extraction and classification scheme(ii)Secondly, investigating the performance of CNN and other deep learning models in classifying pneumonia(iii)Finally, developing a model capable of detecting normal and abnormal (pneumonia) images

The residual of this paper is organized as follows; an examination of related works is stated in Section 2. The proposed deep learning model for detecting pneumonia is explained in Section 3, and its efficiency is shown in Section 4. Finally, Conclusions of this paper are highlighted in Section 6.

Ayan and Ünver [9] compared two CNN models (VGG16 and Xception) for diagnosing pneumonia. In these models, transfer learning and fine-tuning are utilized in the stage of training. The obtained results demonstrated that the Vgg16 model exceeds the Xception model in several metrics: accuracy, specificity, precision, and f-score, by 0.87%, 0.91%, 0.91%, and 0.90%, respectively, while the Xception model exceeds the VGG16 model in sensitivity metric by 0.85%. Furthermore, the Xception model is more effective than the other model in detecting cases of pneumonia, while the VGG16 model is more effective in detecting normal cases. But these models require to be ensemble (combine the strengths) for achieving more effective results in diagnosing pneumonia. Hashmi et al. [10] proposed a model for pneumonia detection in chest X-ray images. In this model, firstly, the dataset was augmented; then, predictions from the pretrained deep learning models (Xception, Inception V3, ResNet 18, MobileNetV3, and DenseNet121) were combined, by utilizing a weighted classifier for computing the final prediction. This proposed model outperforms the other individual models and achieves an accuracy of 98.43%. But the utilized models had highly complex constructions; therefore, it is necessary to provide a model in which the weights according to various models are estimated effectively. Jain et al. [11] presented six CNN models for classifying chest X-ray images into pneumonia and nonpneumonia. These models have differed in the number of utilized parameters, hyperparameters, and convolutional layers. The first and second models include three convolutional layers and provide 85.26% and 92.31% of accuracy, respectively, while the other models are pretrained models (VGG16, VGG19, Inception V3, and ResNet 50) which provide 87.28%, 88.46%, 70.99%, and 77.56% of accuracy, respectively. These presented models are focused on the recall metric as a performance evaluator for minimizing the number of false negatives. The best-obtained recall was achieved by the second model which was 98%. However, these models require to improve the accuracy of classification via fine-tuning each parameter and hyperparameter. Al Mamlook et al. [12] presented seven models for detecting and classifying pneumonia from the images of chest X-rays; these models are random forest, decision tree, -nearest neighbor, adaptive boosting, gradient boost, XGBboost, and CNN. Particularly, all these models were compared using f-score and accuracy score. The CNN model exceeds the other machine learning models with a small margin, and the obtained score of accuracy was 98.46%. Surprisingly, the random forest model achieved well and the score of accuracy was 97.61%. However, these presented models need to construct a large database for training and testing to provide better results. Wu et al. [13] proposed an improved median filtering based on the CNN model using a random forest algorithm. In this model, the adaptive median filter was firstly utilized for removing noises within the images of chest X-ray to be more easily recognizable; then, the architecture of CNN was established depend on dropout for extracting the features of deep activation from each image. Finally, a random forest dependent on GridSearchCV class was employed as a classifier for the features of deep activation in the CNN model. This proposed model not only works on avoiding the overfitting phenomenon in data training, however improving the image classification accuracy as well. The achieved score of accuracy was 96.9% for image size and 93.8% for image size. Regarding the achieved accuracy, the achieved scores for precision, recall, and F1-score were 90%, 95%, and 97.7%, respectively. But this model requires improving the CNN model’s performance to be more efficient with no further preprocessing work. Chouhan et al. [14] presented a deep learning approach to detect pneumonia based on transfer learning. In this framework, firstly, the chest X-ray images were resized to ; then, the augmentation techniques (random horizontal flip, random resized crop, and a varying intensity) were utilized. After that, the features were extracted from images via utilizing several pretrained models on the dataset (AlexNet, Inception V3, DenseNet121, ResNet 18, and GoogLeNet) to be passed to the classifier for prediction. Finally, an ensemble model was employed that utilized the pretrained models and exceeded individual models. The obtained scores of recall and accuracy were 99.62% and 96.4%, respectively. But the performance of this framework requires further improvement either by increasing the size of the dataset or utilizing hand-crafted features. Zhang et al. [15] presented a model based on CNN for diagnosing pneumonia. In this model, the technique of dynamic histogram equalization was firstly utilized to improve the contrast of chest X-ray images; then, the VGG-based CNN model was designed for features extraction and classification. This presented model can classify abnormal and normal chest X-ray images with a 94.41% precision rate and 96.07% accuracy rate. But this model requires exploring a more accurate architecture of classification for diagnosing pneumonia. Manickam et al. [16] preprocessed the input images of chest X-rays for identifying the existence of pneumonia via utilizing the architecture of U-Net based segmentation and classified pneumonia as abnormal and normal via utilizing pretrained models (Inception V3, ResNet 50, and Inception-ResNet V2). The ResNet 50 model exceeds the other models with 96.78% recall, 88.97% precision, 92.71% F1-score, and 93.06% accuracy.

Most of these related works are based on the utilization of a pretrained structure of neural network or finding a specific structure with a specific number of layers. When the number of layers is increased besides the complexity of the features to be detected via the neural network for achieving the required task, the complexity of computations will be increased with no implying any accuracy improvement. Furthermore, the utilization of a few layers can decrease the neural network’s accuracy, since the features at the needed level of complexity are not detected. Therefore, the main aim of this work is to implement an effective deep CNN model on a publicly accessible dataset for detecting pneumonia by achieving a balanced performance in accuracy and complexity terms.

3. Proposed Methodology

The proposed deep learning framework has been constructed and trained many times with various parameters for choosing the preferable hyperparameters and providing a balanced-performing architecture. Generally, it encompasses two main stages. The first stage involves several image preprocesses; firstly, the process of image resizing which is implemented to obtain image size and, secondly, rescaling the value of the image’s pixel to [0,1] interval, while the second stage represents extracting features and image classification utilizing the proposed CNN models.

The proposed CNN model is applied to detect pneumonia from the images of chest X-rays as feature extraction and classification scheme. Figure 1 shows the general structure of the proposed model for detecting pneumonia disease. This structure includes three main parts. The input layer in the CNN model represents the first part (layer) of the CNN structure that passes the input chest X-ray image of size to the next parts.

The feature extraction represents the second part of the CNN structure which includes three blocks, and each block includes the convolution layer, maximum pooling layer, and dropout layer. In the convolutional layer, the input images are converted into matrix forms. The operation convolution is implemented within the input matrix and a feature kernel of dimension, and the outcome represents a feature map. This operation works on reducing the image dimensions to make it easier to be processed.

In order to achieve better performance, all the convolutional layers are followed by the Rectified Linear Unit (ReLU). ReLU is the widely utilized activation function that thresholds the inputs (converts the input to 0 if it is valued less than 0) and creates a nonlinear output.

After that, the max pooling layer is utilized for recognizing the prominent features within the image and reducing the image’s dimensions and the parameters, consequently decreasing the computational complexity. The max pooling layer with a dimension operates on every feature map and scales its dimensions by utilizing the function “MA” which works on selecting the highest value of a pixel from the image window. The dropout is added to the max pooling layers for preventing overfitting.

The output of the second part is subsequently passed to the third part which is the classification part. This part includes several layers; firstly, the flattened layer that is utilized for changing the shape of the data to a one-dimensional vector, secondly, three dense layers each of which is followed by the dropout layer and, finally, the dense layer of sigmoid activation function that works on classifying output image into normal or abnormal. The number of parameters that are utilized in the CNN model for detecting pneumonia disease is demonstrated in Table 1.

As demonstrated in Table 1, the proposed CNN model encompasses twelve layers (six convolutional layers, three max pooling, and three dense layers), and the number of trainable parameters was 103,980,418.

4. Computational Experiments

Python programming language was utilized in the implementation of the proposed deep CNN, ResNet 50, and VGG16 models. Google Colab was utilized for GPU runtime in the stages of training and validation. Each model was fine-tuned for 100 epochs, with 128 batch-size. The NAdam optimizer was utilized for optimizing the function of learning with 0.001 learning rate.

Regarding the implemented pretrained CNN models, VGG16 included sixteen layers (thirteen-convolution and three-dense), and the ResNet 50 included fifty layers (forty-eight-convolution, one-max pooling, and one-average-pooling). VGG16 had approximately 134 million trainable parameters, and ResNet 50 had approximately 23 million trainable parameters. The same image preprocessing steps are utilized in the implemented pretrained models, while the feature extraction and classification steps follow the structure of each model.

4.1. Dataset Description

The three deep learning models for pneumonia detection are trained and tested on the images of the chest X-ray dataset [17], which includes 5880 samples, 80% (4707 samples) were utilized for training these models, and 20% (1173 samples, 855 abnormal, and 318 normal) were utilized for testing. Figure 2 manifests examples of chest X-ray images in which abnormal-viral pneumonia demonstrates an interstitial pattern in the lungs and abnormal-bacterial pneumonia demonstrates the consolidation of focal lobar, while the normal image demonstrates pure lungs without any abnormal opacification areas in the chest X-ray.

4.2. Evaluation Metrics

The utilized performance metrics for identifying the best model are precision, recall, F1-score, and accuracy. In order to compute these metrics, True Negative “,” True Positive “,” False Negative “,” and False Positive “” are provided. The lower the , the fewer classifiers’ performance that capable of detecting normal and abnormal (pneumonia) images. The higher the , the higher classifiers mistakes that misclassify pneumonia images as normal images and conversely. The specificity metric indicates the ability of classifiers to recognize the normal images; it is assigned by as in

The precision metric works on measuring the real abnormal (pneumonia) image percentage from all predicted abnormal images, as in

The recall metric (sensitivity) is a properly classified class from the model of classification, and the sensitivity with a high value will make the model more reliable and robust. This metric is associated with , as in

The accuracy metric is utilized for measuring the classification models’ performance, and in other words, it represents the total classifier performance that is measured by

And finally, F1-score indicates the classifiers’ ability of classification via utilizing the combination of precision and recall metrics as a single evaluation metric of performance, as in

5. Results and Discussion

Tables 24 show the obtained results of the utilized metrics (precision, recall, F1-score, and accuracy) for the proposed CNN model, ResNet 50, and VGG16 models, respectively.

As indicated in Table 2, the CNN model has the best results of precision, recall, F1-score, and accuracy by 98%, 98%, 97%, and 99.82%, respectively.

The obtained results of precision, recall, F1-score, and accuracy for the ResNet 50 model (indicated in Table 3) were 95%, 95%, 95%, and 95.37%, respectively.

The obtained results of precision, recall, F1-score, and accuracy for the VGG16 model (indicated in Table 4) were 73%, 73%, 71%, and 73.40%, respectively.

The confusion matrix offers a perception of the error being obtained via the utilized classifiers. It is utilized for describing the classification performance on the test images for the known true values. Figure 3 demonstrates the confusion matrices for the proposed CNN, ResNet 50, and VGG16 models.

The experiments were achieved with 100 epochs, 128 batch size, and “Nadam” optimizer. The accuracy per epoch and loss per epoch for the proposed CNN, ResNet 50, and VGG16 models are illustrated in Figures 46, respectively.

As demonstrated in Figure 4, the obtained curves of training and validation accuracy and training and validation loss for the proposed CNN model with 100 epochs were 99.82%, 96.53%, 0.0110, and 0.2005, respectively.

The proposed model has been evaluated by comparing it with the ResNet 50 and VGG16 models and recently presented models using the chest X-ray images as shown in Table 5.

As demonstrated in Table 5, the proposed CNN model-based pneumonia detection has achieved a better result of consistency and accuracy, outperforms the ResNet 50 and VGG16 models, and exceeds the other recently existing models presented in the literature.

6. Conclusion

A deep learning model is proposed in this paper for pneumonia disease detection from the images of chest X-rays. The number of layers is not constantly lead to improve the accuracy, and increasing the networks’ layers may yield negative performance. Throughout the construction of the CNN model, an indisputable number of layers was attained that provided the best accuracy.

The obtained results demonstrated that the proposed CNN model-based pneumonia detection has the best high results of precision, recall, F1-score, and accuracy by 98%, 98%, 97%, and 99.82%, respectively, and this leads to the ability to utilize this model rather than other implemented models as a supplement for radiologists in the process of decision-making. The achieved results support the concept that deep learning models are capable of simplifying the process of diagnosis and improving the management of pneumonia disease and thus leading to improve treatment quality. Furthermore, the proposed CNN model exceeds the other recently existing models presented in the literature. This proposed model can be effectively implemented in diagnosing pneumonia disease and other diseases like COVID-19.

Data Availability

All data are available within the manuscript.

Conflicts of Interest

The authors declare no conflicts of interest.


This paper was supported by the University of Information Technology & Communications, University of Baghdad, and Mustansiriyah University.