T HE novel corona virus disease pneumonia (COVID- 19) is a newly emerged viral disease causing a world-wide pandemic. The World Health Organization (WHO) [1] has already listed the COVID-19 outbreak as the sixth international public health emergency, following H1N1 (2009), polio (2014), Ebola in West Africa (2014), Zika (2016) and Ebola in the Democratic Republic of Congo (2019). As of May 2020, it has impacted around 170 countries and regions. There are globally more than 4m identified COVID-19 cases and the number of death is fast approaching 300k. Lock downs and restrictions have been applied by authorities in different countries to slow down its spread. The impact on the world economy has been massive due to restrictions applied to people's movement and the disruption of supply chains.
Screening suspected patients and the early diagnosis of COVID-19 is the best way to prevent its outbreak within a society. The sooner the diagnosis, the faster and smoother the medical recovery. The real-time polymerase chain reaction (real-time PCR) is the standard test for diagnosis of COVID-19 [2] . There are other complementary testing frameworks as well. Chest radiography (X-ray) [3] and computed tomography (CT) scanning have been used for the detection of COVID-19 [4] . These imaging techniques are more accessible in common health settings in many countries. Besides, as real-time PCR is not available at scale in many countries, the interest for COVID-19 diagnosis using medical imaging techniques has increased.
Machine learning techniques, deep learning models, and convolutional neural networks (CNNs) have been widely applied in recent years for medical imaging computer aided diagnosis [5] , [6] , [7] , [8] , [9] . A deep learning framework for detection pneumonia in chest X-ray images is proposed in [10] . Authors use region-based CNNs to configure regional context which helps finding accurate results. [11] proposes a novel deep learning algorithm that can detect pneumonia from chest X-rays at a level exceeding practicing radiologists. The CheXNet is a 121 CNN which has been trained using 112,120 frontal-view chest X-ray images individually labeled [11] .
Training multilayer CNNs requires a massive amount of data and compute resources. Currently the availability of thousands of images with proper labels is a barrier for developing reliable CNNs for the detection of COVID-19 using computer vision techniques. [12] proposed a transfer learning-based framework for early detection of COVID-19 cases using X-ray images. The obtained accuracies for binary and multi-classes are 98.08% and 87.02% respectively. Authors in [13] apply the transfer learning concept and use five pretrained CNNs for extracting features and processing them using feedforward neural networks. Obtained results indicate that the VGG19 and the MobileNet outperform others in terms of the classification accuracy. Also, it is observed that the MobileNet outperforms VGG19 in terms of specificity [13] . ResNet50, InceptionV3, and InceptionResNetV2 networks are used in [14] for automatic detection of COVID-19 using X-rays. Performance results suggest that the ResNet50 pretrained model achieves the highest accuracy of 98% amongst considered CNNs.
A deep learning-based framework for COVID-19 detection using CT images was proposed in [15] . The reported experimental results in the paper show that the proposed model model precisely identifies the COVID-19 cases from others with an AUC of 0.99 and recall (sensitivity) of 0.93. In [16] , machine learning techniques are applied for detection of COVID-19 cases from patches obtained from 150 CT images. Authors in [17] demonstrate that weakly-supervised deep learning algorithms could achieve promising results for COVID-19 detection. The number of collected sample is 499 which are processed using segmentation techniques and 3D CNNs. A deep learning framework is also proposed in [18] for detection COVID-19 and influenza-A viral pneumonia. The overall accuracy of developed models for 618 CT images is 86.7%.
All these studies report promising results for CNN models trained using a limited number of images. Deep neural networks often have hundred and thousands of trainable parameters that their fine tuning requires massive amounts of data. Besides, the limited number of samples raise concerns about epistemic uncertainty [19] . It is not clear how one can trust these models for a new case assuming they have been developed using a very limited number of training samples. These models could easily fail in real world applications if the training and testing samples are different [20] or far from the support of the training set (out of distribution samples) [21] . None of these models are able to report their lack of confidence for new cases. That information is essential for their widespread deployment as a reliable medical diagnosis tool [22] . Identifying and flagging these difficult to predict samples has much more practical values than correctly classifying them. A radiologist may consult with their senior colleagues when dealing with ambiguous or unknown cases. Accordingly, it is too important for DNNs to generate uncertainties as an additional insight to their point estimates [23] . This extra insight greatly improves the overall reliability in decisionmaking as the user will know when and where they can trust predictions generated by the model. The unflagged erroneous diagnosis could lead to unfortunate life losses which could easily blockade further machine and deep learning applications in medicine [19] .
Motivated by these shortcomings, this paper proposes a novel transfer learning-based and uncertainty-aware framework for reliable detection of COVID-19 cases from Xray and CT images. We use four pretrained CNN models (VGG16, DenseNet121, InceptinResNetV2 and ResNet50) to hierarchically extract informative and discriminative features from X-ray and CT images. This transfer learning approach is essential and efficient considering the limited number of samples. Extracted deep features are then passed to a number of machine learning model for the supervised classification task. Different performance metrics are computed for the comprehensive evaluation and the fair comparison of obtained results from different CNN architectures and classifiers. Last but not least, we also investigate the impact of lack of data on the reliability and quality of the classification results. The type of uncertainty that is important for deep learning models used for COVID-19 diagnosis is epistemic uncertainty which captures the model lack of knowledge about the data [24] . We then develop an ensemble of neural network models trained using different deep features to generate predictive uncertainty estimates. The quantified epistemic uncertainties provide informative hints about where and how much one can trust the model predictions.
The rest of the paper is organized as follows. Section II introduces our proposed method for classification and uncertainty quantification. Datasets and classification techniques are explained and introduced in section III. Section IV discusses obtained results and simulations in detail. Finally, the study is summarized in section V.
We will here apply the transfer learning approach to train machine learning models for COVID-19 detection. Two major issues motivate us to solve the COVID-19 detection using a transfer learning framework: (i) training DNN/CNN models require massive amount of data. This is not practical for COVID-19 as the number of collected and labeled images is very limited and often in the order of a few hundreds; (ii) training DNN/CNN models is computationally demanding. Even if thousands and millions of images are available, still it makes sense to first check the usefulness of existing pretrained models for data representation and feature extraction.
The proposed framework purely uses information content of X-rays and CT images to identify the presence of COVID-19. Here we consider five pretrained networks on ImageNet dataset and import and adapt them for the task of COVID-19 detection. These networks are VGG16 [25] , ResNet50 [26] , DenseNet121, and InceptionResNetV2 [27] . All these networks have achieved state of the art performance for correctly classifying images of the ImageNet dataset. Training of these networks is computationally very demanding as they have many layers and millions of trainable parameters. The main hypothesis in the proposed framework is that there are fundamental similarities between image detection/recognition tasks and the binary classification problem of COVID-19 using images. Accordingly, learnings from the former one can be safely ported to the later one to shorten the training process. While all five pretrained networks have been developed using non-medical images, it is reasonable to assume that their transformation of X-ray and CT image pixels could make the classification task easier.
As shown in Fig. 1 , the parameters of the convolutional layers are kept frozen during the training process. The convolutional layers of these five pretrained models are fed by X-ray and CT images for hierarchical feature extractions. The front end of the pretrained networks is then replaced by different machine learning classifiers to separate Covid and non-Covid cases. It is important to mention that we drop the pooling operation in the last convolutional layer of these pretrained networks. This is to avoid loosing informative features before passing them to the classification models.
Any classification study without reporting the predictive uncertainty estimates is not complete. There are two types of uncertainties which needs to be considered for deep learning models [28] :
• Aleatoric uncertainty which is related to the noise inherent in the data generating process. This type of uncertainty is irreducible. Fig.
(1) Block diagram of the proposed transfer learningbased framework for the COVID-19 detection using X-ray and CT images.
• Epistemic uncertainty which captures the ignorance about the model. In contrast to aleatoric uncertainty, epistemic uncertainty is reducible with collection of more training samples from diverse scenarios [29] . In this paper, we mainly focus on epistemic uncertainty as it closely relates to the generalization power of models for new samples [30] [31] [32] . Here we will use an ensemble of diverse models to obtain uncertainties associated with made inferences [30] . An ensemble consists of several models developed with different architectures, types, and sampled subsets. These model development differences cause diversity in the generalization power of models. Predictions obtained from individual models are then aggregated to obtain the final prediction. The prediction variance could be used for the calculation of the epistemic uncertainty [33] .
Similar to work in [24] and [34] , we calculate the prediction entropy as a measure of the epistemic uncertainty. the prediction entropy is a metric to measure the uncertainty in scores generated by different models [34] . The ensemble epistemic uncertainty is calculated as the entropy of the mean predictive distribution (by averaging all predicted distribution):
where θ i is the set of parameters for i th network element, and C ranges over all classes. For instance, suppose for a given input, an individual neural network predicts that the input is belongs to class 1 with x amount of probability and to class 0 with y amount. If we repeat this procedure 10 times for that specified input, it is similar to ensembling 10 networks for predicting the output probability. The final output probability can be calculated using Eq. 1. Now, imagine the average probability predicts that an input belongs to class 1 and 0 with 0.6 and 0.4 respectively. Based on Eq. 2, the prediction entropy can be calculated as 0.6 * log(0.6)+0.4 * log(0.4). It is obvious that the prediction entropy is become zero when the output is assigned to a class with high probability, and become maximum when the network is uncertain about its outcome.
There are two types of datasets used in this study: chest Xray and breast CT scan. These two types of imagery datasets are the main sources of information that clinicians use for COVID-19 diagnosis. The description of these datasets is provided in this section. Also statistical and machine learning classifiers applied to process features extracted by CNNs are briefly introduced.
1) Chest X-ray Dataset: This dataset is formed by taking 25 images of COVID-19 from [35] in the first step. We then add another 75 non-Covid cases of chest X-ray image from [36] . It is important to note that these non-Covid (normal) cases might consist of other unhealthy conditions such as bacterial or viral infections, chronic obstructive pulmonary disease and even a combination of two or more. Accordingly, what we mean by a normal or non-Covid case does not necessarily infer a healthy lower respiratory system. Two images of covid and normal classes are shown in Fig. 2. Fig. 2b displays a normal (non-Covid) case, yet virally infected. All images in this dataset are accessible via this link: https://github.com/dara1400/Covid19-Xray-Dataset.
2) CT Dataset: CT dataset has 349 Covid images and 397 non-Covid images [37] . Health professionals prefer breast CT scans as they carry more information compared to chest Xrays to use for medical diagnosis. Fig. 3 shows both a Covid and a non-Covid case from the CT database.
Here we briefly introduce the four CNNs used in this study for extracting features.
1) VGG16: [25] This model is similar to AlexNet and consists of 13 convolution, nonlinear rectification, pooling and 3 fully connected layers [38] . The filter size of convolutional network is 3 * 3 and the pooling size is 2 * 2. Due to its simple architecture, VGG network is performed better than AlexNet.
2) ResNet50: [26] Residual convolutional network (ResNet) is one the most popular deep structure which is used for classification problem (winner of ImageNet competition in 2015). Residual blocks enables the network to provide direct path to its early layers. This helps the gradient flow easily in the back propagation algorithm.
3) DenseNet121: [39] DenseNet won the ImageNet competition in 2017. Traditional deep networks have only one connection between layers. However in DenseNet, all layers receive all feature maps from previous layers as input [39] . This helps the network to decrease the number of parameters and also relieve the gradient vanishing. 4) InceptionResNetV2: Szegedy et al [27] presented a novel structure which helps to go deeper through convolution networks. Deep networks are prone to overfitting. They solve this solution using inception blocks. Further, they use residual blocks and create InceptionResNetV2 which use the combination of residual and inception blocks wisely.
High level information about these pretrained models is provided in Table I . As illustrated in Fig. 1 , network weights are kept frozen during the transfer learning procedure. The size of our input images is 224×224 for VGG16, ResNet50 and DenseNet121. The input size for the InceptionResNetV2 architecture is 299×299.
The COVID-19 detection is a binary classification problem where the input is an image (chest X-ray or CT image) and the output is a binary label representing the presence or absence of COVID-19. Here images are first processed by the convolutional layers of five pretrained networks. Hierarchically extracted features are then processed by multiple classifiers. We use eight classifiers to process features: k-nearest neighbors (NN), linear support vector machine (linear SVM), radial basis function (RBF) SVM, Gaussian process (GP), random forest (RF), multi-layer perceptron (NN), Adaboost, and Naive Bayes. These classifiers are briefly introduced below:
1) k-Nearest Neighbor (kNN): kNN is one of the simplest classification algorithm. It keeps a copy of all samples and classifies samples based on a similarity measure. This similarity measure is usually a kind of distance in the feature space. Most commonly used distance measures are Euclidean and Minkowski. In this paper, we use k = 2 and Minkowski distance metric for the classification task. The Minkowski is calculated as this:
If p =2, the Minkowski distance is the same as the Euclidean distance.
2) Support Vector Machine (SVM): It is a practical solution for classification problem especially in high dimensions. SVM uses line or hyperplane for dividing the data into appropriate classes. It tries to find a hyperplane with the largest distance to the most near data for each class (margin). The lower generalization error will be achieved when the margin becomes large [40] .
3) RBF SVM: It is a kind of SVM which uses the radial basis function (RBF) kernel for calculating the similarity (distance) between two samples. RBF kernel for two typical samples (x, y) can be calculated as below:
It is a set of random variables in a way that each set is described by a multivariate normal distribution. The final distribution of a GP is a joint distribution of all those random variables. GP uses covariance matrix and its inversion thus it will be a lazy learning algorithm in high dimension space. It outputs a distribution which not only estimates the prediction, but also provides prediction uncertainty estimates. We use RBF kernel with a length-scale equal to one for GP classifiers in this study.
A feedforward NN finds a nonlinear mapping between the fixed size inputs and the output (target). The network is composed of several hidden layers and processing units called neurons. A neuron receives inputs from neurons of the previous layer and generates its own output based on the assigned activation function. The connection weights between layers of the network are trained using training algorithms such as stochastic gradient descent or adaptive moment estimation (Adam).
6) Random forest (RF): RF classifier includes several decision trees developed in parallel. These trees are developed by randomly selecting a subset of features and samples from the original training samples. Each tree will vote and the class which has the most votes will be the final prediction. In this paper, we set the number of decision trees to 10. 7) Adaboost: Adaboost forms an efficient classifier by mixing several weak classifiers. Classifiers are formed in a serial approach in contrast to RF where classifiers are formed in parallel. Each classifier focuses on fixing mistakes made by previous classifiers. We here set the number of weak classifiers to 50. 8) Naive Bayes: Naive Bayes classifiers are the simplest Bayesian networks that use Bayes theorem. We use Gaussian naive Bayes which predict a posterior using a normal prior based on the Bayes theory.
Full information about these classifiers could be found in basic machine learning and statistical books [41] , [42] , [43] , [44] .
The simulation results and discussions are provided in this section. We first present results obtained by different classifiers processing features extracted by pretrained CNNs. We then focus on the uncertainty quantification problem using NN To build an intuition about samples, we first extract deep features using the method shown in Fig. 1 and then map them to the 2D space using principal component analysis (PCA) algorithm. Fig. 4 displays VGG16 features in the 2D space. As reported in Table I , the total number of extracted features for VGG16 is 25,088. Obviously, the number of samples for CT dataset is much higher and it is more balanced than the X-ray dataset. Also, it is interesting to see that normal (non-Covid) and Covid cases are fairly distinguishable for X-ray images in 2D space. In contrast, the decision boundary cannot be reasonably drawn in two dimensions for CT images.
Accuracy, sensitivity, and specificity are considered for the model evaluation. Purely relying on accuracy could lead to misleading results as both datasets and in particular X-ray one are imbalanced. For obtaining statistically valid conclusions, we train every single classifier 100 times using obtained features from pretrained CNNs. For each run, the performance metrics are calculated and then the box plot graph is generated. Fig. 5 represents the box plots for CT and X-ray datasets, respectively for the accuracy, sensitivity and specificity. It is noted that those values are calculated without PCA for all classifiers trained 100 times (all features passed to classifiers).
It is observed that the more the number of features, the less the ability of RBF SVM and GP to correctly classify samples. This is because they use the covariance matrix and its inversion, which in turn drops the sensitivity value to zero, making them unreliable. In contrast, linear SVM and NN prove to be the best ones among considered classifiers. This is because they use simple hyperplanes to separate features of two classes.
ROC curves for all pretrained CNNs and classifiers are shown in Fig. 6 To comprehensively compare different architectures for feature extraction, we train and evaluate each classifier 100 times. Then we average all predictions to obtain a reliable estimate of the sample label. Then performance metrics including accuracy, sensitivity, specificity, and AUC value are calculated. Table II and III report these performance metrics for CT and X-ray datasets. Reported values are given in percent. Having compared all models, we find that no model outperforms others for most cases than others. Linear SVM also achieves best results for each model.
Comparing the designed network to that of [37] , our transfer learning-based method outperforms theirs. The best results are achieved using ResNet50 and linear SVM classifier (an accuracy of 87.9%). This is more than 3% better than the best results reported in [37] . (84.7% accuracy). This improvement is mainly due to a better hierarchical extraction of features using ResNet50 and an optimal selection of the classifier (linear SVM).
It is also important to consider the network size and the number of deep features when comparing performance of pretrained CNNs for COVID-19 detection. Fig. 7 and Fig. 8 show the average of the classification performance (accuracy and AUC) for linear SVM and NN models in the 2D space formed by the number of CNN parameters (millions) and the number of features (ten thousands). The size of each point represents the accuracy and AUC metrics of the trained classifiers using features extracted by pretrained CNNs. The bigger the point, the better the performance. We generate these charts only for linear SVM and NN models as they are the best performing ones according to results presented in Table II and Table III . According to Fig. 7 and Fig. 8 , VGG16 is the most efficient pretrained CNNs for COVID-19 detection. It has the least number of parameters and extracts the smallest number of features. Those features are the most informative and discriminative ones as both linear and NN models achieve the best results using them. In contrast, the massive network of InceptionResNetV2 offers the most It is also quite important to quantify uncertainties associated with predictions. Here, we generate predictive uncertainty estimates for NN models. As mentioned before, there are several ways of generating ensemble networks. We use the entire dataset in the training step because the availability of more samples improves the generalization power of NN models. Twenty individual NN models with different architectures are first trained to form an ensemble. NN models have a hidden layer and their number of hidden neurons is randomly selected between 50 to 400. Fig. 9 shows the predictive uncertainty estimates for both Covid and non-Covid cases in a 2D space. Fig. 9a -9d display epistemic uncertainties for the X-ray dataset. Fig. 9e-9h show epistemic uncertainties for the CT dataset. The 2D space is obtained after applying PCA to reduce dimensionality of obtained features from pretrained CNNs. This projection to the 2D space is done to ensure that samples could be visualized against calculated predictive uncertainty estimates. The darker the color of filled area, the higher the uncertainty level. According Fig. 9a-9d , the level of epistemic uncertainty for the X-ray dataset is fairly low. While the projected features in the 2D space are in different locations for four pretrained CNNs, the NN classifiers generate very similar results. This consistency leads to a low uncertainty. In contrast, the predic-tive uncertainty estimates for CT images are quite high. This is evident from the large dark area in Fig. 9e-9h . These indicate that individual NN models in the ensemble have a different generalization power and produce significantly inconsistent results. There is no perfect agreement between all models about the predictive labels of these samples. Accordingly, more care should be exercised when using machine learning predictions for COVID-19 diagnosis using CT images.
The purpose of this study was to investigate the suitability of deep transfer learning for COVID-19 diagnosis using medical imaging. The key motivation was the lack of access to large repositories of images for developing deep neural networks from scratch. Leveraging the transfer learning framework, we apply 4 pretrained deep convolutional neural networks (VGG16, ResNet50, DenseNet121, and InceptionResNetV2) to hierarchically extract informative and discriminative features from chest X-ray and CT images. The parameters of the convolutional layers are kept frozen during the training process. Extracted features are then processed by multiple classification techniques. Obtained results indicate that linear SVM and multi-layer perceptron outperforms others methods in terms of the medical diagnosis accuracy for both X-ray and CT images. It is also observed that better prediction results and medical diagnosis could be achieved using CT images as they are much richer in information compared to X-ray images.
There are many rooms for improvement and further exploration. The performance of transfer learning algorithms could be majorly improved by fine tuning them to extract more informative and discriminative features. Features obtained from different transfer learning models could be combined to develop hybrid models. Also, predictions from individual models could be combined to form ensembles. Last but not least, state of the art method could be applied for more comprehensive estimation of the uncertainty measures. 