# NTS-YOLO: A Notcurnal Traffic Sign Detection Method Based on Improved YOLOv5
## 2 Methods
### Optimization Loss Function  
In standard loss functions (e.g., cross-entropy loss and mean square error loss), the optimization process of the model may be affected by incorrect label assignments, especially when the target sizes are small or overlapping. In order to improve the accuracy and efficiency of YOLOv5 in nighttime traffic sign recognition, this paper introduced an innovative loss function, the Optimal Transport Assignment (OTA) loss, as illustrated in Figure 6. Specifically, the OTA loss function is defined by the difference between the predicted bounding box and the real bounding box set as the optimal transport cost, which is computed by the following equation:  
\[L_{\text{OTA}}=\sum_{i,j}T_{i,j}\cdot C_{i,j} \tag{5}\]  
where \(T_{i,j}\) is the amount of transmission between the predicted bounding box \(i\) and the real bounding box \(j\), and \(C_{i,j}\) is the corresponding cost, usually measured by the distance or difference between the two.  
Figure 6: OTA loss function structure diagram. The figure shows the process of object detection across multiple ground truth layers (GT0, GT1, GT2) and the background (BG) representation. The input image is first divided into grids, with each grid corresponding to different ground truth values. These grids contain values that represent the presence of different objects in the scene, as indicated by the colored boxes for each ground truth and background category. The loss function operates by matching the ground truth layers with the background and object regions, optimizing the predictions across the different layers to suppress irrelevant areas and enhance the detection performance.  
In this paper, we improved the accuracy of object detection by integrating the optimal transmission analysis (OTA) loss function into the YOLOv5 model. The OTA loss function was specifically designed to quantify the difference between the predicted bounding box and the real bounding box, and its computation is based on the amount of transmissions between the predicted bounding box and the real bounding box, \(T_{i,j}\), and the cost \(C_{i,j}\).  
Furthermore, we introduced the _OTA_ loss as a part of the training of the model, which not only took the alignment accuracy between predicted and real boxes, but also combined it with the traditional category loss, confidence loss, and bounding box loss in order to form a comprehensive loss function for the model. If the traditional YOLOv5 loss consists of the category loss \((L_{\textit{class}})\), the confidence loss \((L_{\textit{conf}})\), and the bounding box loss \((L_{\textit{bbox}})\), then the improved total loss function \((L_{\textit{total}})\) can be expressed as  
\[L_{\textit{total}}=\lambda_{\textit{class}}L_{\textit{class}}+\lambda_{\textit {conf}}L_{\textit{conf}}+\lambda_{\textit{bbox}}L_{\textit{bbox}}+\lambda_{ \textit{OTA}}L_{\textit{OTA}} \tag{6}\]  
Here, \(\lambda_{\textit{class}}\), \(\lambda_{\textit{conf}}\), \(\lambda_{\textit{bbox}}\), and \(\lambda_{\textit{OTA}}\) are the weighting factors used to balance the different loss components.