Vehicle and pedestrian identification method based on improved YOLOv5

By using the Alpha-IOU loss function, adding the P2 detection layer and sparsity training pruning technology in the YOLOv5 model, the problem of missed detection of small targets in complex traffic scenes is solved, the detection accuracy and efficiency are improved, and it is suitable for autonomous driving environments.

CN118608918AInactive Publication Date: 2024-09-06SHANGHAI DIANJI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410738458.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-09-06
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In complex traffic scenarios, it is difficult for existing technologies to improve target detection performance while meeting real-time performance, especially when small targets in the distance are easily missed in detection at different target distances.

Method used

The vehicle pedestrian recognition method based on improved YOLOv5 is adopted, by replacing the loss function with the Alpha-IOU loss function, adding a P2 shallow detection layer, adding L1 regular constraints and sparsity training, and pruning operations to improve the detection accuracy and efficiency of the model.

Benefits of technology

It improves the accuracy and robustness of the model for small target detection, alleviates problems caused by changes in target scale, reduces the amount of model parameters and calculations, and improves detection speed and deployment efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118608918A
    Figure CN118608918A
Patent Text Reader

Abstract

The invention discloses a vehicle and pedestrian identification method based on improved YOLOv5, and the method comprises the following steps: S1, taking a vehicle on different road scenes, shooting vehicle and pedestrian pictures on a road through a camera, and screening a part of pictures in a BDD100K and KITTI public data set; s2, the data set is preprocessed, pictures with unobvious vehicle and pedestrian features are removed, and the shot pictures are marked; s3, standardizing a data set label format, reclassifying label types, and dividing a data set according to a proportion; s4, improving a YOLOv5 algorithm, using Alpha-IOU loss to replace C-IOU loss of an original model as a loss function of bounding box regression, and adding a P2 shallow layer detection layer in the model; s5, the improved YOLOv5 algorithm is trained; and S6, carrying out sparse training and pruning on the algorithm by adding an L1 regular constraint BN layer coefficient. By improving the algorithm, flexibility is provided for the detector, and the learning ability of the algorithm for small target features is improved; and through model pruning, the lightweight effect and the detection speed of the model are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of target detection, and in particular to a vehicle and pedestrian recognition method based on improved YOLOv5. Background Art

[0002] At present, the rapid development of computer vision technology has brought about changes in the environmental perception system of smart cars. The environmental perception system can perceive the surrounding complex environment in a timely and accurate manner, which is of great significance for avoiding collisions and ensuring driving safety.

[0003] After searching, the Chinese patent with the publication number CN112818942B discloses a method and system for pedestrian action recognition during vehicle driving. It proposes that in the scenario of autonomous driving, it is difficult to accurately identify pedestrian actions for pedestrian behavior recognition, and proposes a technical solution to improve the accuracy of pedestrian action recognition by adopting a spatiotemporal fully adaptive graph network;

[0004] The Chinese patent with announcement number CN113536940A discloses a method for sensing the driving environment of a vehicle. It proposes that during the process of unmanned automatic driving, it is necessary to correctly identify vehicles traveling in the same lane to ensure safety. It proposes a technical solution to accurately identify vehicles by using the optical flow method to improve the accuracy of identifying lane lines and vehicles during vehicle driving.

[0005] The Chinese patent with announcement number CN116977964A discloses a method for vehicle environment perception and an autonomous driving vehicle. It points out that the existing environment perception solutions have the problems of low image segmentation accuracy, low efficiency, and poor adaptability to autonomous driving scenarios. It proposes a technical solution of a convolutional network architecture using an edge attention mechanism to solve the above problems.

[0006] However, for autonomous driving, the task of environmental perception is particularly important. How to improve the target detection performance of the model while meeting the real-time requirements, especially in complex traffic scenarios, when different targets are at different distances from the lens, there will be different scales. How to solve the problem of missed detection of small targets in the distance is an urgent problem to be solved. Summary of the invention

[0007] The purpose of the present invention is to solve the defects in the prior art and propose a vehicle pedestrian recognition method based on improved YOLOv5.

[0008] In order to achieve the above object, the present invention adopts the following technical solutions:

[0009] A vehicle and pedestrian recognition method based on improved YOLOv5 includes the following steps:

[0010] S1: Take a car on different road scenes, use a camera to take pictures of vehicles and pedestrians on the road, and select some pictures from the BDD100K and KITTI public datasets to form the dataset required for this model;

[0011] S2: Preprocess the collected data to remove blurry images or images with unclear vehicle and pedestrian features, and use the LabeImg annotation tool to annotate the captured images;

