Diagnosis of Active Pulmonary Tuberculosis and Community Acquired Pneumonia Using Convolution Neural Network Based on Transfer Learning

      Rationale and Objectives

      A convolutional neural network (CNN) model for the diagnosis of active pulmonary tuberculosis (APTB) and community-acquired pneumonia (CAP) using chest radiographs (CRs) was constructed and verified based on transfer learning.

      Materials and Methods

      CRs of 1247 APTB cases, 1488 CAP cases and 1247 normal cases were collected. All CRs were randomly divided into training set (1992 cases), validation set (1194 cases) and test set (796 cases) by stratified sampling in 5:3:2 radio. After normalization of CRs, the convolution base of pre-trained CNN (VGG16) model on ImageNet dataset was used to extract features, and the grid search was used to determine the optimal classifier module, which was added to the convolution base for transfer learning. After the training, the model with the highest accuracy of the validation set was selected as the optimal model to verify in the test set and calculate the accuracy of the model.


      The accuracy of validation set in the 63rd epochs was the highest, which was 0.9430, and the corresponding Categorical crossentropy was 0.1742. The accuracy of the training set was 0.9428, and the Categorical crossentropy was 0.1545. When the optimal model was applied to the test set, the accuracy was 0.9447, and the Categorical crossentropy was 0.1929.


      The transfer learning-based CNN model has good classification performance in the diagnosis of APTB, CAP and normal patients using CRs.

      Key Words

      CNN (convolutional neural network), APTB (active pulmonary tuberculosis), CAP (community-acquired pneumonia), CRs (chest radiographs), TB (tuberculosis), VGG16 (visual Geometry Group Network 16), ReLU (rectified linear unit), AUC (area-under-the-curve)
      To read this article in full you will need to make a payment

      Purchase one-time access:

      Academic & Personal: 24 hour online accessCorporate R&D Professionals: 24 hour online access
      One-time access price info
      • For academic or personal research use, select 'Academic and Personal'
      • For corporate R&D use, select 'Corporate R&D Professionals'


      Subscribe to Academic Radiology
      Already a print subscriber? Claim online access
      Already an online subscriber? Sign in
      Institutional Access: Sign in to ScienceDirect


      1. World Health Organization. Global tuberculosis report 2020. Available at: Accessed December 20, 2021.

        • Lee JH
        • Park S
        • Hwang EJ
        • et al.
        Deep learning-based automated detection algorithm for active pulmonary tuberculosis on chest radiographs: diagnostic performance in systematic screening of asymptomatic individuals.
        Eur Radiol. 2021; 31: 1069-1080
        • Skoura E
        • Zumla A
        • Bomanji J
        Imaging in tuberculosis.
        Int J Infect Dis. 2015; 32: 87-93
      2. World Health Organization. Systematic screening for active tuberculosis: principles and recommendations. 2013. Available at: Accessed December 20, 2021.

        • van Cleeff MR
        • Kivihya-Ndugga L
        • Githui W
        • et al.
        A comprehensive study of the efficiency of the routine pulmonary tuberculosis diagnostic process in Nairobi.
        Int J Tuberc Lung Dis. 2003; 7: 186-189
        • Wang B
        • Li M
        • Ma H
        • et al.
        Computed tomography-based predictive nomogram for differentiating primary progressive pulmonary tuberculosis from community-acquired pneumonia in children.
        BMC Med Imaging. 2019; 19: 63
        • Nambu A
        • Ozawa K
        • Kobayashi N
        • et al.
        Imaging of community-acquired pneumonia: roles of imaging examinations, imaging diagnosis of specific pathogens and discrimination from noninfectious diseases.
        World J Radiol. 2014; 6: 779-793
        • van Cleeff MR
        • Kivihya-Ndugga LE
        • Meme H
        • et al.
        The role and performance of chest X-ray for the diagnosis of tuberculosis: a cost-effectiveness analysis in Nairobi, Kenya.
        BMC Infect Dis. 2005; 12: 111
        • Rajpurkar P
        • O'Connell C
        • Schechter A
        • et al.
        CheXaid: deep learning assistance for physician diagnosis of tuberculosis using chest x-rays in patients with HIV.
        NPJ Digit Med. 2020; 3: 115
        • Nash M
        • Kadavigere R
        • Andrade J
        • et al.
        Deep learning, computer-aided radiography reading for tuberculosis: a diagnostic accuracy study from a tertiary hospital in India.
        Sci Rep. 2020; 10: 210
        • Qin ZZ
        • Sander MS
        • Rai B
        • et al.
        Using artificial intelligence to read chest radiographs for tuberculosis detection: a multi-site evaluation of the diagnostic accuracy of three deep learning systems.
        Sci Rep. 2019; 9: 15000
        • Kim TK
        • Yi PH
        • Hager GD
        • et al.
        Refining dataset curation methods for deep learning-based automated tuberculosis screening.
        J Thorac Dis. 2020; 12: 5078-5085
        • Khan FA
        • Majidulla A
        • Tavaziva G
        • et al.
        Chest x-ray analysis with deep learning-based software as a triage test for pulmonary tuberculosis: a prospective study of diagnostic accuracy for culture-confirmed disease.
        Lancet Digit Health. 2020; 2: e573-e581
        • Sathitratanacheewin S
        • Sunanta P
        • Pongpirul K
        Deep learning for automated classification of tuberculosis-related chest X-Ray: dataset distribution shift limits diagnostic performance generalizability.
        Heliyon. 2020; 6: e04614
      3. Respiratory society of chinese medical association. guidelines for the diagnosis and treatment of community-acquired pneumonia in Chinese adults (2016 edition).
        Chinese J Tuberc Respir Dis. 2016; 39: 253-279
        • Respiratory Group
        Pediatrics society of chinese medical association, editorial board of chinese journal of pediatrics. guidelines for the management of community-acquired pneumonia in children (2013 Revision)(I).
        Chinese J Pediatr. 2013; 51: 745-752
        • Respiratory Group
        Pediatrics society of chinese medical association, editorial board of chinese journal of pediatrics. guidelines for the management of community-acquired pneumonia in children (2013 Revision)(II).
        Chinese J Pediatrics. 2013; 51: 856-862
        • Hwang EJ
        • Park S
        • Jin KN
        • et al.
        Development and validation of a deep learning-based automatic detection algorithm for active pulmonary tuberculosis on chest radiographs.
        Clin Infect Dis. 2019; 69: 739-747
        • Heo SJ
        • Kim Y
        • Yun S
        • et al.
        Deep learning algorithms with demographic information help to detect tuberculosis in chest radiographs in annual workers' health examination data.
        Int J Environ Res Public Health. 2019; 16: 250
        • Lakhani P
        • Sundaram B
        Deep learning at chest radiography: automated classification of pulmonary tuberculosis by using convolutional neural networks.
        Radiology. 2017; 284: 574-582