Next Article in Journal
COTS-Based Architectural Framework for Reliable Real-Time Control Applications in Manufacturing
Previous Article in Journal
Linking Singular Spectrum Analysis and Machine Learning for Monthly Rainfall Forecasting
Order Article Reprints
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:

Transfer Learning with Deep Convolutional Neural Network (CNN) for Pneumonia Detection Using Chest X-ray

Department of Biomedical Physics & Technology, University of Dhaka, Dhaka 1000, Bangladesh
Department of Electrical Engineering, Qatar University, Doha 2713, Qatar
Department of Orthodontics, Bangabandhu Sheikh Mujib Medical University, Dhaka 1000, Bangladesh
Department of Mathematics and Physics, North South University, Dhaka 1229, Bangladesh
Faculty of Robotics and Advanced Computing, Qatar Armed Forces-Academic Bridge Program, Qatar Foundation, Doha 24404, Qatar
Author to whom correspondence should be addressed.
Appl. Sci. 2020, 10(9), 3233;
Received: 4 March 2020 / Revised: 31 March 2020 / Accepted: 8 April 2020 / Published: 6 May 2020
(This article belongs to the Section Computing and Artificial Intelligence)


Pneumonia is a life-threatening disease, which occurs in the lungs caused by either bacterial or viral infection. It can be life-endangering if not acted upon at the right time and thus the early diagnosis of pneumonia is vital. The paper aims to automatically detect bacterial and viral pneumonia using digital x-ray images. It provides a detailed report on advances in accurate detection of pneumonia and then presents the methodology adopted by the authors. Four different pre-trained deep Convolutional Neural Network (CNN): AlexNet, ResNet18, DenseNet201, and SqueezeNet were used for transfer learning. A total of 5247 chest X-ray images consisting of bacterial, viral, and normal chest x-rays images were preprocessed and trained for the transfer learning-based classification task. In this study, the authors have reported three schemes of classifications: normal vs. pneumonia, bacterial vs. viral pneumonia, and normal, bacterial, and viral pneumonia. The classification accuracy of normal and pneumonia images, bacterial and viral pneumonia images, and normal, bacterial, and viral pneumonia were 98%, 95%, and 93.3%, respectively. This is the highest accuracy, in any scheme, of the accuracies reported in the literature. Therefore, the proposed study can be useful in more quickly diagnosing pneumonia by the radiologist and can help in the fast airport screening of pneumonia patients.

1. Introduction

Pneumonia is considered the greatest cause of child fatalities all over the world. Approximately 1.4 million children die of pneumonia every year, which is 18% of the total children died at less than five years old [1]. Globally, overall, two billion people are suffering from pneumonia every year [1]. Pneumonia is a lung infection, which can be caused by either bacteria or viruses. Luckily, this bacterial or viral infectious disease can be well treated by antibiotics and antivirals drugs. Nevertheless, faster diagnosis of viral or bacterial pneumonia and the consequent application of correct medication can help significantly to prevent deterioration of a patient’s condition, which eventually leads to death [2]. Chest X-rays are currently the best method for diagnosing pneumonia [3]. X-ray images of pneumonia are not very clear and are often misclassified to other diseases or other benign abnormalities. Moreover, the bacterial or viral pneumonia images are sometimes miss-classified by the experts, which leads to wrong medication being given to the patients and thereby worsening the condition of the patients [4,5,6]. There are considerable subjective inconsistencies in the decisions of radiologists reported in diagnosing pneumonia. There is also a lack of trained radiologists in low resource countries (LRC), especially in rural areas. Therefore, there is a pressing need for computer-aided diagnosis (CAD) systems, which can help the radiologists in detecting different types of pneumonia from the chest X-ray images immediately after the acquisition.
Currently, many biomedical complications (e.g., brain tumor detection, breast cancer detection, etc.) are using Artificial Intelligence (AI)-based solutions [7,8,9,10]. Among the deep learning techniques, convolutional neural networks (CNNs) have shown great promise in image classification and therefore widely adopted by the research community [11]. Deep Learning Machine learning techniques on chest X-rays are gaining popularity as they can be easily used with low-cost imaging techniques and there is an abundance of data available for training different machine-learning models. Several research groups [1,12,13,14,15,16,17,18,19,20,21,22,23,24,25] have reported the use of deep machine learning algorithms in the detection of pneumonia; however, only one article [16] has reported the classification of bacterial and viral pneumonia.
There are many works where the authors tried varying the parameters of deep layered CNN for pneumonia detection. The pattern of diffuse opacification in the lung radiograph due to pneumonia can be alveolar or interstitial. Patients with alveolar infiltration on the chest radiograph, especially those with lobar infiltrates, have laboratory evidence of a bacterial infection [26]. Again, interstitial infiltrations on radiograph may be linked with viral pneumonia [27]. These might be the distinctive features in the machine learning algorithms in differentiating viral and bacterial pneumonia. Some researchers have promising results, such as Liang et al. [18], Vikash et al. [28], Krishnan et al. [29], and Xianghong et al. [30]. Some groups have combined CNN with rib suppression and lung filed segmentation for other classification tasks, while some highlighted a visualization technique in CNN to find the region of interest (ROI) that can be used to identify pneumonia and distinguish between bacterial and viral types in pediatric chest X-rays. The concept of transfer learning in deep learning framework was used by Vikash et al. [28] for the detection of pneumonia using pre-trained ImageNet models [31] and their ensembles. A customized VGG16 model was used in Xianghong et al. [30], which consists of two parts, lung region identification with a fully convolutional network (FCN) model and pneumonia category classification using a deep convolutional neural network (DCNN). A dataset containing 32,717 patients’ X-rays were used in a deep learning technique by Wang et al. [12] producing promising results. In [13] the authors further went on using data augmentation along with CNN to get better results by training on a small set of images. Rajpurkar et al. [32] reported a 121-layer CNN on chest X-rays to detect 14 different pathologies, including pneumonia using an ensemble of different networks. Jung et al. [33] used a 3D Deep CNN with shortcuts and dense connections which help in solving the gradient vanishing problem. Jaiswal et al. [17] and Siraz et al. [34] used a deep neural network called Mask-RCNN (Region based Convolutional Neural Network) for the segmentation of pulmonary images. This was used along with image augmentation for pneumonia identification, which was ensembled with RetinaNet to localize pneumonia. A pretrained DenseNet-121 and feature extraction techniques were used in the accurate identification of 14 thoracic diseases in [16]. Sundaram et al. [35] used AlexNet and GoogLeNet [36] with data augmentation to obtain an Area Under the Curve (AUC) of 0.94–0.95. The same authors had better results of AUC of 0.99 using modified two-network ensemble architecture.
The highest accuracy reported in the above-mentioned literatures in classifying the normal vs. pneumonia patients and bacterial vs. viral pneumonia using X-ray images using deep learning algorithms was 96.84% and 93.6%, respectively. Therefore, there is significant room for improving the result either by using different deep learning algorithms or modifying the existing outperforming algorithms or combining several outperforming algorithms as an ensemble model to produce a better classification accuracy, particularly in classifying viral and bacterial pneumonia. The proposed study is reporting a transfer learning approach using four different pre-trained network architectures (AlexNet, ResNet18, DenseNet201, and SqueezeNet) and analyzed their performances. The key contribution of this work is to provide a CNN-based transfer-learning approach using different pre-trained models to detect pneumonia and classify bacterial and viral pneumonia with higher accuracy compared to the recent works. In addition, the paper also provides the methodological details of the work, which can be utilized by any research group to take the benefit of this work. Moreover, radiographic findings are poor indicators for the diagnosis of the cause of pneumonia until now. Therefore, the motivation of the present study was to utilize the power of machine learning, firstly to diagnose pneumonia by analyzing radiograph and secondly to differentiate viral and bacterial pneumonia with better accuracy.
The rest of the paper is divided in the following section: Section 2 summarizes different pre-trained networks used for this study and Section 3 describes the methodology used in the study, where the details of the dataset and the pre-processing steps to prepare the data for training and testing are provided. Section 4 provides the results of the classification algorithms, which is compared with some other recent studies, and the results are discussed in this section. Finally, the conclusion is presented in Section 5.

