Rolov5-based motor vehicle model optimization method

By replacing the backbone network with MobileNetV3 in the yolov5 model and performing model sparse pruning, the problem of insufficient detection rate and accuracy in edge computing and mobile devices is solved, and rapid deployment and efficient detection are achieved to adapt to the deployment needs of complex scenarios.

CN119152343APending Publication Date: 2024-12-17NANJING HOWSO TECH

Patent Information

Application Number
CN202411213344.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

In the prior art In the edge computing and mobile device scenarios, the detection rate and accuracy of the yolov5 model are difficult to meet the needs, especially in complex and changing scenarios, and the deployment is difficult and the accuracy is reduced. In addition, INT8 accuracy conversion requires complex calibration methods to quantify. deal with.

Method used

MobileNetV3 is used to replace YOLOv5's backbone network, and through model sparseness and pruning technology, the model parameters and calculation needs are significantly reduced, the inference speed and deployment efficiency are improved, and the deployment efficiency is converted into FP16 precision deployment to maintain high accuracy and reduce deployment difficulty.

Benefits of technology

Achieves a motor vehicle detection model that is rapidly deployed on edge computing and mobile devices, improving detection speed and accuracy, reducing computing power requirements, adapting to complex scenario deployment, avoiding accuracy loss after INT8 accuracy conversion and calibration method complex quantization sex.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119152343A_ABST
    Figure CN119152343A_ABST
Patent Text Reader

Abstract

The invention discloses a method for optimizing a motor vehicle model based on yolov5, and the method comprises the steps: S1, preparing a data set: collecting image data containing various motor vehicles, generating a motor vehicle data set, and dividing the data set into a training set, a verification set and a test set; s2, model training: replacing a backbone network with MobileNetV3 on the basis of a YOLOv5 network structure, and inputting a data set for model training to obtain an algorithm model weight; s3, model rarefaction: carrying out rarefaction training on the model; s4, model pruning processing: pruning the sparse model, and performing weight pruning on the data; and S5, evaluating the precision of the model: carrying out performance test on the pruned model, and evaluating the precision and speed of the model. According to the method, after INT8 precision is converted by bypassing a model, the precision is quantified and improved through a calibration method, the model is optimized, the generalization ability of the model is improved, rapid edge end model deployment is achieved, and the deployment difficulty and time consumption are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of novel artificial intelligence technology, and in particular relates to an optimization method for a motor vehicle model based on YOLOv5. Background Art

[0002] Existing technologies usually use the yolov5s model and convert it into an FP16 precision model through TensorRT for deployment. This deployment will not affect the accuracy of the model, but it requires a large amount of resource consumption. In a resource-constrained environment, the detection rate of the model cannot meet the demand. If an INT8 precision model is used, the model rate meets the requirements, but the model has a large loss and the accuracy of the model will drop significantly. The accuracy can be improved through quantization technology, but the operation is complicated and time-consuming. The adjusted model has the problem of scene limitation. In the same type of scene, the model detection effect is better. If the scene is changed, it still needs to be re-optimized. In edge computing and mobile device scenarios, when storage space and computing power are limited, there are requirements for the detection rate and accuracy of the model. The above methods do not meet the conditions in actual production scenarios.

