A safflower target detection method and device based on an optimized RT-DETR model

CN117853918BActive Publication Date: 2026-10-30CHANGZHOU UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410039910.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-10
Publication Date
2026-10-30
Estimated Expiration
2044-01-10

AI Technical Summary

Technical Problem

然而,这些方法由于在复杂环境下的适应性和准确性受限,特别是在处理红花多变的外观和形态时,效率和效果常常不理想

Benefits of technology

[0033]本发明的有益效果是:本发明提供了一种基于优化后的RT-DETR模型的红花目标检测方法,所述方法包括:S1:基于采集到的红花的图像样本构建数据集;S2:对所述数据集中的图像样本包含的红花目标进行标注生成与所述图像样本对应的标注文件;S3:将所述数据集中的图像样本和与之对应的标注文件划分为训练集和测试集;S4:使用Inner-IoU损失函数和OrthoBasicBlock模块优化RT-DETR目标检测模型;S5:通过所述训练集中包含的图像样本和与之对应的标注文件训练优化后的RT-DETR目标检测模型;S6:利用训练后的已优化的RT-DETR目标检测模型对采集到的红花的图像样本进行检测。提出的改进的RT-DETR目标检测模型通过构建针对农田环境的标注数据集、使用Ineer-IoU损失函数可以区分不同IoU水平的样本,提高模型收敛速度和检测精度。通过采用OrthoBasicBlock模块从而提高特征表达能力,增强模型对目标的识别和定位能力。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117853918B_ABST
    Figure CN117853918B_ABST
Patent Text Reader

Abstract

The application provides a safflower target detection method and device based on an optimized RT-DETR model, comprising the following steps: S1: constructing a data set based on collected safflower image samples; S2: labeling safflower targets contained in the image samples in the data set to generate annotation files corresponding to the image samples; S3: dividing the image samples in the data set and the annotation files corresponding thereto into a training set and a test set; S4: optimizing an RT-DETR target detection model using an Inner-IoU loss function and an OrthoBasicBlock module; S5: training the optimized RT-DETR target detection model through the image samples contained in the training set and the annotation files corresponding thereto; and S6: detecting the collected safflower image samples using the trained and optimized RT-DETR target detection model. By optimizing the RT-DETR target detection model using the Inner-IoU loss function and the OrthoBasicBlock module, the convergence speed and detection accuracy of the model are improved, and the recognition and positioning capabilities of the model for targets are enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of target detection technology, specifically to a method and apparatus for detecting safflower targets based on an optimized RT-DETR model. Background Technology

[0002] Safflower is an important oilseed and medicinal crop, and its yield and quality directly affect farmers' economic interests and the supply of medicinal resources. Therefore, accurately estimating the distribution and density of safflower plants in farmland is of great significance for optimizing planting density, farmland management, and reducing the use of pesticides, water, and fertilizers. This not only helps improve agricultural productivity but also contributes to sustainable agricultural development and reduces negative environmental impacts.

[0003] Traditional methods for recognizing safflower often employ conventional computer vision algorithms and machine learning techniques to process and analyze image data. However, these methods suffer from limitations in adaptability and accuracy in complex environments, particularly when dealing with the varied appearance and morphology of safflowers, resulting in often unsatisfactory efficiency and performance. These traditional methods require complex image preprocessing, such as segmentation and feature extraction, and have limited adaptability to the diverse growth conditions and postures of safflowers. Traditional machine learning algorithms often rely on extensive manual feature design and labeled samples, lacking sufficient generalization ability for diverse safflower images.

[0004] The above-mentioned problems urgently need to be solved. Summary of the Invention

[0005] The present invention aims to overcome at least one of the aforementioned shortcomings of the prior art. On one hand, the present invention provides a method for detecting red flower targets based on an optimized RT-DETR model. The method includes: S1: constructing a dataset based on collected red flower image samples; S2: labeling the red flower targets contained in the image samples in the dataset to generate label files corresponding to the image samples; S3: dividing the image samples in the dataset and their corresponding label files into training and testing sets; S4: optimizing the RT-DETR target detection model using the Inner-IoU loss function and the OrthoBasicBlock module; S5: training the optimized RT-DETR target detection model using the image samples contained in the training set and their corresponding label files; S6: using the trained and optimized RT-DETR target detection model to detect the collected red flower image samples.

[0006] Furthermore, step S2 includes: S210: using the LabelImg annotation tool to annotate the red flower targets contained in the image samples in the dataset to generate an annotation file corresponding to the image samples; the annotation file includes red flower category labels and bounding box coordinate information.