2. Background of Deep Machine Learning Algorithms

2.1. Convolutional Neural Networks (CNNs)

As discussed earlier, CNNs have been popular due to their improved performance in image classification. The convolutional layers in the network along with filters help in extracting the spatial and temporal features in an image. The layers have a weight-sharing technique, which helps in reducing computation efforts [37,38].
Architecture wise, CNNs are simply feedforward artificial neural networks (ANNs) with two constraints: neurons in the same filter are only connected to local patches of the image to preserve spatial structure and their weights are shared to reduce the total number of the model’s parameters. A CNN consists of three building blocks: (i) a convolution layer to learn features, (ii) a max-pooling (subsampling) layer is to down sample the image and reduce the dimensionality and thereby reduction in computational efforts, and (iii) a fully connected layer to equip the network with classification capabilities [39]. The architectural overview of CNN is illustrated in Figure 1.

2.2. Deep Transfer Learning

CNNs typically outperform in a larger dataset than a smaller one. Transfer learning can be useful in those applications of CNN where the dataset is not large. The concept of transfer learning is shown in Figure 2, where the trained model from large datasets, such as ImageNet [40,41], can be used for application with a comparatively smaller dataset.
Recently, transfer learning has been successfully used in various field applications, such as manufacturing, medical and baggage screening [42,43,44]. This removes the requirement of having large dataset and also reduces the long training period, as is required by the deep learning algorithm when developed from scratch [45,46].

2.3. Pre-Trained Convolutional Neural Networks

In this study, four well-known pre-trained deep learning CNNs: AlexNet [11], ResNet [47], DenseNet [47], and SqueezeNet [48] were used for pneumonia detection. A brief introduction of these pre-trained networks is mentioned below:

2.3.1. AlexNet

AlexNet can classify more than 1000 different classes using deep layers consisting of 650k neurons and 60 million parameters. The network is made up of five convolutional layers (CLs) with three pooling layers, two fully connected layer (FLCs), and a Softmax layer [11]. The dimension of input image for the AlexNet has to be 227 × 227 × 3 and the first CL converts input image with 96 kernels sized at 11 × 11 × 3 having a stride of four pixels, which is the input to the second layer [49], and the remaining details are summarized in Figure 3.

2.3.2. ResNet18

ResNet, which is a short form of Residual Network (Figure 4), was originally developed to two problems, such as the vanishing gradient and degradation problem [47]. Residual learning tries to solve both these problems. ResNet has three different variants: ResNet18, ResNet50, and ResNet101 based on the number of layers in the residual network. ResNet was successfully used in biomedical image classification [48] for transfer learning. In this paper, we have used ResNet18 for the pneumonia detection. Typically, deep neural network layers learn low- or high-level features during training, while ResNet learns residuals instead of features.

2.3.3. DenseNet201

DenseNet, which is a short form of the Dense Convolutional Network, needs less numbers of parameters than a conventional CNN, as it does not learn redundant feature maps [50]. The layers in DenseNet are very narrow, i.e., 12 filters, which add a lesser set of new feature-maps. DenseNet has four different variants: DenseNet121, DenseNet169, DenseNet201, and DenseNet264. In this paper, we have used DenseNet201 for the pneumonia detection [51]. Each layer in DenseNet (as shown in Figure 5) has direct access to the original input image and gradients from the loss function. Therefore, the computational cost significantly reduced, which makes DenseNet a better choice for image classification.

