## 3 Proposed Method
### Loss Function  
In this chapter, we introduce a novel loss function named AF_Loss, which plays a crucial role in optimizing the learnable adaptive fusion factor proposed in the AFEM. The implementation details of AF_Loss are presented below:  
\[AF_{-}Loss=\frac{1}{3}\Big{(}(\alpha-\bar{\alpha})^{2}+(\beta-\bar{\beta})^{2 }+(\gamma-\bar{\gamma})^{2}\Big{)} \tag{10}\]  
where \(\alpha\), \(\beta\), and \(\gamma\) represent the learnable adaptive fusion factors of our AFEM. \(\overline{\alpha}\), \(\overline{\beta}\), and \(\overline{\gamma}\) are determined by the number of different-size objects on various layers in each image, which represent the contribution weights of the \(F_{1}\), \(F_{2}\), and \(F_{3}\) feature layers, respectively, for the feature enhancement of small objects. The layer weight calculation formula is as follows:  
Figure 6: On the left is the MNFM block, and on the right is our NFM Bottleneck.  
\[\overline{\alpha} =\frac{e^{n_{s}}}{e^{n_{s}}+e^{-n_{m}}+e^{-n_{l}}} \tag{11}\] \[\overline{\beta} =\frac{e^{-n_{m}}}{e^{n_{s}}+e^{-n_{m}}+e^{-n_{l}}}\] (12) \[\overline{\gamma} =\frac{e^{-n_{l}}}{e^{n_{s}}+e^{-n_{m}}+e^{-n_{l}}} \tag{13}\]  
In the equations provided above, \(n_{s}\), \(n_{m}\), and \(n_{l}\) are determined by searching for objects within their respective receptive fields in the ground truth, based on the varying receptive fields of the detector. These variables represent the numbers of small-scale objects, medium-scale objects, and large-scale objects, respectively.  
The specific query process is as follows: our AFE-YOLOv8 structure uses downsampling 5 times, and the final output feature maps are \(F_{1}\), \(F_{2}\), and \(F_{3}\), with sizes of 80 \(\times\) 80, 40 \(\times\) 40, and 20 \(\times\) 20, respectively. The \(F_{1}\) feature map has a small receptive field and is responsible for detecting targets with a size less than 32 \(\times\) 32, and the \(F_{2}\) feature map is responsible for detecting targets with dimensions greater than 32 \(\times\) 32 but less than 96 \(\times\) 96, and the \(F_{3}\) feature map has a large receptive field and is responsible for detecting targets with a size greater than 96 \(\times\) 96. The query layer is responsible for counting the number of targets at different scales. The targets smaller than 32 \(\times\) 32 are denoted as \(n_{s}\), while the targets larger than 32 \(\times\) 32 and less than 96 \(\times\) 96 are denoted as \(n_{m}\); the targets larger than 96 \(\times\) 96 are denoted as \(n_{l}\).  
As part of our proposed approach, the AF_Loss serves as a critical element within the overall loss function, which is primarily responsible for fine-tuning the learnable adaptive fusion factors in the AFEM. The total loss function comprises three key components: classification loss, regression loss, and AF_Loss.  
\[\text{Loss}\ =\lambda_{1}\ \text{Loss}_{cls}+\lambda_{2}\ \text{Loss}\ \text{reg}\ +\lambda_{3}\ \text{AF}_{-}\text{Loss} \tag{14}\]  
The parameter \(\lambda\) represents the weight of different loss functions in the total loss, where \(\lambda_{1}\) represents the weight of the classification loss, with a value of 0.5; \(\lambda_{2}\) represents the weight of the regression loss, with a value of 1.5; and \(\lambda_{3}\) represents the weight of the fusion loss proposed in this article, with a value of 0.8 (the \(\lambda\) values in the equation were optimized using the cosine annealing algorithm). The classification loss is calculated using binary cross-entropy loss:  
\[\text{Loss}_{cls}=-(y\log(p(x))+(1-y)\log(1-p(x))) \tag{15}\]  
And the regression loss is utilized as a Distribution Focal loss:  
\[\text{Loss}_{\text{reg}}\ =\text{DFL}(S_{i},S_{i+1})=-((y_{i+1}-y)\log(S_{i})+(y-y _{i})\log(S_{i+1})) \tag{16}\]  
Intuitively, \(S_{i}=\frac{y_{i+1}-y_{i}}{y_{i+1}-y_{i}}\), \(S_{i+1}=\frac{y-y_{i}}{y_{i+1}-y_{i}}\), and the DFL allows the network to focus on the values near the target \(y\) more quickly, increasing their probability.