[0012] S3: Standardize the format of BDD100K and KITTI dataset labels, classify the label types in the annotation files, and then divide the dataset into training set, test set, and validation set according to the proportion;

[0013] S4: Build a vehicle and pedestrian recognition algorithm based on the improved YOLOv5. For the loss function, use the Alpha-IOU loss function to replace the C-IOU loss function of the original model as the loss function of the bounding box regression. For the Head detection layer of YOLOv5, add a P2 shallow detection layer on the basis of the original three-layer detection layer of the YOLOv5 network.

[0014] S5: Use the collected data to train the vehicle pedestrian recognition algorithm based on the improved YOLOv5. During the training process, the parameters of the model are continuously adjusted to minimize the loss function;

[0015] S6: The algorithm is trained for sparsity by adding L1 regularization to constrain the BN layer coefficients, and then the algorithm after sparsity training is pruned;

[0016] Furthermore, in step S1, a car is taken on different road scenes, and pictures of vehicles and pedestrians on the road are taken using a camera to simulate road vehicles and pedestrians photographed during the autonomous driving process, wherein the road scenes include driving scenes of city streets, rural roads, and highways.

[0017] Furthermore, in step S2, the captured data set is processed and screened, and the blurred, ghosted, and unclear images during the shooting process and the images that do not contain vehicles and pedestrians are eliminated. The remaining images are cropped, scaled, flipped, and the brightness is adjusted to simulate the conditions of road vehicles and pedestrians in different states. The processed images are labeled using the LabelImg labeling tool.

[0018] Furthermore, in step S3, some data sets are sourced from images in the BDD100K and KITTI public data sets, and the annotation files of the BDD100K and KITTI public data sets have their own unique formats, which need to be parsed and converted into yolo format annotation files that can be recognized by YOLOv5; the label types are reclassified in the annotation files, specifically: the BDD100K data set includes ten categories: Car, Truck, Bus, Bike, Motor, Train, Rider, Person, Light and Sign, and the KITTI data set includes Car, Van, Truck, Pedestrian, Pedestrian-sitt ing, Cyclist, Tram and Misc; remove Light, Sign, Train and Misc, merge Truck and Van into Truck, merge Bus and Tram into Bus, merge Bike, Cyclist, Motor and Rider into Bike, merge Person, Pedestrian and Pedestrian-sitting into Person; after processing, five categories including Car, Truck, Bus, Bike and Person are used as experimental data respectively, and the python script is used to divide the dataset into training set, test set and validation set in the ratio of 6:2:2.

[0019] Furthermore, in step S4, a vehicle and pedestrian recognition algorithm based on improved YOLOv5 is constructed, including:

[0020] (1) For the loss function of YOLOv5, the Alpha-IOU loss function is used to replace the C-IOU loss function of the original model as the loss function of bounding box regression. The principle of obtaining the Alpha-IOU loss function includes the following steps:

[0021] (1.1) For IOU loss: L IOU =1-IOU and perform Box-Cox transformation to obtain α-IOU, as shown in formula (1).

[0022]

[0023] When α→0,

[0024] When α=1, L 1-IOU =1-IOU=L IOU ,

[0025] When α=2,

[0026] (1.2) Simplify α-IOU to get formula (2),

[0027]

[0028] (1.3) Introduce a penalty term P and expand formula (2) to formula (3),

[0029]

[0030] In formula (3), α1 and α2 are greater than 0, and P represents the penalty term based on the relationship between the center point of the predicted box A and the center point of the actual box B.

[0031] (1.4) Let α1 = α2 = α, and we can get the unified form of different IOU-based methods, as shown in formulas (4)-(7),

[0032] L α-IOU =1-IOU α (4)

[0033]

[0034]

[0035]

[0036] In formulas (4)-(7), A and B are the predicted box and the real box respectively. c and B c represents the center point of A and B, C is the minimum enclosing box containing A and B, c is the diagonal length of the minimum enclosing box containing A and B, ρ 2α (A c , B c ) is the Euclidean distance between the predicted box and the true box. Where β is the weight function value, v is the aspect ratio consistency penalty term, and its calculation formula is shown in (8):

[0037]

[0038] In formula (8), and They represent the aspect ratios of the real labeled target box and the predicted box respectively. IOU is the intersection-over-union ratio of the predicted box and the real labeled box, and its expression is as follows:

[0039]

[0040] (2) For the Head detection layer of the YOLOv5 model, a P2 shallow detection layer is added on the basis of the original three-layer detection layer of the YOLOv5 network to alleviate the problems of target scale change and small target detection. The specific steps are as follows:

[0041] (2.1) Modify the Anchors of the YOLOv5 model and add a set of smaller anchor boxes to the Anchors;

[0042] (2.2) Modify the Head module of the YOLOv5 model and continue to perform convolution and upsampling on the feature map after the 17th layer to increase the size of the feature map;

[0043] (2.3) At the 20th layer, the feature map of size 160*160 is fused with the feature map of the second layer in the backbone network in the channel dimension through the Concat operation to obtain a larger feature map for detecting smaller targets.

[0044] Furthermore, in step S5, the YOLOv5 network is trained. The network improved in step S4 is trained using the training set in step S3. The parameters of the model are continuously adjusted during the training process. The trained model is tested and verified on the test set and the validation set to select the α value with the best detection effect and the model with the best detection effect.

[0045] Furthermore, in step S6, the algorithm is trained and pruned for sparsity by adding L1 regularization to constrain the BN layer coefficients, specifically:

[0046] (1) Initialize the network, introduce L1 regularization constraints on the γ coefficient of the BN layer of the YOLOv5 network to train the network, and perform sparse processing on the γ coefficient so that the γ coefficient is updated to a (0,1) normal distribution when propagating in the reverse direction;

[0047] Among them, the specific formula for adding L1 regularization constraint is as follows:

[0048]

[0049] Where L is the loss function of sparse training, the first term is the original loss function of the model, (x, y) represents the input and output targets of the training, W is the trainable weight value, and f(x, W) represents the prediction result of the model input x after the convolutional neural network weight W is calculated; the second term is the constraint, g(·) is the sparsity penalty for the scale factor, g(γ) = |γ| is selected as the coefficient of the BN layer, and λ is the regularization coefficient, which determines the intensity of the sparsification, and balances these two terms;

[0050] Among them, γ and β are two trainable parameters in the BN layer, which are defined as shown in formulas (11) and (12):

[0051]

[0052] z out =γz in+β (12)

[0053] In the formula, μ B and σ B is the mean and standard deviation, z in is the input of the channel, z out is the activation degree of the channel;

[0054] (2) After sparse training, the gradient of the γ coefficient is updated, and the values ​​of a large number of γ coefficients are close to 0. The pruning threshold is set to 30%, and 30% of the channels corresponding to these γ coefficients close to 0 are pruned;

[0055] (3) After pruning, fine-tune the current model, use the same optimization settings in training, and train 50 rounds in sequence to slightly modify the parameters so that the model fully matches the current dataset.

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

[0057] By replacing C-IOU with Alpha-IOU to improve the loss function of the model, the detector is provided with greater flexibility and more robust to small data sets and noisy bounding boxes. By using a suitable α value, the trained model can output more accurate detection boxes.

[0058] By adding a P2 shallow target detection layer, the model is allowed to detect multiple targets of different sizes at the same time, alleviating the problems caused by target scale changes and small target detection, and making up for the shortcomings of single-scale target detection algorithms when the target size range is small.

[0059] By adding L1 regularization to constrain the BN layer coefficients to perform sparsity training and pruning on the algorithm, the number of model parameters and the amount of calculation are reduced, the lightweight effect of the model is improved, and then the deployment efficiency and detection speed of the model are improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0060] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.

[0061] Figure 1 A schematic diagram of the implementation logic of the vehicle and pedestrian recognition method based on the improved YOLOv5 in an embodiment of the present invention;

[0062] Figure 2 A network structure diagram showing an improved algorithm in an embodiment of the present invention with a P2 detection layer added;

[0063] Figure 3 Schematic diagram of performance comparison between α-IOU and CIOU on a data set in an embodiment of the present invention;

[0064] Figure 4 The distribution of γ values ​​after sparse training in an embodiment of the present invention;

[0065] Figure 5 This is a schematic diagram of the detection effect of the original algorithm in the embodiment of the present invention;

[0066] Figure 6 Schematic diagram of the improved algorithm detection effect in an embodiment of the present invention. DETAILED DESCRIPTION

[0067] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.

[0068] Reference Figure 1 , the vehicle and pedestrian recognition method based on the improved YOLOv5 includes the following steps:

[0069] S1: Prepare a dataset of vehicles and pedestrians on different road scenes.

[0070] It should be noted that in order to make the model have higher recognition accuracy and robustness, the process of collecting data sets simulates the environment of autonomous driving. We ride in a car on different road scenes and use a camera to take pictures of vehicles and pedestrians on the road to imitate the road vehicles and pedestrians taken during autonomous driving. We also screen some pictures from the BDD100K and KITTI public data sets. The road scenes in the data sets include driving scenes in different locations such as urban streets, rural roads, and highways. The ratio of the data sets for urban streets, rural roads, and highways is approximately 1:1:1, so as to improve the generalization ability of the model.

