# YOLOv5-Sewer: Lightweight Sewer Defect Detection Model
## 2 YOLOv5-Sewer Network Design
### YOLOv5-Sewer Network Architecture
#### 2.2.5 Loss Function  
The YOLOv5 network employs the Complete Intersection over Union (CIOU) as its localization loss function, taking into account the overlapping area, the distance between the center points, and the aspect ratio of the true and predicted bounding boxes, as shown in Equations (4)-(6).  
\[L_{CIOU}=1-V_{IOU}+\frac{\rho^{2}(b,b^{gt})}{c^{2}}+\alpha v \tag{4}\]  
\[v=\frac{4}{\pi^{2}}(\arctan\frac{w^{gt}}{h^{gt}}-\arctan\frac{w}{h})^{2} \tag{5}\]  
\[\alpha=\frac{v}{(1-V_{IOU})+v} \tag{6}\]  
where \(V_{IOU}\) represents the Intersection over Union (IOU), \(v\) represents the aspect ratio impact factor, \(\alpha\) is the weight, and \(c\) represents the diagonal of the minimum rectangle containing both the true and predicted boxes. \(b\) and \(b^{gt}\) are the central points of the predicted bounding box and the ground-truth bounding box, respectively; \(\rho\) is the Euclidean distance between the center point of the predicted bounding box and the center point of the ground-truth bounding box; \(w^{gt}\) and \(h^{gt}\) are the width and height of the ground-truth boundary box, respectively; and \(w\) and \(h\) are the width and height of the predicted boundary box, respectively.  
The EIOU loss function is built upon CIOU, considering the length and width influence factor of the predicted and true boxes, as shown in Equation (7).  
\[L_{EIOU}=L_{IOU}+L_{dis}+L_{asp}=1-V_{IOU}+\frac{\rho^{2}(b,b^{gt})}{\left(w^ {e}\right)^{2}+\left(h^{c}\right)^{2}}+\frac{\rho^{2}(w,w^{gt})}{\left(w^{e} \right)^{2}}+\frac{\rho^{2}(h,h^{gt})}{\left(h^{c}\right)^{2}} \tag{7}\]  
Figure 6: The structure of coordinate attention.  
where \(L_{IOU}\) represents the loss of overlap between the prediction frame and the real frame, \(L_{dis}\) represents the loss of center distance between the prediction frame and the real frame, \(L_{asp}\) represents the loss of width and height of the predicted box and the real box, and \(w^{c}\) and \(h^{c}\) are the width and height of the smallest enclosing box that covers both boxes.  
The EIOU loss function is composed of three parts, inheriting considerations from the loss function for the overlap area and center point distance between the true and predicted boxes. These three parts are designed to comprehensively address various aspects of bounding box localization. Below is a brief explanation of each part.  
1. The first part is based on the CIOU loss, which considers the overlapping area. This component measures how well the predicted bounding box aligns with the truth bounding box.
2. The second part involves the calculation of the center point distance loss. This loss term evaluates the differences in the x and y coordinates of the center points of the predicted and true bounding boxes. Minimizing this distance contributes to accurate localization.
3. The third part deals with the aspect ratio loss. In this calculation, the lengths and widths of both boxes are separately computed. This component aims to minimize the differences in width and length between the predicted and true bounding boxes. This is particularly important in addressing variations in aspect ratio.