2.3.4. SqueezeNet

SqueezeNet [52] is another CNN, which was trained using ImageNet database [51]. The SqueezeNet was trained with more than 1 million images and it has 50 times fewer parameters than AlexNet. The foundation of this network is a fire module, which consists of the squeeze layer and expand layer. The squeeze layer has only 1 × 1 filters, which are feeding to an expand layer that has a mixture of 1 × 1 and 3 × 3 convolution filters [52] (Figure 6). We have used the SqueezeNet pre-trained model to detect pneumonia and classify bacterial and viral pneumonia in this research.

3. Methodology

3.1. Dataset

In this work, the kaggle chest X-ray pneumonia database was used, which is comprised of 5247 chest X-ray images with resolutions varying from 400p to 2000p [53]. Out of 5247 chest X-ray images, 3906 images are from different subjects affected by pneumonia (2561 images for bacterial pneumonia and 1345 images for viral pneumonia) and 1341 images are from normal subjects (Table 1). Mixed viral and bacterial infection occurs in some cases of pneumonia. However, the dataset used in this study does not include any case of viral and bacterial co-infection. This dataset was segmented into the training and test set.
Table 2 shows a number of train (using augmentation) and test images for different evaluation experiments. Four different algorithms were trained using the training dataset and then evaluated on test dataset. Figure 7 shows two samples for normal, bacterial, and viral pneumonia chest X-ray images.
In this study, MATLAB (2019a) was utilized to train, evaluate, and test different algorithms. Figure 8 illustrates the overview of the methodology of this study. Image sets undergo some pre-processing steps, data augmentation, and then training using pre-trained algorithms: AlexNet, ResNet18, DenseNet201, and SqueezeNet, and all the tested algorithms on the test dataset. The training of the different models was carried out in a computer with Intel© i7-core @3.6GHz processor and 16GB RAM, 2 GB graphics card with graphics processing unit (GPU) on 64-bit Windows 10 operating system. Different parameters used for training the CNN models were shown in the Table 3. ResNet and DenseNet have different variants; however, ResNet18 and DenseNet201 were readily available for Matlab 2019a and therefore used in this study. Moreover, ResNet18 outperforms other ResNet models in terms of radiographic classification.

3.2. Preprocessing

One of the important steps in the data preprocessing was to resize the X-ray images as the image input for different algorithms were different. For AlexNet and SqueezeNet, the images were resized to 227 × 227 pixels, whereas for ResNet18 and DenseNet201, the images were resized to and 224 × 224 pixels. All images were normalized according to the pre-trained model standards.

Data Augmentation

As discussed earlier, CNNs work better with a large dataset. However, the size of the working database is not very large. There is a common trend in training deep learning algorithms to make the comparatively smaller dataset a large one using data augmentation techniques. It is reported that data augmentation can improve the classification accuracy of the deep learning algorithms. The performance of the deep learning models can be improved by augmenting the existing data rather than collecting new data. Some of the deep learning frameworks have data augmentation facility built into the algorithms; however, in this study, authors have utilized three augmentation strategies to generate new training sets (Rotation, Scaling, and Translation), as shown in Figure 9.
The rotation operation used for image augmentation is normally done by rotating the image in the clockwise direction by an angle between 0 to 360 degrees, which rotates the pixel of the image frame and fills the area of the image where there was no image pixel. In this work, the rotation of 315 degrees (counter clockwise 45 degrees) was used. The scaling operation is the magnification or reduction of frame size of the image, which is another augmentation technique used. In total, 10% of image magnification, as done as shown in Figure 9C. Image translation can be done by either translating the image in a horizontal (width shift) or vertical direction (height shift) or in both directions. The original image was horizontally translated by 10% and vertically translated by 10%.

3.3. Visualization of the Activation Layer

We investigated the features of the image by observing which areas in the convolutional layers activated on an image by comparing with the matching regions in the original images. Each layer of a CNN consists of many 2D arrays called channels. The input image was applied to different networks, and the output activations of the first convolution layer was examined.
The activations for different network models is shown in Figure 10. The activation map can take different range values and was therefore normalized between 0 and 1. The strongest activation channels were observed and compared with the original image. It was noticed that this channel activates on edges. It activates positively on light left/dark right edges and negatively on dark left/light right edges.
Most convolutional neural networks learn to detect features like color and edges in their first convolutional layer. In deeper convolutional layers, the network learns to detect features that are more complicated. Later layers build up their features by combining features of earlier layers. Figure 10 shows the activation map in early convolutional layers, the deep convolutional layer, and the strongest activation channel for each of the models.

3.4. Different Experiments

Three different forms of performance evaluations and comparisons were carried out in this study: two classes (normal and pneumonia), three classes (normal, bacterial pneumonia, and viral pneumonia), and two classes (bacterial pneumonia and viral pneumonia) classification using four different deep learning algorithms through transfer learning.
The experiment carried out in this study consists of three steps. In the first step, the dataset divided into normal and pneumonia. In the second step, the dataset divided into normal, bacterial, and viral pneumonia. In the last step, the dataset divided into bacterial and viral pneumonia. An end-to-end training approach was adopted to classify normal, bacterial, and viral pneumonia images.

3.5. Performance Matrix for Classification