[0071] S2: Preprocess the collected data.

[0072] It should be noted that the captured data set is processed and screened, and the blurred, ghosted, and unclear images as well as the images that do not contain vehicles and pedestrians during the shooting process are eliminated. The remaining images are then cropped, scaled, flipped, and the brightness is adjusted to simulate the conditions of road vehicles and pedestrians in different states. The processed data set is annotated using the LabelImg annotation tool.

[0073] S3: Standardize the format of dataset labels.

[0074] It should be noted that the annotation files of the BDD100K and KITTI public datasets have their own unique formats. They need to be parsed and converted into yolo format annotation files that can be recognized by YOLOv5 using Python scripts, and the label types are reclassified in the annotation files: the BDD100K dataset includes ten categories: Car, Truck, Bus, Bike, Motor, Train, Rider, Person, Light and Sign; the KITTI dataset includes Car, Van, Truck, Pedestrian, Pedestrian-sitting, Cyclist, Tram and Misc eight categories; remove Light, Sign, Train and Misc four categories, merge Truck and Van into Truck, merge Bus and Tram into Bus, merge Bike, Cyclist, Motor, Rider into Bike, merge Person, Pedestrian, Pedestrian-sitting into Person; after processing, five categories including Car, Truck, Bus, Bike and Person are used as experimental data respectively, and then use Python script to divide the data set into training set, test set and validation set in the ratio of 6:2:2.

[0075] S4: Build a vehicle and pedestrian recognition algorithm based on improved YOLOv5.

[0076] It should be noted that for the loss function of YOLOv5, the Alpha-IOU loss function is used to replace the C-IOU loss function of the original model as the loss function of the bounding box regression. For the Head detection layer of YOLOv5, a P2 shallow detection layer is added on the basis of the original three-layer detection layer of the YOLOv5 network.

[0077] S5: Train the improved YOLOv5 algorithm.

[0078] It should be noted that the collected data set is used to train the vehicle pedestrian recognition algorithm based on the improved YOLOv5. During the training process, the parameters of the model are continuously adjusted to minimize the loss function.

[0079] S6: The algorithm is trained for sparsity by adding L1 regularization to constrain the BN layer coefficients, and then the algorithm is pruned after sparsity training.

[0080] As a preferred embodiment of the present application, in step S4, the loss function of the YOLOv5 algorithm is improved, and the Alpha-IOU loss function is used to replace the C-IOU loss function of the original model as the loss function of the bounding box regression. The principle of obtaining the Alpha-IOUloss includes the following steps:

[0081] (1) For IOU loss: L IOU =1-IOU and perform Box-Cox transformation to obtain α-IOU, as shown in formula (1).

[0082]

[0083] When α→0,

[0084] When α=1, L 1-IOU =1-IOU=L IOU ,

[0085] When α=2,

[0086] (2) Simplify α-IOU to get formula (2),

[0087]

[0088] (3) Introduce a penalty term P and expand formula (2) to formula (3):

[0089]

[0090] In formula (3), α1 and α2 are greater than 0, and P represents the penalty term based on the relationship between the center point of the predicted box A and the center point of the actual box B.

[0091] (4) Let α1 = α2 = α, and we can get the unified form of different IOU-based methods, as shown in formulas (4)-(7),

[0092] L α-IOU =1-IOU α (4)

[0093]

[0094]

[0095]

[0096] In formulas (4)-(7), A and B are the predicted box and the real box respectively. c and B crepresents the center point of A and B, C is the minimum enclosing box containing A and B, c is the diagonal length of the minimum enclosing box containing A and B, ρ 2α (A c , B c ) is the Euclidean distance between the predicted box and the true box. Where β is the weight function value, v is the aspect ratio consistency penalty term, and its calculation formula is shown in (8):

[0097]

[0098] In formula (8), and They represent the aspect ratios of the real labeled target box and the predicted box respectively. IOU is the intersection-over-union ratio of the predicted box and the real labeled box, and its expression is as follows:

[0099]

[0100] By replacing C-IOU with Alpha-IOU to improve the loss function of the model, the detector is provided with greater flexibility and more robustness to small data sets and noisy bounding boxes. By using a suitable α value, the trained model can output a more accurate detection box. Figure 3 As shown in the figure, when α=3, the model detection accuracy is the highest. Among α-GIOU, α-DIOU and α-CIOU, α-CIOU is better, and the detection accuracy is improved by 0.5 percentage points.

