Traffic flow detection method based on improved YOLOv8 and DeepSORT

By introducing the CBAM attention mechanism and improving the loss function into the YOLOv8 model, and combining it with the Pareto Bayes algorithm to optimize the hyperparameters, the problems of missed detections and false detections in complex traffic scenarios are solved, achieving higher detection accuracy and faster convergence speed, thus meeting the needs of real-time traffic flow monitoring.

CN121236714BActive Publication Date: 2026-06-23SOUTHEAST UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SOUTHEAST UNIV
Filing Date
2025-09-30
Publication Date
2026-06-23

AI Technical Summary

Technical Problem

Existing YOLOv8 models suffer from severe occlusion in densely packed traffic scenes and poor adaptability to changes in lighting, leading to missed detections and false detections. Furthermore, traditional hyperparameter optimization methods are inefficient and struggle to capture nonlinear relationships.

Method used

We introduce the CBAM attention mechanism module and an improved loss function, combine Pareto Bayes algorithm and genetic algorithm to optimize hyperparameters, and use WIoU series loss functions to optimize bounding box regression to construct an end-to-end traffic flow detection framework. We also use tire thickness features for vehicle matching.

Benefits of technology

The model significantly improves detection stability and accuracy in occluded scenarios. After optimization, the accuracy is improved by about 26%, mAP is improved by about 39%, and bounding box loss is reduced by about 19.7%, meeting the needs of real-time dynamic monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121236714B_ABST
    Figure CN121236714B_ABST
Patent Text Reader

Abstract

The application relates to a traffic flow detection method based on improved YOLOv8 and DeepSORT, which comprises the following steps: S1, acquiring a training data set; S2, obtaining initial values of hyperparameters of a target detection model; S3, after the target detection model is trained based on the training data set for multiple times, whether a first exit condition is met is judged, if yes, step S6 is executed, otherwise, step S4 is executed; S4, a Pareto Bayesian algorithm is used to update the hyperparameters to obtain candidate values of multiple groups of hyperparameters, and a genetic algorithm is further used to process the obtained candidate values of the multiple groups of hyperparameters to obtain a candidate value of a group of hyperparameters to replace the hyperparameters in the target detection model; S5, whether a second exit condition is met is judged, if yes, step S6 is executed; S6, each video frame of a to-be-detected video is detected by using the target detection model to obtain traffic flow data. Compared with the prior art, the application has the advantages of improving the detection accuracy in an unmanned aerial vehicle scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of traffic flow detection, and in particular to a traffic flow detection method based on an improved YOLOv8 and DeepSORT. Background Technology

[0002] In recent years, my country's road traffic safety situation has become increasingly severe, with frequent traffic accidents causing significant casualties and property damage. The substantial direct economic losses resulting from these accidents underscore the urgency of strengthening road safety governance and accident prevention systems. Therefore, how to manage the traffic system more intelligently and efficiently to reduce traffic congestion and accidents is a research topic of great significance.

[0003] With the development of drone technology, drones can acquire real-time image data of ground traffic scenes through aerial photography. Compared with traditional technologies such as inductive coil detectors, video, radar, and ultrasonic technology, drones have strong mobility, a wide field of view, high flexibility, and are easy to deploy; drones are also cheaper than manned systems.

[0004] While some existing technologies, such as Chinese patent CN116797979A, disclose a small-model traffic flow detection method based on improved YOLOv5 and DeepSORT, including: acquiring data information containing traffic scenes, using the traffic scene data information for target detection and tracking; training a target detection model based on the data information containing traffic scenes using improved YOLOv5; training a target tracking model based on the targets detected by the target detection model in the traffic scene using improved DeepSORT; performing re-identification training on a vehicle re-identification dataset for different vehicles; detecting and tracking targets in the input traffic scene using the target detection model based on improved YOLOv5 and the target tracking model based on improved DeepSORT; acquiring traffic information of the traffic scene, and visualizing the traffic information of the traffic scene.

