Monitoring method for vehicle identification and quantity statistics based on improved YOLOv5

By improving the YOLOv5 network, combining the cross-attention mechanism and the target tracking algorithm, and using the KL divergence calibration method for INT8 quantization, the problem of repeated counting in vehicle recognition and quantity statistics of deep learning target detection algorithms is solved, achieving higher recognition accuracy and speed.

CN117037085BActive Publication Date: 2026-07-07NANJING HOWSO TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NANJING HOWSO TECH
Filing Date
2023-08-15
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

Existing deep learning object detection algorithms suffer from problems of double counting or undercounting in motor vehicle identification and quantity statistics, especially when vehicles are densely packed, overlapping, or moving rapidly. Furthermore, INT8 quantization leads to a decrease in model accuracy.

Method used

An improved YOLOv5 network is adopted, which combines a cross-attention mechanism and a target tracking algorithm. INT8 quantization is performed using the KL divergence calibration method. Combined with deep learning target detection and target tracking algorithms, vehicle identification and counting are performed through Kalman filtering.

Benefits of technology

It improves the model's recognition accuracy and speed, reduces memory usage, avoids duplicate counting, and meets the needs of vehicle recognition and quantity statistics in complex scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117037085B_ABST
    Figure CN117037085B_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on the monitoring method for vehicle identification and quantity statistics of improved YOLOv5, steps are as follows: S1: generating motor vehicle dataset and carrying out division again pretreatment;S2: using the data set after pretreatment training obtains YOLOv5 motor vehicle identification statistical model;S3: identification YOLOv5 motor vehicle identification statistical model and YOLOv5 motor vehicle identification statistical model is carried out INT8 quantification and calibration, obtain quantified engine model;S4: read the data of image acquisition equipment in monitoring area and obtain each frame image data;S5: each frame image data is input into engine model and detected and result analysis;S6: track trajectory state to motor vehicle ID update;S7: whether motor vehicle ID passes through target area is judged and is counted.The method reduces the loss brought by model INT8 quantification, improves the inference speed of model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of visual positioning technology, specifically to a monitoring method for vehicle identification and quantity statistics based on an improved YOLOv5. Background Technology

[0002] With rapid economic and social development, people's demand for transportation is constantly increasing, especially for long-distance travel. Statistics show that at the end of 2019, the number of civilian vehicles in China reached 261.5 million, an increase of 21.22 million from the end of the previous year. The contradiction between the growth in transportation demand and the existing road conditions is becoming increasingly prominent. Reasonable traffic management can effectively reduce traffic congestion. To improve traffic management, accurate analysis of driving behavior on highways is necessary.

[0003] Currently, deep learning object detection algorithms are commonly used to identify and count motor vehicles. This method relies on the accuracy of the object detection algorithm and cannot solve certain scenarios involving vehicle identification and counting. These algorithms simply count vehicles as soon as they appear within a region, which is clearly unreasonable and leads to duplicate counting in various scenarios.

[0004] Traditional deep learning object detection algorithms may have some limitations in motor vehicle recognition and scalar counting tasks. These algorithms typically rely on detecting and locating bounding boxes of motor vehicles in an image and using these bounding boxes for scalar counting. However, in certain scenarios, this approach may lead to double counting or undercounting, especially when vehicles are densely packed, overlapping, or moving rapidly.

[0005] Simultaneously, using TensorRT to directly convert the ONNX model to INT8 precision is a significant drain on the model, resulting in a substantial drop in accuracy. When performing vehicle recognition and quantity counting, this method is prone to false positives and false negatives, making it highly flawed for production use. Converting the model from floating-point precision to INT8 precision is a common optimization method that can improve inference performance and reduce storage requirements in some cases. However, using TensorRT or other tools to convert the model to INT8 precision may introduce some information loss, leading to a decrease in model accuracy. This loss is typically introduced through quantization techniques, mapping floating-point parameters to a lower-precision integer representation. Reduced precision may cause the model to fail to accurately represent certain features and details, resulting in false positives and false negatives. Especially for tasks requiring high-precision recognition and quantity counting, INT8 precision may not be sufficient.