[0003] Chinese patent document CN 116721373 A discloses a lightweight electric vehicle entering elevator behavior detection method and device based on MobileNetv3. The method is specifically as follows: loading the optimal model to predict the collected elevator image data; the optimal model judges and obtains the category, confidence and corresponding target frame coordinate information of each detection target, and then obtains whether there is an electric vehicle entering the elevator; the optimal model uses the YOLOv5 network as the basic network, uses MobileNetv3 instead of CPSDarknet as the backbone network, and uses a lighter ULSAM attention module to replace the original SE attention module to generate a YOLO-MobileNet network, and trains the YOLO-MobileNet network to obtain the optimal model; compared with the initial YOLOv5 network, the number of parameters is reduced by 34.8%, and the model complexity is reduced by about 32%. This method uses YOLOv5 as the basic network, uses MobileNetv3 instead of CPSDarknet as the backbone network, and uses the lightweight ULSAM attention module to replace the original SE attention module to generate the YOLO-MobileNet network, and trains the YOLO-MobileNet network to obtain the optimal model. Fig.11As shown in the figure, the main steps of this method are to use MobileNetv3 instead of YOLOv5's CPSDarknet as the backbone network, and use a lighter ULSAM attention module to replace the original SE attention module to generate a YOLO-MobileNet network. The YOLO-MobileNet network is trained to obtain the optimal model, which greatly reduces the model size and parameter amount of the network while keeping the detection accuracy basically unchanged, providing a good solution for the detection of electric vehicle entering the elevator in real scenarios.

[0004] The existing technology uses TensorRT to directly convert the onnx model into an INT8 precision model for deployment, which improves reasoning performance and reduces storage requirements. It can be applied to edge detection. The precision loss caused by converting INT8 leads to a decrease in the accuracy of the model, which can be compensated by the calibration method quantization technology. However, the calibration method quantization technology is limited to the scene. If the scene changes, the accuracy of the model will fluctuate greatly. If it is not processed, it will cause missed detection and false detection problems. Therefore, it is necessary to re-quantize for different scenes. The calibration method quantization technology has a certain degree of complexity. For algorithm deployment in complex and changeable scenes, the calibration method quantization for INT8 precision conversion cannot meet the requirements.

[0005] The above method can detect motor vehicles in fixed scenarios, but if the scenario is complex and changeable, the algorithm deployment will be very difficult. Therefore, in actual production, this method is difficult to deploy quickly, and the professional and technical requirements of the deployment personnel are very high, and it is not suitable for large-scale deployment.

[0006] Therefore, in order to solve the problem that the int8 precision is reduced too much and the fp16 model rate cannot keep up, it is necessary to propose an optimization method for the motor vehicle model of yolov5, which is a method to circumvent the model conversion INT8 precision post-calibration method to quantitatively improve the precision. Summary of the invention

[0007] The technical problem to be solved by the present invention is to provide an optimization method for a motor vehicle model based on yolov5, to optimize the model, to improve the generalization ability of the model, to achieve rapid edge deployment of the model, and to reduce the difficulty and time consumption of deployment.

[0008] In order to solve the above technical problems, the technical solution adopted by the present invention is: the optimization method of the motor vehicle model based on yolov5 specifically includes the following steps:

[0009] S1 prepares the data set: collects image data containing various motor vehicles, generates a motor vehicle data set, and divides the data set into a training set, a test set, and a validation set;

[0010] S2 model training: Based on the YOLOv5 network structure, MobileNetV3 is used to replace the backbone network, and the data set is input for model training to obtain the algorithm model weight;

[0011] S3 model sparsification: perform sparse training on the model;

[0012] S4 model pruning: prune the sparse model and prune the data weights;

[0013] S5 evaluates model accuracy: performs performance tests on the pruned model to evaluate the accuracy and speed of the model.

[0014] Using the above technical solution, MobileNetV3-S was used to replace the original backbone network of yolov5, and the model was pruned at the same time, which significantly reduced the number of model parameters and computing requirements, and improved the reasoning speed and deployment efficiency. The backbone network of YOLOv5 was replaced with MobileNetV3-S, and the model was reduced through model pruning. The motor vehicle detection model was trained to identify motor vehicles. The improved YOLOv5 network reduced the model's memory usage and improved computing performance, further improved the model's detection speed and recognition accuracy, and reduced computing power requirements. It can meet more abundant scenarios and meet the deployment of detection in edge computing and mobile device scenarios. At the same time, during the training phase, the performance and generalization ability of target detection are improved. The advantage of using MobileNetV3 is that it can significantly improve the accuracy and efficiency of target detection through efficient feature extraction capabilities and good parameter efficiency. Converting the model to FP16 for deployment will not affect the accuracy of the algorithm, and the algorithm's reasoning speed can meet the needs of edge detection equipment, avoiding the technical complexity of the calibration method quantization technology after converting the INT8 model, optimizing the model, and improving the generalization ability of the model. It can be quickly deployed to various complex scenarios, greatly reducing the difficulty of model deployment.