[0101] like Figure 2 As shown, as a preferred embodiment of the present application, in step S4, in the improvement of the detection layer of the YOLOv5 algorithm, a method of adding a P2 small target detection layer is adopted to alleviate the problem of target scale change and small target detection. The specific steps are:

[0102] (1) Modify the Anchors of the YOLOv5 model and add a set of smaller anchor boxes to the Anchors;

[0103] (2) Modify the Head module of the YOLOv5 model and continue to perform convolution and upsampling on the feature map after the 17th layer to increase the size of the feature map;

[0104] (3) At the 20th layer, the feature map of size 160*160 is fused with the feature map of the second layer in the backbone network in the channel dimension through the Concat operation to obtain a larger feature map for detecting smaller targets.

[0105] It should be noted that by adding detection layers for smaller targets and feature fusion, the algorithm has made significant improvements in multi-scale detection, making it more suitable for complex practical application scenarios. The network structure diagram after the algorithm is improved is shown in the figure below: Figure 2 As shown in the figure, in the network structure, the inner box of the Head part is marked with a newly added smaller detection layer, and the inner box of the Neck part is marked with a newly added feature fusion part of the fourth scale. If the input image size is 640×640, the detection feature map size corresponding to P2 / 4 is 160×160, which is used to detect targets larger than 4×4; the detection feature map size corresponding to P3 / 8 is 80×80, which is used to detect targets larger than 8×8; the detection feature map size corresponding to P4 / 16 is 40×40, which is used to detect targets larger than 16×16; the detection feature map size corresponding to P5 / 32 is 20×20, which is used to detect targets larger than 32×32. By adding a P2 shallow detection layer, the model is allowed to detect multiple targets of different sizes at the same time, alleviating the problems caused by target scale changes and small target detection, and making up for the shortcomings of single-scale target detection algorithms when the target size range is small.

[0106] As a preferred embodiment of the present application, in step S6, in the improvement of the YOLOv5 algorithm, the model volume is also improved by applying L1 regularization to the coefficients of the BN layer, specifically:

[0107] (1) Initialize the network, introduce L1 regularization constraints on the γ coefficient of the BN layer of the YOLOv5 network to train the network, and perform sparse processing on the γ coefficient so that the γ coefficient is updated to a (0,1) normal distribution when propagating in the reverse direction;

[0108] Among them, the specific formula for adding L1 regularization constraint is as follows:

[0109]

[0110] Where L is the loss function of sparse training, the first term is the original loss function of the model, (x, y) represents the input and output targets of the training, W is the trainable weight value, and f(x, W) represents the prediction result of the model input x after the convolutional neural network weight W is calculated; the second term is the constraint, g(·) is the sparsity penalty for the scale factor, g(γ) = |γ| is selected as the coefficient of the BN layer, and λ is the regularization coefficient, which determines the intensity of the sparsification, and balances these two terms;

[0111] Among them, γ and β are two trainable parameters in the BN layer, which are defined as shown in formulas (11) and (12):

[0112]

[0113] z out =γz in +β (12)

[0114] In the formula, μ B and σ B is the mean and standard deviation, z in is the input of the channel, z out is the activation degree of the channel;

[0115] (2) After sparse training, the gradient of the γ coefficient is updated, such as Figure 4 This is the distribution of γ values ​​after sparse training. It can be seen that a large number of γ coefficients are close to 0. The pruning threshold is set to 30%, and 30% of the channels corresponding to these γ coefficients close to 0 are pruned.

[0116] (3) After pruning, fine-tune the current model, use the same optimization settings as in training, and train for 50 rounds in sequence to slightly modify the parameters so that the model fully matches the current dataset.

[0117] By adding L1 regularization to constrain the BN layer coefficients to perform sparsity training and pruning on the algorithm, the number of model parameters and the amount of calculation are reduced, the lightweight effect of the model is improved, and then the deployment efficiency and detection speed of the model are improved.

[0118] In order to better understand the technical solution of the present application, further explanation is given below in conjunction with experiments.

[0119] Experimental environment: CPU is Core TM i9-12900H CPU@2.50GHz, 16.0GB RAM, GPU is NVIDIA GeForce RTX3070, 8GB video memory, Windows11, 64-bit operating system, deep learning framework Pytorch2.2.1, programming language is python, GPU acceleration software is CUDA11.8 and CUDNN8.8.1.