[0006] Chinese patent literature discloses a method for vehicle detection and counting in highway surveillance videos based on YOLOv3. This method also utilizes object detection algorithms from the field of deep learning computer vision. As seen in its method flow, this method uses YOLOv3 as the object detection method, tracks the target based on the detection results, and determines whether the target has entered the target area for counting. The main step in this method is the use of the Kalman filter algorithm for object tracking. Kalman filtering finds the "optimal" estimate by fusing the values ​​predicted by a mathematical model with the measured observations, thus identifying the most accurate target in the next frame and reducing errors in vehicle count.

[0007] For the reasons mentioned above, this method relies on the accuracy of the target detection algorithm, and there are always some scenarios that cannot be solved in the judgment of motor vehicle identification and statistics. These algorithms solve the problem of classifying motor vehicles as motor vehicles and counting them as such when they appear in the area, which is obviously unreasonable, leading to the problem of repeated counting of motor vehicles in various scenarios in a short period of time.

[0008] For the reasons mentioned above, this method reduces the accuracy of the model, making it unable to accurately identify motor vehicles. Therefore, it is necessary to propose a monitoring method based on improved YOLOv5 for vehicle identification and quantity statistics, which reduces the loss caused by INT8 quantization and improves the inference speed of the model. Summary of the Invention

[0009] The technical problem to be solved by this invention is to propose a monitoring method for vehicle recognition and quantity statistics based on improved YOLOv5, which reduces the loss caused by INT8 quantization of the model and improves the inference speed of the model.

[0010] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is: a monitoring method for vehicle identification and quantity statistics based on improved YOLOv5, specifically including the following steps:

[0011] S1: Generate a motor vehicle dataset, divide it into segments, and then preprocess it to obtain a preprocessed dataset;

[0012] S2: The YOLOv5 motor vehicle recognition statistical model is trained using the preprocessed dataset;

[0013] S3: Identify the YOLOv5 vehicle recognition statistical model and perform INT8 quantization and calibration on the YOLOv5 vehicle recognition statistical model to obtain the quantized engine model;

[0014] S4: Read data from the image acquisition devices within the monitoring area and obtain image data for each frame;

[0015] S5: Input each frame of image data into the engine model for detection and result analysis;

[0016] S6: Track the vehicle ID and update the trajectory status;

[0017] S7: Determine whether the vehicle ID has passed through the target area and perform statistics.

[0018] The above technical solution utilizes a cross-attention mechanism and object tracking algorithm added to YOLOv5 for vehicle identification and counting. The improved YOLOv5 network reduces memory usage, improves computational performance, and further enhances detection speed and recognition accuracy. Before vehicle counting, a deep learning object tracking algorithm combined with an object detection algorithm is used to detect whether a vehicle has passed through a target area, establishing a vehicle counting judgment. This combination makes vehicle identification and counting more accurate and real-time, capable of meeting the needs of more diverse scenarios. INT8 quantization is applied to the model to reduce the overhead during model conversion. A second approach based on deep learning object detection and tracking algorithms is also used for vehicle identification and counting. Leveraging the advantages of deep learning object detection and tracking algorithms avoids the problems of double counting or missed counting that occur with traditional deep learning object detection algorithms for vehicle identification and counting. In short, combining multiple technologies solves the difficulty of vehicle identification and counting in complex scenarios.

[0019] Preferably, the specific steps of step S1 are as follows:

[0020] S11: Collect videos of motor vehicles and videos of different types of motor vehicles in simulated shooting development scenarios, and perform frame extraction processing on the captured videos to generate a motor vehicle dataset.

[0021] S12: Divide the motor vehicle dataset into a training set and a validation set;

[0022] S13: Use data augmentation methods to augment the training set and validation set respectively to obtain augmented training set and augmented validation set.

[0023] Preferably, the specific steps of step S2 are as follows:

[0024] S21: Build a YOLOv5 algorithm model and add a Criss-Cross attention mechanism to the YOLOv5 network structure. The formula for the Criss-Cross attention mechanism is:

[0025]

[0026] Among them, H′ u This represents the output vector at the u-th position; T represents the sequence length, H represents the height, W represents the width, and A represents the length. i,u The attention weight is used to weight information from different positions, representing the importance of the i-th position to the u-th position; Φ i,u H represents the eigenvector obtained after affine transformation. u This represents the input vector at the u-th position;

[0027] S22: Input data into the improved YOLOv5 algorithm model and train it to obtain the algorithm model weights, thereby obtaining the YOLOv5 motor vehicle recognition statistical model.

[0028] By adopting the above technical solution, the accuracy of recognition is improved and the memory usage of the model is reduced by adding a cross-cross attention mechanism and using a target tracking algorithm to track and count motor vehicles in real time.

[0029] Preferably, the specific steps of step S3 are as follows:

[0030] S31: Take several samples from the validation set generated in step S1 to create a calibration dataset and generate the calibration dataset;

[0031] S32: Write calibration data to generate the IInt8 relative entropy calibrator;

[0032] S33: Configure the parameters required to build the INT8 quantization model, perform INT8 quantization, continuously adjust the threshold, calculate the relative entropy, and obtain the optimal solution;

[0033] S34: Based on the calculated relative entropy, the YOLOv5 vehicle recognition statistical model is quantized using INT8. Simultaneously, the calibration dataset from step S31 is read, and histograms of activation values ​​for each layer are collected. The minimum threshold of KL divergence is calculated using the KL divergence calibration method for model calibration, resulting in the INT8-quantized engine model. Currently, using TensorRT to convert ONNX models to INT8 precision models results in significant model loss. Therefore, this technical solution utilizes the KL divergence calibration method for INT8 quantization to address this issue, avoiding the information loss associated with TensorRT-based INT8 precision model conversion, which leads to inaccurate vehicle recognition. In short, to improve the speed of vehicle recognition while minimizing accuracy loss, the KL divergence calibration method is used to quantize and calibrate the YOLOv5 trained model using INT8. After INT8 quantization, the model's recognition speed can be increased to three times that of the original YOLOv5 model, significantly improving real-time detection performance.

[0034] Preferably, the formula for the KL divergence calibration method in step S34 is:

[0035] KL(P||Q)=ΣP(x)*log(P(x) / Q(x));

[0036] Here, P represents the actual probability distribution, Q represents the probability distribution output by the model, KL(P||Q) represents the KL divergence, used to measure the difference between two probability distributions P and Q, P(x) represents the probability of probability distribution P on event x, Q(x) represents the probability of probability distribution Q on event x, and Σ represents summation. By reducing model loss through calibration algorithms and improving the real-time performance of detection, and by combining multiple models for joint detection, results for complex scenes are obtained. Each detection step reflects the accuracy of the algorithm, solving the problem of decreased model accuracy caused by traditional model conversion, and improving the accuracy and speed of motor vehicle recognition.

[0037] Preferably, the specific steps of step S5 are as follows: input the image data of each frame obtained in step S4 into the engine model obtained in step S3, and detect each frame of image data; if a motor vehicle is detected in the current frame of image data, save the detection result; that is, put the coordinates of the four points of the rectangle of the detected motor vehicle into an array and save them, and calculate the coordinates of the center point of the rectangle. The calculation formula is: (c_x=((x_left+x_right)) / 2), (c_y=((y_left+y_right)) / 2), where (x_left,y_left) and (x_right,y_right) represent the coordinates of the upper left corner and the lower right corner of the rectangle, and c_x and c_y represent the coordinates of the center point of the rectangle.

[0038] Preferably, the specific steps of step S6 are as follows:

[0039] S61: Use a pre-trained multi-target tracking model (Deepsort model) to detect motor vehicles appearing in each frame of image data and extract the features of each motor vehicle, and assign the motor vehicle ID;

