A method and system for detecting a target of a UAV based on YOLOv12
By employing a YOLOv12-based UAV target detection method, a deformable cross-block sampling non-semantic sparse attention mechanism and a multi-scale global semantic attention mechanism are used for feature extraction and fusion. This solves the accuracy and generalization problems of UAV target detection in complex environments and achieves high-precision and robust target detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-17
- Publication Date
- 2026-04-14
AI Technical Summary
Existing UAV target detection methods struggle to meet practical requirements in complex application environments, especially from the UAV's perspective, where target scale varies greatly and backgrounds are complex.
We design a UAV target detection method based on YOLOv12. We use a deformable cross-block sampling non-semantic sparse attention mechanism for shallow small target feature extraction, combine it with a multi-scale global semantic attention mechanism for deep semantic feature extraction, and use a dynamic lightweight feature fusion mechanism for feature fusion to improve the model’s recognition accuracy and generalization ability for small targets.
It improves the accuracy and generalization ability of UAV target detection, enhances the feature extraction capability of small targets at multiple scales, improves recognition sensitivity and detection accuracy, and enhances the robustness of the model.
Smart Images

Figure CN121330561B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of target detection, and in particular to a method and system for UAV target detection based on YOLOv12. Background Technology
[0002] With the rapid development of the drone industry, drones have been widely used in many fields due to their advantages of flexibility, low cost, and ability to enter complex or dangerous areas, such as security monitoring and border patrol, agricultural and forestry plant protection, infrastructure inspection, disaster emergency response, smart logistics, and environmental protection. In these applications, efficient, accurate, and robust target detection capabilities are the core foundation and key challenge for drones to perform intelligent tasks. Real-time or rapid target detection information is crucial for drones to make autonomous decisions, plan tasks, and intervene precisely.
[0003] In existing technologies, traditional computer vision methods rely on manually designed features and then combine them with classic classifiers for target detection. The feature representation ability is limited, and the robustness to changes in target scale, rotation, occlusion, complex backgrounds, and lighting changes is poor. Especially from the perspective of UAVs, the target scale changes greatly and the background is complex, making it difficult for traditional methods to meet the actual requirements in terms of detection accuracy and generalization ability.
[0004] Therefore, it is important to design a target detection method for unmanned aerial vehicles (UAVs) that avoids interference from complex application environments in order to improve the accuracy and generalization ability of detection. Summary of the Invention
[0005] Based on this, the present invention proposes a UAV target detection method and system based on YOLOv12. It enhances the model's ability to extract features of small targets at multiple scales by designing a deformable cross-block sampling non-semantic sparse attention mechanism for shallow small target feature extraction, thereby improving the sensitivity and accuracy of small target recognition. Furthermore, it designs a multi-scale global semantic attention mechanism for deep semantic feature extraction, extracting semantic feature information at different levels and improving the model's generalization ability. Finally, it designs a dynamic lightweight feature fusion mechanism for feature fusion, which improves the network model's ability to capture the features of the target by adaptively processing features extracted from shallow and deep layers, further enhancing detection accuracy and robustness. The present invention improves the accuracy and generalization ability of UAV target detection.
[0006] This invention proposes a UAV target detection method based on YOLOv12, comprising:
[0007] Acquire UAV target detection data and preprocess it, then input the preprocessed UAV target detection data into the UAV target detection model, which includes a backbone network, a neck fusion network, and a detection head;
[0008] Shallow small target features are extracted based on a deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features. The deformable cross-block sampling non-semantic sparse attention mechanism is based on sparse sampling strategy and dynamic deformation perception.
[0009] Deep semantic features are extracted based on a multi-scale global semantic attention mechanism to obtain deep semantic features. The multi-scale global semantic attention mechanism is based on a multi-scale semantic extraction unit, a deformable semantic fusion unit, and a deep feature attention mechanism unit.
[0010] The dynamic lightweight feature fusion mechanism is used to fuse shallow small target features and deep semantic features to obtain fused features. The final target detection result is then obtained based on the fused features. The dynamic lightweight feature fusion mechanism is based on an adaptive feature fusion architecture, which includes multiple feature fusion blocks.
[0011] In summary, based on the aforementioned UAV target detection method using YOLOv12, this invention enhances the model's ability to extract features from shallow small targets by designing a deformable cross-block sampling non-semantic sparse attention mechanism. This improves the model's sensitivity and accuracy in identifying small targets. Furthermore, a multi-scale global semantic attention mechanism is designed for deep semantic feature extraction, extracting semantic feature information at different levels and enhancing the model's generalization ability. Finally, a dynamic lightweight feature fusion mechanism is designed for feature fusion, adaptively processing features extracted from shallow and deep layers to improve the network model's ability to capture the features of the target being detected, further enhancing detection accuracy and robustness. Therefore, this invention improves the accuracy and generalization ability of UAV target detection. Specifically, the process involves acquiring and preprocessing UAV target detection data, then inputting the preprocessed data into a UAV target detection model. This model comprises a backbone network, a neck fusion network, and a detection head. Shallow small target features are extracted using a deformable cross-block sampling non-semantic sparse attention mechanism. This deformable cross-block sampling non-semantic sparse attention mechanism, based on sparse sampling strategies and dynamic deformation perception, enhances the model's ability to extract multi-scale small target features, improving sensitivity and accuracy in small target recognition. Finally, deep semantic features are extracted using a multi-scale global semantic attention mechanism. Multi-scale semantic extraction unit, deformable semantic fusion unit, and deep feature attention mechanism unit extract semantic feature information at different levels, improving the model's generalization ability. A dynamic lightweight feature fusion mechanism is used to fuse shallow small target features and deep semantic features to obtain fused features. The final target detection result is then obtained based on these fused features. The dynamic lightweight feature fusion mechanism is based on an adaptive feature fusion architecture, which includes multiple feature fusion blocks. By adaptively processing the features extracted from shallow and deep layers, the network model's ability to capture the target features is improved, further enhancing detection accuracy and robustness. This invention improves the accuracy and generalization ability of UAV target detection.
[0012] Furthermore, the step of extracting shallow small target features based on the deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features specifically includes:
[0013] The deformable cross-block sampling non-semantic sparse attention mechanism is based on a feature projection unit, a channel attention weight generation unit, a sparse block unit, a deformable sampling unit, a shallow feature attention mechanism, and a feature reconstruction unit.
[0014] The feature projection unit includes multiple convolutional blocks. The channel dimension of the input feature map of the UAV target detection data is adjusted based on the feature projection unit. The specific algorithm for channel dimension adjustment is as follows:
[0015] ,
[0016] in, X This represents the input feature map of UAV target detection data. X’ This represents the output feature of the feature projection unit. Conv2d This represents the convolution operation. c1 Indicates the input feature channel. c2 Indicates the output feature channel. Identity Represents an identity mapping;
[0017] The channel attention weight generation unit includes a depthwise separable convolutional block, a global average pooling block, and a sigmoid activation function layer. Channel attention weights are generated by the channel attention weight generation unit, and the specific algorithm for generating the channel attention weights is as follows:
[0018] ,
[0019] in, f This represents the output of the channel attention weight generation unit. Sigmoid express Sigmoid Activation function DepthwiseSeparable This represents depthwise separable convolution. Avgpool Indicates global average pooling;
[0020] The sparse block unit divides the input feature map into multiple grid blocks according to the sparsity coefficients and calculates the center coordinates of each grid block. The specific algorithm of the sparse block unit is as follows:
[0021] ,
[0022] ,
[0023] ,
[0024] ,
[0025] in, H step Indicates the height step size of the grid block. W step Indicates the width step of the grid block. H and W The height and width of the input feature map are represented by s, and the sparsity coefficient is s, where block_coords is the number of sparse coefficients. y With block_coordsx The center represents the coordinates of the top-left corner of the grid block. y With center x Indicates the first i Line number j The center coordinates of the column grid blocks;
[0026] Offset prediction and mask prediction are performed based on deformable sampling units to obtain the predicted offset of sampling points and the predicted importance mask of sampling points;
[0027] Feature reconstruction is performed based on shallow feature attention mechanism and feature reconstruction unit to obtain shallow small target features.
[0028] Furthermore, the step of performing offset prediction and mask prediction based on deformable sampling units to obtain the predicted offset of sampling points and the predicted importance weight of sampling points specifically includes:
[0029] The deformable sampling unit includes an offset prediction branch and a mask prediction branch;
[0030] The offset prediction branch performs offset prediction and calculates the offset of each grid block. The specific algorithm for the offset is as follows:
[0031] ,
[0032] ,
[0033] in, block_features Represents grid block features, H step Indicates the height step size of the grid block. W step Indicates the width step of the grid block. block_mean This represents the average feature of the grid block. Indicates the sampling point offset. offset_conv Indicates the offset prediction operation;
[0034] The offset is added to the initial sampling grid block, and dynamic sampling points are obtained according to bilinear interpolation. The specific algorithm for obtaining dynamic sampling points is as follows:
[0035] ,
[0036] in, K The number of sampling points. k Indicates the sampling point ordinal number. P k base Sampling points representing a basic circular distribution;
[0037] The center position of the grid block is normalized and added to each sampling point to obtain the position information of the dynamic sampling point. The specific algorithm for obtaining the position information of the dynamic sampling point is as follows:
[0038] ,
[0039] Among them, P k Indicates the coordinates of the actual sampling point. block_centers Indicates the center position of the grid block;
[0040] The mask prediction branch obtains the predicted importance mask, and the specific algorithm for obtaining the predicted importance mask is as follows:
[0041] ,
[0042] Where M represents the predicted importance mask for the sampling points, mask_conv This indicates a mask prediction operation. This represents the Sigmoid activation function;
[0043] The predicted importance mask is weighted with the output features of the feature projection unit to obtain the output features of the deformable sampling unit. The specific algorithm for obtaining the output features of the deformable sampling unit is as follows:
[0044] ,
[0045] in, grid_sample This represents the bilinear interpolation operation. F s This represents the output characteristics of the deformable sampling unit. X’ This represents the output feature of the feature projection unit. P This represents the coordinates of all sampling points.
[0046] Furthermore, the step of performing feature reconstruction based on the shallow feature attention mechanism and feature reconstruction unit to obtain shallow small target features specifically includes:
[0047] The output features of the deformable sampling unit are concatenated, and attention enhancement processing is performed according to the shallow feature attention mechanism to obtain shallow attention-enhanced features. The specific algorithm for obtaining shallow attention-enhanced features is as follows:
[0048] ,
[0049] in, attn This indicates shallow attention enhancement features. MultiHeadAttention This indicates that the bulls are enhancing their own attention. F s This represents the output characteristics of the deformable sampling unit;
[0050] The feature reconstruction module weights the output of the channel attention weight generation unit with the shallow attention enhancement features to obtain shallow small target features. The specific algorithm for obtaining shallow small target features is as follows:
[0051] ,
[0052] in, This represents the features of shallow, small targets. This indicates element-wise multiplication.
[0053] Furthermore, the step of extracting deep semantic features based on a multi-scale global semantic attention mechanism to obtain deep semantic features specifically includes:
[0054] The multi-scale global semantic attention mechanism is based on a multi-scale semantic extraction unit, a deformable semantic fusion unit, and a deep feature attention mechanism unit.
[0055] The multi-scale semantic extraction unit includes an average pooling block, which extracts semantic information at the global scale, regional scale, and local scale, respectively. The specific algorithm for semantic information extraction is as follows:
[0056] ,
[0057] in, X This represents the input feature map of UAV target detection data. This represents the output features of the multi-scale semantic extraction unit. AdaptivePool Indicates adaptive average pooling. o =1, 2, and 3 represent semantic information extraction at the global, regional, and local scales, respectively.
[0058] The deformable semantic fusion unit includes deformable convolutional blocks that concatenate semantic information extracted from global, regional, and local scales. The specific concatenation algorithm is as follows:
[0059] ,
[0060] in, C This represents the output features of the concatenated multi-scale semantic extraction unit;
[0061] Offset prediction is performed based on the output features of the concatenated multi-scale semantic extraction unit to obtain the output features of the deformable semantic fusion unit. The specific algorithm for obtaining the output features of the deformable semantic fusion unit is as follows:
[0062] ,
[0063] ,
[0064] in, Conv This represents the convolution operation. W This represents the learnable offset prediction weight parameters. F w represents the output feature of the deformable semantic fusion unit. k This represents learnable convolutional weights. p k Indicates the coordinates of the actual sampling point. p k Indicates the coordinate position of the sampling point p First k Predicted offset of each sampling point K The number of sampling points. k Indicates the sampling point ordinal number. M A mask representing the predicted importance of sampling points;
[0065] Deep attention enhancement is performed based on the deep feature attention mechanism unit to obtain deep semantic features.
[0066] Furthermore, the step of performing deep attention enhancement based on the deep feature attention mechanism unit to obtain deep semantic features specifically includes:
[0067] The deep feature attention mechanism unit is based on channel attention and spatial attention mechanisms. The specific algorithm of the deep feature attention mechanism unit is as follows:
[0068] ,
[0069] ,
[0070] ,
[0071] in, Att channel This indicates the channel attention mechanism. Avgpool Indicates global average pooling. σ δ represents the Sigmoid activation function, and δ represents the ReLU activation function. Att spatial This represents the spatial attention mechanism. Conv This represents the convolution operation. f avg This represents the channel average. f max Indicates the maximum value of the channel. output It represents deep semantic features.
[0072] Furthermore, the step of fusing shallow small target features and deep semantic features according to the dynamic lightweight feature fusion mechanism to obtain fused features specifically includes:
[0073] Feature selection is performed on shallow, small target features, and the specific algorithm for feature selection is as follows:
[0074] ,
[0075] in, This indicates the selection of shallow features. This represents the features of shallow, small targets. express Sigmoid Activation function and This represents the shallow weight parameters. express Activation function Indicates global max pooling. Conv Indicates the convolution operation;
[0076] The deep semantic features are enhanced using the following specific algorithm:
[0077] ,
[0078] in, This indicates enhanced deep features. Represents deep semantic features. and Represents the deep weight parameters. Indicates global average pooling;
[0079] The shallow features and enhanced deep features are dynamically fused according to an adaptive weighting algorithm. The specific algorithm for dynamic fusion is as follows:
[0080] ,
[0081] in, Indicates fusion features, Indicates an upsampling operation. This represents a very small constant.
[0082] This invention proposes a UAV target detection system based on YOLOv12, comprising:
[0083] The preprocessing module is used to acquire UAV target detection data and preprocess it, and input the preprocessed UAV target detection data into the UAV target detection model, which includes a backbone network, a neck fusion network and a detection head.
[0084] The shallow feature extraction module is used to extract shallow small target features based on the deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features. The deformable cross-block sampling non-semantic sparse attention mechanism is based on sparse sampling strategy and dynamic deformation perception.
[0085] The deep feature extraction module is used to extract deep semantic features based on a multi-scale global semantic attention mechanism to obtain deep semantic features. The multi-scale global semantic attention mechanism is based on a multi-scale semantic extraction unit, a deformable semantic fusion unit, and a deep feature attention mechanism unit.
[0086] The fusion module is used to perform feature fusion on shallow small target features and deep semantic features according to a dynamic lightweight feature fusion mechanism to obtain fused features, and then obtain the final target detection result based on the fused features. The dynamic lightweight feature fusion mechanism is based on an adaptive feature fusion architecture, which includes multiple feature fusion blocks.
[0087] The present invention also provides a storage medium that stores one or more programs, which, when executed by a processor, implement the UAV target detection method based on YOLOv12 as described above.
[0088] The present invention also provides a computer device, the computer device including a memory and a processor, wherein:
[0089] The memory is used to store computer programs;
[0090] When the processor executes the computer program stored in the memory, it implements the UAV target detection method based on YOLOv12 as described above. Attached Figure Description
[0091] Figure 1 The flowchart shows the UAV target detection method based on YOLOv12 proposed in the first embodiment of the present invention.
[0092] Figure 2 This is a schematic diagram of the structure of the UAV target detection system based on YOLOv12 proposed in the second embodiment of the present invention;
[0093] Figure 3 This is a schematic diagram of the structure of the UAV target detection model of the present invention.
[0094] The following detailed description, in conjunction with the accompanying drawings, will further illustrate the present invention. Detailed Implementation
[0095] To facilitate understanding of the present invention, a more complete description will be given below with reference to the accompanying drawings. Several embodiments of the invention are illustrated in the drawings. However, the invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
[0096] It should be noted that when a component is said to be "fixed to" another component, it can be directly on the other component or there may be an intervening component. When a component is said to be "connected to" another component, it can be directly connected to the other component or there may be an intervening component. The terms "vertical," "horizontal," "left," "right," and similar expressions used in this document are for illustrative purposes only.
[0097] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0098] Please see Figure 1 The diagram shows a flowchart of the UAV target detection method based on YOLOv12 proposed in the first embodiment of the present invention. This UAV target detection method based on YOLOv12 includes steps S01 to S04, wherein:
[0099] Step S01: Acquire UAV target detection data and preprocess it, then input the preprocessed UAV target detection data into the UAV target detection model;
[0100] It should be noted that in this embodiment, the UAV target detection model includes a backbone network, a neck fusion network, and a detection head. For details, please refer to [link / reference needed]. Figure 3 .
[0101] Step S02: Extract shallow small target features based on deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features;
[0102] It should be noted that in this embodiment, the deformable cross-block sampling non-semantic sparse attention mechanism is based on sparse sampling strategy and dynamic deformation perception. The deformable cross-block sampling non-semantic sparse attention mechanism is based on feature projection unit, channel attention weight generation unit, sparse block unit, deformable sampling unit, shallow feature attention mechanism and feature reconstruction unit.
[0103] The feature projection unit includes multiple convolutional blocks. The channel dimension of the input feature map of the UAV target detection data is adjusted based on the feature projection unit. The specific algorithm for channel dimension adjustment is as follows:
[0104] ,
[0105] in, X This represents the input feature map of UAV target detection data. X’ This represents the output feature of the feature projection unit. Conv2d This represents the convolution operation. c1 Indicates the input feature channel. c2 Indicates the output feature channel. Identity Represents an identity mapping;
[0106] The channel attention weight generation unit includes a depthwise separable convolutional block, a global average pooling block, and a sigmoid activation function layer. Channel attention weights are generated by the channel attention weight generation unit, and the specific algorithm for generating the channel attention weights is as follows:
[0107] ,
[0108] in, f This represents the output of the channel attention weight generation unit. Sigmoid express Sigmoid Activation function DepthwiseSeparable This represents depthwise separable convolution. Avgpool Indicates global average pooling;
[0109] The sparse block unit divides the input feature map into multiple grid blocks according to the sparsity coefficients and calculates the center coordinates of each grid block. The specific algorithm of the sparse block unit is as follows:
[0110] ,
[0111] ,
[0112] ,
[0113] ,
[0114] in, H step Indicates the height step size of the grid block. W step Indicates the width step of the grid block. H and W The height and width of the input feature map are represented by s, and the sparsity coefficient is s, where block_coords is the number of sparse coefficients. y With block_coordsx The center represents the coordinates of the top-left corner of the grid block. y With center x Indicates the first i Line number j The center coordinates of the column grid blocks;
[0115] Offset prediction and mask prediction are performed based on deformable sampling units to obtain the predicted offset of sampling points and the predicted importance mask of sampling points;
[0116] Feature reconstruction is performed based on shallow feature attention mechanism and feature reconstruction unit to obtain shallow small target features.
[0117] The deformable sampling unit includes an offset prediction branch and a mask prediction branch;
[0118] The offset prediction branch performs offset prediction and calculates the offset of each grid block. The specific algorithm for the offset is as follows:
[0119] ,
[0120] ,
[0121] in, block_features Represents grid block features, H step Indicates the height step size of the grid block. W step Indicates the width step of the grid block. block_mean This represents the average feature of the grid block. Indicates the sampling point offset. offset_conv Indicates the offset prediction operation;
[0122] The offset is added to the initial sampling grid block, and dynamic sampling points are obtained according to bilinear interpolation. The specific algorithm for obtaining dynamic sampling points is as follows:
[0123] ,
[0124] in, K The number of sampling points. k Indicates the sampling point ordinal number. P k base Sampling points representing a basic circular distribution;
[0125] The center position of the grid block is normalized and added to each sampling point to obtain the position information of the dynamic sampling point. The specific algorithm for obtaining the position information of the dynamic sampling point is as follows:
[0126] ,
[0127] Among them, P k Indicates the coordinates of the actual sampling point. block_centers Indicates the center position of the grid block;
[0128] The mask prediction branch obtains the predicted importance mask, and the specific algorithm for obtaining the predicted importance mask is as follows:
[0129] ,
[0130] Where M represents the predicted importance mask for the sampling points, mask_conv This indicates a mask prediction operation. This represents the Sigmoid activation function;
[0131] The predicted importance mask is weighted with the output features of the feature projection unit to obtain the output features of the deformable sampling unit. The specific algorithm for obtaining the output features of the deformable sampling unit is as follows:
[0132] ,
[0133] in, grid_sample This represents the bilinear interpolation operation. F s This represents the output characteristics of the deformable sampling unit. X’ This represents the output feature of the feature projection unit. P This represents the coordinates of all sampling points.
[0134] The output features of the deformable sampling unit are concatenated, and attention enhancement processing is performed according to the shallow feature attention mechanism to obtain shallow attention-enhanced features. The specific algorithm for obtaining shallow attention-enhanced features is as follows:
[0135] ,
[0136] in, attn This indicates shallow attention enhancement features. MultiHeadAttention This indicates that the bulls are enhancing their own attention. F s This represents the output characteristics of the deformable sampling unit;
[0137] The feature reconstruction module weights the output of the channel attention weight generation unit with the shallow attention enhancement features to obtain shallow small target features. The specific algorithm for obtaining shallow small target features is as follows:
[0138] ,
[0139] in, This represents the features of shallow, small targets. This indicates element-wise multiplication.
[0140] Step S03: Extract deep semantic features based on the multi-scale global semantic attention mechanism to obtain deep semantic features;
[0141] It should be noted that in this embodiment, the multi-scale global semantic attention mechanism is based on a multi-scale semantic extraction unit, a deformable semantic fusion unit, and a deep feature attention mechanism unit.
[0142] The multi-scale semantic extraction unit includes an average pooling block, which extracts semantic information at the global scale, regional scale, and local scale, respectively. The specific algorithm for semantic information extraction is as follows:
[0143] ,
[0144] in, X This represents the input feature map of UAV target detection data. This represents the output features of the multi-scale semantic extraction unit. AdaptivePool Indicates adaptive average pooling. o =1, 2, and 3 represent semantic information extraction at the global, regional, and local scales, respectively.
[0145] The deformable semantic fusion unit includes deformable convolutional blocks that concatenate semantic information extracted from global, regional, and local scales. The specific concatenation algorithm is as follows:
[0146] ,
[0147] in, C This represents the output features of the concatenated multi-scale semantic extraction unit;
[0148] Offset prediction is performed based on the output features of the concatenated multi-scale semantic extraction unit to obtain the output features of the deformable semantic fusion unit. The specific algorithm for obtaining the output features of the deformable semantic fusion unit is as follows:
[0149] ,
[0150] ,
[0151] in, Conv This represents the convolution operation. W This represents the learnable offset prediction weight parameters. F w represents the output feature of the deformable semantic fusion unit. kThis represents learnable convolutional weights. p k Indicates the coordinates of the actual sampling point. p k Indicates the coordinate position of the sampling point p First k Predicted offset of each sampling point K The number of sampling points. k Indicates the sampling point ordinal number. M A mask representing the predicted importance of sampling points;
[0152] Deep attention enhancement is performed based on the deep feature attention mechanism unit to obtain deep semantic features.
[0153] The deep feature attention mechanism unit is based on channel attention and spatial attention mechanisms. The specific algorithm of the deep feature attention mechanism unit is as follows:
[0154] ,
[0155] ,
[0156] ,
[0157] in, Att channel This indicates the channel attention mechanism. Avgpool Indicates global average pooling. σ δ represents the Sigmoid activation function, and δ represents the ReLU activation function. Att spatial This represents the spatial attention mechanism. Conv This represents the convolution operation. f avg This represents the channel average. f max Indicates the maximum value of the channel. output It represents deep semantic features.
[0158] Step S04: Perform feature fusion on shallow small target features and deep semantic features according to the dynamic lightweight feature fusion mechanism to obtain fused features, and then obtain the final target detection result based on the fused features;
[0159] It should be noted that in this embodiment, the dynamic lightweight feature fusion mechanism is based on an adaptive feature fusion architecture, which includes multiple feature fusion blocks for feature selection of shallow small target features. The specific algorithm for feature selection is as follows:
[0160] ,
[0161] in, This indicates the selection of shallow features. This represents the features of shallow, small targets. express Sigmoid Activation function and This represents the shallow weight parameters. express Activation function Indicates global max pooling. Conv Indicates the convolution operation;
[0162] The deep semantic features are enhanced using the following specific algorithm:
[0163] ,
[0164] in, This indicates enhanced deep features. Represents deep semantic features. and Represents the deep weight parameters. Indicates global average pooling;
[0165] The shallow features and enhanced deep features are dynamically fused according to an adaptive weighting algorithm. The specific algorithm for dynamic fusion is as follows:
[0166] ,
[0167] in, Indicates fusion characteristics, Indicates an upsampling operation. This represents a very small constant.
[0168] In summary, based on the aforementioned UAV target detection method using YOLOv12, this invention enhances the model's ability to extract features from shallow small targets by designing a deformable cross-block sampling non-semantic sparse attention mechanism. This improves the model's sensitivity and accuracy in identifying small targets. Furthermore, a multi-scale global semantic attention mechanism is designed for deep semantic feature extraction, extracting semantic feature information at different levels and enhancing the model's generalization ability. Finally, a dynamic lightweight feature fusion mechanism is designed for feature fusion, adaptively processing features extracted from shallow and deep layers to improve the network model's ability to capture the features of the target being detected, further enhancing detection accuracy and robustness. Therefore, this invention improves the accuracy and generalization ability of UAV target detection. Specifically, the process involves acquiring and preprocessing UAV target detection data, then inputting the preprocessed data into a UAV target detection model. This model comprises a backbone network, a neck fusion network, and a detection head. Shallow small target features are extracted using a deformable cross-block sampling non-semantic sparse attention mechanism. This deformable cross-block sampling non-semantic sparse attention mechanism, based on sparse sampling strategies and dynamic deformation perception, enhances the model's ability to extract multi-scale small target features, improving sensitivity and accuracy in small target recognition. Finally, deep semantic features are extracted using a multi-scale global semantic attention mechanism. Multi-scale semantic extraction unit, deformable semantic fusion unit, and deep feature attention mechanism unit extract semantic feature information at different levels, improving the model's generalization ability. A dynamic lightweight feature fusion mechanism is used to fuse shallow small target features and deep semantic features to obtain fused features. The final target detection result is then obtained based on these fused features. The dynamic lightweight feature fusion mechanism is based on an adaptive feature fusion architecture, which includes multiple feature fusion blocks. By adaptively processing the features extracted from shallow and deep layers, the network model's ability to capture the target features is improved, further enhancing detection accuracy and robustness. This invention improves the accuracy and generalization ability of UAV target detection.
[0169] Please see Figure 2 The diagram shows a schematic representation of a UAV target detection system based on YOLOv12 proposed in the second embodiment of the present invention. The system includes:
[0170] Preprocessing module 10 is used to acquire UAV target detection data and preprocess it, and input the preprocessed UAV target detection data into the UAV target detection model, which includes a backbone network, a neck fusion network and a detection head;
[0171] The shallow feature extraction module 20 is used to extract shallow small target features according to the deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features. The deformable cross-block sampling non-semantic sparse attention mechanism is based on sparse sampling strategy and dynamic deformation perception.
[0172] The deep feature extraction module 30 is used to extract deep semantic features according to the multi-scale global semantic attention mechanism to obtain deep semantic features. The multi-scale global semantic attention mechanism is based on the multi-scale semantic extraction unit, the deformable semantic fusion unit and the deep feature attention mechanism unit.
[0173] The fusion module 40 is used to perform feature fusion on shallow small target features and deep semantic features according to the dynamic lightweight feature fusion mechanism to obtain fused features, and then obtain the final target detection result according to the fused features. The dynamic lightweight feature fusion mechanism is based on an adaptive feature fusion architecture, which includes multiple feature fusion blocks.
[0174] The present invention also proposes a computer storage medium storing one or more programs that, when executed by a processor, implement the aforementioned UAV target detection method based on YOLOv12.
[0175] The present invention also proposes a computer device, including a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to implement the above-mentioned UAV target detection method based on YOLOv12.
[0176] Those skilled in the art will understand that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can mean any means that can contain stored, communicated, propagated, or transmitted programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0177] More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which the program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0178] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0179] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0180] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention. Therefore, the scope of protection of this patent should be determined by the appended claims.
Claims
1. A UAV target detection method based on YOLOv12, characterized in that, include: Acquire UAV target detection data and preprocess it, then input the preprocessed UAV target detection data into the UAV target detection model, which includes a backbone network, a neck fusion network, and a detection head; Shallow small target features are extracted based on a deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features. The deformable cross-block sampling non-semantic sparse attention mechanism is based on sparse sampling strategy and dynamic deformation perception. The step of extracting shallow small target features based on the deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features specifically includes: The deformable cross-block sampling non-semantic sparse attention mechanism is based on a feature projection unit, a channel attention weight generation unit, a sparse block unit, a deformable sampling unit, a shallow feature attention mechanism, and a feature reconstruction unit. The feature projection unit includes multiple convolutional blocks. The channel dimension of the input feature map of the UAV target detection data is adjusted based on the feature projection unit. The specific algorithm for channel dimension adjustment is as follows: , in, X This represents the input feature map of UAV target detection data. X’ This represents the output feature of the feature projection unit. Conv2d This represents the convolution operation. c1 Indicates the input feature channel. c2 Indicates the output feature channel. Identity Represents an identity mapping; The channel attention weight generation unit includes a depthwise separable convolutional block, a global average pooling block, and a sigmoid activation function layer. Channel attention weights are generated by the channel attention weight generation unit, and the specific algorithm for generating the channel attention weights is as follows: , in, f This represents the output of the channel attention weight generation unit. Sigmoid express Sigmoid Activation function DepthwiseSeparable This represents depthwise separable convolution. Avgpool Indicates global average pooling; The sparse block unit divides the input feature map into multiple grid blocks according to the sparsity coefficients and calculates the center coordinates of each grid block. The specific algorithm of the sparse block unit is as follows: , , , , in, H step Indicates the height step size of the grid block. W step Indicates the width step of the grid block. H and W The height and width of the input feature map are represented by s, and the sparsity coefficients are represented by block_cooeds. y With block_cooeds x The center represents the coordinates of the top-left corner of the grid block. y With center x Indicates the first i Line number j The center coordinates of the column grid blocks; Offset prediction and mask prediction are performed based on deformable sampling units to obtain the predicted offset of sampling points and the predicted importance mask of sampling points; Feature reconstruction is performed based on shallow feature attention mechanism and feature reconstruction unit to obtain shallow small target features; Deep semantic features are extracted based on a multi-scale global semantic attention mechanism to obtain deep semantic features. The multi-scale global semantic attention mechanism is based on a multi-scale semantic extraction unit, a deformable semantic fusion unit, and a deep feature attention mechanism unit. The dynamic lightweight feature fusion mechanism is used to fuse shallow small target features and deep semantic features to obtain fused features. The final target detection result is then obtained based on the fused features. The dynamic lightweight feature fusion mechanism is based on an adaptive feature fusion architecture, which includes multiple feature fusion blocks.
2. The UAV target detection method based on YOLOv12 according to claim 1, characterized in that, The step of performing offset prediction and mask prediction based on deformable sampling units to obtain the predicted offset of sampling points and the predicted importance weight of sampling points specifically includes: The deformable sampling unit includes an offset prediction branch and a mask prediction branch; The offset prediction branch performs offset prediction and calculates the offset of each grid block. The specific algorithm for the offset is as follows: , , in, block_features Represents grid block features, H step Indicates the height step size of the grid block. W step Indicates the width step of the grid block. block_mean This represents the average feature of the grid block. Indicates the sampling point offset. offset_conv Indicates the offset prediction operation; The offset is added to the initial sampling grid block, and dynamic sampling points are obtained according to bilinear interpolation. The specific algorithm for obtaining dynamic sampling points is as follows: , in, K The number of sampling points. k Indicates the sampling point ordinal number. P k base Sampling points representing a basic circular distribution; The center position of the grid block is normalized and added to each sampling point to obtain the position information of the dynamic sampling point. The specific algorithm for obtaining the position information of the dynamic sampling point is as follows: , Among them, P k Indicates the coordinates of the actual sampling point. block_centers Indicates the center position of the grid block; The mask prediction branch obtains the predicted importance mask, and the specific algorithm for obtaining the predicted importance mask is as follows: , Where M represents the predicted importance mask for the sampling points, mask_conv This indicates a mask prediction operation. This represents the Sigmoid activation function; The predicted importance mask is weighted with the output features of the feature projection unit to obtain the output features of the deformable sampling unit. The specific algorithm for obtaining the output features of the deformable sampling unit is as follows: , in, grid_sample This represents the bilinear interpolation operation. F s This represents the output characteristics of the deformable sampling unit. X’ This represents the output feature of the feature projection unit. P This represents the coordinates of all sampling points.
3. The UAV target detection method based on YOLOv12 according to claim 1, characterized in that, The step of performing feature reconstruction based on the shallow feature attention mechanism and feature reconstruction unit to obtain shallow small target features specifically includes: The output features of the deformable sampling unit are concatenated, and attention enhancement processing is performed according to the shallow feature attention mechanism to obtain shallow attention-enhanced features. The specific algorithm for obtaining shallow attention-enhanced features is as follows: , in, attn This indicates shallow attention enhancement features. MultiHeadAttention This indicates that the bulls are enhancing their own attention. F s This represents the output characteristics of the deformable sampling unit; The feature reconstruction module weights the output of the channel attention weight generation unit with the shallow attention enhancement features to obtain shallow small target features. The specific algorithm for obtaining shallow small target features is as follows: , in, This represents the features of shallow, small targets. This indicates element-wise multiplication.
4. The UAV target detection method based on YOLOv12 according to claim 1, characterized in that, The step of extracting deep semantic features based on a multi-scale global semantic attention mechanism to obtain deep semantic features specifically includes: The multi-scale global semantic attention mechanism is based on a multi-scale semantic extraction unit, a deformable semantic fusion unit, and a deep feature attention mechanism unit. The multi-scale semantic extraction unit includes an average pooling block, which extracts semantic information at the global scale, regional scale, and local scale, respectively. The specific algorithm for semantic information extraction is as follows: , in, X This represents the input feature map of UAV target detection data. This represents the output features of the multi-scale semantic extraction unit. AdaptivePool Indicates adaptive average pooling. o =1, 2, and 3 represent semantic information extraction at the global, regional, and local scales, respectively. The deformable semantic fusion unit includes deformable convolutional blocks that concatenate semantic information extracted from global, regional, and local scales. The specific concatenation algorithm is as follows: , in, C This represents the output features of the concatenated multi-scale semantic extraction unit; Offset prediction is performed based on the output features of the concatenated multi-scale semantic extraction unit to obtain the output features of the deformable semantic fusion unit. The specific algorithm for obtaining the output features of the deformable semantic fusion unit is as follows: , , in, Conv This represents the convolution operation. W This represents the learnable offset prediction weight parameters. F w represents the output feature of the deformable semantic fusion unit. k This represents learnable convolutional weights. p k Indicates the coordinates of the actual sampling point. p k Indicates the coordinate position of the sampling point p First k Predicted offset of each sampling point K The number of sampling points. k Indicates the sampling point ordinal number. M A mask representing the predicted importance of sampling points; Deep attention enhancement is performed based on the deep feature attention mechanism unit to obtain deep semantic features.
5. The UAV target detection method based on YOLOv12 according to claim 4, characterized in that, The step of performing deep attention enhancement based on the deep feature attention mechanism unit to obtain deep semantic features specifically includes: The deep feature attention mechanism unit is based on channel attention and spatial attention mechanisms. The specific algorithm of the deep feature attention mechanism unit is as follows: , , , in, Att channel This indicates the channel attention mechanism. Avgpool Indicates global average pooling. σ δ represents the Sigmoid activation function, and δ represents the ReLU activation function. Att spatial This represents the spatial attention mechanism. Conv This represents the convolution operation. f avg This represents the channel average. f max Indicates the maximum value of the channel. output It represents deep semantic features.
6. The UAV target detection method based on YOLOv12 according to claim 1, characterized in that, The step of fusing shallow small target features and deep semantic features according to the dynamic lightweight feature fusion mechanism to obtain fused features specifically includes: Feature selection is performed on shallow, small target features, and the specific algorithm for feature selection is as follows: , in, This indicates the selection of shallow features. This represents the features of shallow, small targets. express Sigmoid Activation function and This represents the shallow weight parameters. express Activation function Indicates global max pooling. Conv Indicates the convolution operation; The deep semantic features are enhanced using the following specific algorithm: , in, This indicates enhanced deep features. Represents deep semantic features. and Represents the deep weight parameters. Indicates global average pooling; The shallow features and enhanced deep features are dynamically fused according to an adaptive weighting algorithm. The specific algorithm for dynamic fusion is as follows: , in, Indicates fusion features, Indicates an upsampling operation. This represents a very small constant.
7. A UAV target detection system based on YOLOv12, characterized in that, include: The preprocessing module is used to acquire UAV target detection data and preprocess it, and input the preprocessed UAV target detection data into the UAV target detection model, which includes a backbone network, a neck fusion network and a detection head. The shallow feature extraction module is used to extract shallow small target features based on the deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features. The deformable cross-block sampling non-semantic sparse attention mechanism is based on sparse sampling strategy and dynamic deformation perception. The step of extracting shallow small target features based on the deformable cross-block sampling non-semantic sparse attention mechanism to obtain shallow small target features specifically includes: The deformable cross-block sampling non-semantic sparse attention mechanism is based on a feature projection unit, a channel attention weight generation unit, a sparse block unit, a deformable sampling unit, a shallow feature attention mechanism, and a feature reconstruction unit. The feature projection unit includes multiple convolutional blocks. The channel dimension of the input feature map of the UAV target detection data is adjusted based on the feature projection unit. The specific algorithm for channel dimension adjustment is as follows: , in, X This represents the input feature map of UAV target detection data. X’ This represents the output feature of the feature projection unit. Conv2d This represents the convolution operation. c1 Indicates the input feature channel. c2 Indicates the output feature channel. Identity Represents an identity mapping; The channel attention weight generation unit includes a depthwise separable convolutional block, a global average pooling block, and a sigmoid activation function layer. Channel attention weights are generated by the channel attention weight generation unit, and the specific algorithm for generating the channel attention weights is as follows: , in, f This represents the output of the channel attention weight generation unit. Sigmoid express Sigmoid Activation function DepthwiseSeparable This represents depthwise separable convolution. Avgpool Indicates global average pooling; The sparse block unit divides the input feature map into multiple grid blocks according to the sparsity coefficients and calculates the center coordinates of each grid block. The specific algorithm of the sparse block unit is as follows: , , , , in, H step Indicates the height step size of the grid block. W step Indicates the width step of the grid block. H and W The height and width of the input feature map are represented by s, and the sparsity coefficients are represented by block_cooeds. y With block_cooeds x The center represents the coordinates of the top-left corner of the grid block. y With center x Indicates the first i Line number j The center coordinates of the column grid blocks; Offset prediction and mask prediction are performed based on deformable sampling units to obtain the predicted offset of sampling points and the predicted importance mask of sampling points; Feature reconstruction is performed based on shallow feature attention mechanism and feature reconstruction unit to obtain shallow small target features; The deep feature extraction module is used to extract deep semantic features based on a multi-scale global semantic attention mechanism to obtain deep semantic features. The multi-scale global semantic attention mechanism is based on a multi-scale semantic extraction unit, a deformable semantic fusion unit, and a deep feature attention mechanism unit. The fusion module is used to perform feature fusion on shallow small target features and deep semantic features according to a dynamic lightweight feature fusion mechanism to obtain fused features, and then obtain the final target detection result based on the fused features. The dynamic lightweight feature fusion mechanism is based on an adaptive feature fusion architecture, which includes multiple feature fusion blocks.
8. A storage medium, characterized in that, The storage medium stores one or more programs that, when executed by a processor, implement the UAV target detection method based on YOLOv12 as described in any one of claims 1-6.
9. A computer device, characterized in that, The computer device includes a memory and a processor, wherein: The memory is used to store computer programs; When the processor executes the computer program stored in the memory, it implements the UAV target detection method based on YOLOv12 as described in any one of claims 1-6.
Citation Information
Patent Citations
Small target detection method, system and device based on multilayer interactive attention feature fusion mechanism and medium
CN117953203A
DST-YOLO-based unmanned aerial vehicle aerial photography small target detection method
CN119992049A