# An Object Detection and Localization Method Based on Improved YOLOv5 for the Teleoperated Robot
## 2 Method
### Coordinate Attention Module Design
Loss Function Design  
The loss function of the classic YOLOv5 network model is composed of three parts: bounding box regression loss, prediction class loss, and confidence loss. The _GIOU_ is used as the bounding box regression loss function, as shown in Equation (1). \[GIOU=IOU-\frac{|C-(A\cup B)|}{|C|} \tag{1}\]  
where \(A\), \(B\subseteq S\subseteq R^{n}\) represent the ground-truth box and predicted box, \(C\) represents the minimum circumscribed box of \(A\) and \(B\), \(C\subseteq S\subseteq R^{n}\) and \(IOU=|A\cap B|/|A\cup B|\). The _GIOU_[34] function addresses the problem that the _IOU_[35] function is unable to appropriately reflect where the two boxes intersect when the predicted box and the ground truth box do not overlap. The _IOU_ function only pays attention to the overlapping area of the ground-truth box and predicted box. The _GIOU_ function not only pays attention to the overlapping area, but also pays attention to other non-overlapping areas, which can better reflect the degree of overlap between the ground-truth box and predicted box. However, when the predicted box is completely inside the ground-truth box, the _GIOU_ function and the _IOU_ function are the same. In this case, the _GIOU_ function degenerates into the _IOU_ function, which cannot reflect the positional relationship between the ground-truth box and predicted box and causes the bounding box regression slow to converge. Therefore, we changed the loss function of the classic YOLOv5 model from _GIOU_ to _SIOU_[36], as shown in Equations (2)-(5). \[L_{SIOU}=L_{IOU}+L_{ang}+L_{dis}+L_{sha}=2-IOU+\frac{(1-e^{-w_{w}})^{\theta}+ (1-e^{-w_{h}})^{\theta}-e^{-\gamma p_{x}}-e^{-\gamma p_{y}}}{2} \tag{2}\]  
\[w_{w}=\frac{|w-w^{gt}|}{\max(w,w^{gt})},w=\frac{|h-h^{gt}|}{\max(h,h^{gt})} \tag{3}\]  
\[\Lambda=1-2\sin^{2}(\arcsin(\alpha)-\frac{\pi}{4}) \tag{4}\]  
\[\rho_{x}=\left(\frac{b_{x_{x}}^{gt}-b_{c_{x}}}{c_{w}}\right)^{2},\rho_{y}= \left(\frac{b_{v_{y}}^{gt}-b_{c_{y}}}{c_{h}}\right)^{2},\gamma=2-\Lambda \tag{5}\]  
where \((w,h)\) and \((w^{gt},h^{gt})\) represent the width and height of the ground-truth box and predicted box, \((b_{c_{x}},b_{c_{y}})\) and \((b_{c_{x}}^{gt},b_{v_{y}}^{gt})\) represent the center coordinates of the ground-truth box and predicted box, \((c_{w},c_{h})\) represents the minimum bounding box width and height of ground-truth box and predicted box, \(\alpha\) represents the angle between the horizontal line and the center coordinate line of the ground-truth box and predicted box, and \(\theta\in[2,6]\) is an adjustable parameter to control the degree of attention to the \(L_{sha}\). The angle loss \(L_{ang}\), the distance loss \(L_{dis}\), the shape loss \(L_{sha}\), and the _IOU_ loss \(L_{IOU}\) are the four components that make up the _SIOU_ function. The _SIOU_ function achieves faster convergence in the stage of training and better performance in inference compared to existing methods by introducing directionality in the loss function cost. The final structure of the YOLOv5_Tel model is shown in Figure 4.