# Automatic Detection Method of Sewer Pipe Defects Using Deep Learning Techniques
## 3 Materials and Methods
### Sewer Pipe Defect Detection Method Based on Improved YOLOv4
#### 3.3.3 Different Bounding Box Loss Functions  
The effectiveness of the object detection tasks highly depends on the definition of the loss function. The loss function of YOLOv4 is shown in Equation (1), where \(L_{box}\) represents the loss of the bounding box, \(L_{conf}\) represents the loss of target confidence, and \(L_{cla}\) represents the loss of the category to which the target belongs.  
\[Loss=L_{box}+L_{conf}+L_{cla} \tag{1}\]  
There are several methods to calculate the loss of bounding boxes. YOLOv3 uses the mean square error (MSE) to calculate the loss of bounding boxes, but this method does not consider the integrity of the object and cannot continue learning when the predicted bounding box and ground truth do not overlap, so MSE is not used in this paper for testing. YOLOv4 uses CIoU to calculate the bounding box loss, which is a helpful solution to the shortcomings of MSE. However, sewer pipe defect images are different from traditional nature images. In order to find the most suitable loss function, a total of three different bounding box loss functions are investigated in this paper for their impact on model performance, including GIoU [27], DIoU [28] and CIoU [28]. The details of the three loss functions are as follows:  
1. As shown in Equation (2), in addition to considering the overlap area, GIoU adds the minimum outsourcing box as a penalty item, which solves the problem that the learning cannot continue when the predicted bounding box does not overlap the ground truth;
2. As shown in Equation (3), DIoU considers the Euclidean distance of the center point on the basis of GIoU, which solves the problem of large loss values when the distance between the predicted bounding box and ground truth is great;
3. As shown in Equation (4), CIoU considers the degree of overlap, Euclidean distance of the center point and aspect ratio. With the aspect ratio, CIoU can distinguish prediction bounding boxes with the same IOU but different regression effects. \[\text{L}_{boxGIoU}=1-GloU=1-(IoU-\frac{C-(A\cup B)}{C})\] (2)  
Figure 7: Architecture of the improved YOLOv4.  
\[\mathrm{L}_{boxDIoU}=1-DIoU=1-(IoU-\frac{\rho^{2}(b,b^{gt})}{c^{2}}) \tag{3}\]  
\[\mathrm{L}_{boxCIoU}=1-CIoU=1-\left(IoU-\frac{\rho^{2}(b,b^{gt})}{c^{2}}-\alpha v\right) \tag{4}\]  
\[IoU=\frac{|A\cap B|}{|A\cup B|} \tag{5}\]  
In Equation (2), \(A\) denotes the predicted bounding box, \(B\) denotes the ground truth and \(C\) denotes the smallest box which covers \(A\) and \(B\). As shown in Equation (5), \(IoU\) denotes the intersection ratio of \(A\) and \(B\). In Equation (3), \(b\) and \(b^{gt}\) denotes the center point of \(A\) and \(B\), respectively, \(\rho^{2}(b,b^{gt})\) denotes the Euclidean distance between \(b\) and \(b^{gt}\) and \(c\) is the diagonal distance of \(C\) as shown in Figure 8. In Equation (4), \(\alpha\) is the weighting factor and \(v\) is used to measure the consistency of the aspect ratio. The calculations of \(\alpha\) and \(v\) are shown in Equations (6) and (7).  
\[\alpha=\frac{v}{1-IoU+v} \tag{6}\]  
\[v=\frac{4}{\pi^{2}}(\arctan\frac{\omega^{gt}}{h^{gt}}-\arctan\frac{\omega}{h}) \tag{7}\]  
In this paper, we compare the influence of three different bounding box loss functions by replacing \(L_{box}\) in Equation (1) with \(L_{boxGIoU}\), \(L_{boxDIoU}\) and \(L_{boxCIoU}\), respectively.