Four CNNs were trained and evaluated using five-fold cross-validation in this study. The performance of different networks for the testing dataset is evaluated after the completion of the training phase and was compared using the following six performances metrics: accuracy, sensitivity or recall, specificity, precision (PPV), the area under curve (AUC), and F1 score. Table 3 shows six performance metrics for different deep CNNs:
A c c u r a c y = ( T P + T N ) ( T P + F N ) + ( F P + T N )
S e n s i t i v i t y = ( T P ) ( T P + F N )
S p e c i f i c i t y = ( T N ) ( F P + T N )
P r e c i s i o n = ( T P ) ( T N + F P )
F 1   S c o r e = ( 2 T P ) ( 2 T P + F N + F P )
In the above equations, while classifying normal and pneumonia patients, true positive (TP), true negative (TN), false positive (FP), and false negative (FN) were used to denote the number of pneumonia images identified as pneumonia, the number of normal images identified as normal, the number normal images incorrectly identified as pneumonia images, and the number of pneumonia images incorrectly identified as normal, respectively. On the other hand, while classifying viral and bacterial pneumonia, TP, TN, FP, and FN were used to denote the number of viral pneumonia images identified as viral pneumonia, the number of bacterial pneumonia images identified as bacterial pneumonia, the number bacterial pneumonia images incorrectly identified as viral pneumonia images, and the number of viral pneumonia images incorrectly identified as bacterial pneumonia, respectively.

4. Results and Discussions

The comparative performance of training and testing accuracy for different CNNs for classification schemes are shown in Figure 11. It can be noted that, for three classification schemes, DenseNet201 is producing the highest accuracy for both training and testing. For normal and pneumonia classification, the test accuracy was 98%, while, for normal, bacterial, and viral pneumonia classification, it was 93.3%, and, for bacterial and viral pneumonia classification, it was found to be 95%. Figure 12 shows the area under the curve (AUC)/receiver-operating characteristics (ROC) curve (also known as AUROC (area under the receiver operating characteristics)) for different classification schemes, which is one of the most important evaluation metrics for checking any classification model’s performance. It is also evident from Figure 12 that DenseNet201 outperforms the other algorithms.
Figure 13 shows the confusion matrix for outperforming Densenet201 pre-trained model in for three different classifications.
Table 4 summarizes the performance matrix for different CNN algorithms tested for the three different classification schemes. DenseNet201 outperforms other models in three different classification schemes in terms of different performance indices.
The authors have also compared the results in the paper with the results of recently published works in the same problem. Vikash et al. [21] reported the detection of pneumonia using a deep learning technique called CXNet-m1, which showed sensitivity, precision, and accuracy of 99.6%, 93.28%, and 96.39%, respectively. Krishnan et al. [29] evaluated the performance of VGG16 CNNs to classify pneumonia into normal, bacterial, and viral pneumonias. This showed sensitivity, precision, and accuracy of 99.5%, 97.7%, and 96.2%, respectively for pneumonia detection; however, 98.4%, 92%, and 93.6%, respectively, for distinguishing viral and bacterial pneumonias. Table 5 summarized the comparison of others works in pneumonia and types of pneumonia detection from chest X-ray images.
It is evident that DesneNet201 exhibits the highest accuracy of all recent studies to the best of our knowledge, which could be useful in developing a prototype that can automatically classify results into normal, bacterial and viral pneumonia. Training the network using a larger database and working on an ensemble of the pre-trained CNN algorithms might increase the detection accuracy, which can be done as a future study.

5. Conclusions

This study presents a deep-CNN-based transfer learning approach for the automatic detection of pneumonia and its classes. Four different popular CNN-based deep learning algorithms were trained and tested for classifying normal and pneumonia patients using chest x-ray images. It was observed that DenseNet201 outperforms the other three different deep CNN networks. The classification accuracy, precision, and recall of normal and pneumonia images, bacterial, and viral pneumonia images, and normal, bacterial, and viral pneumonia were 98%, 97%, and 99%; 95%, 95% and 96%; and 93.3%, 93.7% and 93.2%, respectively. There are millions of children, who die each year due to this potentially fatal disease. Timely intervention with proper treatment plan through correct diagnosis of the disease can save a significant number of lives. Due to the huge number of patients in outdoor emergencies or emergencies specifically in the third world countries, medical doctors’ time is limited and computer-aided-diagnosis (CAD) can save lives. Moreover, there is a large degree of variability in the input images from the X-ray machines due to the variations in the expertise of the radiologists. DenseNet201 exhibits an excellent performance in classifying pneumonia by effectively training itself from a comparatively lower collection of complex data, such as images, with reduced bias and higher generalization. We believe that this computer-aided diagnostic tool can significantly help the radiologist to take more clinically useful images and to identify pneumonia with its type immediately after acquisition. This fast classification will open up other avenues of application for this CAD tool, more particularly in the airport screening of pneumonia patients.

Author Contributions

Experiments were designed by T.R. and M.E.H.C. Experiments were performed by T.R., K.F.I. and K.R.I. Results were analyzed by T.R., M.E.H.C., A.K., S.B., Z.B.M. and M.A.K. All authors were involved in interpretation of data and paper writing. All authors have read and agreed to the published version of the manuscript.


This work was made possible by NPRP12S-0227-190164 from the Qatar National Research Fund, a member of Qatar Foundation, Doha, Qatar and students’ grant of Qatar University QUST-1-CENG-2020-23. The statements made herein are solely the responsibility of the authors.

Conflicts of Interest

