Unmanned aerial vehicle target detection method based on improved YOLOv5 algorithm
By calculating anchor box parameters on feature maps of different scales, combining Focal Loss and SENet attention mechanisms, the YOLOv5 algorithm is improved, and the problem of insufficient real-time and feature fusion of traditional algorithms in high-resolution image processing is solved, and the improvement is achieved High detection accuracy and generalization ability.
Patent Information
- Application Number
- CN202411426347.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-02-07
AI Technical Summary
The traditional YOLOv5 algorithm has low real-time performance when processing high-resolution images and insufficient feature fusion, which affects detection accuracy.
The YOLOv5 algorithm is improved, and the anchor box parameters are calculated separately on feature maps of different scales, and the Focal Loss loss function and SENet attention mechanism are introduced to optimize the network structure and loss function.
The model's detection ability of targets at different scales is improved, the generalization ability in complex scenarios is enhanced, and the detection accuracy and real-timeness are improved.
Smart Images

Figure CN119399653A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of unmanned aerial vehicle target detection, and specifically is a method for unmanned aerial vehicle target detection based on an improved YOLOv5 algorithm. Background Art
[0002] With the rapid development of drone technology, drones are increasingly used in military, civil and commercial fields. Especially in the fields of monitoring, search and rescue, agriculture, logistics, etc., drone target detection technology has become a key technology to improve mission efficiency and accuracy. However, due to the limited computing resources of drone platforms and the complex and changeable flight environment, traditional target detection algorithms are difficult to meet actual needs in terms of real-time performance and accuracy. As a cutting-edge field of modern intelligent technology, drone target detection technology is gradually changing the traditional operating mode of multiple industries such as monitoring, search and rescue, and agriculture. This technology uses advanced image processing and machine learning algorithms to enable drones to accurately identify and track specific targets and achieve efficient and accurate mission execution. Drone target detection technology mainly collects image data through high-definition cameras, and then uses deep learning algorithms to identify and analyze targets in the image. The algorithm can learn the characteristics of the target, so as to quickly locate the target in a complex environment and track it in real time.
[0003] However, the traditional YOLOv5 algorithm may not be very real-time when processing high-resolution images due to the large amount of calculation, which is a disadvantage for drone target detection that requires fast response. At the same time, the original YOLOv5 algorithm may not be sufficient in feature fusion, resulting in the ineffective use of features of different scales, which may affect the detection accuracy. Summary of the invention
[0004] The purpose of the present invention is to provide a drone target detection method based on an improved YOLOv5 algorithm in order to solve the above-mentioned problems.
[0005] The technical solution adopted by the present invention is as follows: a drone target detection method based on an improved YOLOv5 algorithm, the method comprising the following steps:
[0006] S1: Perform data collection, using the camera carried by the drone to collect target images in different scenes and under different lighting conditions;
[0007] S2: Use the LabelImg annotation tool to annotate the collected images and mark the category and location information of the target;
[0008] S3: Rotate, scale, and flip the annotated images to expand the data set and improve the generalization ability of the model. The data set is then divided into training set, validation set, and test set in a ratio of 7:2:1.
[0009] S4: Improve the YOLOv5 algorithm. The overall structure of the YOLOv5 algorithm includes the input end, the Backbone end, the Neck end, and the Prediction end.
[0010] S5: For the drone target detection task, we design the Focal Loss loss function and introduce the SENet attention mechanism to improve the model's ability to express the target;
[0011] S6: Use the pre-trained YOLOv5 model as the base model and load the pre-trained weights; perform model training: train the model using the training set and set appropriate hyperparameters;
[0012] S7: Evaluate model performance on the validation set and adjust hyperparameters based on the validation results. Model optimization: Based on the validation results, tune the model, including adjusting the network structure and loss function.
[0013] S8: Export the trained model into a format that can be used on the UAV platform;
[0014] S9: Deploy the model and deploy the exported model to the UAV platform to achieve real-time target detection, thus completing the entire UAV target detection process based on the improved YOLOv5 algorithm.
[0015] In a preferred embodiment, in step S1, the acquisition resolution is at least 1080p and the frame rate is not less than 30fps to ensure image clarity and dynamic capture capabilities; the acquisition scenes should cover different terrains such as cities, rural areas, mountains, and waters, as well as different lighting conditions such as sunny days, cloudy days, and nights to enhance the diversity of the data set.
[0016] In a preferred embodiment, in step S2, when using the LabelImg annotation tool to annotate the image, the accuracy of the annotation must be ensured; the specific method is: draw a bounding box for each target instance and mark its category label, including people, vehicles, and animals; during the annotation process, the bounding box should be closely fitted to the target to avoid excessive background areas or missing target parts, while ensuring the consistency and accuracy of the annotation.
[0017] In a preferred embodiment, in step S3, during the data enhancement stage, the annotated image is rotated by 0°, 90°, 180°, 270°, scaled, and flipped; in addition, random cropping and color jittering methods are applied to further expand the data set; after completing the data enhancement, the data set is randomly divided in a ratio of 7:2:1 to ensure the independence and representativeness of the training, validation, and test data.
[0018] In a preferred embodiment, in step S4, the input end mainly consists of three parts: Mosaic image enhancement, adaptive anchor frame calculation, and adaptive picture scaling; Mosaic data enhancement is to splice four pictures by random scaling, random cropping, and random arrangement, which can enrich the background and small target information of the detected object; the idea of the adaptive anchor frame is to automatically calculate the optimal anchor frame parameters of the input image by learning without manual setting, which can improve the accuracy and robustness of target detection; adaptive picture scaling can keep the aspect ratio of the picture unchanged and scale it to a suitable size, which can retain the original information in the picture to a great extent and avoid information loss;
[0019] Adaptive anchor box calculation calculates anchor box parameters on feature maps of different scales to better adapt to targets of different sizes. The specific steps include:
[0020] S4-1. Feature map extraction. In the Backbone network, feature maps of multiple scales are extracted at different stages of the CSPNet structure. Assume that feature maps of three scales are extracted, which are denoted as F1, F2, and F3, respectively, corresponding to different resolutions of the original image.
[0021] S4-2. Anchor box parameter calculation: For each scale feature map, the anchor box parameters are calculated independently; the anchor box parameters usually include the width and height of the anchor box;
[0022] For the feature map Fi of the i-th scale, the calculation formula for the anchor box parameter ai is:
[0023] ai=Clustering(Fi,K), where Clustering is a K-means clustering algorithm used to find the optimal anchor box size, and K is the number of cluster centers, i.e., the number of anchor boxes;
[0024] S4-3. Multi-scale anchor box parameter fusion, design a fusion strategy to weightedly fuse anchor box parameters of different scales; the fusion formula is:
[0025] Let W1, W2, W3 be the weights of the three scales, A1, A2, A3 be the corresponding anchor box parameters, and the fused anchor box parameter A is:
[0026] A=W1·A1+W2·A2+W3·A3;
[0027] The weight Wi can be dynamically adjusted according to the size of the target and the resolution of the feature map, and the formula is:
[0028]
[0029] Where Si is the average object size of the i-th feature map, S targetis the average size of the target, σ is a parameter that controls the smoothness of the weights;
[0030] S4-4. Bounding box regression during training, using the fused anchor box parameters for bounding box regression training; the bounding box regression loss formula is:
[0031]
[0032] Where N is the number of anchor boxes, b i is the ground-truth bounding box, is the predicted bounding box, CIOU is the complete IoU loss function;
[0033] S4-5. Object detection in the prediction stage,In the prediction stage, the fused anchor box parameters are used for object detection;
[0034] Through the above improvements in calculating anchor box parameters on feature maps of different scales, the drone target detection method improves the model's ability to detect targets of different scales, especially for small and large targets, and can achieve more accurate positioning. At the same time, the generalization ability of the model in complex scenes is enhanced, and it can better adapt to the diverse target distribution. The calculation process of the anchor box parameters is optimized, the workload of manually adjusting the anchor box parameters is reduced, and the degree of automation of the model is improved. Through the fusion of multi-scale anchor box parameters, the accuracy of the detection box is improved, and the overall performance of drone target detection is further improved.
[0035] The Backbone part is mainly used to extract image features. First, this part introduces the Focus structure, which periodically extracts pixels from the high-resolution image, and reconstructs the four sub-images into a low-resolution image by channel splicing, thereby realizing downsampling and feature compression of the input feature map. Then, the CSP structure is introduced to convert the input feature map into a Figure 1 After being divided into two, they are concatenated and combined as the input of the next layer after cross-stage processing, which significantly reduces the parameters and calculation amount of the network, while improving the efficiency of feature extraction, thereby speeding up the training and reasoning of the model;
[0036] The Neck part further improves the feature extraction capability; Neck adopts the FPN+PAN structure, uses the FPN structure to transmit strong semantic features from top to bottom, uses the PAN module to build a feature pyramid structure, transmits strong positioning features from bottom to top, and realizes feature fusion between different layers;
[0037] The prediction information in the prediction part mainly consists of the bounding box position information, category, and confidence. The bounding box loss function uses the CIOU_Loss function, and the specific calculation formulas are as follows (1) to (4), which is mainly used to measure the difference between the predicted bounding box and the true bounding box. NMS non-maximum suppression is used to screen the predicted box.
[0038]
[0039] In a preferred embodiment, in step S5, the Focal Loss loss function adds two adjustable parameters: α and γ on the basis of the cross entropy loss, and the calculation formula is:
[0040] FL(pt)=-αt(1-pt)γlog(pt);
[0041] Among them: pt is the model's predicted probability for each category. For the positive category, pt is the model's prediction that the target belongs to the positive category; for the negative category, pt is the model's prediction that the target belongs to the negative category.
[0042] αt is the positive and negative sample balance coefficient, which is used to adjust the weights of positive and negative samples in the loss function; for positive samples, αt = α; for negative samples, αt = 1-α;
[0043] γ is the difficult and easy sample adjustment coefficient, which is used to reduce the weight of simple samples so that the model pays more attention to difficult-to-classify samples;
[0044] (1-pt)γ is the adjustment factor. When pt is close to 1, the adjustment factor is close to 0, reducing the loss contribution of simple samples; when pt is close to 0, the adjustment factor is close to 1, maintaining the loss contribution of difficult samples.
[0045] In a preferred embodiment, in step S5, the calculation step of SENet includes:
[0046] Squeeze operation: perform global average pooling on the feature map to compress the features of each channel and obtain a channel descriptor;
[0047] Excitation operation: The channel descriptor is learned through two fully connected layers to obtain the weight of each channel;
[0048] Reweight operation: The weights obtained by the Excitation operation are recalibrated channel by channel through multiplication.
[0049] In a preferred embodiment, in step S6, during the model training phase, the pre-trained YOLOv5 weights are used as the starting point, the initial learning rate is set to 0.01, and a learning rate decay strategy is adopted according to the training progress; the training batch size is set to 16 or 32, adjusted according to the video memory capacity; the training cycle is determined according to the data set size and the model convergence, and is between 100 and 300 epochs.
[0050] In a preferred embodiment, in step S7, when evaluating the model performance on the validation set, the focus indicators include accuracy, recall rate, and average precision; hyperparameters are adjusted according to the validation results, including learning rate, batch size, and data enhancement strategy; during the model tuning process, the network structure needs to be fine-tuned, including adding or reducing convolution layers, adjusting the convolution kernel size, and optimizing the loss function.
[0051] In a preferred embodiment, in step S8, during the model export phase, the trained model is converted into ONNX or TensorRT format to adapt to the computing resources of the drone platform; during the conversion process, the accuracy and reasoning speed of the model are balanced, and the model size and reasoning speed can be optimized by setting the accuracy threshold;
[0052] In the step S9:, during the model deployment phase, the exported model is integrated into the real-time target detection system on the UAV platform; the compatibility, power consumption, and heat dissipation of the model need to be considered during deployment; after actual deployment, field testing is performed to ensure that the model can run stably in different environments and conditions to achieve the goal of real-time detection; at the same time, field data is collected to provide a basis for further optimization of the model.
[0053] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are:
[0054] 1. In the present invention, by respectively calculating the anchor frame parameters on feature maps of different scales, the drone target detection method improves the model's detection ability for targets of different scales, especially for small and large targets, and can achieve more accurate positioning. At the same time, the generalization ability of the model in complex scenes is enhanced, and it can better adapt to the diverse target distribution. The calculation process of the anchor frame parameters is optimized, the workload of manually adjusting the anchor frame parameters is reduced, and the degree of automation of the model is improved. By fusion of multi-scale anchor frame parameters, the accuracy of the detection frame is improved, and the overall performance of drone target detection is further improved; at the same time, the FPN and PAN structures of the Neck part effectively fuse features of different scales, and improve the network's positioning and recognition capabilities for targets. The FPN structure transmits strong semantic features from top to bottom, while the PAN structure transmits strong positioning features from bottom to top. The combination of the two enables the model to better handle targets of different scales and complexities. By learning the optimal anchor frame parameters of the input image, the adaptive anchor frame calculation improves the accuracy of the detection frame, so that the model can locate the target more accurately. Using CIOU_Loss as the Bounding box loss function can more comprehensively measure the difference between the predicted frame and the true frame, thereby improving the detection accuracy.
[0055] 2. In the present invention, the Focal Loss function introduces the alpha parameter, which can balance the weights of positive and negative samples in the loss function, so that the model pays more attention to minority categories during training, thereby improving the detection performance of these categories. Focal Loss introduces the gamma parameter, which reduces the weight of simple samples in the loss function, making the model pay more attention to samples that are difficult to classify, and improving the model's detection ability for difficult samples.
[0056] 3. In the present invention, the SENet attention mechanism recalibrates the weight of the feature map by learning the importance of each channel, so that the model can pay more attention to the features that are useful for target detection and suppress unimportant features, thereby improving the detection performance of the model. Through the attention mechanism, the model can better adapt to different scenarios and targets, and improve the generalization ability of the model, which is particularly important for drones to perform target detection in different environments and conditions. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a schematic diagram of the process principle of the present invention;
[0058] Figure 2 This is a structural diagram of the improved YOLOv5 model in the present invention. DETAILED DESCRIPTION
[0059] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0060] Reference Figure 1-2 ,
[0061] Example:
[0062] A method for detecting unmanned aerial vehicle targets based on an improved YOLOv5 algorithm, the method comprising the following steps:
[0063] S1: Perform data collection, using the camera carried by the drone to collect target images in different scenes and under different lighting conditions;
[0064] S2: Use labeling tools such as LabelImg to label the collected images and mark the category and location information of the target;
[0065] S3: Rotate, scale, flip and other operations are performed on the annotated images to expand the data set and improve the generalization ability of the model. The data set is then divided into training set, validation set and test set with a ratio of 7:2:1;
[0066] S4: Improve the YOLOv5 algorithm. The overall structure of the YOLOv5 algorithm includes the input end, the Backbone end, the Neck end, and the Prediction end.
[0067] S5: For the drone target detection task, we design the Focal Loss loss function and introduce the SENet attention mechanism to improve the model's ability to express the target;
[0068] S6: Use the pre-trained YOLOv5 model as the base model and load the pre-trained weights. Perform model training: Use the training set to train the model and set appropriate hyperparameters;
[0069] S7: Evaluate model performance on the validation set and adjust hyperparameters based on the validation results. Model optimization: Based on the validation results, tune the model, such as adjusting the network structure and loss function.
[0070] S8: Export the trained model into a format that can be used on the UAV platform;
[0071] S9: Deploy the model and deploy the exported model to the UAV platform to achieve real-time target detection, thus completing the entire UAV target detection process based on the improved YOLOv5 algorithm.
[0072] In step S1, the acquisition resolution is at least 1080p and the frame rate is not less than 30fps to ensure image clarity and dynamic capture capabilities. The acquisition scenes should cover different terrains such as cities, rural areas, mountains, and waters, as well as different lighting conditions such as sunny days, cloudy days, and nights to enhance the diversity of the data set.
[0073] In step S2, when using the LabelImg annotation tool to annotate the image, the accuracy of the annotation must be ensured. The specific method is: draw a bounding box for each target instance and mark its category label, such as people, vehicles, animals, etc. During the annotation process, the bounding box should be closely fitted to the target to avoid excessive background areas or missing target parts, while ensuring the consistency and accuracy of the annotation.
[0074] In step S3, during the data enhancement phase, the annotated images are rotated (0°, 90°, 180°, 270°), scaled (0.8 to 1.2 times), flipped (horizontally flipped, vertically flipped), and other operations are performed. In addition, random cropping, color jittering, and other methods can be used to further expand the data set. After completing the data enhancement, the data set is randomly divided in a ratio of 7:2:1 to ensure the independence and representativeness of the training, validation, and test data.
[0075] In step S4, the input end mainly consists of three parts: Mosaic image enhancement, adaptive anchor frame calculation, and adaptive image scaling. Mosaic data enhancement is to splice four pictures by random scaling, random cropping, and random arrangement, which can enrich the background and small target information of the detected object; the idea of the adaptive anchor frame is to automatically calculate the optimal anchor frame parameters of the input image by learning without manual setting, which can improve the accuracy and robustness of target detection; adaptive image scaling can keep the aspect ratio of the picture unchanged and scale it to a suitable size, which can retain the original information in the picture to a great extent and avoid information loss;
[0076] Adaptive anchor box calculation calculates anchor box parameters on feature maps of different scales to better adapt to targets of different sizes. The specific steps include:
[0077] S4-1. Feature map extraction. In the Backbone network, feature maps of multiple scales are extracted at different stages of the CSPNet structure. Assume that feature maps of three scales are extracted, which are denoted as F1, F2, and F3, respectively, corresponding to different resolutions of the original image.
[0078] S4-2. Anchor box parameter calculation: For each scale feature map, the anchor box parameters are calculated independently; the anchor box parameters usually include the width and height of the anchor box;
[0079] For the feature map Fi of the i-th scale, the calculation formula for the anchor box parameter ai is:
[0080] ai=Clustering(Fi,K), where Clustering is a K-means clustering algorithm used to find the optimal anchor box size, and K is the number of cluster centers, i.e., the number of anchor boxes;
[0081] S4-3. Multi-scale anchor box parameter fusion, design a fusion strategy to weightedly fuse anchor box parameters of different scales; the fusion formula is:
[0082] Let W1, W2, W3 be the weights of the three scales, A1, A2, A3 be the corresponding anchor box parameters, and the fused anchor box parameter A is:
[0083] A=W1·A1+W2·A2+W3·A3;
[0084] The weight Wi can be dynamically adjusted according to the size of the target and the resolution of the feature map, and the formula is:
[0085]
[0086] Where Si is the average object size of the i-th feature map, S target is the average size of the target, σ is a parameter that controls the smoothness of the weights;
[0087] S4-4. Bounding box regression during training, using the fused anchor box parameters for bounding box regression training; the bounding box regression loss formula is:
[0088]
[0089] Where N is the number of anchor boxes, b i is the ground-truth bounding box, is the predicted bounding box, CIOU is the complete IoU loss function;
[0090] S4-5. Object detection in the prediction stage,In the prediction stage, the fused anchor box parameters are used for object detection;
[0091] Through the above improvements in calculating anchor box parameters on feature maps of different scales, the drone target detection method improves the model's ability to detect targets of different scales, especially for small and large targets, and can achieve more accurate positioning. At the same time, the generalization ability of the model in complex scenes is enhanced, and it can better adapt to the diverse target distribution. The calculation process of the anchor box parameters is optimized, the workload of manually adjusting the anchor box parameters is reduced, and the degree of automation of the model is improved. Through the fusion of multi-scale anchor box parameters, the accuracy of the detection box is improved, and the overall performance of drone target detection is further improved.
[0092] The Backbone part is mainly used to extract image features. First, this part introduces the Focus structure, which periodically extracts pixels from the high-resolution image, and reconstructs the low-resolution image by channel splicing of the four sub-images to achieve downsampling and feature compression of the input feature map. Then, the CSP structure is introduced to convert the input feature map into Figure 1 After being divided into two, they are spliced and combined after cross-stage processing as the input of the next layer, which significantly reduces the parameters and calculation amount of the network, while improving the efficiency of feature extraction, thereby speeding up the training and reasoning of the model.
[0093] The Neck part further improves the feature extraction capability. Neck adopts the FPN+PAN structure, uses the FPN structure to transmit strong semantic features from top to bottom, uses the PAN module to build a feature pyramid structure, transmits strong positioning features from bottom to top, and realizes feature fusion between different layers.
[0094] The prediction information in the prediction part mainly consists of the bounding box location information, category, and confidence. The bounding box loss function uses the CIOU_Loss function, and the specific calculation formulas are as follows (1) to (4), which is mainly used to measure the difference between the predicted bounding box and the true bounding box. NMS non-maximum suppression is used to screen the predicted box.
[0095]
[0096] In step S5, the Focal Loss loss function adds two adjustable parameters based on the cross entropy loss: alpha (positive and negative sample balance coefficient) and gamma (difficult sample adjustment coefficient), and the calculation formula is:
[0097] FL(pt)=-αt(1-pt) γ log(pt);
[0098] Among them: pt is the model's predicted probability for each category. For the positive category, pt is the model's prediction that the target belongs to the positive category; for the negative category, pt is the model's prediction that the target belongs to the negative category.
[0099] αt is the positive and negative sample balance coefficient, which is used to adjust the weights of positive and negative samples in the loss function. For positive samples, αt = α; for negative samples, αt = 1-α.
[0100] γ is the difficult and easy sample adjustment coefficient, which is used to reduce the weight of simple samples so that the model pays more attention to difficult-to-classify samples.
[0101] (1-pt) γis the adjustment factor. When pt is close to 1, the adjustment factor is close to 0, reducing the loss contribution of simple samples; when pt is close to 0, the adjustment factor is close to 1, maintaining the loss contribution of difficult samples.
[0102] In step S5, the calculation steps of SENet include:
[0103] Squeeze operation: perform global average pooling on the feature map to compress the features of each channel and obtain a channel descriptor;
[0104] Excitation operation: The channel descriptor is learned through two fully connected layers to obtain the weight of each channel;
[0105] Reweight operation: The weights obtained by the Excitation operation are recalibrated channel by channel through multiplication.
[0106] In step S6, during the model training phase, the pre-trained YOLOv5 weights are used as the starting point, the initial learning rate is set to 0.01, and a learning rate decay strategy (such as StepLR, CosineAnnealingLR, etc.) is adopted according to the training progress. The training batch size is set to 16 or 32, adjusted according to the video memory capacity. The training cycle is determined according to the data set size and model convergence, usually between 100 and 300 epochs.
[0107] In step S7, when evaluating the model performance on the validation set, the indicators of interest include precision, recall, mean average precision (mAP), etc. Hyperparameters such as learning rate, batch size, data enhancement strategy, etc. are adjusted according to the validation results. During the model tuning process, it may be necessary to fine-tune the network structure, such as adding or reducing convolutional layers, adjusting the convolution kernel size, etc., and optimizing the loss function to improve model performance.
[0108] In step S8, during the model export phase, the trained model is converted into ONNX or TensorRT format to adapt to the computing resources of the drone platform. During the conversion process, the accuracy and inference speed of the model are balanced, and the model size and inference speed can be optimized by setting the accuracy threshold.
[0109] In step S9, during the model deployment phase, the exported model is integrated into the real-time target detection system on the drone platform. During deployment, issues such as model compatibility, power consumption, and heat dissipation need to be considered. After actual deployment, field tests are conducted to ensure that the model can run stably in different environments and conditions to achieve the goal of real-time detection. At the same time, field data is collected to provide a basis for further optimization of the model.
[0110] From the above, it can be seen that in the present invention, through the downsampling and feature compression of the Focus structure, not only the amount of calculation is reduced, but also the network's ability to capture image details is enhanced, which is particularly important for the detection of small targets. The use of the CSP structure reduces the parameters and amount of calculation of the network, improves the efficiency of feature extraction, and speeds up the training and reasoning speed of the model, which is very critical for drone target detection with high real-time requirements. At the same time, the FPN and PAN structures of the Neck part effectively integrate features of different scales and improve the network's ability to locate and identify targets. The FPN structure transmits strong semantic features from top to bottom, while the PAN structure transmits strong positioning features from bottom to top. The combination of the two enables the model to better handle targets of different scales and complexities. By learning the optimal anchor frame parameters of the input image, the adaptive anchor frame calculation improves the accuracy of the detection frame, allowing the model to locate the target more accurately. Using CIOU_Loss as the Bounding box loss function can more comprehensively measure the difference between the predicted frame and the real frame, thereby improving the detection accuracy.
[0111] In the present invention, the Focal Loss function introduces the alpha parameter, and Focal Loss can balance the weights of positive and negative samples in the loss function, so that the model pays more attention to minority categories during training, thereby improving the detection performance of these categories. Focal Loss introduces the gamma parameter, and Focal Loss reduces the weight of simple samples in the loss function, so that the model pays more attention to samples that are difficult to classify, and improves the model's detection ability for difficult samples.
[0112] In the present invention, the SENet attention mechanism recalibrates the weight of the feature map by learning the importance of each channel, so that the model can pay more attention to the features that are useful for target detection and suppress unimportant features, thereby improving the detection performance of the model. Through the attention mechanism, the model can better adapt to different scenarios and targets, and improve the generalization ability of the model, which is particularly important for drones to perform target detection in different environments and conditions.
[0113] In summary, step S4 improves the feature extraction efficiency and detection accuracy by improving the network structure of YOLOv5, while step S5 solves the classification imbalance problem by introducing Focal Loss and SENet attention mechanism, improves the detection ability of difficult samples, and enhances the model's attention and generalization ability to the target. These improvements jointly improve the overall performance of the drone target detection method, making it more suitable for practical application scenarios.
[0114] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0115] The above description enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A drone target detection method based on an improved YOLOv5 algorithm, characterized in that: The method comprises the following steps: S1: Perform data collection, using the camera carried by the drone to collect target images in different scenes and under different lighting conditions; S2: Use the LabelImg annotation tool to annotate the collected images and mark the category and location information of the target; S3: Rotate, scale, and flip the annotated images to expand the data set and improve the generalization ability of the model. The data set is then divided into training set, validation set, and test set in a ratio of 7:2:
1. S4: Improve the YOLOv5 algorithm. The overall structure of the YOLOv5 algorithm includes the input end, the Backbone end, the Neck end, and the Prediction end. S5: For the drone target detection task, the FocalLoss loss function is designed, and the SENet attention mechanism is introduced to improve the model's ability to express the target; S6: Use the pre-trained YOLOv5 model as the base model and load the pre-trained weights; perform model training: train the model using the training set and set appropriate hyperparameters; S7: Evaluate model performance on the validation set and adjust hyperparameters based on the validation results. Model optimization: Based on the validation results, tune the model, including adjusting the network structure and loss function. S8: Export the trained model into a format that can be used on the UAV platform; S9: Deploy the model and deploy the exported model to the UAV platform to achieve real-time target detection, thus completing the entire UAV target detection process based on the improved YOLOv5 algorithm.
2. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm according to claim 1, characterized in that: In step S1, the acquisition resolution is at least 1080p and the frame rate is not less than 30fps to ensure image clarity and dynamic capture capabilities; the acquisition scenes should cover different terrains such as cities, rural areas, mountains, and waters, as well as different lighting conditions such as sunny days, cloudy days, and nights to enhance the diversity of the data set.
3. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm as claimed in claim 1, characterized in that: In step S2, when using the LabelImg annotation tool to annotate the image, the accuracy of the annotation must be ensured; the specific method is: draw a bounding box for each target instance and mark its category label, including people, vehicles, and animals; during the annotation process, the bounding box should be closely fitted to the target to avoid excessive background areas or missing target parts, while ensuring the consistency and accuracy of the annotation.
4. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm as claimed in claim 1, characterized in that: In the step S3, during the data enhancement stage, the annotated images are rotated by 0°, 90°, 180°, 270°, scaled, and flipped; in addition, random cropping and color jittering methods are applied to further expand the data set; after completing the data enhancement, the data set is randomly divided in a ratio of 7:2:1 to ensure the independence and representativeness of the training, validation, and test data.
5. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm as claimed in claim 1, characterized in that: In step S4, the input end mainly consists of three parts: Mosaic image enhancement, adaptive anchor frame calculation, and adaptive image scaling; Adaptive anchor box calculation calculates anchor box parameters on feature maps of different scales to better adapt to targets of different sizes. The specific steps include: S4-1. Feature map extraction. In the Backbone network, feature maps of multiple scales are extracted at different stages of the CSPNet structure. Assume that feature maps of three scales are extracted, which are denoted as F1, F2, and F3, respectively, corresponding to different resolutions of the original image. S4-2. Anchor box parameter calculation: For each scale feature map, the anchor box parameters are calculated independently; the anchor box parameters usually include the width and height of the anchor box; For the feature map Fi of the i-th scale, the calculation formula for the anchor box parameter ai is: ai=Clustering(Fi,K), where Clustering is a K-means clustering algorithm used to find the optimal anchor box size, and K is the number of cluster centers, i.e., the number of anchor boxes; S4-3. Multi-scale anchor box parameter fusion, design a fusion strategy to weightedly fuse anchor box parameters of different scales; the fusion formula is: Let W1, W2, W3 be the weights of the three scales, A1, A2, A3 be the corresponding anchor box parameters, and the fused anchor box parameter A is: A=W1·A1+W2·A2+W3·A3; The weight Wi can be dynamically adjusted according to the size of the target and the resolution of the feature map, and the formula is: Where Si is the average object size of the i-th feature map, S target is the average size of the target, σ is a parameter that controls the smoothness of the weights; S4-4. Bounding box regression during training, using the fused anchor box parameters for bounding box regression training; the bounding box regression loss formula is: Where N is the number of anchor boxes, b i is the ground-truth bounding box, is the predicted bounding box, CIOU is the complete IoU loss function; S4-5. Object detection in the prediction stage,In the prediction stage, the fused anchor box parameters are used for object detection.
6. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm as claimed in claim 1, characterized in that: In step S5, the Focal Loss loss function adds two adjustable parameters: α and γ on the basis of the cross entropy loss, and the calculation formula is: FL(pt)=-αt(1-pt)γlog(pt); Among them: pt is the model's predicted probability for each category. For the positive category, pt is the model's prediction that the target belongs to the positive category; for the negative category, pt is the model's prediction that the target belongs to the negative category. αt is the positive and negative sample balance coefficient, which is used to adjust the weights of positive and negative samples in the loss function; for positive samples, αt = α; for negative samples, αt = 1-α; γ is the difficult and easy sample adjustment coefficient, which is used to reduce the weight of simple samples so that the model pays more attention to difficult-to-classify samples; (1-pt)γ is the adjustment factor. When pt is close to 1, the adjustment factor is close to 0, reducing the loss contribution of simple samples; when pt is close to 0, the adjustment factor is close to 1, maintaining the loss contribution of difficult samples.
7. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm as claimed in claim 1, characterized in that: In step S5, the calculation steps of SENet include: Squeeze operation: perform global average pooling on the feature map to compress the features of each channel and obtain a channel descriptor; Excitation operation: The channel descriptor is learned through two fully connected layers to obtain the weight of each channel; Reweight operation: The weights obtained by the Excitation operation are recalibrated channel by channel through multiplication.
8. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm as claimed in claim 1, characterized in that: In step S6, during the model training phase, the pre-trained YOLOv5 weights are used as the starting point, the initial learning rate is set to 0.01, and a learning rate decay strategy is adopted according to the training progress; The training batch size is set to 16 or 32, adjusted according to the video memory capacity; The training period is determined by the dataset size and model convergence, and is between 100 and 300 epochs.
9. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm as claimed in claim 1, characterized in that: In step S7, when evaluating the model performance on the validation set, the indicators of interest include accuracy, recall rate, and average precision; hyperparameters are adjusted according to the validation results, including learning rate, batch size, and data enhancement strategy; during the model tuning process, the network structure needs to be fine-tuned, including adding or reducing convolutional layers, adjusting the convolution kernel size, and optimizing the loss function.
10. The method for detecting unmanned aerial vehicle targets based on the improved YOLOv5 algorithm according to claim 1, characterized in that: In the step S8, during the model export phase, the trained model is converted into ONNX or TensorRT format to adapt to the computing resources of the drone platform; During the conversion process, ensure that the accuracy and inference speed of the model are balanced. You can optimize the model size and inference speed by setting the accuracy threshold. In step S9, during the model deployment phase, the exported model is integrated into the real-time target detection system on the UAV platform; during deployment, the compatibility, power consumption, and heat dissipation of the model need to be considered; after actual deployment, field testing is performed to ensure that the model can run stably in different environments and conditions to achieve the goal of real-time detection; and at the same time, field data is collected to provide a basis for further optimization of the model.
Citation Information
Cited By
Aerial target detection method based on image recognition
CN120635802A
Single-step multi-frame neural network detection model of unmanned aerial vehicle based on sample space depth parameter auxiliary training
CN120853048A
Unmanned aerial vehicle radio spectrum detection method and system based on difficult case mining
CN121418001A