## 3 Methodology
### Prediction of TB Using Ensemble of DCNNs  
The cropped lung regions from the segmentation branch were input into the prediction branch, which classified negative or positive TB. The cropped images were again resized to 512 \(\times\) 512 pixels and enhanced with contrast-limited adaptive histogram equalization (CLAHE) [49]. The prediction stage was based on DCNN. A DCNN scans over an image using the convolutional filters to extract the local features and aggregates these features to generate a prediction for the whole image. DCNNs automatically learn their parameters from a multitude of images labeled with the ground truths using an iterative updating of the parameters to minimize the prediction error, computed by comparing the DCNN prediction against the ground truth. The resulting DCNN can generate predictions on previously unseen images from the testing dataset.  
Twelve DCNN models: AlexNet [50], GoogleNet [51], Inceptionv3 [52], ResNet-50, ResNet-101 [53], VGG-16, VGG-19 [54], XceptionNet [48], SqueezeNet [55], ShuffleNet [56], MobileNet [57], and Densenet [58], trained on ImageNet, were used as the pre-trained models. To use the pre-trained DCNNs for TB detection, a new fully connected layer replaced the last fully connected layer of the pre-trained DCNNs. The new fully connected layer was trained on the training dataset of cropped lung images to generate a binary decision indicating the presence or absence of TB. Let X represent an input chest X-ray image, and the output is a binary label y \(\in\) {0, 1} indicating negative or positive for TB, respectively. For every image in the trained dataset, the weighted binary cross-entropy loss was optimized:  
\[CE(X,y)=\begin{cases}w_{p}\times-logP(Y=1/X)\;if\;y=1\\ w_{n}\times-logP(Y=0/X)\;if\;y=0\end{cases} \tag{1}\]  
where P(Y = i/X) is the probability that DCNN assigned to the label i, w\({}_{p}\) = \(\left\lvert\text{N}\right\rvert/(\left\lvert\text{P}\right\rvert+\left\lvert \text{N}\right\rvert)\) and w\({}_{n}\) = \(\left\lvert\text{P}\right\rvert/(\left\lvert\text{P}\right\rvert+\left\lvert \text{N}\right\rvert)\) where \(\left\lvert\text{P}\right\rvert\) is the number of positive and \(\left\lvert\text{N}\right\rvert\) the number of negative cases in the training dataset.  
Figure 3: Lung segmentation with DLabv3+X: DeepLabv3+ embedded XceptionNet as the backbone.  
All DCNN parameters were trained using stochastic gradient descent with momentum (SGDM) [59]. The hyperparameters of training each model with SGDM were optimized using the Bayesian algorithm [60]. Designing an ensemble by combining twelve DCNNs can be time-consuming, and a poor combination of these networks can overfit and result in poor performance. Thus, the optimal combination of DCNNs is defined using trials and errors. Different possible combinations of the trained DCNNs were established by averaging the probability of each DCNN, and the accuracy of each combination is measured. The combination that provided the highest accuracy is retained as the final ensemble classifier. Supposing m is the number of DCNN models and pn is the probability produced for each model, n, the average probability for an ensemble classifier can be computed using (2).  
\[\textit{average probability}=\frac{\sum_{n=1}^{m}\ p_{n}}{m} \tag{2}\]