A Computationally Efficient Convolutional Neural Network for Pneumonia Detection Based on Chest X-Ray Image Classification

DOI : 10.17577/IJERTV11IS110171

Download Full-Text PDF Cite this Publication

Text Only Version

A Computationally Efficient Convolutional Neural Network for Pneumonia Detection Based on Chest X-Ray Image Classification

Vishal Vinjamuri Broad Run High School Ashburn, United States

Abstract Pneumonia is a severe respiratory disease, affecting many across the world. In developing countries and areas without sufficient resources, pneumonia is especially prevalent, with fatal outcomes if not treated appropriately. Current testing methods pose many issues including cost, accessibility, and accuracy. Several research studies have shown the drastic improvements that early diagnosis of pneumonia can have, preventing fatal outcomes. Deep learning networks have been used to aid this problem, achieving state-of-the-art accuracies in swift diagnosis. However, the large computational costs associated with these standard algorithms prove them ineffective in developing and remote areas of the world. A shallow convolutional neural network was developed to detect pneumonia based on Chest X-Ray images. This network achieved a peak accuracy of 96.21%, demonstrating its practicality and significance in such areas.

KeywordsNeural network, pneumonia, classification, X-Ray


    Pneumonia is a deadly acute respiratory disease, caused when the alveoli are infected by bacteria, fungi, or viruses [9]. This infection then causes inflammation of the air sacs and pleural effusion, filling the lungs with fluid. The three main types of pneumonia are bacterial, viral, and mycoplasma pneumonia [5]. The most common bacterial pneumonia is Streptococcus pneumoniae. Viral pneumonia is caused by viruses, including the flu, and represents approximately one- third of all cases. Mycoplasma pneumonia, also referred to as atypical pneumonia, is caused by the bacterium Mycoplasma pneumoniae, and has different symptoms and signs from the previous two types. Pneumonia accounts for approximately 14 percent of all deaths of children under the age of 5 and killed 740,180 children in the year 2019 [9]. According to the CDC, those more likely to get pneumonia include adults 65 years or older, people who smoke, and children under the age of 5 [1]. The symptoms of this disease can develop either suddenly or after several days [4]. These symptoms include a cough, rapid heartbeat, fever, loss of appetite, and chest pain. Pneumonia is prevalent in impoverished and developing countries, where pollution, overcrowding, and contamination are frequent. Early diagnosis is crucial in these areas for this reason, as it can prevent the progression of pneumonia.

    Figure 1. Map of Global Prevalence of Pneumonia [7]

    Currently, a radiological examination of the lungs is used for diagnosis, through methods including blood tests, magnetic resonance imaging, computed tomography, and radiography. Radiography X-Ray imaging is a relatively inexpensive and non-invasive way to examine the lungs. However, in developing countries, this diagnosis poses many challenges. The World Health Organization states that some of these hardships include inadequate or inappropriately trained staff, poor and low education in caregivers, and a dysfunctional health system. For these reasons, an easier, more accurate method of diagnosis is vital [8].

    Machine learning plays a crucial role in biomedical imaging problems. Specifically, deep learning has empirically been used for image classification tasks. Deep learning models including convolutional neural networks are used commonly for these tasks. These neural networks provide high accuracy and results compared with other types of architectures. Since pneumonia classification from chest X-Rays is a feature full task, our research explores the implementation of a shallow, concise, computationally efficient convolutional neural network architecture for detection at high accuracy.


    The use of artificial intelligence-based techniques for pneumonia classification tasks has been the subject of numerous studies in the past. Convolutional neural networks are preferred for image classification since they automatically extract features through several convolutions. For example,

    studies have utilized powerful multifaceted deep learning architectures for the diagnosis of pneumonia, such as VGG- 16, DenseNet, ResNet, etc. [3,6,11]. Although these approaches have obtained high accuracies, they demand great computational power for training.

    In addition, other research has been done involving using deep learning techniques for segmentation. For example, Chandra et al. used the segmentation of lung X-Rays to extract 8 features, which were then used to classify images after this segmentation [2]. Similarly, Yue et al. segmented lung lobes utilizing the U-Net architecture to extract radiomic features from CT-scan images [10]. However, there are some demerits to utilizing segmentation as a diagnostic tool. Not only are there generally small datasets, making it difficult to generalize, but handcrafted features limit the ability to compute pattern recognition tasks.

    There is a lack of algorithms that not only provide state-of- the-art accuracies but also do not demand high computational power. Therefore, the need for such algorithms is crucial for low-cost diagnosis of pneumonia as well as other disorders.


    1. Dataset Acquisition

      The data used in this work was from retrospective cohorts of pediatric patients aged 1 – 5 from the Guangzhou Women and Childrens Medical Center. The dataset consists of 5856 Chest X-Rays, with 1,583 being normal and 4,273 being patients with pneumonia. The dataset was split into a training, testing, and validation subset; 90% of the images were used for training, 10% were used for testing, and the remaining were used for validation. Examples of normal and infected X- Ray images found in our dataset are shown in Figure 2 and Figure 3.

      Figure 2. Healthy Chest X-Ray

      Figure 3. Infected Chest X-Ray

    2. Data Preprocessing

      The images in this dataset were resized to 256 x 256 pixels to reduce the time for training and memory requirements. In order to do so, a nearest-neighbor interpolation technique was utilized, where groups of pixels assume the magnitude of the pixel that is closest to it. This technique was very efficient, as previous images were of varying sizes, allowing for better interpolation compared with cropping or resizing.

    3. Convolutional Neural Network Architecture

    Since images are classified as either pneumonia or healthy, this is a binary classification problem. To accomplish this task, a 15-layer computationally efficient convolutional neural network was proposed. This model contained 4 convolution layers, 4 pooling layers, a flattening layer, 4 dropout layers, and 2 connected dense layers. The four dropout layers allow for significantly decreased overfitting and give major improvements compared to other regularization methods. In total, 17,165,569 parameters were optimized and trained for this task. The networks architecture is shown below in Table 1. The model utilized the Adaptive Moment Estimation (Adam) optimization algorithm because of its speedy convergence rate in comparison to other optimizers. The activation functions included the rectifier function for the intermediate layers and sigmoid nonlinearity for the final layer. In addition, a binary cross-entropy loss function was utilized. To prevent overfitting, early stopping was implemented, where the network was saved after each epoch, and the network with the lowest loss was utilized. 16 epochs were run, with the accuracy and loss being output by the model.


    Output Shape


    conv2d_1 (Conv2D)

    (None, 256, 256, 32)


    max_pooling2d_1 (MaxPooling)

    (None, 128, 128, 32)


    dropout_1 (Dropout)

    (None, 128, 128, 32)


    conv2d_2 (Conv2D)

    (None, 128, 128, 64)


    max_pooling2d_2 (MaxPooling)

    (None, 64, 64, 64)


    dropout_2 (Dropout)

    (None, 64, 64, 64)


    conv2d_3 (Conv2D)

    (None, 64, 64, 128)


    max_pooling2d_3 (MaxPooling)

    (None, 32, 32, 128)


    dropout_3 (Dropout)

    (None, 32, 32, 128)


    conv2d_4 (Conv2D)

    (None, 32, 32, 256)


    max_pooling2d_4 (MaxPooling)

    (None, 16, 16, 256)


    dropout_4 (Dropout)

    (None, 16, 16, 256)


    flatten_1 (Flatten)

    (None, 65536)


    dense_1 (Dense)

    (None, 256)


    dense_2 (Dense)

    (None, 1)


    Table 1. Architecture of Convolutional Neural Network


    The training of the convolutional neural network can be shown below in Figure 4 and Figure 5. These figures depict both loss and accuracy by each epoch.

    Figure 4. Training and Validation Accuracy by Epoch

    Figure 5. Training and Validation Loss by Epoch