[0007] Furthermore, step S4 includes: S41: Using ResNet18 as the backbone network, combined with the OrthoBasicBlock module, to extract multi-scale feature maps of the image. The backbone network outputs three feature maps at different scales, corresponding to the outputs of the last three stages of the network; S42: Using a hybrid encoder structure including an AIFI module, used to perform feature interaction based on a self-attention mechanism on the high-level semantic feature maps output by the backbone network; and a CCFM module, used to use a convolutional network to perform cross-scale sampling and fusion of the low-level semantic feature maps of the two middle layers in the backbone network and the high-level semantic feature maps encoded by the AIFI module, and outputting a fused feature sequence. Based on the encoder, an IoU-aware query selection module is further adopted. Based on the feature sequence output by the encoder, features with both high classification scores and high IoU scores are selected to initialize the object query of the decoder; S43: A Transformer decoder structure is adopted. Based on the image feature sequence from the encoder and the initial query, the final prediction box and classification result are generated through iterative optimization; S44: The prediction head includes a classification prediction head and a bounding box regression prediction head, which are used for object classification prediction and bounding box coordinate prediction, respectively; and S45: The original IoU loss function is optimized by introducing the Inner-IoU loss function.

[0008] Furthermore, the calculation of the Inner-IoU loss function in step S4 includes: S410: determining the center coordinates, width, and height of the true bounding box; S411: calculating the four boundary coordinates of the auxiliary box of the true bounding box based on a preset scaling factor and the center coordinates, width, and height of the true bounding box; S412: determining the center coordinates, width, and height of the predicted bounding box; S413: calculating the four boundary coordinates of the auxiliary box of the predicted bounding box based on a preset scaling factor and the center coordinates, width, and height of the predicted bounding box; S414: generating the Inner-IoU loss function based on the four boundary coordinates of the auxiliary box of the true bounding box and the four boundary coordinates of the auxiliary box of the predicted bounding box.

[0009] Furthermore, step S414 includes: the four boundary coordinates of the auxiliary box of the true bounding box are:

[0010]

[0011]

[0012]

[0013]

[0014] in, w represents the coordinates of the center point of the true bounding box. gt h is the width of the actual bounding box. gt The actual bounding box height is given by `ratio`, which is a preset scaling factor.

[0015] The coordinates of the four boundaries of the auxiliary box used to predict the bounding box are:

[0016] bl=x c -w′*ratio / 2;

[0017] br = x c +w′*ratio / 2;

[0018] bt = y c -h′*ratio / 2;

[0019] bb=y c +h′*ratio / 2;

[0020] Where, x c y c Here are the coordinates of the center point of the predicted bounding box, w′ is the width of the predicted bounding box, h′ is the height of the predicted bounding box, and ratio is the preset scaling factor.

[0021] The Inner-IoU loss function is:

[0022]

[0023] Among them, B inner To predict the auxiliary box of the bounding box, B gt,inner The auxiliary box is the actual bounding box.

[0024] Furthermore, the construction steps of the OrthoBasicBlock module in step S4 include: S420: Constructing two consecutive 3x3 convolutional layers after the original feature map, with the first convolutional layer followed by a batch normalization layer and a ReLU activation function, and the second convolutional layer followed by a batch normalization layer to obtain the input feature map; S421: Randomly initializing filters according to the size of the input feature map, wherein the filter set is orthogonalized through the Gram-Schmidt process, and then the spatial information of the input feature map is compressed using the orthogonalized filters to obtain a one-dimensional vector; S422: Combining the one-dimensional vector, using full... The connection layer, ReLU function, and Sigmoid function employ the activation steps within the SENet framework to calculate the attention vector. The activation steps within the SENet framework include: E(Z) = σ(W2*δ(W1*Z)); where E(Z) is the final attention vector, σ is the Sigmoid function, δ is the ReLU activation function, W1 and W2 are learnable weight matrices, and Z is a one-dimensional vector with c channels obtained in S421; S423: The attention vector is element-wise multiplied with the input feature map to obtain a weighted feature map, and then added to the residual of the original feature map to generate the output feature map.

[0025] Furthermore, the process of compressing the spatial information of the input feature map includes:

[0026]

[0027] Where c, h, and w refer to the number of channels, height, and width of the input feature map, respectively, and F ortho (X) c Refers to the compressed feature map, K c,h,w X refers to the filter value of channel c at spatial location (h,w). c,h,w This refers to the input feature map value of channel c at spatial location (h, w).

[0028] Furthermore, step S5 includes: S510: setting an initial learning rate and adjusting the learning rate using a cosine annealing function during training; S511: setting the training batch and the number of training epochs; S512: training the optimized RT-DETR object detection model based on the training batch, the number of training epochs, and the learning rate.