[0015] The known technical content of the present invention is as follows:

[0016] YOLOv5 Motor Vehicle Detection Algorithm:

[0017] YOLOv5 technical features, YOLOv5 is a single-stage target detection algorithm. This algorithm adds some new improvement ideas based on YOLOv4, which greatly improves its speed and accuracy, including: Mosaic data enhancement, adaptive anchor box calculation, adaptive image scaling operation at the input end; Focus structure and CSP structure at the reference end; SPP and FPN+PAN structure at the Neck end; loss function GIOU_Loss at the output end.

[0018] Mosaic data enhancement - YOLOv5 still uses the Mosaic data enhancement method in the training model stage. This algorithm is improved on the basis of the CutMix data enhancement method. CutMix only uses two pictures for splicing, while the Mosaic data enhancement method uses 4 pictures and splices them in a random scaling, random cropping and random arrangement manner. This enhancement method can combine several pictures into one, which can not only enrich the data set, but also greatly improve the network training speed, and reduce the memory requirements of the model.

[0019] Adaptive anchor box calculation - In the YOLO series of algorithms, for different data sets, it is necessary to set an anchor box of specific length and width. During the network training phase, the model outputs the corresponding prediction box based on the initial anchor box, calculates the gap between it and the GT box, and performs a reverse update operation to update the parameters of the entire network. Therefore, setting the initial anchor box is also a key step. In the YOLOv3 and YOLOv4 detection algorithms, when training different data sets, the initial anchor box is obtained by running a separate program.

[0020] Adaptive image scaling - For different target detection algorithms, we usually need to perform image scaling operations, that is, scaling the original input image to a fixed size before sending it to the detection network. Common sizes used in the YOLO series of algorithms include 416*416, 608*608, etc.

[0021] Focus structure - The main idea of ​​this structure is to crop the input image through slicing operations. As shown in the figure below, the original input image size is 608*608*3. After slicing and splicing operations, a 304*304*12 feature map is output; then it passes through a convolution layer with 32 channels (this number of channels is only for the YOLOv5s structure, and other structures will have corresponding changes), and a 304*304*32 feature map is output.

[0022] CSP structure: In the yolov4 network structure, the design idea of ​​CSPNet is borrowed (by integrating the feature maps at the beginning and end of the network stage to respect the variability of the gradient). Yolov4 only designs the CSP structure in the backbone network. In YOLOv5, two CSP structures are designed. Taking the YOLOv5s network as an example, the CSP1_X structure is applied to the Backbone backbone network, and the other CSP2_X structure is applied to the Neck network.

[0023] IoU Loss-The so-called IoU Loss, that is, the intersection between the predicted box and the GT box / the union between the predicted box and the GT box.

[0024] GIOU_Loss adds a measurement method for intersection scale, which alleviates the IOU problem when the predicted boxes are the same size when using simple IOU_Loss, and the IOU=0 problem when the predicted box does not intersect with the real box. IOU_loss cannot optimize the situation where the two boxes do not intersect.

[0025] Preferably, the step S1 also includes enhancing the generated motor vehicle data set and adding random noise, generating new data set samples and annotating them, and then dividing the data set.

[0026] Preferably, the specific steps of step S2 are:

[0027] S21: Construct channel-separable convolution, use the first Conv2d layer to expand the number of channels of the input features; apply batch normalization to speed up the training process; use the second Conv2d layer to divide the input features into multiple groups and perform convolution operations on each group independently to achieve channel-separable convolution; finally, perform batch normalization and nonlinear activation on the output;

