Small target detection method for UAV aerial photography based on improved RT-DETR network
By improving the RT-DETR network and using partial convolution, deformable attention module and Wise-IoU loss function, the problem of low detection accuracy of small targets in UAV aerial photography scenes is solved, and more efficient detection results and robustness are achieved. .
Patent Information
- Application Number
- CN202410988027.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-07-23
AI Technical Summary
Small target detection in UAV aerial photography scenes has problems such as complex backgrounds, occlusions, background semantic information interference, and lighting changes, which results in low detection accuracy of existing algorithms in complex environments. In particular, YOLO performs poorly when dealing with complex backgrounds. .
The RT-DETR network is improved by introducing a partial convolution structure and a re-parameterization module to reduce the amount of model parameters and calculations. At the same time, a deformable attention module and a p2 detection head are introduced, combined with the Wise-IoU loss function, to enhance the model's accuracy on small targets. Detection capabilities and robustness.
It improves the accuracy and robustness of small target detection, reduces the number of parameters and calculations of the model, and can handle small targets more effectively in complex environments, improving the accuracy and generalization ability of detection results.
Smart Images

Figure CN118521929B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and to technologies such as target detection, deep learning and image recognition, and is specifically manifested in a method for detecting small targets in drone aerial photography based on an improved RT-DETR network. Background Art
[0002] With the rapid development of drone technology, drone aerial photography has become an important means of obtaining high-resolution, large-scale surface image data. Compared with traditional aerial photography, drone aerial photography has the advantages of high flexibility, low cost, and fast response speed. Therefore, it has been widely used in disaster monitoring, urban planning and other fields. Target detection technology can automatically identify and locate targets in images. This technology can enhance the perception function of drones and provide basic technical support for their autonomous detection and flight. At present, target detection algorithms based on deep learning have made significant progress in the field of image recognition. For example, algorithms such as Faster R-CNN, YOLO, SSD, and RT-DETR can effectively cope with the challenges of small target detection, and combined with drone aerial photography technology, it can achieve efficient monitoring and identification of large areas.
[0003] However, drone aerial photography generally has the characteristics of complex backgrounds because the imaging perspective is different from that of natural scene images. Due to the large scale changes in drone images and the much higher proportion of small targets than natural scene images, challenges such as occlusion under complex backgrounds and interference of background semantic information are more common. In addition, the influence of factors such as lighting and shadows makes the detection of small targets more complicated. Existing technologies such as YOLO, although its real-time performance is high, its processing ability for complex backgrounds is weak, and YOLO's detection is based on a fixed grid size, which leads to low detection accuracy for small targets. Therefore, drone aerial photography scenes may face various complex environmental conditions, such as different lighting, weather, terrain, etc., so the algorithm needs to have a certain degree of environmental adaptability to ensure the accuracy and robustness of detection. Summary of the invention
[0004] In view of the above problems in the prior art, the present invention proposes a small target detection method for UAV aerial photography based on an improved RT-DETR network, which reduces the number of parameters and calculation amount of the model, and can better capture the structural information and semantic features in the image, thereby improving the sensitivity to small targets and obtaining better detection results.
[0005] In order to solve the above technical problems, the technical solution of the present invention is:
[0006] A method for detecting small targets in UAV aerial photography based on an improved RT-DETR network includes the following steps:
[0007] Preprocessing of S1 dataset:
[0008] This paper uses the public visdrone2019 dataset, which is a dataset of small targets taken by drones. However, the format cannot be used directly by RT-DETR and a large number of images do not have the required annotations or labels other than the specified categories. Therefore, the dataset needs to be formatted before the experiment to form a dataset that meets the requirements of the network model.
[0009] S2 configures the training environment:
[0010] The environment is built according to the environment required by the model and the basic hardware conditions. The present invention sets the size of the input image to 640×640, the number of training rounds to 300, and the category of the detection object to 10.
[0011] S3 improves the backbone network:
[0012] The conventional convolution in the original backbone network Resnet-r18 is replaced with a partial convolution structure, which will greatly reduce the number of parameters and computation of the model. The partial convolution utilizes the redundancy of the feature map, reduces the number of memory accesses, and makes fuller use of the computing power of the device. Then the conventional convolution part in the partial convolution network structure is replaced with a re-parameterized structure. By improving the convolution operation and feature representation, the performance and efficiency of the convolutional neural network in the model are improved, ensuring that the accuracy of the model is not reduced while reducing the number of parameters and computation.
[0013] S4 introduces a deformable attention structure in the efficient hybrid encoder:
[0014] The AIFI module of the efficient hybrid encoder in the original model RT-DETR is replaced with a deformable attention module, which introduces local modeling in the attention mechanism, allowing the model to pay more attention to the local area related to the current position in the input sequence, while more flexibly adapting to the spatial relationship and occlusion between objects. The output of the backbone network stage 5 in S3 is used as the input of the deformable attention module, so that the model can better extract the network layer with the richest semantic information.
[0015] The CCFM module of the S5 high-efficiency hybrid encoder introduces the p2 detection head:
[0016] The output of the deformable attention module in S4 and the output of other layers of the backbone network are used as the input part of the CCFM module. Here, the present invention introduces the p2 detection head to obtain the CCFM-p2 module, that is, the stage2 in the backbone network is also input into the CCFM-p2 module, which can provide the model with a higher resolution feature map, thereby better handling the detection of small targets in complex environments.
[0017] Wise-IoU is introduced in S6 model training:
[0018] The output of the efficient hybrid encoder in S5 is first subjected to the IoU-aware classification loss function to obtain a more suitable initialization anchor point, so that suitable object queries can be better screened out for the input part of the detection head. Then, the learnable content query and the position query with selected features are used as the input of the detection head. The present invention introduces Wise-IoU, which has a better effect on small target detection, as the bounding box regression loss. Wise-IoU combines the geometric information of IoU and the optimization target of the loss function to better guide the model to optimize the position and shape of the bounding prediction box.
[0019] S7 analysis experimental results:
[0020] After the model is trained, it will generate a corresponding weight file, and then import these trained weights, as well as the images to be tested and the corresponding labels. After running the program, we can get the tested data and images, and then we will compare whether the recognition effect and detection accuracy meet our expected requirements.
[0021] Preferably, the backbone network Resnet-r18 includes four layers of benchmark modules, namely stage2, stage3, stage4 and stage5, each of which includes two convolutional layers, and the second 3×3 convolution in each of the benchmark modules is replaced with a partial convolution re-parameter module.
[0022] The present invention has the following characteristics and beneficial effects:
[0023] By adopting the above technical solution, in order to reduce the number of parameters and the amount of calculation of the model, the present invention introduces partial convolution in Backbone, which reduces redundant calculations and memory access times and can more effectively extract spatial features; while reducing the number of parameters and the amount of calculation, the present invention does not reduce the accuracy of the model. The re-parameterization structure is introduced in the partial convolution, which is mainly due to the reusability of its feature representation, thereby accelerating the training and reasoning process of the model. At the same time, through the re-parameterization mechanism, the utilization efficiency of parameters and the generalization ability of the network are improved;
[0024] In order to enhance the local modeling capability of the model and improve the model's ability to process small targets, the present invention introduces a deformable attention module to replace the AIFI module in the neck network. The deformable attention module can improve the performance of the model when processing small targets. By introducing deformable convolution, the problem of small targets being interfered with by invalid features in complex backgrounds can be solved, thereby improving the accuracy and robustness of feature extraction.
[0025] In order to further improve the accuracy of small target detection, the present invention introduces a p2 detection head in the CCFM module in the neck network, extracts multi-scale feature representations from the input image through the backbone network, and provides a higher resolution feature map for the model; and introduces the Wise-IoU loss function in the model training to better optimize the network and improve the detection accuracy of small targets. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0027] Figure 1 This is an overall model structure diagram of an embodiment of the method for detecting small targets in drone aerial photography based on an improved RT-DETR network of the present invention.
[0028] Figure 2 for Figure 1 Diagram of the backbone network structure.
[0029] Figure 3 for Figure 1 Part of the convolution re-parameter module structure diagram.
[0030] Figure 4 for Figure 1 Diagram of the deformable attention module structure.
[0031] Figure 5 The figure is a comparison chart of the detection effect of the embodiment of the present invention and the existing case. DETAILED DESCRIPTION
[0032] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0033] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings.
[0034] On the contrary, the present invention covers any substitution, modification, equivalent method and scheme made on the essence and scope of the present invention as defined by the claims. Further, in order to make the public have a better understanding of the present invention, some specific details are described in detail in the detailed description of the present invention below. Those skilled in the art can fully understand the present invention without the description of these details.
[0035] Example 1
[0036] The present invention provides a method for detecting small targets in UAV aerial photography based on an improved RT-DETR network. Figure 1 As shown, the following steps are included:
[0037] Step 1: Obtain and preprocess the public dataset.
[0038] Specifically, in this embodiment, the first step is to obtain a drone aerial photography dataset, and the present invention uses the visdrone2019 dataset. Visdrone2019 contains 288 video clips, consisting of 261,908 frames and 10,209 static images, captured by various drone cameras, covering a wide range, including location (from 14 different cities in China thousands of kilometers apart), environment (urban and rural), objects (pedestrians, vehicles, bicycles, etc.) and density (sparse and crowded scenes). The dataset contains 10 categories of targets, consisting of 6,471 training sets, 548 validation sets, and 1,610 test set images.
[0039] Step 2, construct a small target detection model, which is based on the RT-DETR network. The RT-DETR network includes a backbone network and an efficient hybrid encoder. The conventional convolution in the backbone network Resnet-r18 is replaced by a partial convolution re-parameter module; the AIFI module in the efficient hybrid encoder is replaced by a deformable attention module; the p2 detection head is introduced into the CCFM module of the efficient hybrid encoder to obtain the CCFM-p2 module; Wise-IoU is used as the regression loss function of the difference between the model output prediction value and the true label.
[0040] Step 3: Configure the training environment and use the preprocessed dataset as input to train the small object detection model.
[0041] Specifically, after processing the data set, the data_yaml file of the data set is created, the paths of the training set and the validation set and the category of the visdrone2019 data set are written in data_yaml, and then the parameters such as the number of training times and batch-size under default.yaml are modified according to the requirements of the invention. The environment of the present invention is: cuda12.2, deep learning framework pytorch1.12.1, Intel core i9-13900ks CPU, 128G memory, GPU is NVIDIA GeForce RTX4090, and the video memory is 24G.
[0042] During training, the training coefficient set in the present invention is 300 rounds, and 4 pictures are input for each training. During the training process, the training process is observed in real time through wandb. After the training is completed, the trained weights are saved.
[0043] Step 4: Apply the trained small target detection model, take the target image to be detected as input and output the detection result.
[0044] Specifically, replace the conventional convolution in the backbone network Resnet-r18 with some convolution re-parameter modules:
[0045] In this embodiment, the conventional convolution in the reference module of the original backbone network of the RT-DETR network is replaced with partial convolution. Figure 2 and attached Figure 3 To illustrate, the original backbone network is PResnet-r18. Each benchmark module in stage2 to stage5 in PResnet-r18 has two convolutional layers. The second 3×3 convolution in each benchmark module is replaced by a partial convolution, such as Figure 2 As shown in Figure 2. Introducing partial convolution into the backbone network will greatly reduce the amount of model computation and model parameters. Specifically, partial convolution only needs to apply regular convolution on a portion of the input channels for spatial feature extraction, and keep the remaining channels unchanged. Without losing generality, it is assumed that the input and output feature maps have the same number of channels, so the FLOPs of partial convolution are:
[0046]
[0047] In formula 1, h and w are the width and height of the feature map, respectively, k is the size of the convolution kernel, which is set to 3 in this invention, and c p It is a part of the number of channels c in conventional convolution. The present invention sets c p is c / 4, such as Figure 3 At the same time, the present invention will improve the conventional convolution in the partial convolution. In order to ensure that the accuracy of the model is not reduced while reducing the number of parameters and the amount of calculation, the re-parameterization is introduced to replace the conventional convolution. Figure 3 The accuracy of a single-channel structure model such as conventional convolution is difficult to reach the level of a multi-branch structure. The multi-branch structure makes the model an implicit collection of multiple small models, thereby avoiding the problem of gradient disappearance. In addition, conventional convolution operations will produce a large number of redundant feature representations, while the present invention can better characterize feature reusability and improve the generalization ability of the model by introducing a reparameterization mechanism. Each layer of the reparameterized part has three branches, and its formula is:
[0048] y=x+g(x)+f(x)(2)
[0049] In Formula 2, x is the identity mapping or input, g(x) is a 1×1 convolution, and f(x) is a 3×3 convolution.
[0050] Furthermore, in this embodiment, the AIFI module in the efficient hybrid encoder is improved and replaced with a deformable attention module. Figure 1 and Figure 4 To illustrate. Figure 1 As shown in the figure, the network model inputs the feature map S5 of stage5 with the smallest scale and richest semantic information into the deformable attention module; first, the input feature map is used to generate a unified network of points as a reference, and then the specific Figure 4 It can be seen that the deformable attention module consists of two branches. The reference point of the upper branch is obtained by downsampling with a scale factor r and generating a grid. The reference point size is H r ×W r ×2=H / r×W / r×2; in this embodiment, r is 3, where H and W are the width and height of the feature map, respectively, and 2 is the number of channels, representing the x and y coordinate axes. It should be noted that in this embodiment, the reference point value range becomes: {(0, 0), ..., (H r -1, W r -1)}, and then normalize the coordinates to [-1, 1], where (-1, -1) represents the upper left corner and (1, 1) represents the lower right corner.
[0051] In addition, the following branch is: q = xW q , where q is the query and x is the feature map S5 obtained by linear mapping: x = Flatten (S5); W q is the parameter matrix obtained through training, and then the obtained q is obtained through the offset network: Δp = θ offset (q), where Δp←stanh(Δp) is to limit the value of Δp and determine its maximum offset. s is a predefined constant that determines the amplitude of the tanh function. Then add the obtained offset Δp to the value of the reference point of the upper branch to obtain φ is specifically expressed as:
[0052]
[0053] The sampling function φ is a bilinear interpolation, which is a weighted sum of the pixels around the reference point. x , p y are the x and y coordinates of the offset respectively; the reference point r x , r y Denote z∈R H×W×C The indices of all positions on .
[0054] in:
[0055] g(a, b) = max(0, 1-|ab|) (4)
[0056] Among them, g is only in the distance (p x , p y ) is non-zero at the 4 nearest integer points, so Formula 3 is simplified to a weighted average of the 4 positions. Then sample at the position of the reference point after adding the offset as a key-value pair:
[0057]
[0058] Among them, W k , W v is the parameter matrix obtained through training. Similar to the existing method, the present invention performs Perform multi-head attention and use relative position offset R. Its output is expressed as:
[0059]
[0060] Among them, m is the multi-head attention, which is set to 8 in the present invention; σ is the activation function softmax, T is the transposed matrix, For the matrix dimension, and B is the relative position offset.
[0061] In a further configuration of this embodiment, the CCFM module in the original model is introduced into the p2 detection head to obtain the CCFM-p2 module, that is, the stage2 in the backbone network is also input into the CCFM-p2 module. Figure 1 and attached Figure 2 For small targets, detection is usually performed at a lower feature map, and the p2 detection head can help the network better understand and characterize small targets, because smaller-scale features are usually more suitable for capturing the details and context of small targets. The present invention directly inputs the backbone network stage3 and stage4 into the CCFM-p2 module, while the stage5 with the smallest scale and richest semantic information is first outputted by the deformable attention module F5 and then input into the CCFM-p2 module, as shown in the attached figure. Figure 1 As shown, the present invention also inputs stage2 into the CCFM-p2 module in the efficient hybrid encoder, and the formula is as follows:
[0062] Output=CCFM-p2({S2,S3,S4,F5}) (7)
[0063] In a further configuration of the present invention, the output of the CCFM-p2 module is used to obtain an object query as an initialization anchor and a learnable content query through the classification loss IoU-aware, and then input into the Transformer decoder deformable attention to combine the features of the encoder output and update the query layer by layer, and contrast denoising training is used in the training stage.
[0064] Further, as attached Figure 1 As shown, this embodiment uses the Wise-IoU loss function, which has a better effect on small target detection, as the regression loss of the difference between the model output prediction value and the true label. This gradient distribution strategy makes the model pay more attention to public quality samples, thereby improving the positioning ability of the model. IoU-aware selects variable focal loss as the classification loss. Its loss function expression is:
[0065]
[0066] in, is the predicted value, y is the true value, c represents the true category, and IoU-aware represents variable focal loss. The formula is:
[0067]
[0068] Among them, p represents the predicted IoU-aware classification score, q represents the target score, that is, the ground truth, a soft label related to IoU, that is, the label score of the positive sample is no longer 0 or 1. γ is a hyperparameter that reduces the value of negative samples, and α is to prevent excessive suppression of negative samples. The regression loss function Wise-IoU formula is:
[0069] L WIoU =R WIoU ×L IoU (10)
[0070]
[0071]
[0072] In formula 11 and formula 12, x, y, w and h respectively represent the horizontal coordinate, vertical coordinate, width and height of the prediction box center point, x gt ,y gt 、w gt and h gt Respectively represent the horizontal coordinate, vertical coordinate, width and height of the groundtruth center point, W g and H g The width and height of the minimum enclosing box formed by the prediction box and the groundtruth area, W i and H i is the width and height of the overlapping area between the predicted box and the ground truth. In formula 13 For L IoUThe sliding average of β is the outlier degree. The larger its value is, the worse the sample quality is. In formula 14, γ is the focusing coefficient, α and δ are dynamically adjusted hyperparameters. When β is smaller, γ is allocated smaller, reducing the weight of high-quality anchor boxes in larger loss functions.
[0073] Comparative Example:
[0074] The following is combined with Figure 5 The data illustrate the effect achieved by this invention. In order to further test the effect of the model, the present invention conducted several sets of comparative experiments and ablation experiments. The mAP@.5(%) of the improved model is 3.1% higher than that of the original model, and the number of parameters is reduced by 7M compared with the original model. The experimental results are shown in Table 1.
[0075] Table 1
[0076]
[0077]
[0078] Combined with Table 1, it is concluded through comparative experiments that the algorithm performance of the present invention is better than that of the current mainstream algorithm YOLO series; in the ablation experiment part, the present invention adds the p2 detection head to improve the accuracy of the benchmark model RT-DETR (r-18) by 3.2%, but the calculation amount increases by 20 GFLOPs; in order to reduce its calculation amount, the present invention introduces the partial convolution re-parameter module (Partial-RepConv) module. When the module is introduced on the basis of the benchmark model, the accuracy is only 0.1% lower than the benchmark model, and the number of parameters and the amount of calculation are greatly reduced; however, when the module is introduced on the rtdetr-p2 model, the accuracy is reduced by 0.8%. Therefore, the present invention introduces the deformable attention module on this basis to obtain the final model structure, the model has been improved in accuracy, and the number of parameters has been greatly reduced, and the amount of calculation is 13.7 GFLOPs lower than the rtdetr-p2 model.
[0079] In order to demonstrate the effect achieved by the invention, Figure 5 Explanation: Compare the detection image of the improved model with the original model. The left side is the detection image of the original model, the right side is the detection image of the improved model, and the original image is located above the two images. Figure 5 As shown in (a), it can be seen that in the case of small target detection, the vehicle at the rear that was originally not recognized can be successfully recognized by the improved model, and the car that was originally misidentified can be correctly recognized by the improved model; as shown in the attached figure Figure 5 As shown in (b), under complex background, the original model will mistakenly detect the railing as a truck, while the improved model can correctly identify it. The improved model can successfully identify the motorcycle that was originally missed. The original model will have overlapping frames, while the improved model is more accurate. For comparison, see the attached figure. Figure 5 (a) and (b), it can be seen that the detection performance of the model at multiple angles is better than the original model.
[0080] The embodiments of the present invention are described in detail above with reference to the accompanying drawings, but the present invention is not limited to the described embodiments. For those skilled in the art, various changes, modifications, substitutions and variations of these embodiments including components are made without departing from the principles and spirit of the present invention, and still fall within the scope of protection of the present invention.
Claims
1. A method for detecting small targets in UAV aerial photography based on an improved RT-DETR network, characterized in that: The steps include: Step 1: Obtain and preprocess the public dataset; Step 2, construct a small target detection model, the small target detection model is based on the RT-DETR network, the RT-DETR network includes a backbone network and an efficient hybrid encoder, the backbone network Resnet-r18 includes four layers of benchmark modules, stage2, stage3, stage4 and stage5, each of the benchmark modules includes two convolutional layers, and the second 3×3 convolution in each benchmark module is replaced with a partial convolution re-parameter module; the AIFI module in the efficient hybrid encoder is replaced with a deformable attention module, and the benchmark module output feature map S5 of the stage 5 layer after replacing the partial convolution re-parameter module is input into the deformable attention module; The p2 detection head is introduced into the CCFM module of the efficient hybrid encoder, and the feature map F5 output by the deformable attention module and the feature maps S2, S3, and S4 output by the benchmark module of the stage 2-4 layers after replacing the partial convolution re-parameter module are input into the CCFM-p2 module in the efficient hybrid encoder; Wise-IoU is used as the regression loss function of the difference between the model output prediction value and the true label; Step 3: Configure the training environment and use the preprocessed dataset as input to train the small object detection model. Step 4: Apply the trained small target detection model, take the target image to be detected as input and output the detection result.
2. According to claim 1, a method for detecting small targets in drone aerial photography based on an improved RT-DETR network is characterized in that: The preprocessing method is: converting the data set into image data that conforms to the RT-DETR network format.
3. According to claim 1, a method for detecting small targets in drone aerial photography based on an improved RT-DETR network is characterized in that: The output of the CCFM module is obtained through the classification loss IoU-aware object query as an initialization anchor and learnable content query input to the Transformer decoder, and then the detection result is output.
4. According to claim 3, a method for detecting small targets in drone aerial photography based on an improved RT-DETR network is characterized in that: The IoU-aware selects variable focal loss as the classification loss, and its loss function expression is: in, is the predicted value, y is the true value, c represents the true category, and IoU-aware represents variable focal loss.
5. The method for detecting small targets in drone aerial photography based on an improved RT-DETR network according to claim 1, characterized in that: The regression loss function Wise-IoU formula is: L WIoU =R WIoU ×L IoU Among them, x, y, w and h represent the horizontal coordinate, vertical coordinate, width and height of the prediction box center point respectively. gt ,y gt 、w gt and h gt Respectively represent the horizontal coordinate, vertical coordinate, width and height of the groundtruth center point, W g and H g The width and height of the minimum enclosing box formed by the prediction box and the groundtruth area, W i and H i is the width and height of the overlapping area between the prediction box and the ground truth, For L IoU is the sliding average of , β is the outlier degree, γ is the focusing coefficient, and α and δ are dynamically adjusted hyperparameters.
6. The method for detecting small targets in drone aerial photography based on an improved RT-DETR network according to claim 1, characterized in that: The training method is as follows: the training coefficient is set to 300 rounds, 4 images are input for each training, the training process is observed in real time through wandb, and after the training is completed, the trained weights are saved.