[0029] Furthermore, after step S5, the following steps are also included: S7: using the trained and optimized RT-DETR object detection model to detect image samples in the test set and generate a first detection result; S8: using the original RT-DETR object detection model to detect image samples in the test set and generate a second detection result; S9: evaluating the performance of the optimized RT-DETR object detection model by comparing the first detection result and the second detection result; S10: when the performance of the optimized RT-DETR object detection model is higher than the performance of the original RT-DETR object detection model, proceeding to step S6; S11: when the performance of the optimized RT-DETR object detection model is not higher than the performance of the original RT-DETR object detection model, repeating step S5.

[0030] Secondly, the present invention provides a red flower target detection device based on an optimized RT-DETR model. The device includes: a dataset construction module for constructing a dataset based on collected red flower image samples; an annotation module for annotating the red flower targets contained in the image samples in the dataset to generate annotation files corresponding to the image samples; a partitioning module for partitioning the image samples in the dataset and their corresponding annotation files into a training set and a test set; an optimization module for optimizing the RT-DETR target detection model using the Inner-IoU loss function and the OrthoBasicBlock module; a training module for training the optimized RT-DETR target detection model using the image samples contained in the training set and their corresponding annotation files; and a detection module for detecting the collected red flower image samples using the trained and optimized RT-DETR target detection model.

[0031] In another aspect, the present invention also provides a computer-readable storage medium storing one or more instructions for causing the computer to execute the above-described red flower target detection method based on the optimized RT-DETR model.

[0032] In another aspect, the present invention provides an electronic device, comprising: a memory and a processor; the memory storing at least one program instruction; the processor loading and executing the at least one program instruction to implement the above-described method for detecting red flower targets based on the optimized RT-DETR model.

[0033] The beneficial effects of this invention are as follows: This invention provides a method for detecting red flower targets based on an optimized RT-DETR model. The method includes: S1: constructing a dataset based on collected red flower image samples; S2: labeling the red flower targets contained in the image samples in the dataset to generate label files corresponding to the image samples; S3: dividing the image samples in the dataset and their corresponding label files into training and testing sets; S4: optimizing the RT-DETR target detection model using the Inner-IoU loss function and the OrthoBasicBlock module; S5: training the optimized RT-DETR target detection model using the image samples contained in the training set and their corresponding label files; S6: using the trained and optimized RT-DETR target detection model to detect the collected red flower image samples. The proposed improved RT-DETR target detection model improves the model convergence speed and detection accuracy by constructing a labeled dataset for farmland environments and using the Inner-IoU loss function to distinguish samples with different IoU levels. By employing the OrthoBasicBlock module, the feature representation capability is improved, thereby enhancing the model's ability to identify and locate targets. Attached Figure Description

[0034] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0035] Figure 1 This is a flowchart of a method for detecting safflower targets based on an optimized RT-DETR model, provided in an embodiment of the present invention.

[0036] Figure 2 This is a schematic diagram of an optimized RT-DETR target detection model structure provided in an embodiment of the present invention.

[0037] Figure 3 This is a schematic diagram of an OrthoBasicBlock module network structure provided in an embodiment of the present invention.

[0038] Figures 4a-4b This is a diagram showing the detection effect of a raw RT-DETR for safflower targets provided in an embodiment of the present invention.

[0039] Figures 5a-5b This is a diagram showing the effect of optimized RT-DETR for detecting safflower targets, provided in an embodiment of the present invention.

[0040] Figure 6 This is a schematic diagram of a safflower target detection device based on an optimized RT-DETR model provided in an embodiment of the present invention.

[0041] Figure 7This is a partial block diagram of the electronic device provided in the embodiments of the present invention. Detailed Implementation

[0042] Before discussing the exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the operations as sequential processes, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but may also have additional steps not included in the figures. The process can correspond to a method, function, procedure, subroutine, subroutine, etc.

[0043] It should be understood that although the terms "first," "second," etc., may be used herein to describe various units, these units should not be limited by these terms. These terms are used merely to distinguish one unit from another. For example, without departing from the scope of the exemplary embodiments, a first unit may be referred to as a second unit, and similarly, a second unit may be referred to as a first unit. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.

[0044] The present invention will now be described in detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0045] Example 1

[0046] For ease of subsequent understanding, the overall inventive concept of this invention is described here:

[0047] This invention proposes a safflower target detection method based on an optimized RT-DETR model. By using the Inner-IoU loss function and the OrthoBasicBlock module to optimize the RT-DETR target detection model, safflower can be detected based on the optimized RT-DETR target detection model. Compared with traditional computer vision and machine learning algorithms, it has higher adaptability and robustness to morphological and appearance changes of safflower at different growth stages and under different light conditions, while maintaining high detection efficiency and practicality. It is particularly suitable for safflower growth monitoring in large-scale farmland.

