# An Improved YOLOv5s-Based Helmet Recognition Method for Electric Bikes
## 4 Materials and Methods
### Improved YOLOv5s Helmet Detection Algorithm
#### 4.2.3 Loss Function Improvement
On the contrary, NWD can evaluate the similarity between bounding boxes with differing scales and orientations as it adopts a Gaussian distribution that exhibits scale and direction invariance. Therefore, NWD excels in session scenarios involving mismatched directions and proportions in bounding boxes, which IoU cannot accomplish. 3. IoU tends to underestimate similarity when facing irregularly shaped objects. On the contrary, NWD evaluates similarity by converting bounding boxes into probability distributions, thus proficiently handling irregular shapes. NWD emerges as a more accurate, continuous, and robust metric for measuring similarity between bounding boxes. It performs well in scenes with irregular object shapes and different scales, thus outperforming IoU. 2. Convergence  
Convergence refers to the behavior of a deep learning model during the training process, especially how the performance of the model improves or stabilizes during iterations or epochs. It is an important characteristic for assessing the learning ability and effectiveness of the model. In deep learning, convergence is usually measured by monitoring the loss function or objective function. The loss function quantifies the difference between the model's predictions and the truth labels in the training data. The goal of training is to minimize this loss function and improve performance. In the training process, gradient descent and other optimization algorithms are used to iteratively adjust the parameters of the model to minimize the loss function. As the training progresses, the performance of the model improves and the losses are reduced. Convergence occurs when the loss function reaches a sufficiently low or stable value, indicating that the model has learned to generalize well and make accurate predictions. The convergence of a deep learning model can be evaluated by monitoring changes in training and validation loss. Different scenarios indicate different convergence states. If both training and validation losses are decreasing, it indicates that the network is still learning and improving its performance. On the contrary, if the training loss continues to decrease and the validation loss remains stable, the model may overfit the training data. When the training loss stabilizes and the validation loss decreases, it may indicate a potential problem with the dataset. If the training loss and validation loss are stable, it  
Figure 7: Deviation curve when the proportion of predicted box B is half of the true A.  
indicates that the model has converged or encountered a learning bottleneck, and adjusting the learning rate could be attempted. On the other hand, an increase in training and validation loss indicates a problem with the network architecture or improper setting of training parameters, in which case the training should be immediately stopped for code adjustment. In Figure 8, the change curves of the loss for the model before and after adding the NWD loss function are shown. The blue curve represents the loss change before improvement, while the red curve represents the loss change after modifying the NWD loss function. These curves provide insights into the impact of the modification on the convergence behavior of the model. The cls_loss (Classification Loss) measures the accuracy of the model in classifying object categories, while the box_loss (Bounding Box Loss) measures the accuracy of the model in locating object bounding boxes. The obj_loss (Objectness Loss) measures the accuracy of the model in detecting the presence of objects. According to Figure 8, it can be observed that train_loss and val_loss converge to stability, indicating that the model has converged. However, for cls_loss and box_loss, the NWD modification leads to faster convergence. In contrast, train_obj_loss shows similar behavior before and after the improvement, with overlapping curves. The val_obj_loss for YOLOv5s converges slightly faster.