The early detection of pneumonia is essential to determine the appropriate treatment of the disease and prevent any life- threatening complications. This pulmonary infection accounts for a large number of deaths in children and is most prevalent in developing countries and underdeveloped areas. Not only this, the examination of X-Rays is the traditional method of diagnosis but is often not unanimously agreed upon by radiologists. This problem demonstrates the need for early diagnosis of the disease. In order to alleviate this problem, a computationally efficient convolutional neural network was developed. This was trained on a publicly accessible dataset consisting of 5856 chest X-Rays, with both infected and

uninfected images. Figure 1 and Figure 2 depict examples of healthy and pneumonic chest X-Rays. The model attained a high accuracy, peaking at 96.21%. The networks diagnostic capabilities show its potential as a diagnostic tool in remote areas or areas without sufficient resources or money. It is hoped that this model will also be used to expand upon the knowledge base regarding deep learning architectures for the diagnosis of pneumonia with exceptional accuracy.


[1] Centers for Disease Control and Prevention. (2022, September 30). Risk factors for pneumonia. Centers for Disease Control and Prevention. https://www.cdc.gov/pneumonia/riskfactors.html

[2] Chandra T. & Verma K. Pneumonia detection on chest X-Ray using machine learning paradigm. Proceedings Of 3rd International Conference On Computer Vision And Image Processing. pp. 21-33 (2020)