[0048] The specific implementation method is as follows:

[0049] like Figure 1 The diagram shown is a flowchart of a safflower target detection method based on an optimized RT-DETR model provided by the present invention.

[0050] As an example, the method includes: S1: Constructing a dataset based on collected image samples of safflower.

[0051] Preferably, the images used are taken by a camera at different times and from different angles to obtain safflower samples at different growth stages, under different lighting conditions and shading states, and 1,000 images are selected from them to construct the dataset.

[0052] As an example, the method includes: S2: labeling the red flower targets contained in the image samples in the dataset to generate a label file corresponding to the image samples.

[0053] Preferably, step S2 includes S210: using the LabelImg annotation tool to annotate the red flower targets contained in the image samples in the dataset to generate annotation files corresponding to the image samples; the annotation files include red flower category labels and bounding box coordinate information. Specifically, the LabelImg annotation tool is used to annotate red flower instances in each image in the dataset, accurately marking the positions of all red flower instances in each image, and generating annotation information for the corresponding image in the form of a txt file, which includes red flower category labels and bounding box coordinates.

[0054] As an example, the method includes: S3: dividing the image samples and corresponding annotation files in the dataset into a training set and a test set.

[0055] Preferably, after annotation is completed, all images and their annotation files in the dataset are randomly divided into a training set (80%) and a test set (20%) to ensure the correspondence between image files and annotation files.

[0056] As an example, the method includes: S4: Optimizing the RT-DETR object detection model using the Inner-IoU loss function and the OrthoBasicBlock module.

[0057] Preferred, such as Figure 2 As shown, step S4 includes:

[0058] S41: Employs ResNet18 as the backbone network, combined with the OrthoBasicBlock module, to extract multi-scale feature maps of the image. Specifically, the backbone network uses ResNet18 as the backbone network, combined with the newly introduced OrthoBasicBlock module, to more effectively extract multi-scale feature maps of the image. The backbone network outputs three feature maps at three different scales, corresponding to the outputs of the last three stages of the network.

[0059] S42: The hybrid encoder includes an AIFI module for performing self-attention-based feature interaction on the high-level semantic feature maps output by the backbone network; and a CCFM module for using a convolutional network to sample and fuse the low-level semantic feature maps of the two middle layers of the backbone network and the high-level semantic feature maps encoded by the AIFI module across scales, outputting a fused feature sequence. Specifically, the encoder (Encoder): The hybrid encoder includes the following two components: the AIFI module and the CCFM module. Based on the encoder, an IoU-aware query selection module is further employed to select features with both high classification scores and high IoU scores based on the feature sequence output by the encoder to initialize the decoder's object query.

[0060] S43: Employs a Transformer decoder structure, based on the image feature sequence from the encoder and the initial query, and generates the final prediction box and classification result through iterative optimization.

[0061] S44: The prediction head includes a classification prediction head and a bounding box regression prediction head, used for object classification prediction and bounding box coordinate prediction, respectively; and

[0062] S45: The original IoU loss function is optimized by introducing the Inner-IoU loss function.

[0063] Preferably, the calculation of the Inner-IoU loss function in step S4 includes: S410: determining the center coordinates, width, and height of the true bounding box; S411: calculating the four boundary coordinates of the auxiliary box of the true bounding box based on a preset scaling factor and the center coordinates, width, and height of the true bounding box; S412: determining the center coordinates, width, and height of the predicted bounding box; S413: calculating the four boundary coordinates of the auxiliary box of the predicted bounding box based on a preset scaling factor and the center coordinates, width, and height of the predicted bounding box; S414: generating the Inner-IoU loss function based on the four boundary coordinates of the auxiliary box of the true bounding box and the four boundary coordinates of the auxiliary box of the predicted bounding box.

[0064] Preferably, step S414 includes: the four boundary coordinates of the auxiliary box of the true bounding box are:

[0065]

[0066]

[0067]

[0068]

[0069] in, w represents the coordinates of the center point of the true bounding box. gt h is the width of the actual bounding box. gt The actual bounding box height is given by `ratio`, which is a preset scaling factor with a value between 0.5 and 1.5.

[0070] The coordinates of the four boundaries of the auxiliary box used to predict the bounding box are:

[0071] bl=x c -w′*ratio / 2;

[0072] br = x c +w′*ratio / 2;

[0073] bt = y c -h′*ratio / 2;

[0074] bb=y c +h′*ratio / 2;

[0075] Where, x c y c The coordinates of the center point of the predicted bounding box are given, w′ is the width of the predicted bounding box, h′ is the height of the predicted bounding box, and ratio is a preset scaling factor with a value between 0.5 and 1.5.

[0076] The Inner-IoU loss function is:

[0077]

