# Tailhook Recognition for Carrier-Based Aircraft Based on YOLO with Bi-Level Routing Attention
## 3 Methodology
### Loss Function Optimization  
The loss function \(GLoss\) consists of multiple components, namely classification loss, localization loss, and confidence loss. For the classification loss, cross-entropy loss, \(L_{EC}\), is adopted to measure the difference between the actual class and the predicted class. The formula for cross-entropy loss is as follows:  
\[L_{EC}=-\sum_{i=1}^{N}\sum_{j=1}^{C}y_{ij}log(\hat{y}_{ij})\,, \tag{13}\]  
where \(N\) is the number of samples and \(C\) denotes the number of classes. \(y_{ij}\) is a binary indicator that takes the value of 1 if the \(i\)-th sample belongs to the \(j\)-th class and 0 otherwise. \(\hat{y}_{ij}\) is the probability that the model predicts that the \(i\)-th sample belongs to the \(j\)-th class.  
Localization loss is utilized to quantify the discrepancy between the bounding box predicted by the model and the ground truth bounding box. In this paper, \(L_{geiou}\) is defined; it encompasses primarily distance loss and shape loss. The distance loss metric, denoted as \(L_{d}\), is expressed as follows:  
\[L_{d}=\frac{\lambda\rho^{2}(p,gt)}{c_{w}c_{h}}\,, \tag{14}\]  
Figure 8: The D_C3 module.  
Figure 7: The D_BottleNeck structure.  
where \(\rho(p,gt)\) is the Euclidean distance between the center point of the predicted bounding box and the ground truth bounding box; \(c_{w}\) and \(c_{h}\) denote the width and height of the smallest enclosing rectangle of the ground truth and predicted boxes, respectively, and \(\lambda\) is a scale factor used to adjust the influence of the center point distance.  
The shape loss metric \(L_{ar}\) is expressed as follows:  
\[L_{ar}=\frac{1}{N}\sum_{i=1}^{N}\big{|}ar_{p}-ar_{gt_{i}}\big{|}, \tag{15}\]  
\[ar_{p}=\frac{w_{p}}{h_{p}}, \tag{16}\]  
\[ar_{gt}=\frac{w_{gt}}{h_{gt}}, \tag{17}\]  
where \(ar_{p}\) is used to calculate the aspect ratio of the predicted bounding box; \(ar_{gt}\) is used to calculate the aspect ratio of the ground truth bounding box; \(w_{p}\) and \(h_{p}\) denote the width and height of the predicted bounding box, respectively; \(w_{gt}\) and \(h_{gt}\) denote the width and height of the ground truth bounding box, respectively; \(N\) is the number of preset different scales; \(ar_{gt_{i}}\) is the aspect ratio of the ground truth bounding box at each scale.  
So the \(L_{geiou}\) loss function can be expressed as  
\[L_{geiou}=1-IoU+L_{d}+L_{ar}, \tag{18}\]  
For the confidence loss \(L_{conf}\), it is usually combined with the prediction of object classes, indicating the probability that an object belongs to a specific class under the condition that the object exists. The calculation for the entire grid cell is as follows:  
\[\begin{split} L_{conf}=-\sum_{i=1}^{N}y_{obj}^{i}\log\left( \hat{y}_{obj}^{i}\right)-\\ \sum_{i=1}^{N}\left(1-y_{obj}^{i}\right)\log\left(1-\hat{y}_{obj }^{i}\right)\end{split}, \tag{19}\]  
where \(N\) is the number of grid cells and \(y_{obj}^{i}\) is a binary indicator of whether there is an object in the \(i\)-th grid cell. If there is an object, \(y_{obj}^{i}=1\); otherwise, \(y_{obj}^{i}=0\). \(\hat{y}_{obj}^{i}\) is the probability predicted by the model that an object exists in the \(i\)-th grid cell. In summary, the total loss function \(GLoss\) is given as follows:  
\[GLoss=L_{geiou}+\alpha L_{EC}+\beta L_{conf}. \tag{20}\]  
By comprehensively considering multiple loss information, \(GLoss\) enhances the accuracy and robustness of the model in object-detection tasks. Through hyperparameters \(\alpha\) and \(\beta\), \(GLoss\) can be used to adjust the relative importance among classification loss, localization loss, and confidence loss, thereby balancing the model's performance according to the requirements of specific tasks.