[3] Liang, G., & Zheng, L. (2020). A transfer learning method with deep residual network for pediatric pneumonia diagnosis. Computer Methods and Programs in Biomedicine, 187, 104964. https://doi.org/10.1016/j.cmpb.2019.06.023

[4] Mujahid, M., Rustam, F., Álvarez, R., Luis Vidal Mazón, J., Díez, I. de, & Ashraf, I. (2022). Pneumonia classification from X-ray images with inception-V3 and Convolutional Neural Network. Diagnostics, 12(5), 1280. https://doi.org/10.3390/diagnostics12051280

[5] Pneumonia. Pneumonia | Johns Hopkins Medicine. (n.d.). https://www.hopkinsmedicine.org/health/conditions-and- diseases/pneumonia

[6] Rahman, T., Chowdhury, M. E., Khandakar, A., Islam, K. R., Islam, K. F., Mahbub, Z. B., Kadir, M. A., & Kashem, S. (2020). Transfer learning with deep convolutional neural network (CNN) for pneumonia detection using chest X-ray. Applied Sciences, 10(9), 3233. https://doi.org/10.3390/app10093233

[7] Rudan, I. (2008). Epidemiology and etiology of childhood pneumonia. Bulletin of the World Health Organization, 86(5), 408416. https://doi.org/10.2471/BLT.07.048769

[8] Were, W., & Qazi, S. (n.d.). The context and key problems of pneumonia diagnosis in low resource settings. World Health Organization – Guidelines. https://www.malariaconsortium.org/userfiles/file/Were_Qazi-


[9] World Health Organization. (n.d.). Pneumonia in children. World Health Organization. https://www.who.int/news-room/fact- sheets/detail/pneumonia

[10] Yue, H., Yu, Q., Liu, C., Huang, Y., Jiang, Z., Shao, C., Zhang, H., Ma,

B., Wang, Y., Xie, G., Zhang, H., Li, X., Kang, N., Meng, X., Huang,

S., Xu, D., Lei, J., Huang, H., Yang, J., Qi, X. (2020). Machine learning-based CT radiomics method for predicting hospital stay in patients with pneumonia associated with SARS-COV-2 infection: A multicenter study. Annals of Translational Medicine, 8(14), 859859. https://doi.org/10.21037/atm-20-3026

[11] Zubair S. An Efficient Method to Predict Pneumonia from Chest X- Rays Using Deep Learning Approach. The Importance Of Health Informatics In Public Health During A Pandemic. 272 pp. 457 (2020)