[0028] S22: Construct an attention mechanism module (SE), perform global average pooling on the input feature map, compress the spatial dimension of each channel into a 1x1 convolution kernel, and thus obtain a channel descriptor; use a 1x1 convolution kernel to compress the number of channels, and then perform batch normalization on the compressed feature map; then apply the ReLU activation function to increase nonlinearity; finally, use a 1x1 convolution kernel to restore the number of channels, and generate a weight for each channel through the learned weights; and remove the previous bottleneck layer connection;

[0029] S23: Use the training set data to train the improved YOLOv5 model; and test it. After the model training is completed, use the validation set to detect the accuracy and inference speed of the model.

[0030] Preferably, in step S3, L1 regularization is added to constrain the BN layer coefficients so that the coefficients are sparse; the formula of L1 normalization is:

[0031] L=∑ (x,y) l(f(x,W),y)+λ∑ γ∈Γ g(γ);

[0032] Among them, (x, y) represents the input and target of the training, W represents the weight of the training, is the original loss function, In the equation, g(s)=|s|, λ is the regularization coefficient.

[0033] Preferably, the specific steps of the sparse training in step S3 are:

[0034] S31 Modify the loss function: On the basis of the original loss function, add the L1 regularization term for the γ coefficient of the BN layer; the L1 regularization term encourages the model parameters to move closer to 0, thereby achieving sparsification; the regularization coefficient λ starts from 0 and gradually increases;

[0035] S32 training model: Use the modified loss function to train the model. During the training process, as the number of epochs increases, more and more γ coefficients will approach 0;

[0036] S33 Model Validation: Evaluate the accuracy of the model on the validation set, and evaluate the performance of the model under different λ values ​​through cross-validation (such as K-fold cross-validation). Evaluate the performance of the model under different λ values ​​through cross-validation (such as K-fold cross-validation), and select the λ value that minimizes the error on the validation set as the best parameter; this usually means that the model can generalize well to unseen data while maintaining a certain complexity.

[0037] Preferably, the specific steps of evaluating the performance of the model under different λ values ​​by cross-validation (such as K-fold cross-validation) in step S33 are: by dividing the data set into K subsets of equal size (if possible), and then taking turns to use K-1 subsets as training sets and the remaining subset as a test set, repeating this process K times, and calculating the model performance indicators (such as accuracy, recall rate, etc.) each time, and finally taking the average value of the model performance indicators as an estimate of the model performance.

[0038] Preferably, the specific steps of step S4 are:

[0039] S41: Perform model pruning according to the weight size of the sparse model, set a weight threshold, prune the weights in the model that are less than the model threshold, and remove the channels whose weight files are less than the weight threshold;

[0040] S42: The performance of the pruned model usually decreases, so fine-tune the pruned model.

[0041] MobileNet V3 network and model pruning, MobileNet is a series of convolutional neural networks (CNNs) that have achieved state-of-the-art performance on image classification tasks while maintaining computational efficiency. MobileNet V3 is a further development of the MobileNet series. Based on the previous two versions, it adds neural network architecture search (NAS) and h-swish activation function, and introduces SE channel attention mechanism, with excellent performance and speed. The main function of model pruning is to reduce the number of parameters and calculations of deep learning models, improve inference speed, reduce memory usage, and try to maintain the performance of the model. Pruning is mainly divided into the following types: one is weight pruning: pruning unimportant weights to make the weight matrix of the model sparse. The other is structured pruning: pruning the entire filter, channel or layer to make the structure of the model more concise. The present invention adopts weight pruning to prune unimportant weights so that the weight matrix of the model becomes sparse.

[0042] Preferably, the specific steps of step S42 are:

[0043] S421: setting the learning rate of the model to be lower than the original model learning rate;

[0044] S422: Retrain the model using the prepared dataset and fine-tuned parameters;

[0045] S423: During the training process, monitor the loss value and performance indicators of the model; determine the training rounds based on the convergence and performance of the model.