[0078] Among them, B inner To predict the auxiliary box of the bounding box, B gt,inner The auxiliary box is the actual bounding box.

[0079] Specifically, this embodiment replaces the IoU loss function used in the original RT-DETR model with Inner-IoU as the loss function. While the traditional IoU loss function provides an intuitive measure of the similarity between predicted and ground truth bounding boxes, it fails to fully utilize the differences between high-IoU and low-IoU samples to improve model performance at various IoU levels. More importantly, the IoU loss function uses a uniform approach for all samples, lacking the necessary flexibility and specificity when dealing with predicted boxes of varying quality, thus slowing down model convergence and performing poorly when handling samples of different quality. Therefore, this embodiment introduces the Inner-IoU loss function, which refines IoU calculation by introducing an auxiliary bounding box and an adjustable scaling factor. The introduction of the auxiliary bounding box allows the Inner-IoU loss function to more precisely describe the degree of matching between predicted and ground truth boxes, especially when dealing with samples at different IoU levels, providing more discriminative feedback to more effectively guide the model's bounding box regression behavior. The Inner-IoU loss function uses auxiliary bounding boxes of different scales to calculate the loss for high-IoU and low-IoU samples. Smaller auxiliary bounding boxes are used for high-IoU samples to increase sensitivity to small offsets, which helps improve the convergence speed and accuracy of the model. For low-IoU samples, larger auxiliary bounding boxes are used to expand the effective range of regression, helping the model to better capture boundary information, thereby improving the regression efficiency of these samples.

[0080] Preferred, such as Figure 3 As shown, the construction steps of the OrthoBasicBlock module in step S4 include:

[0081] S420: Two consecutive 3x3 convolutional layers are constructed after the original feature map. The first convolutional layer is followed by a batch normalization layer and a ReLU activation function; the second convolutional layer is followed only by a batch normalization layer, resulting in an input feature map with height, width, and number of channels h, w, and c, respectively.

[0082] S421: Randomly initialize filters based on the size of the input feature map, wherein the filter set is orthogonalized through a Gram-Schmidt process. Specifically, during the module initialization phase, a filter set of a size matching the input feature map is randomly generated, and the orthogonality of the filter set is ensured through a Gram-Schmidt orthogonalization process, thereby providing a better initialization state for the attention module and facilitating convergence to a better solution. Next, orthogonal filters are used to compress the spatial information of the input feature map. The process of compressing the spatial information of the input feature map includes: Where c, h, and w refer to the number of channels, height, and width of the input feature map, respectively, and Fortho (X) c Refers to the compressed feature map, K c,h,w X refers to the filter value of channel c at spatial location (h,w). c,h,w This refers to the input feature map value of channel c at spatial location (h,w), which ultimately yields a one-dimensional vector with c channels.

[0083] S422: Based on a one-dimensional vector with c channels, the attention weights for each channel are calculated using a fully connected layer, ReLU function, and sigmoid function. Specifically, the attention vector is calculated using the excitation step proposed by SENet. The excitation step process is as follows:

[0084] E(Z) = σ(W2*δ(W1*Z));

[0085] Where E(Z) is the final attention vector, σ is the Sigmoid function, δ is the ReLU activation function, W1 and W2 are learnable weight matrices, and Z is a one-dimensional vector with c channels obtained from S421.

[0086] S423: Multiply the attention vector element-wise with the input feature map to obtain a weighted feature map, and add it to the residual of the original feature map to generate an output feature map.

[0087] In summary, this embodiment makes significant structural improvements to ResNet18 in the RT-DETR-based object detection network. The traditional BasicBlock module is replaced with the OrthoBasicBlock module, which employs orthogonal filters and attention mechanisms to improve the spatial dimensionality compression efficiency and feature representation capability of features.

[0088] More specifically, the OrthoBasicBlock module consists of the following steps: First, two consecutive 3x3 convolutional layers are used to perform preliminary feature extraction on the original feature map. Then, the output of the first convolutional layer is standardized by a batch normalization layer and connected to a Rectified Linear Unit (ReLU) activation function to introduce non-linear transformations and enhance the model's ability to capture complex features. The output of the second convolutional layer is then processed only by batch normalization to obtain the input feature map. Based on the number of channels c, height h, and width w of the input feature map, an h*w*c filter is randomly initialized. Next, the randomly initialized filter is processed through a Gram-Schmidt orthogonalization process to ensure its orthogonality and diversity. Then, the filter generated by the Gram-Schmidt process and the input feature map are summed element-wise, thereby compressing the spatial information of each feature channel into a scalar value, resulting in a one-dimensional vector with c channels. Finally, the one-dimensional vector is input into two fully connected layers. The first fully connected layer reduces the vector dimension to 1 / 16 of its original size and increases the non-linear expressive power of the entire network through the ReLU function. The second fully connected layer restores the original dimension and generates an attention vector of dimension c through the Sigmoid activation function. This vector is multiplied channel-by-channel with the input feature map, achieving dynamic recalibration of the feature map. After being concatenated with the residual of the original feature map, it is output, allowing the network to focus more on features that are more important to the current task.