[0005] However, due to its fixed hyperparameters, the YOLOv8 model exhibits poor adaptability in complex traffic scenes captured by drones, particularly in densely packed vehicle environments with severe occlusion and varying lighting conditions, leading to frequent false positives and missed detections. Furthermore, the model lacks adaptive focusing capabilities based on the most relevant channel and spatial location information of vehicle targets within the image, resulting in poor performance in dynamic viewpoints and small target detection. The default CIoU loss function is inefficient, slow, and inaccurate in occluded scenarios. Moreover, traditional methods struggle to capture nonlinear relationships when optimizing YOLOv8 model hyperparameters; existing grid search methods require extensive training and validation; Bayesian optimization is complex to tune in high-dimensional spaces; and manual tuning is ineffective when dealing with a large number of hyperparameters. Summary of the Invention

[0006] The purpose of this invention is to provide a traffic flow detection method based on improved YOLOv8 and DeepSORT to overcome the shortcomings of the existing technology.

[0007] The objective of this invention can be achieved through the following technical solutions:

[0008] A traffic flow detection method based on improved YOLOv8 and DeepSORT includes:

[0009] Step S1: Obtain the training dataset, wherein the training samples in the training dataset include images and the target annotation results of the images;

[0010] Step S2: Initialize the random population to obtain the initial values ​​of the hyperparameters of the target detection model;

[0011] Step S3: After training the object detection model multiple times based on the training dataset, determine whether the first exit condition is met. If yes, proceed to step S6; otherwise, proceed to step S4.

[0012] Step S4: The Pareto Bayes algorithm is used to update the hyperparameters to obtain multiple sets of candidate values ​​for hyperparameters, and then a genetic algorithm is used to process the obtained multiple sets of candidate values ​​for hyperparameters to obtain a set of candidate values ​​for hyperparameters to replace the hyperparameters in the target detection model.

[0013] Step S5: Determine whether the second exit condition is met. If yes, proceed to step S6; otherwise, proceed to step S3.

[0014] Step S6: Use the object detection model to detect each video frame of the video to be detected, obtain the objects contained in each video frame, and further obtain traffic flow data based on the objects contained in each video frame.

[0015] The target detection model is an improved YOLOv8 model:

[0016] A CBAM dual attention mechanism is inserted into the YOLOv8 model, wherein the CBAM dual attention mechanism integrates a channel attention module and a spatial attention module;

[0017] After the image is input into the object detection model, the corresponding feature map is extracted and input into the channel attention module and the spatial attention module.

[0018] The output of the channel attention module is:

[0019] M c (F)=σ(MLP(AvgPool(F))+MLP(MaxPool(F)))

[0020] Where: Mc (·) represents the output of the channel attention module, F represents the feature map, AvgPool(·) represents the global average pooling operation, MaxPool(F) represents the global max pooling operation, MLP(·) represents the multilayer perceptron, and σ(·) represents the Sigmoid function normalization process.

[0021] The output of the spatial attention module is:

[0022] M s (F)=σ(f 7×7 ([AvgPool(F);MaxPool(F)]))

[0023] Where: M s (F) is the output of the spatial attention module, f 7×7 It is a 7×7 convolutional layer.

[0024] The loss function of the target detection model is:

[0025] L WIoUv3 =rL WIoUv1

[0026]

[0027] L WIoUV1 =R WIoU L IoU

[0028]

[0029] Where: L WIoUv3 Let L be the loss function of the object detection model. WIoUv1 The distance metric loss is given by r, the non-monotonic focusing coefficient, β, the outlier, α, and δ, where R is the distance metric loss. WIoU For distance attention, L IoU For bounding box loss, W g H g x represents the width and height of the minimum bounding rectangle of the predicted bounding box and the ground truth bounding box, respectively. gt y gt , where x and y are the x and y coordinates of the center point of the ground truth bounding box, respectively, and x and y are the x and y coordinates of the center point of the predicted bounding box, respectively.

[0030] The Pareto Bayes algorithm employs a hypervolume improvement as the acquisition function:

[0031] HV(P)=λ d (U y∈p [yj,rp])

[0032] HVI(P,yj * )=HV(P∪{yj*})-HV(P)

[0033]