[0046] Preferably, in step S5, the performance of the pruned model and the original model is evaluated on multiple test sets, including accuracy indicators and speed indicators.

[0047] Preferably, in step S1, the labelImg tool is used to label the sample images in the data set, and the labeling format is consistent with the YOLO format; and the data set is divided into a training set, a validation set and a test set in a ratio of 8:1:1.

[0048] Compared with the prior art, the present invention has the following beneficial effects:

[0049] (1) It solves the workload caused by model quantization INT8, eliminates the need for quantization optimization for specific scenarios, and reduces the complexity of model deployment;

[0050] (2) Use MoblieNetV3 to replace the YOLOv5 backbone network, optimize the model pruning, and greatly reduce the number of model parameters, so that the model maintains a high accuracy while significantly reducing the resource consumption of loading the model; it can support deployment on various mobile devices;

[0051] (3) As the number of parameters decreases, the amount of computation also gradually decreases. Compared with the original model, the YOLOv5 model using MobileNetV3 as the backbone network is faster in inference;

[0052] (4) The model itself is lightweight and can be converted to FP16 precision by TensorRT during deployment to meet the requirements; FP16 has almost no impact on accuracy and does not require quantization optimization like INT8 precision models. This significantly reduces the difficulty of model deployment. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 It is a flow chart of the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0054] Figure 2 It is a network structure diagram of MobileNetV3 in the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0055] Figure 3 It is a yolov5s network structure diagram in the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0056] Figure 4 The network structure diagram of replacing the backbone network of yolov5s with MobileNetV3 in the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0057] Figure 5 It is a yolov5s detection performance diagram in the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0058] Figure 6 It is a yolov5s_MobileNetV3 detection performance diagram in the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0059] Figure 7 It is the channel separable convolution map in step S2 of the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0060] Figure 8 It is a SE module diagram in step S2 of the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0061] Fig. 9A bottleneck layer modification diagram in the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0062] Fig.10 It is a BN layer gamma pruning graph in the optimization method of the motor vehicle model based on yolov5 of the present invention;

[0063] Fig.11 It is a flow chart of the prior art in the optimization method of the motor vehicle model based on yolov5 of the present invention; DETAILED DESCRIPTION

[0064] The embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solutions of the present invention and are not intended to limit the protection scope of the present invention.

[0065] Example: Figure 1 As shown, the optimization method of the motor vehicle model based on yolov5 specifically includes the following steps:

[0066] S1 prepares the data set: collects image data containing various motor vehicles to ensure that the data set is diverse, including different types of motor vehicles (such as cars, trucks, motorcycles, etc.), as well as different environments, angles and lighting conditions, generates a motor vehicle data set, and divides the data set into a training set, a test set and a validation set; the step S1 also includes enhancing the generated motor vehicle data set, adding random noise, generating new data set samples and annotating them, and then dividing the data set; in the step S1, the labelImg tool is used to annotate the sample images in the data set, and the annotation format is consistent with the YOLO format; and the data set is divided into a training set, a validation set and a test set in a ratio of 8:1:1;

[0067] S2 model training: Based on the YOLOv5 network structure, MobileNetV3 is used to replace the backbone network, such as Figure 2 As shown, input the data set for model training to obtain the algorithm model weight;

[0068] The specific steps of step S2 are:

[0069] S21: Construct channel-separable convolution, use the first Conv2d layer to expand the number of channels of the input features; apply batch normalization to speed up the training process; use the second Conv2d layer to divide the input features into multiple groups and perform convolution operations on each group independently to achieve channel-separable convolution; finally, perform batch normalization and nonlinear activation on the output; Figure 7 As shown;