[0089] As an example, the method includes: S5: training an optimized RT-DETR object detection model using image samples and corresponding annotation files contained in the training set.

[0090] Preferably, step S5 includes: S510: setting an initial learning rate and adjusting the learning rate using a cosine annealing function during training; S511: setting the training batch and the number of training epochs; S512: training the optimized RT-DETR object detection model based on the training batch, the number of training epochs, and the learning rate. Specifically, the initial learning rate is set to 0.0001, and the learning rate is adjusted using a cosine annealing function during training. The training batch is set to 8, and the number of training epochs is set to 500. Subsequently, the improved RT-DETR object detection model is trained.

[0091] Preferably, after step S5, the method further includes: S7: using the trained and optimized RT-DETR object detection model to detect image samples in the test set and generate a first detection result; S8: using the original RT-DETR object detection model to detect image samples in the test set and generate a second detection result; S9: evaluating the performance of the optimized RT-DETR object detection model by comparing the first detection result and the second detection result; S10: when the performance of the optimized RT-DETR object detection model is higher than the performance of the original RT-DETR object detection model, proceeding to step S6; S11: when the performance of the optimized RT-DETR object detection model is not higher than the performance of the original RT-DETR object detection model, repeating step S5.

[0092] As an example, the method includes: S6: using the trained and optimized RT-DETR target detection model to detect the collected image samples of safflower.

[0093] Preferably, step S6 includes: training the weights of the improved RT-DETR object detection model and performing detection on the test set of the red flower plant dataset.

[0094] First, as shown in Table 1, the performance of models using the traditional IoU loss function and the Inner-IoU loss function is compared to demonstrate the role of the new loss function in the model. Second, based on the Inner-IoU loss function, the performance of models using the traditional BasicBlock module and the OrthoBasicBlock module in the backbone network is compared to demonstrate the improvement effect of OrthoBasicBlock on feature extraction. Finally, the complete improved RT-DETR model is compared with the original RT-DETR model to evaluate the combined performance improvement of all improvements.

[0095] Table 1: Comparison of detection performance of the improved model and the original model on the safflower dataset.

[0096]

[0097] As shown in Table 1 above, the optimized RT-DETR model of the present invention significantly improves the accuracy and efficiency of safflower plant detection by introducing the Innner-IoU loss function and the OrthoBasicBlock module.

[0098] like Figures 5a-5b The detection results obtained from the improved RT-DETR algorithm model. Figures 4a-4bThe comparison shows the detection performance of the original RT-DETR algorithm model. It can be seen that the improved RT-DETR algorithm model misses fewer samples when detecting red flower targets in farmland environments, demonstrating stronger robustness and adaptability, making it suitable for accurate detection tasks under complex backgrounds and varying lighting conditions. Therefore, the technical solution proposed in this invention has practical application value and can provide an effective solution strategy for similar target detection problems.

[0099] Example 2

[0100] Please see Figure 6 This embodiment provides a schematic diagram of a safflower target detection device based on an optimized RT-DETR model.

[0101] As an example, the device includes:

[0102] The dataset construction module 610 is used to construct a dataset based on the collected safflower image samples;

[0103] The annotation module 620 is used to annotate the red flower targets contained in the image samples in the dataset and generate annotation files corresponding to the image samples;

[0104] The partitioning module 630 is used to divide the image samples and their corresponding annotation files in the dataset into a training set and a test set.

[0105] Optimization module 640 is used to optimize the RT-DETR object detection model using the Inner-IoU loss function and the OrthoBasicBlock module;

[0106] Training module 650 is used to train an optimized RT-DETR object detection model using image samples and corresponding annotation files contained in the training set;

[0107] The detection module 660 is used to detect the collected safflower image samples using the trained and optimized RT-DETR target detection model.

[0108] It is not difficult to see that this embodiment is a device embodiment corresponding to the first embodiment, and this embodiment can be implemented in conjunction with the first embodiment. The relevant technical details mentioned in the first embodiment are still valid in this embodiment, and will not be repeated here to reduce repetition. Accordingly, the relevant technical details mentioned in this embodiment can also be applied to the first embodiment.

[0109] It is worth mentioning that all modules involved in this embodiment are logical modules. In practical applications, a logical unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. Furthermore, to highlight the innovative aspects of this invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by this invention; however, this does not mean that other units are absent from this embodiment.