[0040] S62: Use the detection results of the engine model as the target bounding box input of the multi-object tracking model Deepsort, and use the resulting trajectory as the trajectory of the current frame;

[0041] S63: Perform intersection-union (IOU) matching on the target bounding box and trajectory of the current frame image data, use Kalman filtering to predict the target bounding box state of the next frame image data based on the trajectory state, and update all trajectory states using Kalman filter observations and estimates, thereby completing the tracking of the vehicle ID.

[0042] The DeepSORT multi-object tracking algorithm used in the Deepsort multi-object tracking model of this invention is an improvement on the SORT algorithm, adding cascaded matching and trajectory state judgment. During the matching process, the predicted bounding box, trajectory, and their state can represent three scenarios of targets: targets that continuously appear in the video, newly appearing targets, and disappeared old targets. For continuously appearing targets, Kalman filtering prediction is performed based on the results of the current frame, and matching continues in the next frame based on the detection results and prediction results. For newly appearing targets, the processing is similar to the first frame, directly converting them into trajectory information, temporarily retaining them, and continuing to match them in subsequent frames. For disappeared old targets, their trajectory information is temporarily retained until they disappear a certain number of times, at which point the trajectory is deleted. The biggest feature of SORT is that it is based on the Faster R-CNN object detection method and utilizes the Kalman filtering algorithm + Hungarian algorithm, greatly improving the speed of multi-object tracking while achieving state-of-the-art accuracy. This algorithm is indeed widely used in practical applications, and its core consists of two algorithms: Kalman filtering and the Hungarian algorithm. The Kalman filtering algorithm is divided into two processes: prediction and update. This algorithm defines the target's motion state as eight normally distributed vectors. Prediction: As the target moves, the algorithm predicts the target's position and velocity in the current frame based on the target bounding box and velocity parameters from the previous frame. Update: The predicted and observed values ​​are linearly weighted to obtain the current predicted state. The Hungarian algorithm solves a bipartite graph assignment problem. In the main steps of MOT, it calculates the similarity cost matrix (IOU) to obtain the similarity matrix between consecutive frames. The Hungarian algorithm solves this similarity matrix to find the truly matched target between consecutive frames.

[0043] The main features of DeepSORT are: It incorporates appearance information into the SORT algorithm, borrowing from the ReID domain model to extract appearance features (i.e., the Deep Association Metric mentioned in the title), thus reducing the number of ID switching operations. The matching mechanism has changed from the original IOU cost matrix-based matching to cascaded matching + IOU matching.

[0044] Preferably, the specific steps of step S7 are as follows:

[0045] S71: Determine whether the motor vehicle has entered the designated area based on the center point coordinates of the motor vehicle detected in step S5, draw the polygon using OpenCV in the designated area, and use the coordinate points of the polygon as parameters to obtain the target area.

[0046] S72: Determine whether the motor vehicle is passing through the target area for the first time within a certain time period. If so, mark the motor vehicle as counted and increment the motor vehicle count by one. Then, use a multi-target tracking model (Deepsort model) to continue tracking the motor vehicle to prevent double counting when the vehicle passes through the target area again. If not, do not count the vehicles and keep the vehicle count unchanged.

[0047] S73: The process ends after saving the information on vehicles passing through the target area and their numbers to the database. OpenCV, short for Open Source Computer Vision Library, is a cross-platform computer vision library.

[0048] Preferably, in step S4, the video from the image acquisition device is read via video or RTSP streaming. Using the above technical solution, after the INT8 quantization of the model is completed, the video from the camera is read via RTSP streaming. Motor vehicles in the video are continuously detected, and the ID of each vehicle is determined using a target tracking algorithm. During the continuous detection of motor vehicles, it is determined whether a motor vehicle has passed through the target area, and the number of motor vehicles is counted. The information on motor vehicles passing through the target area and their numbers is saved to the database, and the algorithm ends.