[0120] Experimental data set: As shown in Table 1, it lists the number of each type of target in the data set. Table 2 divides the data set into training set, validation set and test set in a ratio of 6:2:2, as well as the number of each part.

[0121] Table 1. Number of dataset labels

[0122] Label car truck bus bicycle person quantity 32581 7960 6194 4022 28998

[0123] Table 2. Dataset division

[0124] Dataset train valid test total quantity 5080 1694 1694 8468

[0125] Network training and testing:

[0126] In order to evaluate the performance of the algorithm, this paper uses several performance indicators such as precision P (precision), recall R (recall), mean average precision mAP (mean average precision) of multiple categories, storage space occupied (unit: MB), number of parameters, number of detection frames per second FPS (frames per second) and number of floating point operations FLOPS (floating point operations). Some of their calculation formulas are as follows.

[0127]

[0128]

[0129]

[0130]

[0131] In the formula, TP (true positives) represents the number of targets detected correctly, FP (false positives) represents the number of targets detected incorrectly, FN (false negatives) represents the number of targets not detected, AP (average precision) represents the average precision of a target class, and n represents the total number of categories that need to be classified.

[0132] The experimental settings basically adopt the official recommended parameter settings of YOLOv5, using adaptive anchors, mosaic data enhancement, the input image size is 640×640, the batchsize is set to 16 during experimental training, the batchsize is set to 1 during testing, the epoch is 200, the initialization learning rate is 0.01, and the learning rate momentum is 0.928.

[0133] Experiment and result analysis:

[0134] 1) Experimental analysis of improved loss function

[0135] This experiment is based on YOLOv5s and evaluates the performance of different α values ​​of α-IOU by comparing α-IOU with α-GIOU, α-DIOU, α-CIOU, and CIOU. Figure 3 The results in show that α-IOU improves the performance of the model when α is between 2 and 4, and the largest improvement is observed when α = 3. Among α-GIOU, α-DIOU, and α-CIOU, α-CIOU is superior, with a detection accuracy improvement of 0.5 percentage points compared to CIOU.

[0136] 2) Experimental analysis of adding P2 detection layer

[0137] This experiment is based on YOLOv5s and adds a smaller P2 detection layer. The improved multi-scale algorithm is called YOLOv5s-M. It is compared with the original YOLOv5s model. The experimental results are shown in Table 3.

[0138] Table 3. Experimental comparison of adding P2 detection layer

[0139] Model Volume / MB <![CDATA[Parameter quantity / 10 6 > GFLOPs mAP@0.5 / % FPS YOLOv5s 14.02 7.20 16.8 92.3 78 YOLOv5s-M 14.42 7.34 19.6 93.5 72

[0140] As can be seen from Table 3, after adding a smaller detection layer, although the size of YOLOv5s-M increased by 0.4MB, the number of parameters and the amount of calculation also increased slightly, and the FPS decreased, these did not have a substantial impact on the overall algorithm model. The frame rate of the improved algorithm 72 is not low and will not affect the use effect. In this case, the detection accuracy is improved by 1.2 percentage points.

[0141] 3) Ablation experiment

[0142] The three improvement methods used in the experiment are A (Alpha-IOU loss), M (multi-scale detection) and L (adding L1 regularization). The detection effects of different improvement methods are compared through ablation experiments. The ablation experiment results are shown in Table 4.

[0143] Table 4. Ablation experiments

[0144]

[0145]

[0146] Through ablation experiments, it can be seen that compared with the original algorithm, YOLOv5s-AML has a 0.6% increase in average accuracy and a much smaller model size. Considering the model size (model pruning rate is 30%), the model can be compressed to 7.21MB, which is 51.4% of YOLOv5s. The model size is greatly reduced. At the same time, from the detection rate point of view, the detection rate of this algorithm is better than YOLOv5s, which is increased by 20.5%.

[0147] 4) Comparative test

[0148] In order to further demonstrate the superiority of this algorithm, the algorithm model YOLOv5s-AML proposed in this paper is experimentally compared with YOLOv5s, YOLOv5m, YOLOv5l, YOLOv5x, YOLOX-tiny, YOLOX-X, YOLOv4-tiny, YOLOv4, SSD and Faster R-CNN algorithms on this dataset. The results are shown in Table 5 below.

[0149] Table 5. Comparative test