[0034] Where: HV(·) is the volume enclosed by the Pareto front and the reference point, λ d For R d The Lebesgue test on the above, yj is a solution in the Pareto front, rp is the reference point, HVI(·) is the hypervolume improvement, PDF μ,σ Let f(x) be the probability density function of a Gaussian distribution, and let U be the fitting function. y∈p Let EHVI(·) be a Pareto front, denoted by EHVI(·), which measures the expected improvement of the new solution yj* with respect to the current hypervolume. Let μ be the mean, σ be the standard deviation, P be all Pareto front solutions in the subspace, yj* be the new solution, and R be the mean. d It is a geometric space.

[0035] There are eight hyperparameters: initial learning rate, loop learning rate, learning rate momentum, weight decay coefficient, warm-up learning rate, warm-up learning momentum, object presence / absence coefficient, cls loss coefficient, anchor aspect ratio, and IoU training threshold.

[0036] Step S6 includes:

[0037] Step S6-1: Take the first video frame of the video as the current frame, input the current frame into the target detection model to obtain the included targets and the descriptors of each target, wherein the descriptors include bounding box coordinates, center coordinates, bounding box size features, target type, geometric features, vehicle type features and average tire wall thickness.

[0038] Step S6-3: Use the current frame as the reference frame, use the next video frame as the current frame, input the current frame into the target detection model to obtain the included targets and the descriptors of each target, wherein the descriptors include bounding box coordinates, center coordinates, bounding box size features, target type, geometric features, vehicle type features and tire thickness features;

[0039] Step S6-3: Match the targets in the reference frame and the current frame, and assign the same ID number to all matched targets;

[0040] Step S6-4: Determine if there are any untraversed video frames. If yes, return to step S6-3; otherwise, execute step S6-5.

[0041] Step S6-5: Initialize the first position marker and the second position marker for each target to state one. Iterate through the detection results of each video frame. If the target in any video frame is located on one side of the first reference line, set the first position marker of the target to state two. If the target in any video frame is located on the other side of the first reference line, set the second position marker of the target to state two. The first reference line is the road cross-section line.

[0042] Step S6-6: Summarize the number of targets where both the first and second location markers are in state two to obtain the traffic flow.

[0043] The tire thickness characteristics include the tire thickness ratio and the average tire thickness. The tire thickness ratio is the ratio of the maximum wall thickness to the minimum wall thickness of the same tire, and the average tire thickness is the average of the maximum wall thickness and the minimum wall thickness of the same tire.

[0044] A traffic flow detection device based on improved YOLOv8 and DeepSORT includes a memory, a processor, and a program stored in the memory, wherein the processor executes the program to implement the method described above.

[0045] A storage medium having a program stored thereon, which, when executed, implements the method described above.

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

[0047] 1. The Pareto Bayes algorithm is used to update hyperparameters to obtain multiple sets of candidate hyperparameter values. Then, a genetic algorithm is used to process the obtained candidate hyperparameter values ​​to obtain a set of candidate hyperparameter values ​​to replace the hyperparameters in the object detection model. This solves the problems of low efficiency and easy trapping in local optima in traditional hyperparameter tuning methods. Using this algorithm, a new set of hyperparameters is obtained and put into the YOLOv8 model for learning and training. After optimization, the accuracy is improved by about 26%, mAP is improved by about 39%, and the bounding box loss is reduced by about 19.7%.

[0048] 2. A CBAM attention mechanism module was introduced, and the algorithm performance before and after the improvement was compared. The improved mAP on the test set was found to be 0.538. The WIoU series loss functions were used to optimize the bounding box regression, and the confidence threshold of the accuracy was improved to 0.927, which significantly improved the detection stability in occluded scenes.

[0049] 3. By combining the improved YOLOv8 and DeepSORT multi-target tracking algorithms, an end-to-end traffic flow parameter extraction framework is constructed to realize continuous vehicle trajectory tracking, traffic volume statistics and vehicle speed estimation, meeting the needs of real-time dynamic monitoring.

[0050] 4. By introducing tire thickness features for target matching, the problem of low matching accuracy when the vehicles are too similar can be solved during side-view photography.

[0051] 5. The technology based on the first and second position markers can effectively reduce the computational load and improve the efficiency of low-computing-power UAV platforms. Attached Figure Description

[0052] Figure 1 This is a schematic diagram of the main steps of the method of the present invention;

[0053] Figure 2 This is a schematic diagram illustrating the principle of the hyperparameter optimization method of the present invention. Detailed Implementation

[0054] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments. These embodiments are based on the technical solution of the present invention and provide detailed implementation methods and specific operating procedures. However, the scope of protection of the present invention is not limited to the following embodiments.

[0055] A traffic flow detection method based on improved YOLOv8 and DeepSORT, such as Figure 1 As shown, it includes:

[0056] Step S1: Obtain the training dataset, wherein the training samples in the training dataset include images and the target annotation results of the images;

[0057] The target annotation results are generally obtained manually using computer technology. For example, the annotation results must include the target type, which is given manually. Other information such as the target's bounding box coordinates, center coordinates, bounding box size features, target type, geometric features, vehicle type features, and average tire thickness are automatically identified by the computer.

[0058] Step S2: Initialize the random population to obtain the initial values ​​of the hyperparameters of the target detection model;

[0059] To address the issues of false positives and false negatives in the YOLOv8 model, this paper proposes optimization strategies including introducing an attention mechanism module and improving the model's loss function. The improvements to the YOLOv8 model are as follows: The CBAM attention mechanism is embedded in YOLOv8, fusing channel and spatial attention to enhance the ability to focus on key features. The WIoU series of loss functions replaces the model's default CIoU loss function, optimizing bounding box regression and reducing false positives and false negatives.

[0060] The object detection model is an improved YOLOv8 model:

[0061] The CBAM dual attention mechanism is inserted into the YOLOv8 model, which integrates the channel attention module and the spatial attention module.

[0062] After the image is input into the object detection model, the corresponding feature map is extracted and input into the channel attention module and the spatial attention module.

[0063] The output of the channel attention module is:

[0064] M c (F)=σ(MLP(AvgPool(F))+MLP(MaxPool(F)))

[0065] Where: M c (·) represents the output of the channel attention module, F represents the feature map, AvgPool(·) represents the global average pooling operation, MaxPool(F) represents the global max pooling operation, MLP(·) represents the multilayer perceptron, and σ(·) represents the Sigmoid function normalization process.

[0066] The output of the spatial attention module is:

[0067] M s (F)=σ(f 7×7 ([AvgPool(F);MaxPool(F)]))

[0068] Where: M s (F) is the output of the spatial attention module, f 7×7 It is a 7×7 convolutional layer.

[0069] The loss function of the object detection model is:

[0070] L WIoUv3 =rL WIoUv1

[0071]

[0072] L WOoUv1 =R WIoU L IoU

[0073]

[0074] Where: L WIoUv3 Let L be the loss function of the object detection model. WIoUv1 The distance metric loss is given by r, the non-monotonic focusing coefficient, β, the outlier, α, and δ, where R is the distance metric loss. WIoU For distance attention, L IoU For bounding box loss, W g H gx represents the width and height of the minimum bounding rectangle of the predicted bounding box and the ground truth bounding box, respectively. gt y gt , where x and y are the x and y coordinates of the center point of the ground truth bounding box, respectively, and x and y are the x and y coordinates of the center point of the predicted bounding box, respectively.

[0075] In addition, there are eight hyperparameters in this embodiment: initial learning rate, loop learning rate, learning rate momentum, weight decay coefficient, warm-up learning rate, warm-up learning momentum, object presence / absence coefficient, cls loss coefficient, anchor aspect ratio, and IoU training threshold.

[0076] Step S3: After training the object detection model multiple times based on the training dataset, determine whether the first exit condition is met. If yes, proceed to step S6; otherwise, proceed to step S4.

[0077] Step S4: The Pareto Bayes algorithm is used to update the hyperparameters to obtain multiple sets of candidate values ​​for hyperparameters, and then a genetic algorithm is used to process the obtained multiple sets of candidate values ​​for hyperparameters to obtain a set of candidate values ​​for hyperparameters to replace the hyperparameters in the target detection model.

[0078] To improve the design hyperparameter optimization algorithm for the YOLOv8 model and make it more suitable for current detection methods, a multi-objective hyperparameter tuning strategy integrating Pareto Bayesian optimization and NSGA-II genetic algorithm is proposed to optimize eight key parameters of learning rate type. Pareto Bayesian optimization uses the hypervolume improvement (EHVI) as the acquisition function to model the probability distribution of the objective function; the NSGA-II genetic algorithm maintains the diversity of the solution set through non-dominated sorting and crowding distance. The Pareto Bayesian algorithm uses the hypervolume improvement as the acquisition function.

[0079] HV(P)=λ d (U y∈p [yj,rp])

[0080] HVI(P,yj * )=HV(P∪{yj *})-HV(P)

[0081]

[0082] Where: HV(·) is the volume enclosed by the Pareto front and the reference point, λ d For R d The Lebesgue test on the above, yj is a solution in the Pareto front, rp is the reference point, HVI(·) is the hypervolume improvement, PDF μ,σ Let f(x) be the probability density function of a Gaussian distribution, and let U be the fitting function. y∈pLet EHVI(·) be a Pareto front, denoted by EHVI(·), which measures the expected improvement of the new solution yj* with respect to the current hypervolume. Let μ be the mean, σ be the standard deviation, P be all Pareto front solutions in the subspace, yj* be the new solution, and R be the mean. d It is a geometric space.

[0083] If EHVI > 0, the new solution is superior to all solutions in the frontier at least in one objective; if EHVI = 0, the new solution is dominated by a solution in the frontier, where y represents a solution in the Pareto frontier, P represents all Pareto frontier solutions in the subspace, and r represents the reference point.

[0084] Building upon this, the concept of a genetic algorithm is introduced: the position of particles is updated using a genetic algorithm, and a crossover operation is used to select parent particles and generate offspring particles. Among the offspring particles, those with stronger dominance are selected and assigned to the parent generation to generate new parent particles.

[0085] The introduction of non-dominated sorting aims to dynamically maintain the Pareto front in mixed optimization by selecting non-dominated solutions from the current population. By stratifying the obtained solutions according to the number of their dominant solutions, the Pareto front is preserved, ensuring it is not contaminated by inferior solutions. Furthermore, in subsequent crossover and mutation, solutions with the Pareto front are preferentially used to generate offspring, accelerating convergence.

[0086] Introducing crowding maintenance aims to maintain the uniformity of the Pareto front distribution and prevent the solution set from clustering in local regions. Prioritizing Pareto front layers and using crowding maintenance yields a wider range of more diverse solutions.

[0087] Introducing sensitivity-guided mutations aims to calculate the independent influence of each hyperparameter on the target. Applying larger mutation amplitudes to high-sensitivity parameters accelerates the discovery of potential optimal values; applying smaller mutation amplitudes to low-sensitivity parameters avoids ineffective perturbations.

[0088] Introduce an elite retention strategy: During algorithm iteration, retain the historical best solution to avoid losing high-quality solutions during crossover and mutation.

[0089] Step S5: Determine whether the second exit condition is met. If yes, proceed to step S6; otherwise, proceed to step S3.

[0090] Step S6: Use the object detection model to detect each video frame of the video to be detected, obtain the objects contained in each video frame, and further obtain traffic flow data based on the objects contained in each video frame, including:

[0091] Step S6-1: Take the first video frame of the video as the current frame, input the current frame into the target detection model to obtain the included targets and the descriptors of each target. The descriptors include bounding box coordinates, center coordinates, bounding box size features, target type, geometric features, vehicle model features and average tire wall thickness.

[0092] Step S6-3: Use the current frame as the reference frame, use the next video frame as the current frame, and input the current frame into the target detection model to obtain the included targets and the descriptors of each target. The descriptors include bounding box coordinates, center coordinates, bounding box size features, target type, geometric features, vehicle type features, and tire thickness features.

[0093] Step S6-3: Match the targets in the reference frame and the current frame, and assign the same ID number to all matched targets;

[0094] Step S6-4: Determine if there are any untraversed video frames. If yes, return to step S6-3; otherwise, execute step S6-5.

[0095] Step S6-5: Initialize the first position marker and the second position marker for each target to state one. Iterate through the detection results of each video frame. If the target in any video frame is located on one side of the first reference line, set the first position marker of the target to state two. If the target in any video frame is located on the other side of the first reference line, set the second position marker of the target to state two. The first reference line is the road cross-section line.

[0096] Step S6-6: Summarize the number of targets where both the first and second location markers are in state two to obtain the traffic flow.

[0097] In this embodiment, the tire thickness features include the tire thickness ratio and the average tire thickness. The tire thickness ratio is the ratio of the maximum wall thickness to the minimum wall thickness of the same tire, and the average tire thickness is the average of the maximum wall thickness and the minimum wall thickness of the same tire. Since many vehicles are designed to be relatively similar, it is difficult to distinguish them using set features, color features, and texture features. Therefore, using tire thickness features to match different vehicles can take load factors into account, thereby improving accuracy.

[0098] Finally, an exemplary traffic flow detection method based on improved YOLOv8 and DeepSORT is as follows:

[0099] Experimental verification was performed on the above embodiments:

[0100] 1. Environment Configuration

[0101] The hardware and software platform for this experiment was: an Intel Core i7 processor, a computer with 16GB of RAM, an NVIDIA 3060 graphics card, CUDA 11.8, CUDNN 8.9, and the deep learning framework was Tensorflow. In this experiment, all hyperparameters were the original parameters of the YOLOv8 model, such as lr0 being 0.01. The confusion matrix is ​​shown in Table 1.

[0102] 2. Dataset Analysis and Processing

[0103] To verify the performance of the improved algorithm, the following experiments used the same dataset. The training, test, and validation sets consisted of 6471, 1610, and 548 images, respectively, specifically including three classes: person (class 0), car (class 1), and longvehicle (class 2). In this experiment, the training epoch was 100, the image size was 640, and the batch size for image loading was 4. Before conducting the experiments, the images in the dataset needed to be labeled using the labelimg software. The following are the relevant formulas for evaluating the model's learning performance:

[0104] Table 1

[0105] Actually a positive category Actually a negative category Predicted as positive category TP FP Predicted as negative category FN TN

[0106]

[0107] 3. Experimental Results and Analysis

[0108] (1) Comparison of attention mechanism embedding in YOLOv8

[0109] After embedding the attention mechanism module into the YOLOv8 model, the average precision increased from 0.497 to 0.532, demonstrating improved accuracy in detecting targets. Not only did the overall detection accuracy improve, but the model's accuracy for each category of targets also showed an upward trend. This is because the CBAM attention mechanism module adaptively adjusts the weights of each channel in the feature map, enabling more efficient use of multi-scale features to improve the detection of small and occluded targets. Embedding the CBAM attention mechanism module effectively reduces false positives and false negatives, as indicated by the red box.

[0110] (2) Comparison of different loss functions in YOLOv8 model

[0111] From the overall model performance, the confidence thresholds corresponding to the detection accuracy of the four loss functions CIoU, WIoU v1, v2, and v3 are 0.910, 0.927, 0.906, and 0.899, respectively. This indicates that the WIoU-v1 loss function significantly improves the model's ability to filter high-confidence predictions; that is, even with a higher confidence threshold of 0.927, the model can still guarantee zero false detections across all categories. In contrast, using the WIoU-v2 and WIoU-v3 loss functions results in a decrease in model performance, reflecting insufficient generalization ability and a tendency to misclassify low-confidence samples or miss detections in high-confidence intervals.

[0112] Furthermore, in the high-confidence region, WIoU-v1 exhibits a large convergence slope, reaching perfect accuracy more quickly, indicating that the model is more accurate in discriminating high-confidence predictions. In contrast, the other three loss functions may require more lenient confidence thresholds to achieve the same accuracy, which increases the risk of missed detections and false positives.

[0113] (3) Comparison of hyperparameters before and after optimization

[0114] Eight parameters that significantly impact the model training results were selected from a large pool of parameters for optimization, while the remaining parameters were left at their initial values. Furthermore, to avoid an overly large search range that could lead to unfitting results, a variable range was assigned to each hyperparameter to be optimized.

[0115] Table 2