[0049] Preferably, data augmentation is performed using a mosaic technique in step S1. Augmenting the dataset improves the model's generalization ability.

[0050] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0051] (1) The KL divergence calibration method reduces the significant loss of accuracy caused by the model when performing INT8 quantization; it solves the problem of the decrease in accuracy after the model performs INT8 quantization, so that the model can improve the recognition speed to three times that of the original model without losing the accuracy of the model.

[0052] (2) The improved network was used for training. A cross-attention mechanism was added to the original YOLOv5s network structure, which saved GPU memory and had higher computing performance.

[0053] (3) A method for solving complex problems by using multiple models in combination is proposed, which can be used reasonably according to the needs. At the same time, it can effectively avoid the problem of repeated counting of motor vehicles within a certain period of time. That is, the improved YOLOv5+Deepsort tracking algorithm is used to complete the algorithm development for complex scenarios, and the algorithm is completed by using multiple models in combination to solve complex problems. Attached Figure Description

[0054] Figure 1 This is a flowchart illustrating the monitoring method for vehicle identification and quantity statistics based on the improved YOLOv5 of this invention.

[0055] Figure 2 This is a flowchart of step S3 of the monitoring method for vehicle identification and quantity statistics based on the improved YOLOv5 in this invention, which involves INT8 quantization and calibration.

[0056] Figure 3 This is a flowchart of steps S3 to S7 in the vehicle identification and quantity counting monitoring method based on the improved YOLOv5 of the present invention.

[0057] Figure 4 This is a block diagram of the Criss-Cross attention mechanism added in step S2 of the vehicle recognition and quantity statistics monitoring method based on the improved YOLOv5 of this invention.

[0058] Figure 5 This is a diagram of the improved YOLOv5 network structure in step S2 of the monitoring method for vehicle identification and quantity statistics based on improved YOLOv5 in this invention. Detailed Implementation

[0059] The technical solutions in the embodiments of the present invention will now be clearly and completely described with reference to the accompanying drawings.

[0060] Example: Figure 1 As shown, this monitoring method for vehicle identification and quantity counting based on improved YOLOv5 specifically includes the following steps:

[0061] S1: Generate a motor vehicle dataset, divide it into segments, and then preprocess it to obtain a preprocessed dataset;

[0062] The specific steps of step S1 are as follows:

[0063] S11: Collect a large number of videos about motor vehicles and videos of different types of motor vehicles in simulated shooting development scenarios, and perform frame extraction processing on the shot videos to generate a motor vehicle dataset; the dataset includes the types of motor vehicles to be detected, such as cars, dump trucks, and trucks.

[0064] S12: Divide the motor vehicle dataset into a training set and a validation set;

[0065] S13: Data augmentation methods are used to augment the training set and validation set respectively to obtain augmented training set and augmented validation set; data augmentation in step S1 uses a mosaic method, such as rotation, cropping, and increasing or decreasing image brightness.

[0066] S2: The YOLOv5 motor vehicle recognition statistical model is trained using the preprocessed dataset;

[0067] The specific steps of step S2 are as follows:

[0068] S21: Build a YOLOv5 algorithm model and add a Criss-Cross attention mechanism to the YOLOv5 network structure. The formula for the Criss-Cross attention mechanism is:

[0069]

[0070] Among them, H ′ u This represents the output vector at the u-th position; T represents the sequence length, H represents the height, W represents the width, and A represents the length. i,u The attention weight is used to weight information from different positions, representing the importance of the i-th position to the u-th position; Φ i,u H represents the eigenvector obtained after affine transformation. u This represents the input vector at the u-th position;

[0071] S22: Input data into the improved YOLOv5 algorithm model and train it to obtain the algorithm model weights, thereby obtaining the YOLOv5 motor vehicle recognition statistical model.

[0072] S3: Identify the YOLOv5 vehicle recognition statistical model and perform INT8 quantization and calibration on the YOLOv5 vehicle recognition statistical model to obtain the quantized engine model;

[0073] The specific steps of step S3 are as follows:

[0074] S31: Take several samples from the validation set generated in step S1 to create a calibration dataset and generate the calibration dataset; In this embodiment, take about 500 calibration samples from the validation set of the dataset used for training. This calibration dataset has good sample representativeness.

[0075] S32: Write the calibration data generator to generate the IInt8 relative entropy calibrator; that is, build the IInt8 relative entropy calibrator when quantizing the model.

[0076] S33: Configure the parameters required to build the INT8 quantization model, perform INT8 quantization, continuously adjust the threshold, calculate the relative entropy, and obtain the optimal solution;

[0077] S34: Based on the calculated relative entropy, the YOLOv5 vehicle recognition statistical model is quantized using INT8. Simultaneously, the calibration dataset from step S31 is read, and histograms of activation values ​​for each layer are collected during inference under an FP32 precision network. The minimum threshold of KL divergence is calculated using the KL divergence calibration method for model calibration, resulting in the INT8 quantized engine model. Currently, using TensorRT to convert ONNX models to INT8 precision models results in significant model loss. Therefore, this technical solution utilizes the KL divergence calibration method for INT8 quantization to address this issue, thus avoiding the information loss associated with using TensorRT for INT8 precision model conversion, which could lead to inaccurate vehicle recognition.

[0078] The formula for the KL divergence calibration method in step S34 is:

[0079] KL(P||Q)=ΣP(x)*log(P(x) / Q(x));

[0080] Where P represents the actual probability distribution, Q represents the probability distribution output by the model, KL(P||Q) represents the KL divergence, which measures the difference between two probability distributions P and Q, P(x) represents the probability of probability distribution P on event x, Q(x) represents the probability of probability distribution Q on event x, and Σ represents summation.

[0081] S4: Read data from the image acquisition devices within the monitoring area and obtain image data for each frame;

[0082] In step S4, the video from the image acquisition device is read in the form of video or RTSP streaming; S5:

[0083] Each frame of image data is input into the engine model for detection and result analysis;

[0084] The specific steps of step S5 are as follows: input the image data of each frame obtained in step S4 into the engine model obtained in step S3, and detect each frame of image data; if a motor vehicle is detected in the current frame of image data, save the detection result; that is, put the coordinates of the four points of the rectangle of the detected motor vehicle into an array and save it, and calculate the coordinates of the center point of the rectangle. The calculation formula is: (c_x=((x_left+x_right)) / 2), (c_y=((y_left+y_right)) / 2), where (x_left,y_left) and (x_right,y_right) represent the coordinates of the upper left corner and the lower right corner of the rectangle, and c_x and c_y represent the coordinates of the center point of the rectangle.

[0085] S6: Track the vehicle ID and update the trajectory status;

[0086] The specific steps of step S6 are as follows:

[0087] S61: Use a pre-trained multi-target tracking model (Deepsort model) to detect motor vehicles appearing in each frame of image data and extract the features of each motor vehicle, and assign the motor vehicle ID;

[0088] S62: Use the detection results of the engine model as the target bounding box input of the multi-object tracking model (Deepsort model), and the resulting trajectory is used as the trajectory of the current frame;

[0089] S63: Perform intersection-union (IOU) matching on the target bounding box and trajectory of the current frame image data, use Kalman filtering to predict the target bounding box state of the next frame image data based on the trajectory state, and update all trajectory states using Kalman filter observations and estimates, thereby completing the tracking of the vehicle ID.