[0070] S22: Construct an attention mechanism module (SE), such as Figure 8 As shown in the figure; perform global average pooling on the input feature map, compress the spatial dimension of each channel into a 1x1 convolution kernel, and thus obtain a channel descriptor; use a 1x1 convolution kernel to compress the number of channels, and then perform batch normalization on the compressed feature map; then apply the ReLU activation function to increase nonlinearity; finally, use a 1x1 convolution kernel to restore the number of channels, and generate a weight for each channel through the learned weights; and remove the previous bottleneck layer connection; further reduce the network parameters, which can effectively reduce the inference time by 11%, with almost no performance loss; as shown in the figure Fig. 9 As shown;

[0071] S23: Use the training set data to train the improved YOLOv5 model; and test it. After the model training is completed, use the validation set to detect the accuracy and inference speed of the model; Figure 3 to Figure 6 As shown in the figure, compared with the original algorithm model, the comparison results of the model after replacing the backbone network show that after replacing the backbone network with MobileNetV3_Small, the number of layers increases and more features can be learned. The number of parameters is reduced from 7.23 million to 3.28 million, and GFLOPs is reduced from 16.6 to 5.9; the size of the model after training is also reduced from 14.12M to 6.62M;

[0072] S3 model sparsification: sparse training of the model; sparse training of the model is a technique to reduce the number of parameters and computational complexity of deep learning models, aiming to improve the generalization ability and efficiency of the model. This paper adds L1 regularization to constrain the BN layer coefficients to make the coefficients sparse; after sparse training, the sparse layers are very small, and the corresponding activations are also small, which has a low impact on the performance of the model. By repeatedly iterating this process, a very effective model can be obtained;

[0073] In step S3, L1 regularization is added to constrain the BN layer coefficients to make the coefficients sparse; the formula of L1 normalization is:

[0074] L=∑ (x,y) l(f(x,W),y)+λ∑ γ∈Γ g(γ);

[0075] Among them, (x, y) represents the input and target of the training, W represents the weight of the training, is the original loss function, g(s)=|s|, λ is the regularization coefficient;

[0076] The specific steps of the sparse training in step S3 are:

[0077] S31 Modify the loss function: On the basis of the original loss function, introduce the sparsity constraint, that is, add the L1 regularization term of the BN layer γ coefficient; the L1 regularization term will encourage the model parameters to move closer to 0, thereby achieving sparsity; the regularization coefficient λ starts from 0 and gradually increases;

[0078] S32 training model: Use the modified loss function to train the model. During the training process, as the number of epochs increases, more and more γ coefficients will approach 0;

[0079] S33 Model Validation: Evaluate the accuracy of the model on the validation set, and evaluate the performance of the model under different λ values ​​through cross-validation (such as K-fold cross-validation); Evaluate the performance of the model under different λ values ​​through cross-validation (such as K-fold cross-validation), and select the λ value that minimizes the error on the validation set as the best parameter; this usually means that the model can generalize well to unseen data while maintaining a certain complexity;

[0080] The specific steps of evaluating the performance of the model under different λ values ​​by cross-validation (such as K-fold cross-validation) in step S33 are as follows: by dividing the data set into K subsets of equal size (if possible), and then using K-1 subsets as training sets in turn, and the remaining subset as a test set, repeating this process K times, and calculating the model performance indicators (such as accuracy, recall rate, etc.) each time, and finally taking the average value of the model performance indicators as an estimate of the model performance; when the model meets the expected results, using the model for sparse training, so that the model weights are more compact, and some channels with smaller weights can be removed to achieve the purpose of model pruning; the specific operation is to introduce sparsity constraints during the training process, and use L1 regularization to constrain the BN layer coefficients, so as to prune those channels with relatively small contributions;

[0081] K-fold Cross-Validation is a technique for evaluating model performance. It splits the dataset into K subsets of equal size (if possible), then uses K-1 of the subsets as training sets and the remaining subset as a test set in turn, repeats this process K times, and calculates the model performance indicators (such as accuracy, recall, etc.) each time. Finally, the average of these performance indicators is taken as an estimate of model performance.

[0082] By repeatedly iterating the model, the accuracy of the final sparse model is basically the same as that of the model without sparseness. The performance comparison is shown in Table 1.