The authors declare no conflict of interest.


  1. Imran, A. Training a CNN to detect Pneumonia. 2019. Available online: (accessed on 23 December 2019).
  2. Aydogdu, M.; Ozyilmaz, E.; Aksoy, H.; Gursel, G.; Ekim, N. Mortality prediction in community-acquired pneumonia requiring mechanical ventilation; values of pneumonia and intensive care unit severity scores. Tuberk Toraks 2010, 58, 25–34. [Google Scholar] [PubMed]
  3. WHO. Standardization of Interpretation of Chest Radiographs for the Diagnosis of Pneumonia in Children; World Health Organization: Geneva, Switzerland, 2001. [Google Scholar]
  4. Neuman, M.I.; Lee, E.Y.; Bixby, S.; DiPerna, S.; Hellinger, J.; Markowitz, R.; Servaes, S.; Monuteaux, M.C.; Shah, S. Variability in the interpretation of chest radiographs for the diagnosis of pneumonia in children. J. Hosp. Med. 2011, 7, 294–298. [Google Scholar] [CrossRef] [PubMed]
  5. Dele Davies, H.; Wang, E.E.-L.; Manson, D.; Babyn, P.S.; Shuckett, B. Reliability of the chest radiograph in the diagnosis of lower respiratory infections in young children. Pediatr. Infect. Dis. J. 1996, 15, 600–604. [Google Scholar] [CrossRef] [PubMed]
  6. Hopstaken, R.; Witbraad, T.; Van Engelshoven, J.; Dinant, G. Inter-observer variation in the interpretation of chest radiographs for pneumonia in community-acquired lower respiratory tract infections. Clin. Radiol. 2004, 59, 743–752. [Google Scholar] [CrossRef] [PubMed]
  7. Tahir, A.M.; Chowdhury, M.E.H.; Khandakar, A.; Al-Hamouz, S.; Abdalla, M.; Awadallah, S.; Reaz, M.B.I.; Al-Emadi, N. A Systematic Approach to the Design and Characterization of a Smart Insole for Detecting Vertical Ground Reaction Force (vGRF) in Gait Analysis. Sensors 2020, 20, 957. [Google Scholar] [CrossRef][Green Version]
  8. Chowdhury, M.E.H.; Alzoubi, K.; Khandakar, A.; Khallifa, R.; Abouhasera, R.; Koubaa, S.; Ahmed, R.; Hasan, A. Wearable Real-Time Heart Attack Detection and Warning System to Reduce Road Accidents. Sensors 2019, 19, 2780. [Google Scholar] [CrossRef][Green Version]
  9. Chowdhury, M.E.H.; Khandakar, A.; Alzoubi, K.; Mansoor, S.; Tahir, A.M.; Reaz, M.B.I.; Al-Emadi, N. Real-Time Smart-Digital Stethoscope System for Heart Diseases Monitoring. Sensors 2019, 19, 2781. [Google Scholar] [CrossRef][Green Version]
  10. Kallianos, K.; Mongan, J.; Antani, S.; Henry, T.; Taylor, A.; Abuya, J.; Kohli, M. How far have we come? Artificial intelligence for chest radiograph interpretation. Clin. Radiol. 2019, 74, 338–345. [Google Scholar] [CrossRef]
  11. Krizhevsky, A.; Sutskever, I.; Hinton, G.E. Pdf ImageNet classification with deep convolutional neural networks. Commun. ACM 2017, 60, 84–90. [Google Scholar] [CrossRef]
  12. Wang, X.; Peng, Y.; Lu, L.; Lu, Z.; Bagheri, M.; Summers, R.M. ChestX-ray8: Hospital-Scale Chest X-ray Database and Benchmarks on Weakly-Supervised Classification and Localization of Common Thorax Diseases. In Proceedings of the 2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Honolulu, HI, USA, 21–26 July 2017; pp. 3462–3471. [Google Scholar]
  13. Ronneberger, O.; Fischer, P.; Brox, T. U-Net: Convolutional Networks for Biomedical Image Segmentation. In Proceedings of the Lecture Notes in Computer Science; Springer Science and Business Media LLC: Cham, Switzerland, 2015; Volume 9351, pp. 234–241. [Google Scholar]
  14. Woźniak, M.; Polap, D.; Capizzi, G.; Sciuto, G.L.; Kośmider, L.; Frankiewicz, K. Small lung nodules detection based on local variance analysis and probabilistic neural network. Comput. Methods Programs Biomed. 2018, 161, 173–180. [Google Scholar] [CrossRef]
  15. Gu, Y.; Lu, X.; Yang, L.; Zhang, B.; Yu, D.; Zhao, Y.; Gao, L.; Wu, L.; Zhou, T. Automatic lung nodule detection using a 3D deep convolutional neural network combined with a multi-scale prediction strategy in chest CTs. Comput. Boil. Med. 2018, 103, 220–231. [Google Scholar] [CrossRef] [PubMed]
  16. Ho, T.K.K.; Gwak, J. Multiple Feature Integration for Classification of Thoracic Disease in Chest Radiography. Appl. Sci. 2019, 9, 4130. [Google Scholar] [CrossRef][Green Version]
  17. Jaiswal, A.K.; Tiwari, P.; Kumar, S.; Gupta, N.; Khanna, A.; Rodrigues, J.J.P.C. Identifying pneumonia in chest X-rays: A deep learning approach. Measurement 2019, 145, 511–518. [Google Scholar] [CrossRef]
  18. Liang, G.; Zheng, L. A transfer learning method with deep residual network for pediatric pneumonia diagnosis. Comput. Methods Programs Biomed. 2020, 187, 104964. [Google Scholar] [CrossRef]
  19. Souza, J.C.; Diniz, J.O.B.; Ferreira, J.L.; Da Silva, G.L.F.; Silva, A.C.; De Paiva, A.C. An automatic method for lung segmentation and reconstruction in chest X-ray using deep neural networks. Comput. Methods Programs Biomed. 2019, 177, 285–296. [Google Scholar] [CrossRef]
  20. Taylor, A.G.; Mielke, C.; Mongan, J. Automated detection of moderate and large pneumothorax on frontal chest X-rays using deep convolutional neural networks: A retrospective study. PLoS Med. 2018, 15, e1002697. [Google Scholar] [CrossRef]
  21. Xu, S.; Wu, H.; Bie, R. CXNet-m1: Anomaly Detection on Chest X-rays With Image-Based Deep Learning. IEEE Access 2018, 7, 4466–4477. [Google Scholar] [CrossRef]
  22. Toğaçar, M.; Ergen, B.; Cömert, Z.; Özyurt, F. A Deep Feature Learning Model for Pneumonia Detection Applying a Combination of mRMR Feature Selection and Machine Learning Models. IRBM 2019. [Google Scholar] [CrossRef]
  23. Saraiva, A.; Santos, D.; Costa, N.; Sousa, J.; Ferreira, N.; Valente, A.; Soares, S. Models of Learning to Classify X-ray Images for the Detection of Pneumonia using Neural Networks. In Proceedings of the 12th International Joint Conference on Biomedical Engineering Systems and Technologies, Prague, Czech, 22–24 February 2019; pp. 76–83. [Google Scholar]
  24. Ayan, E.; Unver, H.M. Diagnosis of Pneumonia from Chest X-ray Images Using Deep Learning. In Proceedings of the 2019 Scientific Meeting on Electrical-Electronics & Biomedical Engineering and Computer Science (EBBT), Istanbul, Turkey, 24–26 April 2019; pp. 1–5. [Google Scholar]
  25. Khatri, A.; Jain, R.; Vashista, H.; Mittal, N.; Ranjan, P.; Janardhanan, R. Pneumonia Identification in Chest X-ray Images Using EMD. In Internet of Things—Applications and Future; Springer Science and Business Media LLC: Singapore, 2020; pp. 87–98. [Google Scholar]
  26. Virkki, R.; Juvén, T.; Rikalainen, H.; Svedstrom, E.; Mertsola, J.; Ruuskanen, O. Differentiation of bacterial and viral pneumonia in children. Thorax 2002, 57, 438–441. [Google Scholar] [CrossRef][Green Version]
  27. Ishiguro, T.; Kobayashi, Y.; Uozumi, R.; Takata, N.; Takaku, Y.; Kagiyama, N.; Kanauchi, T.; Shimizu, Y.; Takayanagi, N. Viral Pneumonia Requiring Differentiation from Acute and Progressive Diffuse Interstitial Lung Diseases. Intern. Med. 2019, 58, 3509–3519. [Google Scholar] [CrossRef][Green Version]
  28. Chouhan, V.; Singh, S.K.; Khamparia, A.; Gupta, N.; Tiwari, P.; Moreira, C.; Damasevicius, R.; De Albuquerque, V.H.C. A Novel Transfer Learning Based Approach for Pneumonia Detection in Chest X-ray Images. Appl. Sci. 2020, 10, 559. [Google Scholar] [CrossRef][Green Version]
  29. Rajaraman, S.; Candemir, S.; Kim, I.; Thoma, G.R.; Antani, S. Visualization and Interpretation of Convolutional Neural Network Predictions in Detecting Pneumonia in Pediatric Chest Radiographs. Appl. Sci. 2018, 8, 1715. [Google Scholar] [CrossRef][Green Version]
  30. Gu, X.; Pan, L.; Liang, H.; Yang, R. Classification of Bacterial and Viral Childhood Pneumonia Using Deep Learning in Chest Radiography. In Proceedings of the 3rd international conference on Mobile and ubiquitous multimedia—MUM ’04; Association for Computing Machinery (ACM), Guiyang China, 16–18 March 2018; pp. 88–93. [Google Scholar]
  31. Gershgorn, D. The Data that Transformed AI Research—and Possibly the World. 2017. Available online: (accessed on 23 December 2019).
  32. Rajpurkar, P.; Irvin, J.; Ball, R.L.; Zhu, K.; Yang, B.; Mehta, H.; Duan, T.; Ding, D.; Bagul, A.; Langlotz, C.P.; et al. Deep learning for chest radiograph diagnosis: A retrospective comparison of the CheXNeXt algorithm to practicing radiologists. PLoS Med. 2018, 15, e1002686. [Google Scholar] [CrossRef] [PubMed]
  33. Jung, H.; Kim, B.; Lee, I.; Lee, J.; Kang, J. Classification of lung nodules in CT scans using three-dimensional deep convolutional neural networks with a checkpoint ensemble method. BMC Med. Imag. 2018, 18, 48. [Google Scholar] [CrossRef] [PubMed]
  34. Sirazitdinov, I.; Kholiavchenko, M.; Mustafaev, T.; Yixuan, Y.; Kuleev, R.; Ibragimov, B. Deep neural network ensemble for pneumonia localization from a large-scale chest x-ray database. Comput. Electr. Eng. 2019, 78, 388–399. [Google Scholar] [CrossRef]
  35. Lakhani, P.; Sundaram, B. Deep Learning at Chest Radiography: Automated Classification of Pulmonary Tuberculosis by Using Convolutional Neural Networks. Radiology 2017, 284, 574–582. [Google Scholar] [CrossRef]
  36. Szegedy, C.; Liu, W.; Jia, Y.; Sermanet, P.; Reed, S.; Anguelov, D.; Erhan, D.; Vanhoucke, V.; Rabinovich, A. Going deeper with convolutions. In Proceedings of the 2015 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Boston, MA, USA, 7–12 June 2015; pp. 1–9. [Google Scholar]
  37. Albawi, S.; Mohammed, T.A.; Al-Azawi, S. Understanding of a convolutional neural network. In Proceedings of the 2017 International Conference on Engineering and Technology (ICET), Antalya, Turkey, 21–23 August 2017; pp. 1–6. [Google Scholar]
  38. Goyal, M.; Goyal, R.; Lall, B. Learning Activation Functions: A new paradigm of understanding Neural Networks. arXiv 2019, arXiv:1906.09529. [Google Scholar]
  39. Bailer, C.; Habtegebrial, T.; Varanasi, K.; Stricker, D. Fast Feature Extraction with CNNs with Pooling Layers. arXiv 2018, arXiv:1805.03096. [Google Scholar]
  40. Deng, J.; Dong, W.; Socher, R.; Li, L.-J.; Li, K.; Fei-Fei, L. Imagenet: A large-scale hierarchical image database. In Proceedings of the 2009 IEEE Conference on Computer Vision and Pattern Recognition, Miami, FL, USA, 20–25 June 2009; pp. 248–255. [Google Scholar]
  41. Wang, S.-H.; Xie, S.; Chen, X.; Guttery, D.; Tang, C.; Sun, J.; Zhang, Y.-D. Alcoholism Identification Based on an AlexNet Transfer Learning Model. Front. Psychol. 2019, 10, 205. [Google Scholar] [CrossRef][Green Version]
  42. Christodoulidis, S.; Anthimopoulos, M.; Ebner, L.; Christe, A.; Mougiakakou, S.G. Multisource Transfer Learning With Convolutional Neural Networks for Lung Pattern Analysis. IEEE J. Biomed. Health Inform. 2016, 21, 76–84. [Google Scholar] [CrossRef][Green Version]
  43. Yang, H.; Mei, S.; Song, K.; Tao, B.; Yin, Z. Transfer-Learning-Based Online Mura Defect Classification. IEEE Trans. Semicond. Manuf. 2017, 31, 116–123. [Google Scholar] [CrossRef]
  44. Akcay, S.; Kundegorski, M.E.; Devereux, M.; Breckon, T.P. Transfer learning using convolutional neural networks for object classification within X-ray baggage security imagery. In Proceedings of the 2016 IEEE International Conference on Image Processing (ICIP), Phoenix, AZ, USA, 25–28 September 2016; pp. 1057–1061. [Google Scholar]
  45. Tajbakhsh, N.; Shin, J.Y.; Gurudu, S.R.; Hurst, R.T.; Kendall, C.B.; Gotway, M.B.; Liang, J. Convolutional Neural Networks for Medical Image Analysis: Full Training or Fine Tuning? IEEE Trans. Med. Imag. 2016, 35, 1299–1312. [Google Scholar] [CrossRef] [PubMed][Green Version]
  46. Pan, S.J.; Yang, Q. A Survey on Transfer Learning. IEEE Trans. Knowl. Data Eng. 2009, 22, 1345–1359. [Google Scholar] [CrossRef]
  47. ResNet, AlexNet, VGGNet, Inception: Understanding various architectures of Convolutional Networks. Available online: (accessed on 23 December 2019).
  48. LeCun, Y.; Kavukcuoglu, K.; Farabet, C. Convolutional networks and applications in vision. In Proceedings of the 2010 IEEE International Symposium on Circuits and Systems, Paris, France, 30 May–2 June 2010; pp. 253–256. [Google Scholar]
  49. LeCun, Y.; Boser, B.E.; Denker, J.S.; Henderson, D.; Howard, R.E.; Hubbard, W.E.; Jackel, L.D. Handwritten digit recognition with a back-propagation network. In Advances in Neural Information Processing Systems; The MIT Press: Massachusetts, MA, USA, 1990; pp. 396–404. [Google Scholar]
  50. Huang, G.; Liu, Z.; Van Der Maaten, L.; Weinberger, K.Q. Densely Connected Convolutional Networks. In Proceedings of the 2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Honolulu, HI, USA, 21–26 July 2017; pp. 2261–2269. [Google Scholar]
  51. DenseNet: Better CNN Model than ResNet. Available online: (accessed on 23 December 2019).
  52. Iandola, F.N.; Han, S.; Moskewicz, M.W.; Ashraf, K.; Dally, W.J.; Keutzer, K. SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and < 0.5 MB model size. arXiv 2016, arXiv:1602.07360. [Google Scholar]
  53. Mooney, P. Chest X-ray Images (Pneumonia). 2018. Available online: (accessed on 23 December 2019).
  54. Cohen, J.P.; Bertin, P.; Frappier, V. Chester: A Web Delivered Locally Computed Chest X-ray Disease Prediction System. arXiv 2019, arXiv:1901.11210. [Google Scholar]
