# Improving Tire Specification Character Recognition in the YOLOv5 Network
## 2 Improving the YOLOv5 Network
### Improved Regression Loss Function  
As a loss function, IoU-Loss is used to measure the similarity between predicted bounding boxes and actual annotations, with more emphasis on the overlap between the predicted results and the ground truth [22]. It is the most widely used metric for measuring the similarity between bounding boxes, but in tire logo recognition, the characters are relatively small, and using IoU may result in cases where the predicted bounding box and the ground truth do not intersect, resulting in the IoU being zero and unable to be optimized. GIoU [23] adds the minimum bounding box of the predicted and actual bounding boxes, which solves the problem of the IoU being zero, but when the predicted and actual bounding boxes have the same widths and heights and are on the same horizontal or vertical line,  
Figure 4: The C3 module. Figure 5: The C3-Faster module. GIoU degenerates into IoU. DIoU [24] adds a Euclidean distance between the center points of the two bounding boxes and a Euclidean distance between the two diagonal vertices of the minimum rectangle box based on GIoU, but DIoU degenerates into IoU when the two bounding boxes have the same center point but different aspect ratios. CIoU [25] is used as the loss function in YOLOv5. CIoU considers the consistency of the aspect ratio between the predicted and ground truth bounding boxes based on DIoU, and it adds a penalty term for the aspect ratio. However, due to the use of complex function calculations, CIoU consumes a lot of computing power in the calculation process, increasing the training time. WIoU [26] proposes a dynamic non-monotonic focus mechanism which uses \"out-lierness\" instead of IoU to evaluate the quality of anchor boxes, and it adopts a gradient gain allocation strategy to not only reduce the competitiveness of high-quality anchor boxes but also reduce the harmful gradients produced by low-quality anchor boxes, which enables WIoU to focus on low-quality anchor boxes and improve the overall performance of the detector. There are three versions of WIoU, among which WIoUv1 constructs an attention-based bounding box loss and WIoUv2 and WIoUv3 are obtained by adding a gradient gain to the focus mechanism on the basis of v1. In Figure 6[26], the green rectangle indicates the annotation box, the gray rectangle indicates the prediction box, and the blue rectangle indicates the minimum bounding box. The calculation formula of the loss function \(L_{WIoUv1}\)[26] for _WIoUv1_ is shown in Equations (1)-(3):  
\[L_{IoU}=1-IoU=1-\frac{W_{i}H_{i}}{wh+w_{gt}h_{gt}-W_{i}H_{i}}\overline{IoU}, \tag{1}\]  
\[R_{WIoU}=exp(\frac{\left(x-x_{gt}\right)^{2}+\left(y-y_{gt}\right)^{2}}{\left( W_{g}^{2}+H_{g}^{2}\right)}),\text{and} \tag{2}\]  
\[L_{WIoUv1}=R_{WIoU}L_{IoU}. \tag{3}\]  
The calculation formula for the loss function \(L_{WIoUv2}\)[26] of _WIoUv2_ is shown in Equation (4):  
\[L_{WIoUv2}=\left(\frac{L^{*}{}_{IoU}}{L_{IoU}}\right)^{\gamma}L_{WIoUv1}. \tag{4}\]  
Figure 6: Schematic diagram of annotation box, prediction box, and minimum bounding box. In Equation (4), \(L^{*}_{IoU}\) represents the monotonic attention coefficient and \(\overline{L_{IoU}}\) is the mean value, which is normalized in the formula to keep the gradient gain at a high level. The calculation formula for the loss function \(L_{WIoUv3}\)[26] of \(WIoUv3\) is shown in Equations (5) and (6):  
\[\beta=\frac{L_{IoU}^{*}}{L_{IoU}}\in[0,+\infty),\text{and} \tag{5}\]  
\[L_{WIoUv3}=rL_{WIoUv1},r=\frac{\beta}{\delta\alpha^{\beta-\delta}}. \tag{6}\]  
In Equations (5) and (6), \(\beta\) is the non-monotonic focusing coefficient and \(\alpha\) and \(\delta\) are hyperparameters. When \(\beta=\delta\), \(r=1\), and when the outlier degree of the anchor box satisfies \(\beta=\text{C}\) (C is a fixed value), the anchor box will obtain the highest gradient gain. The values of \(\beta\) and \(r\) are controlled by the hyperparameters \(\alpha\) and \(\delta\).