[0150] Model Volume / MB P / % R% mAP@0.5 / % FPS YOLOv5s 14.02 94.3 87.6 92.3 78 YOLOv5m 40.72 94.2 90.1 93.3 71 YOLOv5l 89.21 93.9 91.2 93.6 57 YOLOv5x 165.96 94.3 91.8 94.5 50 YOLOX-tiny 19.4 92.4 84.3 90.5 43 YOLOX-X 378.5 93.2 88.7 94.2 25 YOLOv4-tiny 23.2 78.9 50.4 66.8 106 YOLOv4 245.9 92.1 74.9 87.1 33 SSD 100.3 89.5 64.7 72.8 56 Faster R-CNN 108.9 65.2 84.3 83.9 21 YOLOv5s-AML 7.21 91.6 83.7 92.9(+0.6) 94(+16)

[0151] By observing the experimental results of different algorithm models in the table, it can be seen that the YOLOv5s-AML algorithm used in this article has a higher detection speed than other versions of the algorithm model. Compared with the YOLOX-tiny algorithm with similar detection accuracy and model size, the YOLOv5s-AML algorithm occupies less than half the volume of the YOLOX-tiny, and the detection speed is more than doubled. It has a significant volume advantage and a high detection speed; the YOLOv4-tiny with the highest detection speed has the lowest detection accuracy and cannot meet the actual application requirements. In comparison, the YOLOv5s-AML algorithm with similar detection speed has the smallest model size and excellent detection accuracy, which is more suitable for embedded devices.

[0152] In summary, the YOLOv5s-AML algorithm proposed in this application has high detection accuracy while maintaining lightweight, and maintains good real-time performance. The overall performance is outstanding, proving the superiority of the algorithm proposed in this paper. In order to make a more intuitive evaluation, this paper shows the comparison of the effects before and after the improvement, such as Figure 5 Figure 6 shown.

[0153] From the comparison in the figure, it can be seen that in the context of a road with dense vehicles and pedestrians, the YOLOv5s-AML algorithm proposed in this application has improved the problem of missed detection when detecting small targets such as distant vehicles and pedestrians compared to the original algorithm.

[0154] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. A vehicle and pedestrian recognition method based on improved YOLOv5, characterized in that: The following steps are involved: S1: Take a car on different road scenes and use a camera to take pictures of vehicles and pedestrians on the road. Select some pictures from the BDD100K and KITTI public datasets to form the dataset required for this model. S2: Preprocess the collected data to remove blurry images or images with unclear vehicle and pedestrian features, and annotate the captured images using the LabelImg annotation tool; S3: Standardize the format of BDD100K and KITTI dataset labels, classify the label types in the annotation files, and then divide the dataset into training, test, and validation sets according to the proportions. S4: Build a vehicle and pedestrian recognition algorithm based on the improved YOLOv5. In this algorithm, the Alpha-IOU loss function is used to replace the C-IOU loss function of the original model as the loss function for bounding box regression. For the head detection layer of YOLOv5, a P2 shallow detection layer is added on top of the original three-layer detection layer of the YOLOv5 network. S5: Use the collected dataset to train the vehicle-pedestrian recognition algorithm based on the improved YOLOv5. During the training process, continuously adjust the model parameters to minimize the loss function; S6: The algorithm is trained for sparsity by adding L1 regularization to constrain the BN layer coefficients, and then the algorithm after sparsity training is pruned.

2. The vehicle-pedestrian recognition method based on improved YOLOv5 according to claim 1, characterized in that: In step S1, a car is taken on different road scenes, and pictures of vehicles and pedestrians on the road are taken using a camera to simulate road vehicles and pedestrians photographed during the autonomous driving process, wherein the road scenes include driving scenes of city streets, rural roads, and highways.

3. The vehicle-pedestrian recognition method based on improved YOLOv5 according to claim 2, characterized in that: In step S2, the captured data set is processed and screened, and the blurred images, ghosting images, and unclear images that do not contain vehicles and pedestrians are removed; The remaining images are cropped, scaled, flipped, and brightness adjusted to simulate the conditions of road vehicles and pedestrians in different states. The processed dataset is labeled using the LabelImg annotation tool.

4. The vehicle-pedestrian recognition method based on improved YOLOv5 according to claim 3, characterized in that: In step S3, the data sets are sourced from different road scene images taken by individuals, as well as BDD100K and KITTI data sets. The annotation files of the BDD100K and KITTI public data sets have their own unique formats, which need to be parsed and converted into yolo format annotation files that can be recognized by YOLOv5. The label types are reclassified in the annotation files, specifically: the BDD100K data set includes ten categories: Car, Truck, Bus, Bike, Motor, Train, Rider, Person, Light, and Sign; the KITTI data set includes ten categories: Car, Van, Truck, Pedestrian, Pedestrian-s The dataset is divided into eight categories: sitting, cyclist, tram and misc; the four categories of light, sign, train and misc are removed, and truck and van are merged into truck, bus and tram are merged into bus, bike, cyclist, motor and rider are merged into bike, and person, pedestrian and pedestrian-sitting are merged into person. After processing, the five categories of car, truck, bus, bike and person are used as experimental data respectively. The Python script is used to divide the dataset into training set, test set and validation set in the ratio of 6:2:

2.

5. The vehicle-pedestrian recognition method based on improved YOLOv5 according to claim 4, characterized in that: In step S4, a vehicle and pedestrian recognition algorithm based on the improved YOLOv5 is constructed, including: (1) For the loss function of YOLOv5, the Alpha-IOU loss function is used to replace the C-IOU loss function of the original model as the loss function of bounding box regression. The principle of obtaining the Alpha-IOU loss function includes the following steps: For IOU loss:L IOU =1-IOU and perform Box-Cox transformation to obtain α-IOU, as shown in formula (1), When α→0, When α = 1, L 1-IOU = 1 - IOU = L IOU , When α=2, Simplifying α-IOU, we can get formula (2): Introducing a penalty term P, formula (2) is expanded to formula (3), In formula (3), α1 and α2 are greater than 0, P represents the penalty term based on the relationship between the center point of the predicted box A and the center point of the actual labeled box B. Let α1 = α2 = α, and we can get the unified form of different IOU-based methods, such as formulas (4)-(7), L α-IOU =1-IOU α (4) In formulas (4)-(7), A and B are the predicted box and the real box respectively. c and B c represents the center point of A and B, C is the minimum enclosing box containing A and B, c is the diagonal length of the minimum enclosing box containing A and B, ρ 2α (A c , B c ) is the Euclidean distance between the predicted box and the true box, where β is the weight function value, and v is the aspect ratio consistency penalty term, which is calculated as shown in (8): In formula (8), and They represent the aspect ratios of the true labeled target box and the predicted box respectively. IOU is the intersection-union ratio of the predicted box and the true labeled box, and its expression is as follows: (2) For the Head detection layer of the YOLOv5 model, a P2 shallow detection layer is added on the basis of the original three-layer detection layer of the YOLOv5 network to alleviate the problems of target scale change and small target detection. The specific steps are as follows: Modify the Anchors of the YOLOv5 model and add a new set of smaller anchor boxes in the Anchors; Modify the Head module of the YOLOv5 model to continue convolution and upsampling the feature map after layer 17 to increase the size of the feature map; At the 20th layer, the feature map of size 160*160 is fused with the feature map of the second layer in the backbone network in the channel dimension through the Concat operation.

6. The vehicle-pedestrian recognition method based on improved YOLOv5 according to claim 5, characterized in that: In step S5, the YOLOv5 network is trained. The network improved in step S4 is trained using the training set in step S3. The parameters of the model are continuously adjusted during the training process. The trained model is verified and tested on the test set and validation set to select the α value with the best detection effect and the model with the best detection effect.

7. The vehicle-pedestrian recognition method based on improved YOLOv5 according to claim 6, characterized in that: In step S6, the algorithm is trained and pruned for sparsity by adding L1 regularization to constrain the BN layer coefficients, specifically: Initialize the network, introduce L1 regularization constraints on the γ coefficient of the BN layer of the YOLOv5 network to train the network, and perform sparse processing on the γ coefficient so that the γ coefficient is updated to a (0,1) normal distribution when propagating in the reverse direction; The specific formula for adding L1 regularization constraint is as follows: Where L is the loss function for sparsification training, the first term is the original loss function of the model, (x, y) represents the input and output targets of the training, W is the trainable weight value, and f(x, W) represents the prediction result of the model input x after the convolutional neural network weight W is calculated; the second term is the constraint, g(·) is the sparsity penalty for the scale factor, g(γ) = |γ| is selected as the coefficient of the BN layer, and λ is the regularization coefficient, which determines the strength of the sparsification, and balances these two terms; Among them, γ and β are two trainable parameters in the BN layer, which are defined as follows: With out =γz in +β (12) Where μ B and σ B are the mean and standard deviation values, z in is the input of the channel, z out is the activation degree of the channel; After sparse training, the gradient of the γ coefficient is updated, and the values ​​of a large number of γ coefficients approach 0. The pruning threshold is set to 30%, and 30% of the channels corresponding to these γ coefficients approaching 0 are pruned; After pruning, the current model is fine-tuned. Using the same optimization settings as in training, 50 rounds of training are performed to slightly modify the parameters so that the model fully matches the current dataset.