[0110] Example 3

[0111] This invention also proposes a storage medium storing a red flower target detection method based on an optimized RT-DETR model. When the red flower target detection program based on the optimized RT-DETR model is executed by a processor, it implements the steps of the red flower target detection method based on the optimized RT-DETR model as described above. Since this storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought about by the technical solutions of the above embodiments, which will not be repeated here.

[0112] Example 4

[0113] Please see Figure 7 The present invention also provides an electronic device, including: a memory and a processor; the memory stores at least one program instruction; the processor loads and executes the at least one program instruction to implement the red flower target detection method based on the optimized RT-DETR model provided in Embodiment 1.

[0114] The memory 602 and processor 601 are connected via a bus, which may include any number of interconnecting buses and bridges, connecting various circuits of one or more processors 601 and memory 602 together. The bus may also connect various other circuits, such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and therefore will not be described further herein. A bus interface provides an interface between the bus and the transceiver. The transceiver may be a single element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices over a transmission medium. Data processed by processor 601 is transmitted over a wireless medium via an antenna, which further receives data and transmits it to processor 601.

[0115] Processor 601 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Memory 602 can be used to store data used by processor 601 during operation.

[0116] The above descriptions are merely embodiments of the present invention. Commonly known structures and characteristics are not described in detail here. Those skilled in the art are aware of all common technical knowledge in the field prior to the application date or priority date, are aware of all existing technologies in that field, and have the ability to apply conventional experimental methods prior to that date. Those skilled in the art can, based on the guidance provided in this application, improve and implement this solution in combination with their own capabilities. Some typical known structures or methods should not be obstacles for those skilled in the art to implement this application. It should be noted that those skilled in the art can make several modifications and improvements without departing from the structure of the present invention. These should also be considered within the scope of protection of the present invention, and will not affect the effectiveness of the implementation of the present invention or the practicality of the patent. The scope of protection claimed in this application should be determined by the content of its claims, and the specific embodiments described in the specification can be used to interpret the content of the claims.

Claims

1. A method for detecting safflower targets based on an optimized RT-DETR model, characterized in that, The method includes: S1: Construct a dataset based on the collected image samples of safflower; S2: Annotate the red flower targets contained in the image samples in the dataset to generate annotation files corresponding to the image samples; S3: Divide the image samples and their corresponding annotation files in the dataset into a training set and a test set; S4: Optimize the RT-DETR object detection model using the Inner-IoU loss function and the OrthoBasicBlock module; S5: Train the optimized RT-DETR object detection model using the image samples and corresponding annotation files contained in the training set; S6: Use the trained and optimized RT-DETR target detection model to detect the collected safflower image samples; Step S4 includes: S41: ResNet18 is used as the backbone network, combined with the OrthoBasicBlock module, to extract multi-scale feature maps of the image. The backbone network outputs three feature maps at three different scales, which correspond to the outputs of the last three stages of the network. S42: The encoder with a hybrid structure includes an AIFI module for performing feature interaction based on a self-attention mechanism on the high-level semantic feature maps output by the backbone network; and a CCFM module for using a convolutional network to perform cross-scale sampling and fusion of the low-level semantic feature maps of the two middle layers in the backbone network and the high-level semantic feature maps encoded by the AIFI module, outputting a fused feature sequence; based on the encoder, an IoU-aware query selection module is further adopted, which selects features with both high classification scores and high IoU scores based on the feature sequence output by the encoder to initialize the object query of the decoder; S43: Employs a Transformer decoder structure, based on the image feature sequence from the encoder and the initial query, and generates the final predicted bounding box and classification result through iterative optimization; S44: The prediction head includes a classification prediction head and a bounding box regression prediction head, used for object classification prediction and bounding box coordinate prediction, respectively; and S45: The original IoU loss function is optimized by introducing the Inner-IoU loss function.

2. The method for detecting safflower targets based on the optimized RT-DETR model according to claim 1, characterized in that, Step S2 includes: S210: Use the LabelImg annotation tool to annotate the red flower targets contained in the image samples in the dataset to generate annotation files corresponding to the image samples; The annotation file includes a red flower category label and bounding box coordinate information.

3. The method for detecting safflower targets based on the optimized RT-DETR model according to claim 1, characterized in that, The calculation of the Inner-IoU loss function in step S4 includes: S410: Determine the center coordinates, width, and height of the actual bounding box; S411: Based on the preset scaling factor and the center coordinates, width, and height of the real bounding box, calculate the four boundary coordinates of the auxiliary box of the real bounding box; S412: Determine the center point coordinates, width, and height of the predicted bounding box; S413: Based on the preset scaling factor and the center point coordinates, width, and height of the predicted bounding box, calculate the four boundary coordinates of the auxiliary box of the predicted bounding box; S414: Generate an Inner-IoU loss function based on the four boundary coordinates of the auxiliary box of the true bounding box and the four boundary coordinates of the auxiliary box of the predicted bounding box.

