# TCE-YOLOv5: Lightweight Automatic Driving Object Detection Algorithm Based on YOLOv5
## 3 Method
### Loss Function  
The loss function is very important in the training process because it can effectively measure the difference between the predicted results of the model and the real data. Well-designed loss functions play a dual role in improving model performance and training efficiency by accelerating convergence. In YOLOv5, the loss function integrates three key components: confidence loss, classification loss and localization loss. Localization loss is an important concept used in object detection to measure the degree of overlap between the bounding box and the ground truth, and thus to evaluate the accuracy of object detection, known as the Intersection over Union (IOU). However, the traditional IOU loss function has a significant drawback: when the bounding box does \begin{table}
\begin{tabular}{l c c c} \hline \hline
**Area** & **Small** & **Mediume** & **Large** \\  & **(IoU = 0.5:0.95)** & **(IoU = 0.5:0.95)** \\ \hline C3 & 0.461 & 0.616 & 0.781 \\ C3 Res2 Net & 0.467 & 0.623 & 0.751 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Detection results of C3 and C3 Res2 Net for targets of different sizes. Figure 5: Replace the Bottleneck in C3 with Res2 Net. not intersect with the target frame, the value of IOU is 0, which leads to the loss function failing to provide effective gradient information for the model, thus hindering further optimization of the model. YOLOv5 uses GIOU [37] as a localization loss function to solve the problem that the bounding box and the ground truth do not intersect and the original IOU is not differentiable. GIOU encloses the bounding box and the ground truth using the area of the minimum external rectangle, then calculates the proportion of the minimum external rectangle that is not part of the bounding box and the ground truth, and finally subtracts this proportion from the IOU to obtain the GIOU. The definition of GIOU is shown in the equation:  
\[GIOU=IOU-\frac{C-(A-B)}{C}. \tag{2}\]  
GIOU is better able to focus on the degree of overlap between the bounding box and the ground truth, but when there is an inclusion relationship between the bounding box and the ground truth, GIOU has difficulty distinguishing the relative position of the two. DIOU [38] solves this problem by directly measuring the Euclidean distance between the predicted box and the ground truth. The definition of DIOU is shown in the equation:  
\[DIOU=IOU-\frac{\rho^{2}(b,b^{gt})}{c^{2}}, \tag{3}\]  
where \(b\) represents the center point of the prediction box, and \(b^{gt}\) represents the center point of the real box, \(p\) represents the Euclidean distance between the two center points, and \(c\) represents the diagonal length of the minimum external rectangle. However, DIOU does not consider the aspect ratio of the bounding box and the ground truth, but the bounding box and the ground truth center point is the same, DIOU effect is not good. Therefore, CIOU [39] increases the aspect ratio on the basis of DIOU, which can effectively solve the problem of DIOU. The definition of CIOU is shown in the Equation (4), where \(v\) is the parameter used to compare the consistency of the aspect ratio, \(a\) is the weighting factor. \[CIOU=IOU-\left(\frac{\rho^{2}(b,b^{gt})}{c^{2}}+av\right), \tag{4}\]  
\[a=\frac{v}{(1-IOU)+v}, \tag{5}\]  
\[v=\frac{4}{\pi^{2}}\Bigg{(}arctan\frac{w^{gt}}{h^{gt}}-arctan\frac{w}{h} \Bigg{)}^{2}. \tag{6}\]  
Although CIOU has increased the aspect ratio, the definition of the aspect ratio is vague. EIOU [38] proposes to disentangle the influence of aspect ratio by independently calculating the length and width of the predicted bounding box and the ground truth. The description of EIOU is shown in Figure 6. The EIOU loss consists of three components: overlap loss, central distance loss, and width-height loss. The first two components follow the methodology established in CIOU, while the width-height loss specifically minimizes the discrepancy between the dimensions of the predicted and ground truth boxes, thereby accelerating the convergence speed of the model training process.