[0090] The DeepSORT multi-object tracking algorithm used in this invention (Deepsort model) is an improvement on the SORT algorithm, adding cascaded matching and trajectory state judgment. During the matching process, the predicted bounding box, trajectory, and their state can represent three scenarios of targets: targets that continuously appear in the video, newly appearing targets, and disappeared old targets. For continuously appearing targets, Kalman filtering prediction is performed based on the results of the current frame, and matching continues in the next frame based on the detection results and prediction results. For newly appearing targets, the processing is similar to the first frame, directly converting them into trajectory information, temporarily retaining them, and continuing to match them in subsequent frames. For disappeared old targets, their trajectory information is temporarily retained until they disappear a certain number of times, at which point the trajectory is deleted. The biggest feature of SORT is that it is based on the Faster R-CNN object detection method and utilizes the Kalman filtering algorithm + Hungarian algorithm, greatly improving the speed of multi-object tracking while achieving state-of-the-art accuracy. This algorithm is indeed widely used in practical applications, and its core consists of two algorithms: Kalman filtering and the Hungarian algorithm. The Kalman filtering algorithm consists of two processes: prediction and update. This algorithm defines the target's motion state as eight normally distributed vectors. Prediction: As the target moves, the algorithm predicts the target's position and velocity in the current frame based on the target bounding box and velocity parameters from the previous frame. Update: The predicted and observed values ​​are linearly weighted to obtain the current predicted state. The Hungarian algorithm solves a bipartite graph assignment problem. In the main steps of MOT, it calculates the similarity cost matrix (IOU) to obtain the similarity matrix between consecutive frames. The Hungarian algorithm solves this similarity matrix to find the truly matched target between consecutive frames.

[0091] The main features of DeepSORT are: It incorporates appearance information into the SORT algorithm, borrowing from the ReID domain model to extract appearance features (i.e., the Deep Association Metric mentioned in the title), thus reducing the number of ID switching operations. The matching mechanism has changed from the original IOU cost matrix-based matching to cascaded matching + IOU matching.

[0092] S7: Determine whether the vehicle ID has passed through the target area and perform statistics;

[0093] The specific steps of step S7 are as follows:

[0094] S71: Determine whether the motor vehicle has entered the designated area based on the center point coordinates of the motor vehicle detected in step S5. Draw the target area using OpenCV and use the coordinates of the polygon as parameters. OpenCV stands for Open Source Computer Vision Library, which is a cross-platform computer vision library.

[0095] S72: Determine whether the motor vehicle is passing through the target area for the first time within a certain time period. If so, mark the motor vehicle as counted and increment the motor vehicle count by one. Then, use a multi-target tracking model (Deepsort model) to continue tracking the motor vehicle to prevent double counting when the vehicle passes through the target area again. If not, do not count the vehicles and keep the vehicle count unchanged.

[0096] S73: The process ends after saving the information on the number of vehicles passing through the target area to the database.

[0097] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A monitoring method for vehicle identification and quantity statistics based on improved YOLOv5, characterized in that, Specifically, the following steps are included: S1: Generate a motor vehicle dataset, divide it into segments, and then preprocess it to obtain a preprocessed dataset; S2: The YOLOv5 motor vehicle recognition statistical model is trained using the preprocessed dataset; S3: Identify the YOLOv5 vehicle recognition statistical model and perform INT8 quantization and calibration on the YOLOv5 vehicle recognition statistical model to obtain the quantized engine model; S4: Read data from the image acquisition devices within the monitoring area and obtain image data for each frame; S5: Input each frame of image data into the engine model for detection and result analysis; S6: Track the vehicle ID and update the trajectory status; S7: Determine whether the vehicle ID has passed through the target area and perform statistics; The specific steps of step S1 are as follows: S11: Collect videos of motor vehicles and videos of different types of motor vehicles in simulated shooting development scenarios, and perform frame extraction processing on the captured videos to generate a motor vehicle dataset. S12: Divide the motor vehicle dataset into a training set and a validation set; S13: Use data augmentation techniques to augment the training set and validation set respectively, to obtain augmented training set and augmented validation set; The specific steps of step S2 are as follows: S21: Build a YOLOv5 algorithm model and add a cross-attention mechanism to the YOLOv5 network structure. The formula for the cross-attention mechanism is: ; in, This represents the output vector at the u-th position; T represents the sequence length, H represents the height, and W represents the width. The attention weight is used to weight information from different positions, representing the importance of the i-th position to the u-th position. This represents the eigenvector obtained after an affine transformation; This represents the input vector at the u-th position; S22: Input data into the improved YOLOv5 algorithm model and train it to obtain the algorithm model weights, thereby obtaining the YOLOv5 motor vehicle recognition statistical model; The specific steps of step S3 are as follows: S31: Take several samples from the validation set generated in step S1 to create a calibration dataset and generate the calibration dataset; S32: Write calibration data to generate the IInt8 relative entropy calibrator; S33: Configure the parameters required to build the INT8 quantization model, perform INT8 quantization, continuously adjust the threshold, calculate the relative entropy, and obtain the optimal solution; S34: Perform INT8 quantization on the YOLOv5 motor vehicle recognition statistical model based on the calculated relative entropy. At the same time, read the calibration dataset from step S31, collect the histogram of activation values ​​for each layer, and use the KL divergence calibration method to calculate the minimum threshold of KL divergence for model calibration, thus obtaining the INT8 quantized engine model.

