# Attention-Based Transfer Learning for Efficient Pneumonia Detection in Chest X-ray Images
## 3 Results  
### Results  
The primary goal of our approach is to improve the accuracy of pneumonia diagnosis using chest X-ray images. We prepared three types of pre-trained models based on a different domain to check the generalization of our framework. Feature vectors were extracted using the backbone structures of pre-trained ResNet152, DenseNet121, ResNet18 to confirm the performance of the classification of pneumonia and normal. Each dimension of the feature vector of the model is 2048, 1024, 512. To verify our framework, we concatenate each feature vector with the same 1024 embedding dimensions. We applied three types of attention mechanisms, Self-Attention, SE, ECA. The proposed approach has been trained on 5216 images from Guangzhou Women and Children's medical center, while the rest of the 624 images were used for testing the performance of the model. We redefined the final layer of each of the pre-trained models with a new classifier suitable for classifying pneumonia and normal images. For the experiment, we implemented the Adam optimizer [33] and the NLL (Negative Log-Likelihood) loss function. The learning rate started at 0.0001 and was reduced by \(\gamma=0.1\) after every 10 epochs. The epoch represents the number of training sessions for training the datasets. The computations in the neural network are divided into forward pass, which goes through the calculation process of each layer's weight from input to output, and backward pass, which goes back to the calculation process and modifies the weight. Once the two processes are completed, one epoch was performed. All models were trained within 30 epochs. The results from each model are shown in Table 2. We used Recall, Precision, Area Under the Curve(AUC), and Test Accuracy as our evaluation metrics. The following can be obtained by calculating the Recall and Precision by referring to Figure 9 and Equation (5).There are a total of four possible outcomes from the binary classification we performed. It is divided into True Positive(TP), True Negative(TN), False Positive(FP), False Negative(FN). True and False  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Category** & **Train** & **Validation** & **Test** \\ \hline Normal & 1341 & 8 & 234 \\ Pneumonia & 3875 & 8 & 390 \\ \hline Total & 5216 & 16 & 624 \\ \hline \hline \end{tabular}
\end{table}
Table 1: The splits of the pneumonia datasets from Guangzhou Women and Children’s Medical Center.  
Figure 8: A sample of dataset.  
means whether the model was correctly or incorrectly predicted. The prediction of normal by the model means Positive, while predicting pneumonia means Negative.  
\[\text{Recall}=\frac{\text{TP}}{\text{TP}+\text{FN}} \tag{5}\] \[\text{Precision}=\frac{\text{TP}}{\text{TP}+\text{FP}}\]  
AUC uses Fall-out and Recall indicators. Fall-out is obtained as follows (shown in Equation (6)), and a graph resulting from Fall-out on the x-axis and Recall on the y-axis is called the Receiver Operating Characteristic(ROC) curve, and the area of the graph is called AUC. F-score is the harmonic mean of Precision and Recall (shown in Equation (7)), and is an indicator of the performance of the model if the data labels are unbalanced. Test accuracy indicates classification accuracy using test datasets (shown in Equation (8))  
\[\text{Fall-out}=\frac{\text{FP}}{\text{TN}+\text{FP}} \tag{6}\]  
\[\text{F score}=2\times\frac{\text{Precision}\times\text{Recall}}{\text{ Precision}+\text{Recall}} \tag{7}\]  
\[\text{Accuracy}=\frac{\text{TP}+\text{TN}}{\text{TP}+\text{FN}+\text{FP}+ \text{TN}} \tag{8}\]  
The proposed models were evaluated by metrics such as recall, precision, AUC, F-score and accuracy. SE achieved an accuracy, F-score, AUC, precision and recall of 96.63%, 0.973%, 96.03%, 96.23%, and 98.46%, respectively. SE achieved the best performance in terms of accuracy, followed by ECA and Self-Attention.