Figure 1. Convolutional Neural Network (CNN) Architecture.
Figure 1. Convolutional Neural Network (CNN) Architecture.
Applsci 10 03233 g001
Figure 2. Concept of transfer learning.
Figure 2. Concept of transfer learning.
Applsci 10 03233 g002
Figure 3. AlexNet Structure.
Figure 3. AlexNet Structure.
Applsci 10 03233 g003
Figure 4. Structure of ResNet18.
Figure 4. Structure of ResNet18.
Applsci 10 03233 g004
Figure 5. DenseNet201 architecture.
Figure 5. DenseNet201 architecture.
Applsci 10 03233 g005
Figure 6. SqueezeNet architecture.
Figure 6. SqueezeNet architecture.
Applsci 10 03233 g006
Figure 7. Data samples from the dataset, (A) shows normal cases, (B) shows bacterial pneumonia cases, and (C) shows viral pneumonia cases.
Figure 7. Data samples from the dataset, (A) shows normal cases, (B) shows bacterial pneumonia cases, and (C) shows viral pneumonia cases.
Applsci 10 03233 g007
Figure 8. Overview of the methodology.
Figure 8. Overview of the methodology.
Applsci 10 03233 g008
Figure 9. Original chest X-ray image (A), chest X-ray image after rotation (B), chest X-ray image after scaling (C), and chest-X-ray image after translation (D).
Figure 9. Original chest X-ray image (A), chest X-ray image after rotation (B), chest X-ray image after scaling (C), and chest-X-ray image after translation (D).
Applsci 10 03233 g009
Figure 10. Activation map for different network models of (i) the first convolutional layer, (ii) the strongest activation channel, (iii) the deep layer images set, and (iv) the deep convolutional layer in specific image.
Figure 10. Activation map for different network models of (i) the first convolutional layer, (ii) the strongest activation channel, (iii) the deep layer images set, and (iv) the deep convolutional layer in specific image.
Applsci 10 03233 g010
Figure 11. Comparison of training and testing accuracy for normal pneumonia (A), normal, bacterial, and viral pneumonia (B), and bacterial and viral pneumonia (C) classification using different models.
Figure 11. Comparison of training and testing accuracy for normal pneumonia (A), normal, bacterial, and viral pneumonia (B), and bacterial and viral pneumonia (C) classification using different models.
Applsci 10 03233 g011
Figure 12. Comparison of the receiver-operating characteristics (ROC) curve for normal pneumonia (A), normal, bacterial, and viral pneumonia (B), and bacterial and viral pneumonia (C) classification using CNN-based models.
Figure 12. Comparison of the receiver-operating characteristics (ROC) curve for normal pneumonia (A), normal, bacterial, and viral pneumonia (B), and bacterial and viral pneumonia (C) classification using CNN-based models.
Applsci 10 03233 g012
Figure 13. Confusion matrix for (a) normal pneumonia, (b) bacterial and viral, and (c) normal, bacterial, and viral pneumonia classification using DenseNet201.
Figure 13. Confusion matrix for (a) normal pneumonia, (b) bacterial and viral, and (c) normal, bacterial, and viral pneumonia classification using DenseNet201.
Applsci 10 03233 g013
Table 1. Complete dataset details.
Table 1. Complete dataset details.
TypeNumber of X-ray Images
Bacterial Pneumonia2561
Viral Pneumonia1345
Table 2. Details of the training and test set.
Table 2. Details of the training and test set.
TypesTraining Set
(Using Augmentation)
Test Set
Normal and PneumoniaNormal4500205
Normal, Bacterial, and Viral PneumoniaNormal4500199
Bacterial Pneumonia4500197
Viral Pneumonia4500201
Bacterial and Viral PneumoniaBacterial Pneumonia4500197
Viral Pneumonia4500201
Table 3. Training parameters of different pre-trained CNN models.
Table 3. Training parameters of different pre-trained CNN models.
SoftwarePre-Trained CNN ModelsImage SizeOptimizationMomentumMini-BatchLearning Rate
AlexNet227 × 227Gradient Descent0.9160.0003
ResNet18224 × 224
DenseNet201224 × 224
SqueezeNet227 × 227
Table 4. Different performance metrics for different deep learning networks.
Table 4. Different performance metrics for different deep learning networks.
Area under Curve (AUC)F1 Scores
Normal and PneumoniaAlexNet0.9450.9530.9260.9310.9420.943
Normal, Bacterial Pneumonia and Viral PneumoniaAlexNet0.8840.8830.9410.8860.9110.885
Bacterial and Viral PneumoniaAlexNet0.900.940.8450.860.890.921
Table 5. Comparison with other recent similar works.
Table 5. Comparison with other recent similar works.
AuthorClassesTechniqueImage No.Recall
Precision (%)AUC
Vikash et al. [21]Normal & PneumoniaDifferent pre-trained CNN model523299.693.2899.3496.39
Sivarama krishnan et al. [29]Normal & Pneumoniacustomized VGG16 CNN model585699.597.099.096.2
Kermanyetal. [54]Normal & PneumoniaInception V3 pretrained CNN model523293.290.1-92.8
* M.Togacar et al. [22]Normal & PneumoniaDeep CNN model584996.8396.8896.8096.84
A. A. Saraiva et al. [23]Normal & PneumoniaNeural network584094.594.394.594.4
Enes AYAN et al. [24]Normal & PneumoniaVGG16 deep learning model585689.191.387.084.5
Xianghong Gu et al. [30]Bacterial & Viral PneumoniaDeep Convolutional neural network488277.5588.8682.380.4
* Sivarama krishnan et al. [29]Bacterial & Viral Pneumoniacustomized VGG16 CNN model388398.492.096.293.6
Archit Khatri et al. [25]Bacterial & Viral PneumoniaEMD approach14489.580.088.083.30
** This workNormal & PneumoniaDifferent pre-trained CNN model524799.
** This workBacterial & Viral PneumoniaDifferent pre-trained CNN model524796.
* The best performing algorithms reported in the literature while ** shows the performance of this study.

Share and Cite

MDPI and ACS Style

Rahman, T.; Chowdhury, M.E.H.; Khandakar, A.; Islam, K.R.; Islam, K.F.; Mahbub, Z.B.; Kadir, M.A.; Kashem, S. Transfer Learning with Deep Convolutional Neural Network (CNN) for Pneumonia Detection Using Chest X-ray. Appl. Sci. 2020, 10, 3233.

AMA Style

Rahman T, Chowdhury MEH, Khandakar A, Islam KR, Islam KF, Mahbub ZB, Kadir MA, Kashem S. Transfer Learning with Deep Convolutional Neural Network (CNN) for Pneumonia Detection Using Chest X-ray. Applied Sciences. 2020; 10(9):3233.

Chicago/Turabian Style

Rahman, Tawsifur, Muhammad E. H. Chowdhury, Amith Khandakar, Khandaker R. Islam, Khandaker F. Islam, Zaid B. Mahbub, Muhammad A. Kadir, and Saad Kashem. 2020. "Transfer Learning with Deep Convolutional Neural Network (CNN) for Pneumonia Detection Using Chest X-ray" Applied Sciences 10, no. 9: 3233.

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop