Small target road vehicle detection method and device, and storage medium
By adopting the CP6-YOLOv8 model in the detection of small-target road vehicles, introducing the CBAM attention module and p6 detection head, and using the SIoU loss function, the problems of low accuracy and many missed detections are solved, and a higher level of detection is achieved detection accuracy and efficiency.
Patent Information
- Application Number
- CN202411608186.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2025-02-14
AI Technical Summary
The existing small-target road vehicle detection methods have problems such as low accuracy and frequent missed inspections, especially in complex traffic environments and harsh weather conditions.
Using the CP6-YOLOv8 model, the CBAM attention module is introduced into the backbone network, combined with the additional p6 detection head and the feature pyramid network backend, and the SIoU loss function is used for training.
The average accuracy of vehicle detection is improved, the model's detection ability of small targets and complex scenarios is enhanced, the calculation cost is reduced, and the training efficiency is improved.
Smart Images

Figure CN119445083A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of target detection, and in particular relates to a small target road vehicle detection method, device and storage medium. Background Art
[0002] In actual road vehicle detection, the distance between the camera and the vehicle is often far, resulting in a small proportion of distant vehicles in high-resolution images. The complex traffic environment makes it easy for small target vehicles to merge with the background, thereby reducing the effect of feature extraction and increasing the difficulty of detection. In addition, when there are dense vehicles on the road, the occlusion problem is particularly serious. The occlusion between vehicles can only extract the features of the visible part, resulting in incomplete information, which makes the target regression box and classification results inaccurate, and increases the risk of false detection or re-detection. In addition, when the vehicle is driving in severe weather conditions such as rain, fog, snow or hail, the image captured by the camera is easily blurred, resulting in missed detection and false detection. When driving at night, the decline in image quality also significantly increases the probability of missed detection and false detection. As the most common traffic participants on the road, improving the detection accuracy and speed of vehicles is crucial to ensuring driving safety, which has a far-reaching impact on the research and application of traffic safety and related detection technologies. With the rapid development of intelligent transportation systems, dynamic target detection for small target vehicles faces new challenges, and a real-time and high-precision vehicle detection method is urgently needed.
[0003] In recent years, deep learning-based target detection algorithms have been widely used in vehicle detection, and the YOLO model has been proposed to unify the classification and positioning of targets. YOLO uses regression thinking to solve the problem of object detection, which can achieve a one-step implementation from inputting images to obtaining the position and category of bounding boxes. However, the existing methods still have problems such as low accuracy and many missed detections. An improved model is urgently needed to find the best balance between accuracy and real-time performance to meet the needs of increasingly complex driving environments. Summary of the invention
[0004] The purpose of the embodiments of the present invention is to provide a small target road vehicle detection method, device and storage medium to solve the problems of low accuracy and high number of missed detections in existing methods.
[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0006] A small target road vehicle detection method comprises the following steps:
[0007] S1: Build the CP6-YOLOv8 model;
[0008] S2: Build a dataset and train a model;
[0009] S3: Use the trained model to perform vehicle detection.
[0010] Furthermore, the S1 includes:
[0011] S11: Build backbone network;
[0012] S12: Building the neck network;
[0013] S13: Build the head network.
[0014] Furthermore, the S11 includes:
[0015] S111: In the backbone network, the input image first passes through the first convolution block, the second convolution block, and then passes through the first feature fusion module, the third convolution block, the second feature fusion module, the fourth convolution block, the third feature fusion module, the fifth convolution block, and the fourth feature fusion module, and the convolution attention module CBAM is added after the fourth feature fusion module;
[0016] S112: Then pass through the sixth convolution block and the fifth feature fusion module in sequence, add a convolutional attention module CBAM after the fifth feature fusion module, and finally pass through the spatial pyramid pooling module SPPF.
[0017] Furthermore, the S11 further includes:
[0018] S113: In the backbone network, the convolutional attention module CBAM includes a channel attention module and a spatial attention module. The calculation of the convolutional attention module CBAM is shown in the following formula:
[0019]
[0020] Among them, F is the input feature map of the convolutional attention module CBAM, F∈R C×H×W , C represents the number of channels, H represents the height of the feature map, W represents the width of the feature map, R represents a real number set, F' represents the output feature map of the channel attention module, M C (F) is the generated channel attention feature map; M S (F') is the generated spatial attention feature map, and F" represents the final output of the convolutional attention module CBAM. Represents an element-by-element multiplication operation;
[0021] The calculation formula of the channel attention module is as follows:
[0022]
[0023] Among them, σ represents the sigmoid function; W0 is the dimension reduction matrix, r is the compression ratio, C is the channel; W1 is the dimension increase matrix; MLP represents the multi-layer perception mechanism, Avgpool(F) represents the average pooling operation of the feature map F, and maxpool(F) represents the maximum pooling operation of the feature map F. Respectively represent the feature vectors obtained by average pooling and maximum pooling; Represents the feature vector after the maximum pooling The dimension reduction operation is performed through the dimension reduction matrix W0. Represents the feature vector after dimensionality reduction Perform dimension-raising operation through dimension-raising matrix W1;
[0024] The calculation formula of the spatial attention module is as follows:
[0025]
[0026] Among them, f 7×7 Indicates a convolution operation with a kernel size of 7x7; Avgpool(F') indicates a global average pooling operation on F', and Maxpool(F') indicates a global maximum pooling operation on F'; represents the feature map obtained by the average pooling operation, Represents the feature map obtained by maximum pooling; Indicates that and Concatenate in the channel dimension.
[0027] Furthermore, in said S12,
[0028] In the neck network, after the feature map output from the backbone network spatial pyramid pooling module SPPF passes through the first upsampling module, the feature map output from the first upsampling module is subjected to the first concat splicing operation with the output of the fourth feature fusion module of the backbone network. The feature map output from the first concat splicing operation passes through the first feature fusion module and the second upsampling module in sequence, and the output from the second upsampling module is subjected to the second concat splicing operation with the output from the third feature fusion module of the backbone network. The feature map output from the second concat splicing operation passes through the second feature fusion module and the third upsampling module in sequence, and the output from the third upsampling module is subjected to the third concat splicing operation with the output from the second feature fusion module of the backbone network. The third concat splicing operation The output feature map passes through the third feature fusion module and the first convolution module in sequence, and the output of the first convolution module and the output of the second feature fusion module are subjected to the fourth concat splicing operation. The output feature map of the fourth concat splicing operation passes through the fourth feature fusion module and the second convolution module in sequence, and the feature map output by the second convolution module and the feature map output by the first feature fusion module are subjected to the fifth concat splicing operation. The output feature map of the fifth concat splicing operation passes through the fifth feature fusion module and the third convolution module in sequence, and the output of the third convolution module and the feature map output by the backbone network space pyramid pooling module SPPF are subjected to the sixth concat splicing operation. Finally, the output feature map of the sixth concat splicing operation passes through the sixth feature fusion module.
[0029] Further, the S13 includes:
[0030] S131: In the head network, a detection head is combined with the outputs of the third feature fusion module, the fourth feature fusion module, the fifth feature fusion module, and the sixth feature fusion module of the neck network respectively;
[0031] S132: Each detection head has two branches. The first branch is composed of two convolution modules and a two-dimensional convolution layer Conv2d in sequence, and then optimized using the bounding box loss function; the second branch is composed of two convolution modules and a two-dimensional convolution layer Conv2d in sequence, and then optimized using the classification loss function;
[0032] S133: Introduce the scaled intersection-over-union loss function SIoU as the bounding box loss function in the detection head.
[0033] Further, the S133 includes:
[0034] S1331: Calculate the angle cost. The calculation formula is as follows:
[0035]
[0036]
[0037] Where: is the horizontal coordinate of the center point of the predicted bounding box, is the ordinate of the center point of the predicted bounding box; is the horizontal coordinate of the center point of the real bounding box, is the ordinate of the center point of the real bounding box; c h is the range of the vertical coordinate difference between the center point of the predicted bounding box and the center point of the real bounding box, σ is the distance between the center point of the predicted bounding box and the center point of the real bounding box, α is the vector angle, that is, the angle between the direction vector between the center point of the predicted bounding box and the center point of the real bounding box and the horizontal axis; Λ represents the angle cost of the loss function, Indicates the maximum value of the difference between the ordinates of all predicted boxes and the center points of the real boxes. Indicates the minimum value of the difference between the ordinates of all predicted boxes and the center points of the real boxes; x represents the range c of the difference between the ordinates of the predicted bounding box and the center point of the real bounding box h The normalized value is obtained;
[0038] S1332: Calculate the distance cost. The calculation formula is as follows:
[0039]
[0040]
[0041] γ=2-Δ (12)
[0042] Where: c w is the difference between the horizontal coordinates of the predicted box and the center point of the real box, Δ represents the distance cost of the loss function, e represents the base of the natural logarithm, and ρ x , y Respectively represent the standardized difference between the center point of the predicted bounding box and the center point of the true bounding box in the horizontal and vertical coordinate directions; t represents the coordinate direction of the center point of the bounding box, which can be x or y; x and y represent the horizontal and vertical coordinate directions of the center point of the bounding box, and ρ t It refers to the standardized difference between the center point of the predicted bounding box and the center point of the true bounding box in the horizontal or vertical direction, and γ is the weight parameter;
[0043] S1333: Calculate the shape cost. The calculation formula is as follows:
[0044]
[0045] Where: ω, h are the width and height of the predicted bounding box respectively; w gt 、h gt are the width and height of the real bounding box respectively; Ω represents the shape cost, ω w ,ω hThey represent the standardized difference between the predicted bounding box and the true bounding box in width and height respectively; w represents the width of the predicted bounding box, w gt represents the width of the true bounding box, h represents the height of the predicted bounding box, and h gt represents the height of the true bounding box; ω t represents the normalized difference between the predicted bounding box and the true bounding box in the width w direction or height h direction, t represents the size direction of the bounding box, which can be w or h; |ww gt | represents the absolute value of the difference between the width of the predicted bounding box and the width of the true bounding box; |hh gt | represents the absolute value of the difference between the height of the predicted bounding box and the height of the true bounding box;
[0046] S1334: Calculate the overlap cost IoU, the calculation formula is as follows:
[0047]
[0048] Among them, |b∩b gt | represents the area of the intersection between the predicted bounding box and the true bounding box, |b∪b gt | represents the area of the union of the predicted bounding box and the true bounding box;
[0049] S1335: The calculation formula of the scaled intersection-over-union loss function SIoU is:
[0050]
[0051] Another technical solution adopted by the present invention is:
[0052] A small target road vehicle detection device adopts the above method to realize small target road vehicle detection.
[0053] Another technical solution adopted by the present invention is:
[0054] A small target road vehicle detection storage medium adopts the above method to realize small target road vehicle detection.
[0055] The beneficial effects of the present invention are:
[0056] 1. Compared with the prior art, the present invention introduces the CBAM attention module in the Backbone part of YOLO v8, which can realize feature refinement and extraction in two different dimensions, channel and space, and specifically targets local vehicle information in the image, aiming to reduce the loss of feature extraction in scenes with complex backgrounds and occlusions. The overall goal is to enhance the expression ability of the network and improve the average accuracy of dense vehicle detection under surveillance.
[0057] 2. At the same time, combined with the additional p6 detection head, it is fused with the feature pyramid network backend to fuse more feature paths. The additional detection head for extremely small targets constitutes four detection heads corresponding to extremely small, small, medium, and large-scale targets respectively, making CP6-YOLOv8 have a wider detection range and effectively improve the performance of small target detection.
[0058] 3. Using the SIoU loss function can make the training process more stable, especially when dealing with complex scenes or when there is severe target overlap. In addition, the calculation of the SIoU loss function is relatively simple and does not involve complex distance metrics and division operations, thereby reducing the computational cost. This simplified calculation method not only improves the training efficiency of the model, but also further accelerates the convergence process. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0060] Figure 1 It is a process framework diagram of the present invention.
[0061] Figure 2 It is a process framework diagram of the convolutional block attention module CBAM.
[0062] Figure 3 It is a flow chart of the detection head in the present invention.
[0063] Figure 4 It is a representative scene graph of the UA-DETRAC dataset.
[0064] Figure 5 This is the detection result diagram of YOLOv8n.
[0065] Figure 6 This is the detection result diagram of YOLOv6.
[0066] Figure 7 This is the detection result diagram of YOLOv3-tiny.
[0067] Figure 8 It is a diagram of the detection results of the method of the present invention. DETAILED DESCRIPTION
[0068] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0069] The complete steps of the method of the present invention are as follows: Figure 1 As shown:
[0070] S1: Build the CP6-YOLOv8 model.
[0071] S11: Build the backbone network. In the original YOLOv8 backbone, since repeated use of the C2f module for feature extraction in the P4 and P5 layers may cause feature degradation, the CBAM attention mechanism is used to enhance the C2f module to reduce the number of times the C2f module is reused and achieve efficient feature extraction. The specific steps are described as follows:
[0072] S111: In the backbone network, the input image first passes through the first convolution block, the second convolution block, and then passes through the first feature fusion module, the third convolution block, the second feature fusion module, the fourth convolution block, the third feature fusion module, the fifth convolution block, and the fourth feature fusion module, and the CBAM convolution block attention module is added after the fourth feature fusion module;
[0073] S112: Then pass through the sixth convolution block and the fifth feature fusion module in sequence, add a CBAM convolution block attention module after the fifth feature fusion module, and finally pass through the spatial pyramid pooling module SPPF;
[0074] S113: In the backbone network, the CBAM convolutional block attention module is a lightweight attention mechanism module, such as Figure 2 As shown, it includes channel attention module and spatial attention module, which map on two-dimensional space and channel in turn. The formula of CBAM is shown as follows:
[0075]
[0076] Among them, F is the input feature map, F∈R C×H×W , C represents the number of channels, H represents the height of the feature map, W represents the width of the feature map, R represents a real number set, F' represents the output feature map of the channel attention module, M C (F) is the generated one-dimensional channel attention feature map, M C ∈R C×1×1 ;M S (F') is the generated two-dimensional spatial attention feature map, M S ∈R1×H×W , F" represents the final output of the CBAM module, Represents an element-wise multiplication operation.
[0077] The channel attention module prefers channels with robust feature information. The input feature map is subjected to global maximum pooling and global average pooling to derive a one-dimensional vector of channel attention. This process achieves the compression of the spatial dimension, aggregates the spatial information of the feature map, and then sums the outputs of the two branches through the shared perceptron MLP module, and applies the activation function to obtain the weighted coefficient. The formula of the channel attention mechanism is shown in the following formula:
[0078]
[0079] First, the spatial information of the feature map is aggregated using average pooling and maximum pooling operations to generate two different spatial descriptors. Then, both descriptors are forwarded to the shared network to generate our channel attention map M C ∈R C ×1×1 The shared network consists of a hidden layer of multi-layer perceptron (MLP), whose main function is to effectively map and weight the input features. MLP maps the input features through nonlinear transformation to extract more discriminative feature representations. This mapping helps the model capture more complex feature relationships and improve the expressiveness of features. In order to reduce parameter overhead, the hidden activation size is set to R C / r×1×1 , where r is the reduction ratio. After applying the shared network to each descriptor, we merge the output feature vectors using element-wise summation.
[0080] Among them, σ represents the sigmoid function; the shared weights are W0 and W1, W0 is the dimension reduction matrix, r is the compression ratio, C is the channel, and the purpose is to reduce the input features from C dimensions to dimensions through linear transformation. W1 is a dimension-raising matrix used to map the features after dimension reduction back to C dimension; E1∈R C×C / r MLP means multi-layer perception mechanism, Avgpool(F) means average pooling of feature map F, and maxpool(F) means maximum pooling of feature map F. Respectively represent the feature vectors obtained by average pooling and maximum pooling; Represents the feature vector after the maximum pooling The dimension reduction operation is performed through the dimension reduction matrix E0. Represents the feature vector after dimensionality reduction Perform dimension-raising operation through dimension-raising matrix E1;
[0081] The spatial attention module aims to prioritize the more important information in the input image. The spatial relationship of the features is used to generate a spatial attention map. Unlike channel attention, spatial attention focuses on "where", which is the informative part and is complementary to channel attention. To calculate spatial attention, first, global maximum pooling and global average pooling operations are used to generate a comprehensive feature description, which is then connected to the channel, and finally the weight coefficient is obtained through the convolution layer and sigmoid function. The formula of the spatial attention mechanism is shown in formula (3), including f 7×7 is a 7x7 convolution kernel; feature description includes global maximum pooling and global average pooling On top of the concatenated feature descriptors, we apply a convolutional layer to generate a spatial attention map M S (F')∈R H×W , which encodes the position of emphasis or suppression.
[0082]
[0083] Among them, f 7×7 Indicates a convolution operation, the size of this convolution kernel is 7x7; Avgpool(F') indicates a global average pooling operation on F', and Maxpool(F') indicates a global maximum pooling operation on F'; represents the feature map obtained by the average pooling operation, Represents the feature map obtained by maximum pooling. Indicates that and Concatenate in the channel dimension.
[0084] The present invention adds two CBAM attention mechanism modules in the backbone to realize feature refinement and extraction in two different dimensions, channel and space, specifically targeting local vehicle information in the image, aiming to reduce the loss of feature extraction in scenes such as complex background and occlusion. The overall goal is to enhance the expression ability of the network and improve the average accuracy of dense vehicle detection under surveillance.
[0085] S12: Construct the neck network. Compared with the feature pyramid network in the original YOLOv8, the P6 layer is additionally introduced. The specific steps are described as follows:
[0086] In the neck network, after the feature map output from the backbone network spatial pyramid pooling module SPPF passes through the first upsampling module, the feature map output from the first upsampling module is subjected to the first concat splicing operation with the output of the fourth feature fusion module of the backbone network. The feature map output from the first concat splicing operation passes through the first feature fusion module and the second upsampling module in sequence, and the output from the second upsampling module is subjected to the second concat splicing operation with the output from the third feature fusion module of the backbone network. The feature map output from the second concat splicing operation passes through the second feature fusion module and the third upsampling module in sequence, and the output from the third upsampling module is subjected to the third concat splicing operation with the output from the second feature fusion module of the backbone network. The third concat splicing operation The output feature map passes through the third feature fusion module and the first convolution module in sequence, and the output of the first convolution module and the output of the second feature fusion module are subjected to the fourth concat splicing operation. The output feature map of the fourth concat splicing operation passes through the fourth feature fusion module and the second convolution module in sequence, and the feature map output by the second convolution module and the feature map output by the first feature fusion module are subjected to the fifth concat splicing operation. The output feature map of the fifth concat splicing operation passes through the fifth feature fusion module and the third convolution module in sequence, and the output of the third convolution module and the feature map output by the backbone network space pyramid pooling module SPPF are subjected to the sixth concat splicing operation. Finally, the output feature map of the sixth concat splicing operation passes through the sixth feature fusion module.
[0087] Since an additional p6 layer is introduced in the neck network, repeated use of the C2f module for feature extraction may lead to feature degradation. However, the attention mechanism can efficiently extract features from the shallow network and guide the subsequent network modules to perform feature fusion through a top-down path, which can generate more discriminative features. That is, the model can extract features that can better distinguish vehicles of different categories or different states. These features include the appearance, shape, color, size, and relationship with the environment of the vehicle.
[0088] S13: Build the head network. Compared with the original YOLOv8 head network, it combines an additional detection head, such as Figure 3 As shown in the figure, the path to merge with the feature pyramid network backend to merge more features. The specific steps are as follows:
[0089] S131: In the head network, a detection head is combined with the outputs of the third feature fusion module, the fourth feature fusion module, the fifth feature fusion module, and the sixth feature fusion module of the neck network.
[0090] S132: There are two branches in each detection head. The first branch is composed of two convolution modules and a two-dimensional convolution layer Conv2d in sequence, and then optimized using bounding box regression loss; the second branch is composed of two convolution modules and a two-dimensional convolution layer Conv2d in sequence, and then optimized using category classification loss.
[0091] Since the attention-guided bidirectional feature pyramid network has a more efficient feature generation capability, the present invention maintains the same advantage in the number of model parameters as mentioned in S11 by reducing the number of feature maps generated by the C2f module, and uses the CBAM attention mechanism to enhance the C2f module to reduce the number of times the C2f module is reused, and to achieve efficient feature extraction. At the same time, an additional detection head is added for extremely small target detection, forming four detection heads corresponding to four types of targets of extremely small, small, medium, and large scales, so that CP6-YOLOv8 has a wider detection range. That is, it can be used to detect extremely small vehicles such as motorcycles, small electric vehicles, or long-distance cars. The purpose of this is to improve the model's detection capability for targets of different sizes.
[0092] S133: Introduce loss function.
[0093] The YOLOv8 model uses Complete IoU (CIoU) as the bounding box loss function. CIoU calculates the regression positioning loss through three geometric parameters: the aspect ratio between the predicted box and the true box, the center point distance, and the overlapping area. As a distance-based loss function, CIoU involves division operations, which can cause gradient explosion or vanishing phenomena when there is little overlap between bounding boxes. In addition, CIoU is highly sensitive to the distance between bounding boxes, especially in the early stages of training. Its value will oscillate frequently with the changes in the bounding boxes, which may lead to instability in the regression process, thereby affecting the convergence speed of the model and the overall training effect.
[0094] Unlike CIoU, SIoU is an area-based loss function, and its calculation result is only related to the area of the target box and is not directly affected by the change of the bounding box. This feature makes the training process more stable, especially when dealing with complex scenes or when the target overlaps severely. The SIoU loss function introduces the vector angle between the predicted box and the true box when defining the loss metric. The SIoU loss function consists of four components: angle cost, distance cost, shape cost, and overlapping area cost. This multi-dimensional loss calculation method enables SIoU to more comprehensively evaluate the quality of the predicted box under different conditions. In the actual application of vehicle detection, the SIoU loss function can improve the detection accuracy of the target, especially in the case of overlapping vehicles, complex backgrounds, or different target sizes, and enhance the robustness and reliability of the model. This is very important for applications such as traffic monitoring, autonomous driving, and intelligent transportation systems, which can ensure that the model can accurately identify and locate vehicles in various complex situations.
[0095] In addition, the calculation of the SIoU loss function is relatively simple and does not involve complex distance metrics and division operations, thereby reducing the computational cost. This simplified calculation method not only improves the training efficiency of the model, but also helps the prediction box quickly adjust to the closest axis by considering the matching direction, thereby further accelerating the convergence process.
[0096] In practical applications, the introduction of SIoU loss function significantly improves the performance of the target detection model, especially when the bounding box overlap is small, and its stability and efficiency can effectively alleviate the instability in training. This is crucial for real-time detection systems, as these systems require high accuracy and efficiency in rapidly changing environments.
[0097] S1331: Calculate angle cost (Angel cost).
[0098]
[0099] Where: is the coordinate of the center point of the predicted bounding box; is the horizontal coordinate of the center point of the predicted bounding box, is the ordinate of the center point of the predicted bounding box; is the coordinate of the center point of the real bounding box, is the horizontal coordinate of the center point of the real bounding box, is the ordinate of the center point of the real bounding box; c h is the range of the vertical coordinate difference between the center point of the predicted bounding box and the center point of the real bounding box, σ is the distance between the center point of the predicted bounding box and the center point of the real bounding box, and α is the vector angle, that is, the angle between the direction vector between the center point of the predicted bounding box and the center point of the real bounding box and the horizontal axis. Λ represents the angle cost of the SIoU loss function, Represents the maximum value of the difference in ordinate between the center points of all matched prediction boxes and real boxes. Indicates the minimum value of the difference between the ordinates of all matching predicted boxes and the center points of the real boxes. x represents the range c of the difference between the ordinates of the predicted bounding box and the center points of the real bounding box. h The normalized value.
[0100] S1332: Calculate distance cost.
[0101]
[0102]
[0103] γ=2-Δ (12)
[0104] Where: c w is the difference between the horizontal coordinates of the predicted box and the center point of the real box, Δ represents the distance cost of the SIoU loss function, e represents the base of the natural logarithm, and ρ x , y Respectively represent the standardized difference between the center point of the predicted bounding box and the center point of the true bounding box in the horizontal and vertical coordinate directions; t represents the coordinate direction of the center point of the bounding box, which can be x or y; x and y represent the horizontal and vertical coordinate directions of the center point of the bounding box, and ρ t Refers to the standardized difference between the center point of the predicted bounding box and the center point of the true bounding box in the horizontal or vertical direction. γ is a weight parameter. The initial value is 2 and it will be dynamically adjusted according to Δ during the calculation process.
[0105] S1333: Calculate shape cost (Shape cost).
[0106]
[0107] Where: ω, h are the width and height of the predicted bounding box respectively; w gt 、h gt are the width and height of the true bounding box respectively;
[0108] Ω represents the shape cost, ω w ,ω h They represent the standardized difference between the predicted bounding box and the true bounding box in width and height respectively; w represents the width of the predicted bounding box, w gt represents the width of the true bounding box, h represents the height of the predicted bounding box, and h gt represents the height of the true bounding box; ω t It represents the normalized difference between the predicted bounding box and the true bounding box in the width w direction or the height h direction, and t represents the size direction of the bounding box, which can be w or h.
[0109] S1334: Calculate the overlap cost (IoU cost).
[0110]
[0111] Among them, |b∩b gt | represents the area of the intersection between the predicted bounding box and the true bounding box, |b∪b gt | represents the area of the union of the predicted bounding box and the true bounding box, and IoU represents the intersection over union ratio;
[0112] S1335: SIoU loss function Loss SIoU The calculation formula is:
[0113]
[0114] S2: Build a dataset and train a model.
[0115] The UA-DETRAC dataset was jointly released by the University of Alberta and the University of Science and Technology of China as a benchmark dataset designed specifically for multi-target vehicle detection and tracking. The dataset contains 10 hours of video shot with a Canon EOS 550D camera (Canon USA, Inc., Lake Success, NY, USA). The video is recorded at a frame rate of 25 frames per second and contains more than 140,000 frames and 1.21 million annotated object detection boxes. The training set contains 60 video sequences totaling 83,791 images, while the test set contains 40 video sequences totaling 56,340 images. The UA-DETRAC dataset presents various challenges, with representative scenes such as Figure 4 The dataset covers four vehicle categories: cars, buses, trucks, etc. In addition, it also includes four weather conditions: sunny, night, cloudy, and rainy, as well as scenes with high vehicle density and occlusion rate.
[0116] In the vehicle detection experiment, we first exclude images without labels, and obtain a training set of 82,085 images and a test set of 56,167 images. To avoid overfitting, we sample every 10 frames, and finally obtain 8,209 training images and 5,617 evaluation images. For the vehicle tracking experiment, we use 40 video sequences in the test set for evaluation.
[0117] The GPU device used in these experiments is NVIDIA GeForce RTX 4090 (NVIDIA Corporation, Santa Clara, California, USA), and the CPU device is Core i9-12900K@3.20GHz CPU (Intel Corporation, Chengdu, China). The experiments were conducted on Windows 11 system, and the deep learning environment was based on PyTorch 1.7.0, CUDA 11.0, and Python 3.7. The training parameters were set as follows: the number of training epochs was 100, the batch size was 16, and the pre-trained weights were not used during training.
[0118] S3: Use the trained model for detection.
[0119] Model Evaluation:
[0120] In vehicle detection, precision (P), recall (R), mAP@0.5, and mAP@0.5:0.95 are used to evaluate the experimental results. P represents the proportion of true positive samples among all samples detected as positive, as shown in formula (17):
[0121]
[0122] R represents the proportion of correctly detected positive samples among all actual positive samples, as shown in formula (18):
[0123]
[0124] Among them, TP is the number of true positive samples, FP is the number of false positive samples, and FN is the actual number of positive samples that are misclassified as negative samples.
[0125] The average accuracy (AP) represents the area under the PR curve of a certain type of samples, as shown in formula (19):
[0126]
[0127] mAP@0.5 is the mean average precision over all classes with an IoU threshold of 0.5.
[0128] mAP@0.5:0.95 is the mean average precision over all classes with an IoU threshold ranging from 0.5 to 0.95 with a step size of 0.05.
[0129] In vehicle tracking, the multi-target tracking accuracy MOTA, identity F1 score IDF1 and identity switching number IDS are used to evaluate the experimental results. MOTA measures the accuracy of the tracking algorithm, taking into account various errors that occur during the tracking process, such as false positives, missed detections and identity switching. As shown in formula (20):
[0130]
[0131] Among them, FN t Indicates the number of missed detections at time t, FP t represents the number of false alarms at time t, IDSW t represents the number of identity switches at time t, GT t represents the true number of targets at time t.
[0132] IDF1 is a measure of the identity consistency and continuity of the tracking algorithm, as shown in formula (21):
[0133]
[0134] Where IDP represents the proportion of correctly identified targets among detected targets, and IDR represents the ratio of correctly detected target identities to actual target identities.
[0135] IDS represents the number of identity switches that occur during tracking, i.e. the same target is assigned different identities. Lower values indicate that the tracker performs better in maintaining identity consistency.
[0136] In order to verify the performance of CP6-YOLOv8 proposed in the present invention, it is compared with the unimproved YOLO algorithm. All algorithms are trained on the UA-DETRAC dataset, and are trained on the training set for 100 rounds respectively. After the training is completed, the model is saved and tested on the self-collected test set, and AP and mAP calculations are performed. Because the model will automatically generate corresponding Precision and Recall during the training process, AP, mAP and FPS are used to measure the quality of the model detection performance. Table 1 shows the comparative detection results of the method of the present invention and other detection methods on the UA-DETRAC dataset.
[0137] Table 1
[0138]
[0139] From the data in Table 1, we can see that the introduction of a CBAM module between p4 and p5 in the original YOLOv8 model improves precision by 1.212%, which verifies the effectiveness of the CBAM module in extracting vehicle features. The introduction of the p6 detection head improves precision by 5.439%, mAP@0.5 by 1.2%, and mAP@0.5:0.95 by 2.204%, demonstrating the significant advantages of p6 in dealing with multi-scale problems. When the CBAM module and the p6 detection head are introduced at the same time, precision increases by 15.227%, mAP@0.5 by 1.568%, and mAP@0.5:0.95 by 1.793%, proving that the combination of these two modules can better extract and integrate detection features. Finally, with two CBAM modules, mAP@0.5 increases slightly by 1.691% and precision increases significantly by 11.234%, laying the foundation for more accurate vehicle detection in the subsequent stage. Compared with the baseline model, the superiority of the improved model in dealing with vehicle detection scenarios is fully verified.
[0140] In order to further demonstrate the progress of the improved model in vehicle detection, the experimental results are visualized and analyzed, such as Figure 5 , Figure 6 , Figure 7 , Figure 8 As shown in the first column of pictures, the detection accuracy of the first car is the highest, YOLOv8n+2CBAM+P6(ours), which is 0.8, indicating that the model accuracy has increased; the tiny vehicle in the upper right corner of the second column of pictures is only detected by YOLOv8n and YOLOv8n+2CBAM+P6(ours), and the accuracy of YOLOv8n+2CBAM+P6(ours) is higher, indicating that the detection effect of small and distant vehicles has been improved; the van in the middle of the fourth column of pictures is only detected by YOLOv6 and YOLOv8n+2CBAM+P6(ours), indicating that the error rate of the model of the present invention has been reduced.
[0141] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0142] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A small target road vehicle detection method, characterized in that: The following steps are involved: S1: Build the CP6-YOLOv8 model; S2: Build a dataset and train a model; S3: Use the trained model to perform vehicle detection.
2. A small target road vehicle detection method according to claim 1, characterized in that: The S1 includes: S11: Build backbone network; S12: Building the neck network; S13: Build the head network.
3. A small target road vehicle detection method according to claim 2, characterized in that: The S11 includes: S111: In the backbone network, the input image first passes through the first convolution block, the second convolution block, and then passes through the first feature fusion module, the third convolution block, the second feature fusion module, the fourth convolution block, the third feature fusion module, the fifth convolution block, and the fourth feature fusion module, and the convolution attention module CBAM is added after the fourth feature fusion module; S112: Then pass through the sixth convolution block and the fifth feature fusion module in sequence, add a convolutional attention module CBAM after the fifth feature fusion module, and finally pass through the spatial pyramid pooling module SPPF.
4. A small target road vehicle detection method according to claim 3, characterized in that: The S11 further includes: S113: In the backbone network, the convolutional attention module CBAM includes a channel attention module and a spatial attention module. The calculation of the convolutional attention module CBAM is shown in the following formula: Among them, F is the input feature map of the convolutional attention module CBAM, F∈R C×H×W , C represents the number of channels, H represents the height of the feature map, W represents the width of the feature map, R represents a real number set, F' represents the output feature map of the channel attention module, M C (F) is the generated channel attention feature map; M S (F') is the generated spatial attention feature map, and F" represents the final output of the convolutional attention module CBAM. Represents an element-by-element multiplication operation; The calculation formula of the channel attention module is as follows: Among them, σ represents the sigmoid function; W0 is the dimension reduction matrix, r is the compression ratio, C is the channel; W1 is the dimension increase matrix; MLP represents the multi-layer perception mechanism, Avgpool represents the average pooling operation of the feature map F, and maxpool(F) represents the maximum pooling operation of the feature map F. Respectively represent the feature vectors obtained by average pooling and maximum pooling; Represents the feature vector after the maximum pooling The dimension reduction operation is performed through the dimension reduction matrix W0. Represents the feature vector after dimensionality reduction Perform dimension-raising operation through dimension-raising matrix W1; The calculation formula of the spatial attention module is as follows: Among them, f 7×7 Indicates a convolution operation with a kernel size of 7x 7; Avgpool(F') indicates a global average pooling operation on F', and Maxpool(F') indicates a global maximum pooling operation on F'; represents the feature map obtained by the average pooling operation, Represents the feature map obtained by maximum pooling; Indicates that and Concatenate in the channel dimension.
5. A small target road vehicle detection method according to claim 2, characterized in that: In the S12, In the neck network, after the feature map output from the backbone network spatial pyramid pooling module SPPF passes through the first upsampling module, the feature map output from the first upsampling module is subjected to the first concat splicing operation with the output of the fourth feature fusion module of the backbone network. The feature map output from the first concat splicing operation passes through the first feature fusion module and the second upsampling module in sequence, and the output from the second upsampling module is subjected to the second concat splicing operation with the output from the third feature fusion module of the backbone network. The feature map output from the second concat splicing operation passes through the second feature fusion module and the third upsampling module in sequence, and the output from the third upsampling module is subjected to the third concat splicing operation with the output from the second feature fusion module of the backbone network. The third concat splicing operation The output feature map passes through the third feature fusion module and the first convolution module in sequence, and the output of the first convolution module and the output of the second feature fusion module are subjected to the fourth concat splicing operation. The output feature map of the fourth concat splicing operation passes through the fourth feature fusion module and the second convolution module in sequence, and the feature map output by the second convolution module and the feature map output by the first feature fusion module are subjected to the fifth concat splicing operation. The output feature map of the fifth concat splicing operation passes through the fifth feature fusion module and the third convolution module in sequence, and the output of the third convolution module and the feature map output by the backbone network space pyramid pooling module SPPF are subjected to the sixth concat splicing operation. Finally, the output feature map of the sixth concat splicing operation passes through the sixth feature fusion module.
6. A small target road vehicle detection method according to claim 2, characterized in that: The S13 includes: S131: In the head network, a detection head is combined with the outputs of the third feature fusion module, the fourth feature fusion module, the fifth feature fusion module, and the sixth feature fusion module of the neck network respectively; S132: Each detection head has two branches. The first branch is composed of two convolution modules and a two-dimensional convolution layer Conv2d in sequence, and then optimized using the bounding box loss function; the second branch is composed of two convolution modules and a two-dimensional convolution layer Conv2d in sequence, and then optimized using the classification loss function; S133: Introduce the scaled intersection-over-union loss function SIoU as the bounding box loss function in the detection head.
7. A small target road vehicle detection method according to claim 6, characterized in that: The S133 includes: S1331: Calculate the angle cost. The calculation formula is as follows: Where: is the horizontal coordinate of the center point of the predicted bounding box, is the ordinate of the center point of the predicted bounding box; is the horizontal coordinate of the center point of the real bounding box, is the ordinate of the center point of the real bounding box; c h is the range of the vertical coordinate difference between the center point of the predicted bounding box and the center point of the real bounding box, σ is the distance between the center point of the predicted bounding box and the center point of the real bounding box, α is the vector angle, that is, the angle between the direction vector between the center point of the predicted bounding box and the center point of the real bounding box and the horizontal axis; Λ represents the angle cost of the loss function, Indicates the maximum value of the difference between the ordinates of all predicted boxes and the center points of the real boxes. Indicates the minimum value of the difference between the ordinates of all predicted boxes and the center points of the real boxes; x represents the range c of the difference between the ordinates of the predicted bounding box and the center point of the real bounding box h The normalized value is obtained; S1332: Calculate the distance cost. The calculation formula is as follows: Δ=∑ t=x,y (1-e -γρt ) (9) γ=2-Δ (12) Where: c w is the difference between the horizontal coordinates of the predicted box and the center point of the real box, Δ represents the distance cost of the loss function, e represents the base of the natural logarithm, and ρ x , y Respectively represent the standardized difference between the center point of the predicted bounding box and the center point of the true bounding box in the horizontal and vertical coordinate directions; t represents the coordinate direction of the center point of the bounding box, which can be x or y; x and y represent the horizontal and vertical coordinate directions of the center point of the bounding box, and ρ t It refers to the standardized difference between the center point of the predicted bounding box and the center point of the true bounding box in the horizontal or vertical direction, and γ is the weight parameter; S1333: Calculate the shape cost. The calculation formula is as follows: Where: ω, h are the width and height of the predicted bounding box respectively; w gt 、h gt are the width and height of the true bounding box respectively; Ω represents the shape cost, ω w ,ω h They represent the standardized difference between the predicted bounding box and the true bounding box in width and height directions respectively; w represents the width of the predicted bounding box, w gt represents the width of the true bounding box, h represents the height of the predicted bounding box, and h gt represents the height of the true bounding box; ω t represents the normalized difference between the predicted bounding box and the true bounding box in the width w direction or height h direction, t represents the dimension direction of the bounding box, which can be w or h; |ww gt | represents the absolute value of the difference between the width of the predicted bounding box and the width of the true bounding box; |hh gt Represents the absolute value of the difference between the height of the predicted bounding box and the height of the true bounding box; S1334: Calculate the overlap cost IoU, the calculation formula is as follows: Among them, |b∩b gt | represents the area of the intersection between the predicted bounding box and the true bounding box, |b∪b gt | represents the area of the union of the predicted bounding box and the true bounding box; S1335: The calculation formula of the scaled intersection-over-union loss function SIoU is:
8. A small target road vehicle detection device, characterized in that: The method as described in any one of claims 1 to 7 is used to realize small target road vehicle detection.
9. A small target road vehicle detection storage medium, characterized in that: The method as described in any one of claims 1 to 7 is used to realize small target road vehicle detection.
Citation Information
Cited By
Lightweight vehicle target detection method and system based on RT-DETR
CN121861623A