# Multi-Target Detection Algorithm for Fusion Images Based on an Attention Mechanism
## 4 Architecture Improvements for Multi-Target Detection
### Loss Function Improvement  
In this paper, the primary modification is applied to the CIoU loss component within the regression loss of the YOLOv8 framework. Intersection over Union (IoU) is often used to indicate the similarity between the model's prediction results and the true annotations, as shown in Figure 13.  
Figure 11: GAM spatial attention module. Figure 12: Improved YOLOv8 network model. The calculation process of IoU is as follows: first calculate the intersection and union area between the predicted area and the real marked area, then divide the intersection area by the union area, and finally get a ratio value, which is between 0 and 1. The calculation formula of IoU is shown in Equation (7). \[IoU(B_{1},B_{2})=\frac{|B_{1}\cap B_{2}|}{|B_{1}\cup B_{2}|} \tag{7}\]  
The closer the IoU is to 1, the closer the predicted result is to the real area. When the IoU value is greater than a certain threshold, it can be considered that the predicted box matches the real box and the prediction is correct. The IoU loss is defined as  
\[L_{IoU}=1-IoU(B,B_{gt}) \tag{8}\]  
There are some problems with IoU loss. When IoU loss is equal to 1, the predicted box and the real box do not overlap at all, but this cannot confirm how far apart the two boxes are, which makes it impossible to return the gradient for further training; when IoU loss is the same, it can only confirm that the intersection and union between the two boxes are the same size, and cannot reflect the overlap between the two boxes. It is shown in Figure 14.  
YOLOv8 uses CIU loss, which is more sensitive to target size than IoU loss. The schematic diagram of CIU is shown in Figure 15. The center line of the two rectangles of the predicted box and the true box is represented as \(l=\rho^{2}(b,b^{gt})\), and the diagonal of the minimum rectangle union of the predicted box and the true box is represented as c.  
Figure 14: Same IoU, different overlap methods. Figure 13: IoU diagram. The calculation formula of CIoU Loss is  
\[ \begin{split} CloULoss&=1-CloU=1-(IoU-\frac{\rho^{2}(b,b^{ gt})}{c^{2}}-\alpha v)\\ v&=\frac{4}{\pi^{2}}(arctan\frac{w^{gt}}{h^{gt}}- arctan\frac{w}{h})^{2}\\ \alpha&=\frac{v}{(1-IoU)+v}\end{split}  \tag{9}\]  
Among them, \(w^{gt}\) and \(w\) represent the width of the real box and the predicted box, respectively, \(h^{gt}\) and \(h\) represent the height of the real box and the predicted box, respectively, \(\alpha v\) is a penalty term with weights, \(\alpha\) is the weight value of \(v\), \(v\) represents the difference in aspect ratio between the predicted box and the real box, \(\frac{w^{gt}}{h^{gt}}\) contained in the v calculation formula is the aspect ratio of the real box, \(\frac{w}{h}\) is the aspect ratio of the predicted box, and the greater the difference between the two, the greater the value of \(v\). During the training of object detection networks, low-quality data, such as mislabeled bounding boxes or overlapping targets, can adversely affect model performance. CIoU loss penalizes predictions based on geometric discrepancies, including distance and aspect ratio. However, when trained on noisy data, this may result in overfitting and poor generalization. To mitigate this issue, we replace CIoU with WIoU [27], an adaptive loss function that reduces penalties for high-overlap predictions on low-quality samples, thereby improving the model's robustness and generalization capability. 1. Wise-IoU v1 The calculation equation of WIoUv1 is \[ \begin{split} L_{WIoUv1}&=R_{WIoU}L_{IoU}\\ R_{WIoU}&=exp(\frac{(x-x_{gt})^{2}+(y-y_{gt})^{2}}{( W_{g}^{2}+H_{S}^{2})^{*}})\end{split} \] (10)  
From Equation (10), we can derive \(R_{WIoU}\in[1,e)\), which is the penalty term of \(L_{IoU}\). When \(L_{IoU}\in(0,0.7)\), it is a normal anchor box, \(R_{WIoU>1}\), which can enlarge \(L_{IoU}\), but the enlargement coefficient of \(L_{IoU}\) is different in different cases. When \(L_{IoU}\to 1,(x-x_{gt})^{2}+(y-y_{gt})^{2}\to 0,R_{WIoU}\to 1\),the penalty term is the minimum value.