# Rotating Target Detection Method of Concrete Bridge Crack Based on YOLO v5
## 3 Enhanced YOLO v5 Model  
### Angle Regression  
The precision of crack annotation is correlated with the convergence time of network training, with fewer redundant details in annotations proving advantageous in guiding the training direction and accelerating the network's convergence speed. The original YOLO v5s network employs horizontal rectangular bounding boxes to determine object positions and categories. However, the cracks in concrete structure images exhibit elongated features, sometimes spanning the entire structural surface, with intersections and varying orientations. Evidently, rotated rectangular bounding boxes are more suitable for crack annotation, circumventing issues like overlapping true object boxes caused by original rectangular boxes and situations where larger boxes entirely enclose smaller ones. The annotation effect is depicted in Figure 3. It can be observed that rotated rectangular target boxes contain fewer redundant details, with the addition of angle information to represent orientation over the original horizontal bounding boxes. Therefore, this paper selects the YOLO v5s network model as a foundation and introduces modifications to create the new R-YOLO v5, specifically tailored for rotation-aware crack detection in concrete structures. Figure 3: Comparison of annotation effects between two types of rectangular boxes. (**a**) Original rectangular bounding boxes; (**b**) rotated rectangular bounding boxes. Figure 2: YOLO v5 network architecture. Common methods for defining rotated boxes often encounter angle boundary issues. Taking the long edge definition method as an example, the label comprises five parameters \((x,\;y,\;w,\;h,\;\;\alpha)\): \(x\) and \(y\), respectively, represent the horizontal and vertical coordinates of the rotated box's center point, while \(w\) and \(h\) denote the long and short sides of the rotated box. \(\alpha\) stands for the angle between the long side and the \(x\)-axis. The angle is measured within a range of \(180^{\circ}\), with an angle scope of \([-90^{\circ},90^{\circ})\), as illustrated in Figure 4.  
From Figure 3, it is evident that the boundary values of \(-90^{\circ}\) and \(90^{\circ}\) are essentially the same, but numerically they differ by \(180^{\circ}\). This discontinuity leads to issues of non-differentiability in the Intersection over Union (IOU) computation of rotated boxes. Consequently, in the regression loss calculation, the Smooth-L1 loss function [31], known for its adaptability to discontinuities at boundaries, is usually employed. However, minimizing the Smooth-L1 loss during training does not necessarily directly correspond to optimal performance in IOU evaluation, resulting in inconsistencies between model loss values and detection accuracy. To address this, a fundamental approach is offered by the Gaussian Wasserstein distance (GWD)-based regression loss [32], which approximates the non-differentiable rotated IOU loss by converting rotated boxes into two-dimensional Gaussian distributions. Even when two rotated bounding boxes do not overlap, GWD can effectively measure the loss value of bounding boxes. We transform any rotated box \((x,\;y,\;w,\;h,\;\;\alpha)\) into a two-dimensional Gaussian distribution \(N(\mu,\;\Sigma)\), with \(\mu\) representing the mean of the two-dimensional Gaussian distribution. It is composed of the center point's horizontal coordinate \(x\) and vertical coordinate \(y\). The calculation is as follows:  
\[\sum=\sum^{1/2}\sum^{1/2} \tag{1}\]  
\[\sum^{1/2}= \begin{bmatrix}\cos\alpha&-\sin\alpha\\ \sin\alpha&\cos\alpha\end{bmatrix}\begin{bmatrix}\frac{w}{2}&0\\ 0&\frac{h}{2}\end{bmatrix}\begin{bmatrix}\cos\alpha&\sin\alpha\\ -\sin\alpha&\cos\alpha\end{bmatrix} = \begin{bmatrix}\frac{w}{2}\cos^{2}\alpha+ \frac{h}{2}\sin^{2}\alpha&\frac{w-h}{2}\cos\alpha\sin\alpha\\ \frac{w-h}{2}\cos\alpha\sin\alpha&\frac{h}{2}\cos^{2}\alpha+\frac{w}{2}\sin^{ 2}\alpha\end{bmatrix}