4. The method for detecting safflower targets based on the optimized RT-DETR model according to claim 3, characterized in that, Step S414 includes: The coordinates of the four boundaries of the auxiliary bounding box of the true bounding box are: ; ; ; ; in, , The coordinates of the center point of the actual bounding box. The width of the actual bounding box. The actual bounding box height is given by `ratio`, which is a preset scaling factor. The coordinates of the four boundaries of the auxiliary box used to predict the bounding box are: ; ; ; ; in, , To predict the coordinates of the center point of the bounding box, To predict the width of the bounding box, To predict the height of the bounding box, ratio is a preset scaling factor; The Inner-IoU loss function is: ; in, To predict the auxiliary box of the bounding box, The auxiliary box is the actual bounding box.

5. The method for detecting safflower targets based on the optimized RT-DETR model according to claim 1, characterized in that, The construction steps of the OrthoBasicBlock module in step S4 include: S420: Two consecutive 3x3 convolutional layers are constructed after the original feature map. The first convolutional layer is followed by a batch normalization layer and a ReLU activation function, and the second convolutional layer is followed by a batch normalization layer to obtain the input feature map. S421: Randomly initialize the filter according to the size of the input feature map, wherein the filter set is orthogonalized by the Gram-Schmidt process, and the spatial information of the input feature map is compressed by the orthogonal filter to obtain a one-dimensional vector; S422: Combining the aforementioned one-dimensional vector, using a fully connected layer, ReLU function, and Sigmoid function, and employing the activation steps within the SENet framework, the attention vector is calculated. The activation steps within the SENet framework include: ; Where E(Z) is the final attention vector, It is the Sigmoid function. It is the ReLU activation function, W1 and W2 are learnable weight matrices, and Z is a one-dimensional vector with c channels obtained from S421; S423: Multiply the attention vector element-wise with the input feature map to obtain a weighted feature map, and add it to the residual of the original feature map to generate an output feature map.

6. The method for detecting safflower targets based on the optimized RT-DETR model according to claim 5, characterized in that, The process of compressing the spatial information of the input feature map includes: ; in, The height of the input feature map. The width of the input feature map is denoted by , where c, h, and w represent the number of channels, the index in the height direction, and the index in the width direction of the input feature map, respectively. F ortho (X) c Refers to the compressed feature map, K c,h,w X refers to the filter value of channel c at spatial location (h, w). c,h,w This refers to the input feature map value of channel c at spatial location (h, w).

7. The method for detecting safflower targets based on the optimized RT-DETR model according to claim 1, characterized in that, Step S5 includes: S510: Set the initial learning rate and adjust the learning rate using a cosine annealing function during training; S511: Set the training batch and number of training rounds; S512: Train the optimized RT-DETR object detection model based on the training batch, training rounds, and learning rate.

8. The method for detecting safflower targets based on the optimized RT-DETR model according to claim 1, characterized in that, Step S5 is followed by: S7: Use the trained and optimized RT-DETR object detection model to detect image samples in the test set and generate the first detection result; S8: Use the original RT-DETR target detection model to detect image samples in the test set and generate a second detection result; S9: Evaluate the performance of the optimized RT-DETR target detection model by comparing the first detection result and the second detection result; S10: When the performance of the optimized RT-DETR target detection model is higher than that of the original RT-DETR target detection model, proceed to step S6; S11: Repeat step S5 if the performance of the optimized RT-DETR target detection model is not higher than that of the original RT-DETR target detection model.

9. A safflower target detection device based on an optimized RT-DETR model, performing the safflower target detection method based on an optimized RT-DETR model as described in any one of claims 1 to 8, characterized in that, The device includes: The dataset construction module is used to build datasets based on the collected safflower image samples; The annotation module is used to annotate the red flower targets contained in the image samples in the dataset and generate annotation files corresponding to the image samples; The partitioning module is used to divide the image samples and their corresponding annotation files in the dataset into a training set and a test set. The optimization module is used to optimize the RT-DETR object detection model using the Inner-IoU loss function and the OrthoBasicBlock module; The training module is used to train the optimized RT-DETR object detection model using image samples and corresponding annotation files contained in the training set; The detection module is used to detect the collected safflower image samples using the trained and optimized RT-DETR target detection model.

Citation Information

Patent Citations

  • Infrared weak and small target detection method based on infrared small sample amplification and YOLOv5

    CN115861599A

  • Remote sensing image ship target detection method based on convolutional neural network

    CN116563726A