[0116] Hyperparameters initial value Optimization value lr0 0.01 0.032 lrf 0.01 0.012 momentum 0.937 0.933 weight_decay 0.0005 0.00044 warmup_epochs 3.0 3.0 warmup_momentum 0.8 0.82 obj 1.0 1.0 cls 0.5 1.5

[0117] Using optimized hyperparameters allows the model to achieve higher confidence thresholds, exhibiting greater variability compared to the original model. Target detection results across all categories are more stable and accurate. Furthermore, in low-confidence regions, the optimized model converges with a steeper slope, indicating faster convergence and stronger learning ability. In contrast, the original model requires more training iterations to achieve the same accuracy, resulting in lower efficiency.

[0118] Compared to the original model, the PR curve of the model after hyperparameter optimization is closer to the upper right corner, and the curve of the optimized model completely wraps around the curve of the original model, indicating that hyperparameter optimization can effectively improve the average accuracy of the target detection model.

[0119] Experimental results show that, compared to the original YOLOv8 model, the hyperparameters optimized by the genetic Pareto Bayes algorithm improve accuracy by approximately 26%, mAP by approximately 39%, and bounding box loss by approximately 19.7%, demonstrating a significant overall performance improvement. This hyperparameter tuning framework is reusable and particularly suitable for traffic scenarios where both real-time performance and accuracy are critical.

[0120] Input video footage captured by a drone and detect vehicles frame by frame. Use DeepSORT cascaded matching to associate vehicle IDs, complete vehicle counting, draw vehicle trajectories, and output average vehicle speed, density, and distance between vehicles.

[0121] 4. The main conclusions of this application are as follows:

[0122] (1) Design a vehicle detection algorithm based on an improved YOLOv8. The CBAM attention mechanism module is introduced, and the performance of the algorithm before and after the improvement is compared. It is found that the mAP on the test set is improved to 0.538 after the improvement. The WIoU series loss functions are used to optimize the bounding box regression, and the confidence threshold of the accuracy is improved to 0.927, which significantly improves the detection stability in occluded scenes.

[0123] (2) A hyperparameter optimization method was designed, proposing a multi-objective hyperparameter tuning strategy that integrates Pareto Bayesian optimization and NSGA-II genetic algorithm to balance model accuracy and inference speed, thus solving the problems of low efficiency and susceptibility to local optima in traditional hyperparameter tuning methods. A new set of hyperparameters was obtained using this algorithm and fed into the YOLOv8 model for training. Compared with the original model, the optimized model showed an accuracy improvement of approximately 26%, an mAP improvement of approximately 39%, and a bounding box loss reduction of approximately 19.7%.

[0124] (3) Design an integrated traffic flow detection system for unmanned aerial vehicles (UAVs), combine the improved YOLOv8 and DeepSORT multi-target tracking algorithms, construct an end-to-end traffic flow parameter extraction framework, realize continuous vehicle trajectory tracking, traffic volume statistics and vehicle speed estimation, and meet the needs of real-time dynamic monitoring.

[0125] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

Claims

1. A traffic flow detection method based on improved YOLOv8 and DeepSORT, characterized in that, The method comprises the following steps: Step S1: obtaining a training data set, wherein a training sample in the training data set comprises a picture and a target annotation result of the picture; Step S2: initializing a random population to obtain initial values of hyperparameters of a target detection model; Step S3: after training the target detection model based on the training data set for multiple times, determining whether a first exit condition is met, if yes, executing Step S6, otherwise, executing Step S4; Step S4: updating the hyperparameters by using a Pareto Bayesian algorithm to obtain multiple groups of candidate values of the hyperparameters, and further processing the obtained multiple groups of candidate values of the hyperparameters by using a genetic algorithm to obtain a group of candidate values of the hyperparameters to replace the hyperparameters in the target detection model; Step S5: determining whether a second exit condition is met, if yes, executing Step S6, otherwise, executing Step S3; Step S6: detecting each video frame of a to-be-detected video by using the target detection model to obtain targets contained in each video frame, and further obtaining traffic flow data according to the targets contained in each video frame; The target detection model is an improved YOLOv8 model: A CBAM dual attention mechanism is inserted into the YOLOv8 model, wherein the CBAM dual attention mechanism is fused with a channel attention module and a spatial attention module; After the picture is input into the target detection model, corresponding feature maps are extracted and input into the channel attention module and the spatial attention module; In the Pareto Bayesian algorithm, hyper-volume improvement is used as a collection function: where: is the volume enclosed by the Pareto front and the reference point, is R d is the Lebesgue measure on In the Pareto Bayesian algorithm, hyper-volume improvement is used as a collection function: is a solution in the Pareto front, rp is the reference point, is the hypervolume improvement, is the Gaussian distribution probability density function, is the fitting function, is a Pareto front, is the measure of the new solution The step S6 comprises: is the expected improvement over the current hypervolume, Step S6-1: taking a first video frame of the video as a current frame, inputting the current frame into the target detection model to obtain contained targets and descriptors of each target, wherein the descriptors comprise bounding box coordinates, center coordinates, bounding box size features, target types, geometric features, vehicle type features and tire thickness features; is the mean, Step S6-2: taking the current frame as a reference frame, taking a next video frame as the current frame, inputting the current frame into the target detection model to obtain contained targets and descriptors of each target, wherein the descriptors comprise bounding box coordinates, center coordinates, bounding box size features, target types, geometric features, vehicle type features and tire thickness features; is the standard deviation, P is all the Pareto front solutions in the subspace, Step S6-3: matching the targets of the reference frame and the current frame, and assigning all matched targets with the same ID number; is the new solution, R d is the geometric space; Step S6-4: determining whether there is an untraversed video frame, if yes, returning to Step S6-3, otherwise, executing Step S6-5; Step S6-5: initializing a first position marker and a second position marker of each target as state one, traversing the detection results of each video frame, if a target in any video frame is located on one side of a first reference line, setting the first position marker of the target as state two, if a target in any video frame is located on the other side of the first reference line, setting the second position marker of the target as state two, wherein the first reference line is a road section line; Step S6-6: summarizing the number of targets with the first position marker and the second position marker both in state two to obtain traffic flow. The output of the channel attention module is: ​ ​ ​ 2. The traffic flow detection method based on improved YOLOv8 and DeepSORT according to claim 1, wherein, ​ wherein: is an output of the channel attention module, F is a feature map, is a global average pooling operation, is a global max pooling operation, is a multi-layer perceptron, is a Sigmoid function normalization process; An output of the spatial attention module is: wherein: is the output of the spatial attention module, is a 7x7 convolutional layer.

3. The traffic flow detection method based on improved YOLOv8 and DeepSORT according to claim 1, characterized in that, A loss function of the target detection model is: wherein: is a loss function of the target detection model, is a distance metric loss, r is a non-monotonic focusing coefficient, β is an outlier degree, α is a hyper-parameter, delta is a preset threshold, is a distance attention, is a bounding box loss, W g , H g are a width and a height of a minimum bounding rectangle of a predicted box and a real box respectively, x gt , y gt are a horizontal coordinate and a vertical coordinate of a center point of a real box respectively, x , y are a horizontal coordinate and a vertical coordinate of a center point of a predicted box respectively.

4. The traffic flow detection method based on improved YOLOv8 and DeepSORT according to claim 1, characterized in that, The eight hyperparameters are: initial learning rate, cycle learning rate, learning rate momentum, weight decay coefficient, pre-warming learning rate, pre-warming learning momentum, whether to have a material system coefficient, cls loss coefficient, anchor length-width ratio, and IoU training threshold.

5. The traffic flow detection method based on improved YOLOv8 and DeepSORT according to claim 1, characterized in that, The tire thickness features include a tire thickness ratio and a tire average thickness, the tire thickness ratio being a ratio of a maximum wall thickness to a minimum wall thickness of the same tire, and the tire average thickness being a mean value of the maximum wall thickness and the minimum wall thickness of the same tire.

6. An improved YOLOv8 and DeepSORT based traffic flow detection device, comprising a memory, a processor, and a program stored in the memory, characterized in that, The processor implements the method of any one of claims 1-5 when executing the program.

7. A storage medium having stored thereon a program, characterized by The program is executed to implement the method of any one of claims 1-5.