# Research on Improved Bridge Surface Disease Detection Algorithm Based on YOLOv7-Tiny-DBB
## 3 Algorithm Enhancement
### Refinement of the Loss Function  
In the object detection field, the bounding boxes accuracy is crucial as it directly impacts the performance of detection algorithms. The traditional Intersection over Union (IoU) loss function quantifies the ratio between the intersection area and union area of the predicted bounding boxes and the ground truth bounding boxes [30; 31], as illustrated in Formula (2). This metric assesses the degree of overlap between two bounding boxes. Figure 4: Schematic diagram of the DBB network structure after integration. Figure 3: Schematic diagram of multi-scale convolution. When the predicted bounding box does not overlap with the ground truth bounding box, i.e., IoU = 0, it fails to reflect the distance discrepancy between the two bounding boxes. To address this issue, researchers have subsequently proposed GIoU, DIoU, CIoU, and EIoU [32; 33; 34]. These metrics tackle various problems, including non-overlapping predictions versus ground truths, overlapping scenarios, distances between center points, and discrepancies in aspect ratios, respectively. \[\text{IoU}=\frac{\beta_{\text{gt}}\cap\beta_{\text{prd}}}{\beta_{\text{gt}} \cup\beta_{\text{prd}}} \tag{2}\]  
In the equation: \(\beta_{\text{prd}}\) represents the predicted bounding box; \(\beta_{\text{gt}}\) denotes the ground truth bounding box. In the YOLOv7-Tiny algorithm, a combination of two loss functions, Focal Loss and CIoU Loss, is employed. The Focal Loss addresses the issue of class imbalance by reducing the weight of easily classified samples. On the other hand, CIoU Loss is an IoU-based loss function that takes into account not only the distance between the centers of bounding boxes but also their aspect ratios. This enhancement allows for a more accurate assessment of spatial relationships between target boxes, ultimately contributing to improved detection accuracy. However, when the predicted bounding box and the ground truth bounding box share the same aspect ratio but differ in their width and height values, the traditional loss functions (such as GIoU, DIoU, CIoU, and EIoU) may lose their effectiveness. This limitation hinders optimization processes and restricts both the convergence speed and accuracy of bounding box regression. The MPDIoU [35] boundary box loss function is a novel regression loss function based on the minimum point distance, which integrates the advantages of CIoU and EIoU. It also addresses the limitations encountered by CIoU and EIoU when the predicted boundary box and the ground truth boundary box share identical aspect ratios but differ in width and height values. Inspired by the rectangular characteristics of boundary boxes, the MPDIoU comprehensively considers relevant factors, such as overlapping areas, distances between center points, and deviations in width and height. It directly minimizes the distances between the top-left corner and bottom-right corner points of the predicted boundary box and its corresponding annotated ground truth box, as illustrated in Figure 5 (where green boxes represent predicted boxes and red boxes denote ground truth). The MPDIoU simplifies the computational process, as demonstrated in Equations (3)-(5). \[d_{1}^{2}=\left(x_{1}^{prd}-x_{1}^{gt}\right)^{2}+\left(y_{1}^{prd}-y_{1}^{gt} \right)^{2} \tag{3}\]  
\[d_{2}^{2}=\left(x_{2}^{prd}-x_{2}^{gt}\right)^{2}+\left(y_{2}^{prd}-y_{2}^{gt} \right)^{2} \tag{4}\]  
\[MPDIoU=IoU-\frac{\text{d}_{1}^{2}}{w^{2}+h^{2}}-\frac{\text{d}_{2}^{2}}{w^{2 }+h^{2}}=\frac{A\cap B}{A\cup B}-\frac{\text{d}_{1}^{2}}{w^{2}+h^{2}}-\frac{ \text{d}_{2}^{2}}{w^{2}+h^{2}} \tag{5}\]  
In the equation, \(w\) denotes the width; \(h\) represents the height; \(A\) and \(B\) are two arbitrary convex shapes; \(\left(x_{1}^{gt},y_{1}^{gt}\right)\) and \(\left(x_{2}^{gt},y_{2}^{gt}\right)\) indicate the coordinates of the center point of the ground truth bounding box; \(\left(x_{1}^{prd},y_{1}^{prd}\right)\) and \(\left(x_{2}^{prd},y_{2}^{prd}\right)\) signify the coordinates of the center point of the predicted bounding box.