[0083] Table 1 Performance comparison before and after model sparsification

[0084] model map mode size yolov5s_MobileNetV3 0.892 6.62M yolov5s_MobileNetV3 (sparse) 0.896 6.62M

[0085] S4 model pruning: prune the sparse model and prune the data weights. After pruning, the performance of the model usually decreases. In order to restore or improve the model performance, it is usually necessary to fine-tune the pruned model to restore the detection accuracy of the model.

[0086] The specific steps of step S4 are:

[0087] S41: Perform model pruning according to the weight size of the sparse model, set a weight threshold, prune the weights in the model that are less than the model threshold, and remove the channels whose weight files are less than the weight threshold; the weight threshold here is set to 0.01;

[0088] S42: The performance of the pruned model usually decreases, so the pruned model is fine-tuned. After model pruning, the model parameter size is reduced by 34%, and the map is reduced by 6 points. The pruned model is fine-tuned, and the training process is the same as before pruning. Therefore, the parameters need to be fine-tuned.

[0089] The specific steps of step S42 are:

[0090] S421: Set the learning rate of the model to be lower than the original model learning rate; using a smaller learning rate helps the model to adjust parameters stably during fine-tuning;

[0091] S422: Retrain the model using the prepared dataset and fine-tuned parameters;

[0092] S423: During the training process, monitor the model's loss value and performance indicators such as accuracy and recall rate; determine the training rounds based on the model's convergence and performance; after fine-tuning, use the validation set or test set to evaluate the model's performance; compare the performance indicators before and after fine-tuning to evaluate the effect of fine-tuning; after fine-tuning, the model map is improved to 0.883, which basically reaches the performance of the original model;

[0093] S5 evaluates model accuracy: performs a performance test on the pruned model to evaluate the accuracy and speed of the model; in step S5, the performance of the pruned model and the original model are evaluated on multiple test sets, including accuracy indicators and speed indicators.

[0094] The performance of the improved model is evaluated by comparing the accuracy and model size of the original model. The specific performance parameters are shown in Table 2 below:

[0095] Table 2 Comparison of performance parameters of the original model and the improved model

[0096] mode map speed(ms) mode_size yolov5s 0.902 12.5 14.12M yolov5s_MobileNetV3 0.883 10.2 4.73M

[0097] From the results, it can be seen that compared with the original model, the size of the model after replacing the backbone network model and pruning is one-third of the original model, the inference speed of the model is also improved by 18%, and the accuracy of the model is slightly reduced. After verification, the accuracy meets the on-site requirements.

[0098] For ordinary technicians in this field, the specific embodiments are only illustrative descriptions of the present invention. It is obvious that the specific implementation of the present invention is not limited to the above-mentioned methods. As long as various non-substantial improvements are made using the method concepts and technical solutions of the present invention, or the concepts and technical solutions of the present invention are directly applied to other occasions without improvement, they are all within the protection scope of the present invention.

Claims

1. An optimization method for a motor vehicle model based on yolov5, characterized in that: The specific steps include: S1 prepares the data set: collects image data containing various motor vehicles, generates a motor vehicle data set, and divides the data set into a training set, a test set, and a validation set; S2 model training: Based on the YOLOv5 network structure, MobileNetV3 is used to replace the backbone network, and the data set is input for model training to obtain the algorithm model weight; S3 model sparsification: perform sparse training on the model; S4 model pruning: prune the sparse model and perform weight pruning on the data; S5 evaluates model accuracy: performs performance tests on the pruned model to evaluate the accuracy and speed of the model.

2. The optimization method of the motor vehicle model based on yolov5 according to claim 1, characterized in that: The step S1 also includes enhancing the generated motor vehicle data set and adding random noise, generating new data set samples and annotating them, and then dividing the data set.

