The novel coronavirus disease (COVID-19) is a pandemic disease that has been spreading rapidly across the world and poses a serious threat to global public health. Till July 2020, COVID-19 has caused more than 13 million infections and 600k deaths across the globe.
Radiology plays a fundamental role in diagnosing the disease. Although less sensitive than chest CT, chest radiography (X-ray) is typically the first-line imaging modality used for patients with suspected COVID-19 [1] . Due to the international attention of the disease, there has been an increase in publicly available X-ray images of patients with COVID-19 related Pneumonia. This enables us to identify patterns and construct models that could automatically detect COVID-19 from chest X-ray images.
Because COVID-19 is still relatively new, naturally there are significantly less X-ray images of COVID-19 compared to non-COVID-19 diseases. This inevitably means that these datasets will be imbalanced with few COVID-19 samples which can hinder classification accuracy and limit model generalization.
To address these challenges, we propose a Focal Loss bAsed Neural Network EnsembLe (FLANNEL) model. FLANNEL utilizes an ensemble structure, using five state-of-the-art convolutional neural network (CNN) classifiers as based models. The Neural Weight
Module combines each base model using a learnt weighted ensemble to get the final classification results. To handle the class-imbalanced dataset issue, the model adapts Focal loss traditionally proposed for binary classification task to our multi-class classification task. This loss function back-propagates and updates the parameters of the Neural Weight Module.
We train and evaluate the proposed FLANNEL architecture on a combination of publicly available datasets. The combined data consists of 5508 chest x-ray images across 2874 patients. There are 4 types of X-ray images: Normal (n=1118), Bacterial Pneumonia (n=2787), COVID-19 Pneumonia (n=100), and non-COVID-19 viral Pneumonia (n=1503). These 4 types of X-rays naturally form a 4-way classification problem, where our focus is to make accurate prediction on COVID-19 cases without hindering the performance of other classes.
The convolutional neural networks (CNNs) have established themselves as the golden standard for most computer vision tasks such as image classification and object detection.
The basic building blocks for all CNN architectures are convolutional layers that extract feature maps from the input followed by pooling layers and a fully-connected and softmax layer at the very end. The yearly The ImageNet Large Scale Visual Recognition Challenge (ILSVRC) competition has motivated some of the best state-of-the-art CNN architectures, showing improvements on image classification tasks on standard image datasets such as CIFAR 1 and ImageNET 2 every year. Starting from standard 8-layer AlexNet [2] , CNNs have gotten more sophisticated with the addition of techniques such as Inception Modules and Residual Blocks [3] [4] [5] [6] .
For specific COVID-19 challenge, some works based on CNNs are created for various imaging data. Most of them focus on region segmentation and COVID diagnosis [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] .
For example, [21] designed and developed a contactless patient positioning system for scanning patients in a completely remote and contactless fashion. Chest CT based COVID-19 cases identification or localization segmentation tasks are studied in [22] [23] [24] [25] [26] [27] [28] [29] [30] .
[31] presented a deep learning method for COVID-19 classification based on lung ultrasound data. Several of them make prediction on 3D images (sequential CT-slice / Ultrasound-slice) [22, 24, 25, 26, 27, 29, 30, 31] . Different from those existing works, we focus on identification task on X-ray images which are 2D images as they are more commonly used in routine clinical visits. As the first-line imaging modality for assessing patients with suspected COVID-19, 2D chest X-ray is less sensitive than chest CT and hence posts a bigger technical challenge. The most related work is COVID-Net, a neural network architecture for X-ray based COVID cases detection [20] . We added COVID-Net [20] and AI-COVID [22] as baselines in the experiments.
Moreover we adopted several state-of-the-art CNN architectures as base models in FLANNEL for X-ray based COVID-19 detection. Due to limited number of COVID-19 X-ray images exist in training data, each of these models alone could suffer from high error and variance. In order to solve this issue and improve reliability, we utilize the power of Ensemble methods.
Ensemble Learning is a process of combining different independent classifiers, called base learners, to increase the robustness and accuracy of the final classification. As long as these base learners are diverse and able to capture the patterns in the data independently, the ensemble model is able to generalize significantly better by reducing individual errors [7] . Instead of training a complex single neural network with a large number of layers and parameters, decomposing the architecture into smaller and simpler individual base models have shown to be more accurate and require less time and memory for training [8, 9] . The individual base learners in Neural Network Ensembles capture patterns over different regions and/or granularities of the input space [10] , which contributes to its higher overall performance. Instead of relying on traditional methods of Ensemble voting such as Bagging, our proposed model introduces a Neural Ensemble Layer to adopt a Heterogeneous Ensemble strategy that uses different state-of-the-art CNNs as base learners to get the better accuracy compared with the individual classifiers.
Class imbalance in datasets is a very common but significant problem that often hinders model performance and generalization. Re-sampling, via undersampling or oversampling is a common tactic to solve the imbalance issue [11] [12] [13] . However, oversampling tends to be error-prone due to overfitting or added noise and undersampling reduces the amount of training data the model can learn from [14] , causing both methods ineffective in our setting. GANs (Generative Adversarial Networks) have shown to be decent augmentation tools to rebalance such datasets [15] , but GANs are quite difficult to train and can lead to the same problems as oversampling. Focal Loss is a special loss function proposed for imbalance binary classification task, in which the standard Cross-Entropy loss of model is reshaped such that the well-classified examples are down-weighted and it can focus on learning the hard imbalanced negatives [16] . In this paper, we adapt Focal loss to our multiple classification task.
Our main task is to differentiate between chest x-ray images of COVID-19 and other pneumonia and healthy patients which can be considered as a multiple classification task.
We combined two publicly available datasets: 1) COVID Chest X-ray (CCX) dataset 3 and 2) Kaggle Chest X-ray (KCX) images (Pneumonia) dataset 4 to generate the experimental data. The Kaggle chest X-ray data only contains three types of X-ray images: normal, Bacterial Pneumonia, and non-COVID-19 viral Pneumonia. We get the COVID-19
Pneumonia images from the CCX dataset, which contains a few X-ray images from the other classes as well. The choice of these two datasets for our experiment is guided by the fact that both are open source and fully accessible to the research community and the general public. As these public datasets grow, the model can continue to improve and scale continuously.
All of KCX images and most CCX images are based on anteroposterior (AP) or posteroanterior (PA) view. For consistency purposes, we only included images with both AP and PA view in our final experimental dataset. The dataset comprises a total of 5508 chest radiography images across 2874 independent patient cases. All images in KCX data are all in AP/PA view. CCX data has 131 images, of which 119 are AP/PA images. We only selected the 119 AP/PA images in our experiments, which includes 100 covid-related pneumonia, 11 viral pneumonia, 7 bacterial pneumonia, and 1 normal patient Chest X-ray images.
Because AP and PA are two different type of X-ray views, we introduced horizontal flips and random noise to convert PA into AP view. This method of data preprocessing allows us to train the same model for both views and allows the model to be view-independent.
We used a train-test split ratio of 4:1 to randomly generate the training and testing set to be used in the model. We furthermore use 5-fold cross-validation on training data to acquire 5 resulting models, and then record ensemble (average) performance of these 5 models on testing data. The reason we did this instead of one-time standard train, validation, test splits is that we want to maximize the sample usage because of the limited samples in this study. The detailed statistics of experimental data are shown in Table 1 .
For image preprocessing, we resized the original input images first to size 256x256 and then randomly cropped them in the center to size 224x224. The original X-ray images have some symbols in the corners correlated with our labels that could lead to feature leakage, so we introduce this crop around the center to mask that. The resolution 224x224 was chosen as it is the default input size for all of our base models. Although this downsampling in resolution may lead to loss of image details, it allows a simpler model that is easier to train and less prone to overfitting. Most state-of-the-art CNNs adopt this resolution for the same reason. The data is then augmented using random flip and noise and normalized before entering the model. 
As shown in Figure 1 , our proposed FLANNEL is composed of two stages. First, several base learners are independently trained for COVID-19 classification. Second, the resulting weights from all base learners are used to train the overall ensemble model. We also provide pseudocode in Table 2 to elaborate on the algorithm in detail.
The convolutional neural networks (CNNs) have been widely used in image classification and get huge successes. Here, we choose 5 popular and state-of-the-art CNN classification models as base learners to model the COVID-19 identification task. These following models were chosen due to their flexibility and high performance with general image classification.
Network [3, 17] . Due to the limited amount of training data of X-ray images, we use the listed pretrained models from the ImageNet Large Scale Visual Recognition Challenge (ILSVRC 5 ) and
fine-tune each model with respect to the COVID-19 identification task. For fine-tuning, all parameters of the models were retrained with no layer being frozen. This method of finetuning models pretrained on a general image set speeds up the training process and also helps with generalization. We modify the last classification layer for each base learner such that it produces a 4-length vector for 4-way classification.
We then take all the N (number of pretrained base learners and here is 5) M-length vectors where (1 − = T )^is a modulating factor with a tunable focusing parameter , and T represents a weight factor vector that balances the importance of the different classes.
When an example is misclassified and = T is small, the modulating factor is close to 1 and the loss is unaffected. As = T →1, the factor goes to 0 and the loss for well-classified examples is down-weighted. can be adjusted to tune the rate of this down-weighting. As increases, the effect of the modulating factor is likewise increased (we found =3 to work best in our experiments). For T , we can set the bigger value for the minority class and the smaller value for the majority class to make all classes contribute equally to our loss. 
Firstly, we compare FLANNEL with the chosen 5 base learners of FLANNEL framework, Resnet152, Densenet161, InceptionV3, VGG19-bn, and ResNeXt101. These models are some of the most popular state-of-the-art CNNs for image classification, known to have high classification rates for most image datasets. All of these models were fine-tuned using their default parameter settings and by using the Adam optimizer [19] .
Furthermore, we also compare FLANNEL with two recent Covid-19 deep learning models, COVID-Net [20] and AI-Covid [22] . COVID-Net is a tailored deep convolutional neural network design for COVID-19 cases detection. AI-Covid presented a deep network framework for sequential CT-slice image, and hence we just use slice-level classification networks for our identification task since we only have one X-ray image per sample in our dataset.
To verify the advantages of FLANNEL on ensemble learning, we also selected two traditional ensemble strategies voting and stacking to ensemble the 5 chosen base learners. These will be denoted as Voting and Ensemble_MLP respectively. For 
All the base models and FLANNEL are implemented in PyTorch and trained on 3 NVIDIA Tesla P100 GPUs over 200 epochs. The 5 base models 6 are fine-tuned using the respective pre-trained models with the default model architecture. The data is augmented 6 InceptionV3, Densenet161, Resnet152, ResNeXt101, Vgg19_bn with random flips, crops and scaling during the fine-tuning process.
After all the base models are trained separately, FLANNEL is trained by passing in the concatenated output layers of the base models as the input features.
In order to overall verify the prediction accuracy, we firstly measure the overall accuracy of the model in distinguishing the four classes (COVID19 viral pneumonia, Non-COVID19 viral pneumonia, bacterial pneumonia and normal images). The main intention of the study is the detection of Covid-19 among kinds of respiratory related X-ray images. For each class of images, the classification metric F1-score, which conveys the balance between the precision and the recall, is recorded.
In this section, we present the experimental results to show the performance of our proposed FLANNEL and all baseline methods.
First, we note that overall accuracy is not a great metric for evaluation the model. Since the classes in our dataset is heavily unbalanced in favor of non-COVID-19 Pneumonia images, even a significant increase in COVID-19 detection performance will not affect overall accuracy very much. Therefore, we present the F1-score for COVID-19 vs. rest comparing different models in Figure 2 . Obviously, it shows that FLANNEL outperforms other state-of-the-art models in detecting COVID-19 cases.
Moreover, we also present F1-score for each disease classification and macro-F1 score for all classes of the label set, which is shown in Table 3 . From Table 3 , we can observe that COVID-Net achieves better performance than other baseline models, since it is specifically designed for COVID detection. AI-Covid does not show apparent performance improvement on COVID detection. It is probably because AI-Covid mainly focus on fast features extraction followed by multi-slice ensemble for final 3-D CT image prediction, not specifically for 2D image classification. Multi-layer perceptron based ensemble strategy can improve detection performance on other majority classes, but has poor performance on minority class (COVID class). And, COVID-detection accuracy degrades with more-layers employment. More fully connected layers cannot effectively model limited features (concatenated outputs from base learners) specifically for this class-imbalance challenge. From Table 3 , FLANNEL shows a higher macro-F1 score with 2% increase, especially a 6% relative increase for COVID-19 cases over the best performing baseline model.
Loss, FLANNEL shows an increase of almost 6% in F1 score for COVID-19 cases. It is also clear that resampling strategies help improve performance in case of class imbalance. Traditional resampling strategies (FLANNEL_w/o_Focal + Sampling) increased F1 score for COVID-19 cases by almost 2%, while still almost 4% behind compared to FLANNEL. Also most importantly, FLANNEL was able to increase the performance of COVID-19 classification without negatively impacting the performance for other classes. Table 3 Performance comparison on F1-score: Class-specific F1-score is calculated using one class vs. the rest strategy. In order to verify model performance under single-view condition, we show performance evaluation (specifically for F1 score for COVID-19 vs. Rest) on AP-view X-ray images in Figure 5 . From Figure 5 , we can find that all models have performance degradation because of heavier imbalance with fewer samples with COVID label. Nevertheless, our
proposed FLANNEL still has best F1 score compared to all the baselines.
Then, Figure 6 presents the visual explanations for the classification results. We use Class Activation Mapping (CAM) to visualize the models' attention over inputs. The visual results are shown below. Here, we show each of the 5 base models' visual attention heatmaps. We observe that FLANNEL can pay more attention to specific regions in each base model parameters which allows it to make the correct overall prediction.
The most notable observation from the base models is that most of them perform poorly at detecting the Pneumonia caused by Viruses (both COVID-19 and non-COVID-19). This poor performance is likely due to the fact that 1) there are more bacterial and normal than viral images in our dataset and 2) the addition of the COVID-19 X-ray images makes it more difficult to differentiate between the two different classes of Viral Pneumonia since they are more similar to each other than they are to others. Our proposed FLANNEL has the possibility of differentiating chest x-ray images of COVID-19 against other pneumonia and healthy patients. Moreover, the significant feature of proposed FLANNEL is that it manages to sharply enhance COVID-19 identification performance without decreasing that of other classes. In fact, FLANNEL had the highest F1 score out of every single category except the normal class.
However, due to the limited specific COVID-19 Pneumonia related images, it is inevitable to combine multiple source data from different datasets to construct experimental data which has been described in section III in details. Even standard X-ray images look slightly different depending on the data source. For example, as noted before, there are some specific flags on images which originate from different X-ray acquisition equipment. The existing data source features can impact model learning for the core classification task.
We have implemented some preprocessing methods, such as random center crop, to to alleviate the impacts from data sources. However, it is still a challenge to conduct source agnostic image classification that utilizes big scale data from multiple data source to learn class features and mapping rules to infer the classification task without considering the different data source impacts. Source-free classification for COVID-19 is future work that might significantly improve the performance of the model.
Another direction to consider is to incorporate hierarchical classification. In our case, we can consider first separating healthy from sick patients based on their X-rays, then further separating bacteria, viral pneumonia and COVID among the sick. The naïve approach requires training multiple models at different levels which can create challenges at the granular level (e.g., viral pneumonia vs. COVID) due to the small sample size. Multiple models also introduce more computation and maintenance challenges in the long run. A single model that directly incorporates the hierarchical class structure is an interesting but challenging task in itself. One can consider designing a proper loss function to capture the intricate class hierarchy. We consider this topic as an important future work.
COVID-19 is an acute resolved pneumonia disease with high fatality rate. As the most commonly ordered imaging study for patients with respiratory complaints, X-ray can help COVID-19 diagnosis. Hence, it is significant to study automatic diagnosis of the disease.
Our objective is to explore effective deep learning methods to model X-ray images and improve prediction performance in identifying Covid-19 from other pneumonia images and healthy images.
With the power of Ensemble Learning, FLANNEL has the ability to detect and diagnose COVID-19 from Pneumonia X-ray images with high accuracy, even when trained on just around 100 available COVID-19 X-ray images. We have shown that it is able to automatically combine and use the outputs of individual base learners as features to create a more accurate global model. Focal Loss allows us to use all the training samples effectively without having to sample our already limited imbalanced dataset and solves the imbalance problem that hinders other traditional loss functions such as Cross-Entropy loss.
FLANNEL vastly outperforms all other state-of-the art CNN architectures especially on the COVID-19 detection without much added model complexity or parameters.
This model could be used to supplement current COVID-19 diagnosis kits to improve testing availability and alleviate supply shortages through just examining X-ray images.
With millions of confirmed cases only expected to grow in the future, neural networks could make a real impact in limiting the spread of the disease.
This research received no specific grant from any funding agency in the public, commercial or not-for-profit sectors. 