2. The monitoring method for vehicle identification and quantity statistics based on improved YOLOv5 according to claim 1, characterized in that, The formula for the KL divergence calibration method in step S34 is: ; Where P represents the actual probability distribution, and Q represents the probability distribution output by the model. KL divergence is used to measure the difference between two probability distributions P and Q. This represents the probability of probability distribution P on event x. This represents the probability of probability distribution Q on event x. This indicates a summation.

3. The monitoring method for vehicle identification and quantity statistics based on improved YOLOv5 according to claim 1, characterized in that, The specific steps of step S5 are as follows: input the image data of each frame obtained in step S4 into the engine model obtained in step S3, and detect each frame of image data; if a motor vehicle is detected in the current frame of image data, save the detection result; that is, put the coordinates of the four points of the rectangle of the detected motor vehicle into an array and save them, and calculate the coordinates of the center point of the rectangle. The calculation formula is: (c_x=((x_left+x_right)) / 2), (c_y=((y_left+y_right))⁄2), where (x_left,y_left) and (x_right,y_right) represent the coordinates of the upper left and lower right corners of the rectangle, and c_x and c_y represent the coordinates of the center point of the rectangle.

4. The monitoring method for vehicle identification and quantity statistics based on improved YOLOv5 according to claim 3, characterized in that, The specific steps of step S6 are as follows: S61: Use a pre-trained multi-target tracking model to detect motor vehicles appearing in each frame of image data and extract the features of each motor vehicle, and assign the motor vehicle ID; S62: Use the detection results of the engine model as the target box input of the multi-object tracking model, and use the resulting trajectory as the trajectory of the current frame; S63: Perform intersection-union (IOU) matching on the target bounding box and trajectory of the current frame image data, use Kalman filtering to predict the target bounding box state of the next frame image data based on the trajectory state, and update all trajectory states using Kalman filter observations and estimates, thereby completing the tracking of the vehicle ID.

5. The monitoring method for vehicle identification and quantity statistics based on improved YOLOv5 according to claim 4, characterized in that, The specific steps of step S7 are as follows: S71: Determine whether the motor vehicle has entered the designated area based on the center point coordinates of the motor vehicle detected in step S5, draw the polygon using OpenCV in the designated area, and use the coordinate points of the polygon as parameters to obtain the target area. S72: Determine whether the motor vehicle is passing through the target area for the first time within a certain time period. If so, mark the motor vehicle as counted and increment the motor vehicle count by one. Then, use a multi-target tracking model to continue tracking the motor vehicle to prevent double counting when the vehicle passes through the target area again. If not, do not count the vehicle and keep the vehicle count unchanged. S73: The process ends after saving the information on the number of vehicles passing through the target area to the database.

6. The monitoring method for vehicle identification and quantity statistics based on improved YOLOv5 according to claim 5, characterized in that, In step S4, the video from the image acquisition device is read in the form of video or RTSP streaming.

7. The monitoring method for vehicle identification and quantity statistics based on improved YOLOv5 according to claim 2, characterized in that, In step S1, data augmentation is performed using the Mosaic method.