3. The optimization method of the motor vehicle model based on yolov5 according to claim 1 is characterized in that, The specific steps of step S2 are: S21: Construct channel-separable convolution, use the first Conv2d layer to expand the number of channels of the input features; apply batch normalization to speed up the training process; use the second Conv2d layer to divide the input features into multiple groups and perform convolution operations on each group independently to achieve channel-separable convolution; finally, perform batch normalization and nonlinear activation on the output; S22: Construct an attention mechanism module, perform global average pooling on the input feature map, compress the spatial dimension of each channel into a 1x1 convolution kernel, and thus obtain a channel descriptor; use a 1x1 convolution kernel to compress the number of channels, and then perform batch normalization on the compressed feature map; Then apply the ReLU activation function to increase nonlinearity; finally, use a 1x1 convolution kernel to restore the number of channels, and generate a weight for each channel through the learned weights; And remove the previous bottleneck layer connection; S23: Use the training set data to train the improved YOLOv5 model; and test it. After the model training is completed, use the validation set to detect the accuracy and inference speed of the model.

4. The optimization method of the motor vehicle model based on yolov5 according to claim 3 is characterized in that: In step S3, L1 regularization is added to constrain the BN layer coefficients to make the coefficients sparse; the formula of L1 normalization is: L=∑ (x,y) l(f(x,W),y)+λ∑ γ∈Γ g(γ); Among them, (x, y) represents the input and target of the training, W represents the weight of the training, is the original loss function, In the equation, g(s)=|s|, λ is the regularization coefficient.

5. The optimization method of the motor vehicle model based on yolov5 according to claim 4 is characterized in that, The specific steps of the sparse training in step S3 are: S31 Modify the loss function: Based on the original loss function, add the L1 regularization term for the γ coefficient of the BN layer; S32 training model: train the model using the modified loss function; S33 Model Validation: Evaluate the accuracy of the model on the validation set and use cross-validation to evaluate the performance of the model under different λ values.

6. The optimization method of the motor vehicle model based on yolov5 according to claim 5, characterized in that: The specific steps of evaluating the performance of the model under different λ values ​​by cross-validation in step S33 are: by dividing the data set into K subsets of equal size, and then taking turns to use K-1 subsets as training sets and the remaining subset as a test set, repeating this process K times, and calculating the model performance index each time, and finally taking the average value of the model performance index as an estimate of the model performance.

7. The optimization method of the motor vehicle model based on yolov5 according to claim 5, characterized in that: The specific steps of step S4 are: S41: Perform model pruning according to the weight size of the sparse model, set a weight threshold, prune the weights in the model that are less than the model threshold, and remove the channels whose weight files are less than the weight threshold; S42: Fine-tune the pruned model.

8. The optimization method of the motor vehicle model based on yolov5 according to claim 7 is characterized in that: The specific steps of step S42 are: S421: setting the learning rate of the model to be lower than the original model learning rate; S422: Retrain the model using the prepared dataset and fine-tuned parameters; S423: During the training process, monitor the loss value and performance indicators of the model; determine the training rounds based on the convergence and performance of the model.

9. The optimization method of the motor vehicle model based on yolov5 according to claim 8, characterized in that: In step S5, the performance of the pruned model and the original model is evaluated on multiple test sets, including accuracy indicators and speed indicators.

10. The optimization method of the motor vehicle model based on yolov5 according to claim 2, characterized in that: In step S1, the labelImg tool is used to label the sample images in the data set, and the labeling format is consistent with the YOLO format; and the data set is divided into a training set, a validation set, and a test set in a ratio of 8:1:1.

Citation Information

Patent Citations

  • Method and equipment for identifying elevator entering behavior of electric vehicle based on YOLO-MobileNet

    CN116721373A

  • Traffic scene multi-target detection method and device

    CN115512329A

  • Lightweight and network optimization method based on YOLOX

    CN116306813A

  • Convolutional neural network pruning method based on feature map sparsification

    US11030528B1

Cited By

  • Crown block hook identification method and system based on YOLOv8

    CN120807959A