# Multi-Defect Detection Network for High-Voltage Insulators Based on Adaptive Multi-Attention Fusion
## 3 AC-YOLO Target Detection Network
### SIoU Loss Function  
The GIoU (generalized intersection over union) [23] loss function only focuses on the overlap area between the prediction frame and the real frame without considering the balance of difficult and easy samples, and there is a certain degree of fuzziness. For the problems above existing in the GIoU and in view of the insulator defect detection, the model convergence speed is slow, and the target prediction frame may not be able to match the real frame during training correctly. Therefore, this paper adopts the SIoU [24] loss function, and then, based on the GIoU loss function, the vector angle between the centers of the two frames is considered when the prediction frame returns to the real frame. This makes the prediction frame move quickly to the nearest coordinate axis and then return to a single coordinate (\(x\) or \(y\)), effectively reducing the free variables in the loss function and improving the classification accuracy of the model. The SIoU loss function consists of three parts: angular loss, distance loss, and shape loss. The SIoU loss function incorporates the angle between the center of the true bounding box \(B_{gt}\) and the predicted bounding box \(B\), resulting in a reduction of distance-related variables. The calculation of this function is as follows:  
\[\left\{ \begin{array}{l}\sigma_{d}=\sqrt{\left(B_{cx}^{gt}-B_{cx}\right)^{2}+ \left(B_{cy}^{gt}-B_{cy}\right)^{2}}\\ C_{H}=\text{max}(B_{cy}^{gt},B_{cy})-\text{min}(B_{cx}^{gt},B_{cx})\\ x=C_{H}/\sigma_{d}=\text{sin}(\alpha)\\ \Lambda=1-2\times\text{sin}^{2}(\text{arcsin}(x)-\frac{\pi}{4})\end{array} \,\right. \tag{10}\]  
Figure 9: Heat map visualization results, the dark red or yellow in the figure indicates the area that the CBAM attention mechanism focuses on. (**a**) Original YOLOv5 heat map; (**b**) added CBAM attention mechanism heat map. where \(\Lambda\) is the angle final result, \(\sigma_{d}\) is the distance between the prediction box and the center point of the real frame, \(C_{H}\) is the height difference between the prediction box and the center point of the real box, \(B_{cx}\) and \(B_{cy}\) are the center coordinates of the prediction box, and \(B_{cx}^{gt}\) and \(B_{gt}\) are the center coordinates of the real box, as shown in Figure 10a. Considering the angular loss defined above, the distance loss \(\Delta\) can be redefined as follows:  
\[\left\{ \begin{array}{l}\rho_{\rm x}=\left(\frac{\rm{B}_{\rm{x}}^{gt}-\rm{B}_ {\rm{x}}}{C_{w}}\right),\;\rho_{\rm y}=\left(\frac{\rm{B}_{\rm{y}}^{gt}-\rm{B}_ {\rm{y}}}{C_{h}}\right),\;\gamma=2-\Lambda\\ \Delta=\sum_{t=x,y}\left(1-e^{-\gamma p_{\rm t}}\right)\end{array} \right., \tag{11}\]  
where \(C_{\rm h}\) and \(C_{w}\) are the minimum external box length and width, respectively. As \(\alpha\) approaches 0, the contribution of \(\Delta\) decreases; conversely, the closer \(\alpha\) is to \(\pi/4\), the larger the contribution of \(\Delta\). Thus, as the angle increases, \(\gamma\) is assigned a time-preferred distance value. When \(\alpha\) tends to 0, the distance loss becomes more regular, as depicted in Figure 10b. The final shape loss, denoted as \(\Omega\), is calculated as follows:  
\[\rm{W}_{\rm w}=\frac{\left|w-w^{gt}\right|}{max(w,w^{gt})},\rm{W}_{h}=\frac{ \left|h-h^{gt}\right|}{max(h,h^{gt})}, \tag{12}\]  
\[\Omega=\left(1-e^{-\rm{w}_{w}}\right)^{\theta}+\left(1-e^{-\rm{w}_{h}}\right) ^{\theta}, \tag{13}\]  
where \((w,h)\) and \((w^{gt},h^{gt})\) are the width and height of the prediction frame and the real frame, respectively; \(\theta\) denotes the attention factor, and the specific value of the shape loss varies for different datasets. In this study, the shape loss was determined to be 5 based on the experimental results.