## 2 Method
### Improved YOLOv5 Algorithm
#### 2.2.3 SloU Loss Function  
The detection head of the YOLOv5 algorithm consists of three loss functions: classification loss, confidence loss, and localisation loss. In this paper, the GIoU loss function in the localisation loss is replaced with the SloU loss function. SloU takes into account the vector angle between the required regression loss and the matching direction of the ground truth box and the model-predicted box. It redefines the penalty metric, which can accelerate the convergence speed during training and improve the accuracy of inference. The SloU loss function consists of four cost functions, including angle cost, distance cost, shape cost, and IoU cost.  
Figure 4: ECA mechanism.  
The schematic diagram of the SIoU loss function calculation scheme is shown in Figure 5. The definitions of each cost function are as follows:  
\[\textcircled{1}\text{Angle cost}:\Lambda=1-2*\sin^{2}\Bigl{(}\arcsin \Bigl{(}\frac{c_{h}}{\sigma}\Bigr{)}-\frac{\pi}{4}\Bigr{)}\ =\cos\Bigl{(}2*\Bigl{(}\arcsin \Bigl{(}\frac{c_{h}}{\sigma}\Bigr{)}-\frac{\pi}{4}\Bigr{)}\Bigr{)} \tag{5}\]  
where \(\sigma=\sqrt{\Bigl{(}\mathrm{B}_{z_{x}}^{\mathrm{gt}}-\mathrm{B}_{z_{y}} \Bigr{)}^{2}+\Bigl{(}\mathrm{B}_{z_{y}}^{\mathrm{gt}}-\mathrm{B}_{z_{y}} \Bigr{)}^{2}}\), and \(c_{h}=\max\Bigl{(}\mathrm{B}_{z_{y}}^{\mathrm{gt}},\mathrm{B}_{z_{y}}\Bigr{)} -\min\Bigl{(}\mathrm{B}_{z_{y}}^{\mathrm{gt}},\mathrm{B}_{z_{y}}\Bigr{)}\), \(\Bigl{(}\mathrm{B}_{z_{x}}^{\mathrm{gt}},\mathrm{B}_{z_{y}}^{\mathrm{gt}} \Bigr{)}\) and \(\Bigl{(}\mathrm{B}_{z_{x}},\mathrm{B}_{z_{y}}\Bigr{)}\) represent the centre coordinates of the true and predicted boxes, respectively.  
\[\textcircled{2}\text{Distance cost}:\Delta=\sum_{t=x,y}\bigl{(}1-e^{-\gamma \rho_{t}}\bigr{)}\ =2-e^{-\gamma\rho_{x}}-e^{-\gamma\rho_{y}} \tag{6}\]  
where \(\rho_{x}=\Bigl{(}\frac{\mathrm{B}_{z_{x}}^{\mathrm{gt}}-\mathrm{B}_{z_{y}}}{ \mathrm{C}_{w}}\Bigr{)}\), \(\rho_{y}=\Bigl{(}\frac{\mathrm{B}_{z_{y}}^{\mathrm{gt}}-\mathrm{B}_{z_{y}}}{ \mathrm{C}_{h}}\Bigr{)}\), and \(\gamma=2-\Lambda\). \(C_{w}\) and \(C_{h}\) represent the width and height of the minimum enclosing rectangle for the ground truth box and predicted box, respectively.  
\[\textcircled{3}\text{Shape cost}:\Omega=\sum_{t=w,h}\bigl{(}1-e^{-w_{t}}\bigr{)} ^{\theta}=\bigl{(}1-e^{-w_{w}}\bigr{)}^{\theta}+\bigl{(}1-e^{-w_{h}}\bigr{)}^ {\theta} \tag{7}\]  
where \(w_{w}=\frac{\left|w-w^{\theta}\right|}{\max(w,w^{\theta})}\) and \(w_{h}=\frac{\left|h-h^{\theta}\right|}{\max(h,h^{\theta})}\); \(w\) and \(h\) represent the width and height of the predicted box, respectively; \(w_{\mathrm{gt}}\) and \(h_{\mathrm{gt}}\) represent the width and height of the ground truth box, respectively. The parameter \"\(\theta\)\" controls the attention given to shape loss. To prevent excessive emphasis on shape loss, which could hinder the movement of the predicted box, the parameter range is constrained to [2; 6].  
\[\textcircled{4}\text{IoU}\ \cos\text{t}:\text{IoU}=\frac{\left|\mathrm{B} \cap\mathrm{B}^{\mathrm{gt}}\right|}{\left|\mathrm{B}\cup\mathrm{B}^{\mathrm{gt }}\right|} \tag{8}\]  
where B and \(\mathrm{B}^{\mathrm{gt}}\) represent the region framed by the model prediction and the region framed by the actual label, respectively.  
Based on the calculations mentioned above, the SIoU loss function can be obtained:  
\[\textcircled{3}\text{IoU}:L_{box}=1-\text{IoU}+\frac{\Delta+\Omega}{2} \tag{9}\]