A small target pest detection method and system for crops

By constructing a small-target pest detection model and combining it with an improved backbone network and detection head network, the problem of low accuracy in detecting small and medium-sized pests in crop pests has been solved, and efficient and accurate detection of small-target pests has been achieved.

CN119540523BActive Publication Date: 2025-10-24SOUTH CHINA AGRICULTURAL UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411526135.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2025-10-24
Estimated Expiration
2044-10-30

AI Technical Summary

Technical Problem

In existing technologies, the detection accuracy of crop pest detection methods is low for small and medium-sized target pests, making it difficult to achieve efficient and accurate detection.

Method used

A small-target pest detection method is adopted, which includes acquiring a crop pest dataset, preprocessing, constructing a small-target pest detection model (backbone network, feature fusion network, and detection head network), setting a total loss function to train the model, and obtaining the final detection result through non-maximum suppression (NMS). Combined with an improved backbone network, feature fusion, and detection head network structure, the feature extraction and detection accuracy are enhanced.

Benefits of technology

It improves the detection accuracy of small target pests, enhances the robustness of the model, reduces overfitting, and achieves accurate and rapid detection of small target pests in crops.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119540523B_ABST
    Figure CN119540523B_ABST
Patent Text Reader

Abstract

The application discloses a kind of small target pest detection method and system for crops, it is related to the technical field of computer vision and target detection, including obtaining crop pest dataset, including several crop pest images with pest annotation;Crop pest dataset is preprocessed, obtain the preprocessed crop pest dataset, input small target pest detection model, set total loss function and train, when total loss function value is minimum, obtain the trained small target pest detection model;Obtain the crop image to be detected, input the trained small target pest detection model, obtain the detection result and positioning result of all pests in the crop image to be detected, and carry out NMS non-maximum suppression, obtain the final pest detection result of the crop image to be detected.The application can accurately and quickly detect small target pests in crops.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer vision and object detection, and more particularly, to a small target pest detection method and system for crops. BACKGROUND

[0002] Pests can cause serious harm to crop production, leading to crop reduction or even destruction. Therefore, it is necessary to develop efficient and accurate pest detection methods to timely release pest monitoring information and help farmers and relevant management departments take timely measures to avoid major losses caused by pest outbreaks. At present, China mainly uses manual methods for pest monitoring. However, manual pest monitoring consumes a large amount of manpower and financial resources, and cannot guarantee detection accuracy. To solve this problem, with the development of machine vision, image processing and other technologies, researchers have proposed various automatic crop pest detection methods, which have better compensated for the drawbacks of manual methods.

[0003] Early crop pest detection methods were mainly based on traditional machine learning, which relied on manual feature design and detection performance depended on the designed manual features, so the overall detection performance was affected to a certain extent. In recent years, the development of crop pest detection methods based on deep learning has become a better option. Deep learning-based target detection algorithms can automatically extract features, mainly divided into two categories: two-stage-based target detection methods and single-stage-based target detection methods. Two-stage-based crop pest detection methods have high accuracy, but slow detection speed. Single-stage-based crop pest detection methods have slightly lower accuracy, but faster detection speed, and are suitable for real-time pest detection tasks with high requirements. Given the latter's better detection accuracy and faster detection speed, single-stage detection methods are widely used in pest detection.

[0004] Although some progress has been made in crop pest detection methods based on deep learning in recent years, due to the multi-scale distribution of pests in the image dataset and the presence of many small target pests, the detection accuracy of large target pests is high, but there is still much room for improvement in the detection accuracy of small and medium target pests. SUMMARY

[0005] One of the purposes of the present application is to provide a small target pest detection method for crops to overcome the low detection accuracy of small and medium target pests in the prior art. The second purpose is to provide a small target pest detection system for crops. The third purpose is to provide a computer device.

[0006] To solve the above technical problems, the technical solutions of the present application are as follows:

[0007] The application provides a small target pest detection method for crops, comprising:

[0008] S1: obtaining a crop pest data set comprising a plurality of crop pest images with pest annotations;

[0009] S2: preprocessing the crop pest data set to obtain a preprocessed crop pest data set;

[0010] S3: constructing a small target pest detection model comprising a backbone network, a feature fusion network and a detection head network connected in sequence;

[0011] S4: inputting the preprocessed crop pest data set into the small target pest detection model, setting a total loss function for training, and obtaining a trained small target pest detection model when the total loss function value is minimum;

[0012] S5: obtaining a crop image to be detected and inputting it into the trained small target pest detection model to obtain detection results and positioning results of all pests in the crop image to be detected;

[0013] S6: performing NMS non-maximum suppression on the detection results and positioning results of all pests to obtain final pest detection results of the crop image to be detected.

[0014] Preferably, the preprocessing comprises any one or more of horizontal flipping, vertical flipping, random rotation, random cropping, deformation scaling, HSV transformation and mosaic enhancement.

[0015] Preferably, the backbone network comprises a first convolutional layer, a first batch normalization layer, a first activation function layer, a maximum pooling layer, a first feature extraction unit, a second feature extraction unit, a third feature extraction unit and a fourth feature extraction unit connected in sequence; the output ends of the second feature extraction unit, the third feature extraction unit and the fourth feature extraction unit are connected to the input end of the feature fusion network.

[0016] The first feature extraction unit, the second feature extraction unit, the third feature extraction unit and the fourth feature extraction unit each comprise a plurality of neck subunits connected in sequence.

[0017] The neck subunit comprises a first dynamic convolutional layer, a second batch normalization layer, a second dynamic convolutional layer, a third batch normalization layer, a third dynamic convolutional layer, a fourth batch normalization layer, a first addition point and a second activation function layer connected in sequence; the input end of the first dynamic convolutional layer is also connected to the input end of the first addition point.

[0018] It should be noted that the backbone network is improved based on the ResNet50 neural network, the first 44 layers of the ResNet50 neural network are retained, and a full-dimensional dynamic convolution layer is introduced to replace the traditional convolution layer; the backbone network of the present application is pruned for the characteristics of small target pests on the ResNet50 neural network, and a full-dimensional dynamic convolution is introduced, by pruning the network layer with the largest parameter quantity but the least feature extraction, the difficulty of training the backbone network is reduced, and the feature extraction capability of the backbone network for small target pests is enhanced.

[0019] Preferably, the feature fusion network comprises a first CBS block, a first upsampling layer, a second addition point, a second convolution layer, a third convolution layer, a fourth convolution layer, a second CBS block, a second upsampling layer, a third addition point, a fifth convolution layer, a sixth convolution layer, a seventh convolution layer, a third CBS block, a fourth addition point, an eighth convolution layer, a ninth convolution layer, a tenth convolution layer, a fourth CBS block, a fifth addition point, an eleventh convolution layer, a twelfth convolution layer and a thirteenth convolution layer connected in sequence;

[0020] The input end of the first CBS block is connected with the output end of the fourth feature extraction unit, and the output end of the first CBS block is also connected with the input end of the fifth addition point; the input end of the second addition point is also connected with the output end of the third feature extraction unit; the output end of the second CBS block is also connected with the input end of the fourth addition point; the input end of the third addition point is also connected with the output end of the second feature extraction unit;

[0021] The output ends of the seventh convolution layer, the tenth convolution layer and the thirteenth convolution layer are all connected with the input end of the detection head network.

[0022] It should be noted that the first CBS block, the first upsampling layer, the second addition point, the second convolution layer, the third convolution layer, the fourth convolution layer, the second CBS block, the second upsampling layer and the third addition point form a pyramid feature fusion network structure, which is used for preliminarily fusing the feature information extracted by the second feature extraction unit, the third feature extraction unit and the fourth feature extraction unit, and transmitting the fused feature information from top to bottom; the fifth convolution layer, the sixth convolution layer, the seventh convolution layer, the third CBS block, the fourth addition point, the eighth convolution layer, the ninth convolution layer, the tenth convolution layer, the fourth CBS block, the fifth addition point, the eleventh convolution layer, the twelfth convolution layer and the thirteenth convolution layer form a path aggregation network structure, which is used for receiving the fused feature information transmitted by the pyramid feature fusion network structure, and transmitting the feature information from bottom to top.

[0023] Preferably, the detection head network comprises a first decoupling head unit, a second decoupling head unit and a third decoupling head unit arranged side by side, and the input ends of the first decoupling head unit, the second decoupling head unit and the third decoupling head unit are all connected with the output ends of the seventh convolution layer, the tenth convolution layer and the thirteenth convolution layer.

[0024] The first decoupling head unit, the second decoupling head unit and the third decoupling head unit are structurally identical, and each includes a classification task decoupling head branch unit, a positioning task decoupling head branch unit and a confidence decoupling head branch unit arranged side by side;

[0025] The classification task decoupling head branch unit includes a first reshaping layer, a first fully connected layer, a second fully connected layer, a third fully connected layer and a second reshaping layer connected in sequence; the input end of the first reshaping layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer;

[0026] The positioning task decoupling head branch unit includes a fourteenth convolutional layer, a fifteenth convolutional layer and a sixteenth convolutional layer connected in sequence; the input end of the fourteenth convolutional layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer;

[0027] The confidence decoupling head branch unit includes a third reshaping layer, a fourth fully connected layer, a fifth fully connected layer and a fourth reshaping layer connected in sequence; the input end of the third reshaping layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer.

[0028] It should be noted that the classification task decoupling head branch unit is used to obtain the classification result of the small target pest in the crop image, the positioning task decoupling head branch unit is used to obtain the positioning result of the small target pest in the crop image, and the confidence decoupling head branch unit is used to obtain the confidence result. The detection head network adopts three parallel decoupling head structures, which decouples the classification and positioning tasks, provides better bounding box information and more accurate loss evaluation for small target pests, and improves the detection accuracy of small target pests; the decoupling head structure reduces the number of parameters and the amount of calculation of the model, greatly speeds up the training and inference speed of the model, improves the perception ability of the model to target features of different scales, and thus improves the robustness and accuracy of the model and reduces the occurrence of overfitting.

[0029] Preferably, the total loss function includes:

[0030]

[0031] In the formula, Loss represents the total loss function, N represents the number of detection layers, L cls represents the classification loss function, L obj represents the confidence loss function, L box represents the positioning loss function, and λ1, λ2 and λ3 represent the first weight, the second weight and the third weight, respectively.

[0032] Preferably, the classification loss function includes:

[0033]

[0034] wherein L cls represents a classification loss function, M represents a total number of pest categories, y j represents a probability of being predicted as the jthcategory, represents a true value of the jthcategory.

[0035] Preferably, the positioning loss function comprises:

[0036] L box = αL NWD +(1-α)L MPDIoU

[0037] wherein L box represents a positioning loss function, L NWD represents a first bounding box similarity loss function, L MPDIoU represents a second bounding box similarity loss function, and a represents a weight; wherein:

[0038] L NWD = 1-NWD

[0039]

[0040] wherein NWD represents a normalized Wasserstein distance between a predicted bounding box and a true bounding box, x, y respectively represent horizontal and vertical coordinates of a center point of the predicted bounding box, w, h respectively represent a width and a height of the predicted bounding box, x gt ,y gt respectively represent horizontal and vertical coordinates of a center point of the true bounding box, w gt ,h gt respectively represent a width and a height of the true bounding box, and C represents a constant;

[0041] L MPDIoU = 1-MPDIoU

[0042]

[0043] wherein MPDIoU represents a minimum distance between a top-left corner and a bottom-right corner of a predicted bounding box and a true bounding box, IoU represents an intersection over union of a predicted bounding box and a true bounding box, w p ,h p respectively represent a width and a height of a crop pest image, d1 represents a Euclidean distance between a top-left corner of a predicted bounding box and a top-left corner of a true bounding box, and d2 represents a Euclidean distance between a bottom-right corner of a predicted bounding box and a bottom-right corner of a true bounding box.

[0044] It should be noted that the present application improves the positioning loss function, combines the NWD loss and the MPDIoU loss, reduces the sensitivity of the MPDIoU loss to small target objects, and is more suitable for small target pest detection tasks. After the combination of the two, the factors such as overlapping or non-overlapping area, center point distance, width and height deviation are considered, and the detection model can be effectively optimized under the same aspect ratio; and the small target distribution similarity is measured with the assistance of the Wasserstein distance measurement, the small target pest detection accuracy is improved, and the detection accuracy of the detection model is further improved.

[0045] The present application also provides a small target pest detection system for crops, which is used to realize the small target pest detection method for crops.

[0046] A data acquisition module is configured to acquire a crop pest data set, wherein the crop pest data set includes a plurality of crop pest images with pest annotations.

[0047] A data preprocessing module is configured to preprocess the crop pest data set to obtain a preprocessed crop pest data set.

[0048] A model construction module is configured to construct a small target pest detection model, including a backbone network, a feature fusion network and a detection head network connected in sequence.

[0049] A model training module is configured to input the preprocessed crop pest data set into the small target pest detection model, set a total loss function for training, and obtain a trained small target pest detection model when the total loss function value is minimum.

[0050] A pest detection unit is configured to acquire a crop image to be detected, input the crop image to be detected into the trained small target pest detection model, and obtain detection results and positioning results of all pests in the crop image to be detected.

[0051] A final detection unit is configured to perform NMS non-maximum suppression on the detection results and positioning results of all pests to obtain final pest detection results of the crop image to be detected.

[0052] The present application also provides a computer device including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the small target pest detection method for crops when executing the computer program.

[0053] Compared with the prior art, the technical scheme of the present application has the following beneficial effects:

[0054] The present invention first obtains several crop pest images with pest labels to form a crop pest dataset. The crop pest dataset is then preprocessed and input into a small-target pest detection model. A total loss function is set for training. When the total loss function value is minimized, a trained small-target pest detection model is obtained. The established small-target pest detection model includes a backbone network, a feature fusion network, and a detection head network, which are connected in sequence for feature extraction, feature fusion, and classification and localization of small-target pests, respectively. This enhances the feature extraction capability of small-target pests and fully integrates the multi-scale features of small-target pests. The total loss function is more suitable for small-target pest detection, improving the detection accuracy of small-target pests, enhancing the robustness of the model, and reducing the occurrence of overfitting. Finally, the crop image to be detected is input into the trained small-target pest detection model to obtain detection results and localization results for all pests in the crop image to be detected. NMS non-maximum suppression is then performed to obtain the final pest detection result for the crop image to be detected. The present invention can achieve accurate and rapid detection of small-target pests in crops. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] Figure 1 This is a flow chart of a small-target pest detection method for crops described in Example 1;

[0056] Figure 2 This is a schematic diagram of the structure of the small target pest detection model described in Example 2;

[0057] Figure 3 This is a schematic diagram of the backbone network structure described in Example 2;

[0058] Figure 4 This is a schematic structural diagram of the neck subunit described in Example 2;

[0059] Figure 5 This is a schematic diagram of the structure of the fusion network described in Example 2;

[0060] Figure 6 This is a schematic diagram of the structure of the detection head network described in Example 2;

[0061] Figure 7 This is a schematic structural diagram of the first decoupling head unit, the second decoupling head unit, and the third decoupling head unit described in Example 2;

[0062] Figure 8 This is a schematic structural diagram of a small-target pest detection system for crops described in Example 3;

[0063] Figure 9 This is a structural diagram of a computer device described in Example 3. DETAILED DESCRIPTION

[0064] The accompanying drawings are only used for illustrative purposes and cannot be understood as limiting the patent;

[0065] In order to better illustrate the embodiments, some components in the drawings may be omitted, enlarged or reduced, and do not represent the actual size of the product;

[0066] For those skilled in the art, it is understandable that some well-known structures and their descriptions in the drawings may be omitted.

[0067] The technical solutions of the present application will be further described below in combination with the drawings and embodiments.

[0068] Embodiment 1

[0069] The present embodiment provides a small target pest detection method for crops, as shown in Figure 1 , comprising:

[0070] S1: Obtain a crop pest data set, wherein the crop pest data set comprises a plurality of crop pest images with pest annotations;

[0071] S2: Preprocess the crop pest data set to obtain a preprocessed crop pest data set;

[0072] S3: Construct a small target pest detection model, comprising a backbone network, a feature fusion network and a detection head network connected in sequence;

[0073] S4: Input the preprocessed crop pest data set into the small target pest detection model, set the total loss function for training, and obtain the trained small target pest detection model when the total loss function value is minimum;

[0074] S5: Obtain the crop image to be detected and input it into the trained small target pest detection model to obtain the detection result and positioning result of all pests in the crop image to be detected;

[0075] S6: Perform NMS non-maximum suppression on the detection result and positioning result of all pests to obtain the final pest detection result of the crop image to be detected.

[0076] In the implementation process, the embodiment first acquires a plurality of crop pest images with pest annotations to form a crop pest dataset; then inputs the preprocessed crop pest dataset into a small target pest detection model, sets a total loss function for training, and obtains the trained small target pest detection model when the total loss function value is minimum; the established small target pest detection model includes a backbone network, a feature fusion network and a detection head network connected in sequence, which are respectively used for feature extraction, feature fusion and classification and positioning of small target pests, enhance the feature extraction capability of small target pests, fully fuse the multi-scale features of small target pests, set the total loss function more suitable for small target pest detection, improve the detection accuracy of small target pests, improve the robustness of the model, and reduce the occurrence of overfitting. Finally, the crop image to be detected is input into the trained small target pest detection model to obtain the detection result and positioning result of all pests in the crop image to be detected, and NMS non-maximum suppression is performed to obtain the final pest detection result of the crop image to be detected. The embodiment can accurately and quickly detect small target pests in crops.

[0077] Embodiment 2

[0078] The embodiment provides a small target pest detection method for crops, which comprises the following steps:

[0079] S1: acquiring a crop pest dataset, wherein the crop pest dataset comprises a plurality of crop pest images with pest annotations;

[0080] S2: preprocessing the crop pest dataset to obtain a preprocessed crop pest dataset;

[0081] The preprocessing includes any one or more of horizontal flipping, vertical flipping, random rotation, random cropping, deformation scaling, HSV transformation and mosaic enhancement;

[0082] S3: constructing a small target pest detection model, as shown in Figure 2 The small target pest detection model comprises a backbone network, a feature fusion network and a detection head network connected in sequence;

[0083] As shown in Figure 3 The backbone network comprises a first convolutional layer, a first batch normalization layer, a first activation function layer, a maximum pooling layer, a first feature extraction unit, a second feature extraction unit, a third feature extraction unit and a fourth feature extraction unit connected in sequence; the output ends of the second feature extraction unit, the third feature extraction unit and the fourth feature extraction unit are connected with the input end of the feature fusion network;

[0084] The first feature extraction unit, the second feature extraction unit, the third feature extraction unit and the fourth feature extraction unit each comprise a plurality of neck sub-units connected in sequence; in the embodiment, the first feature extraction unit comprises 3 neck sub-units connected in sequence, the first feature extraction unit comprises 3 neck sub-units connected in sequence, the second feature extraction unit comprises 6 neck sub-units connected in sequence, the third feature extraction unit comprises 4 neck sub-units connected in sequence, and the fourth feature extraction unit comprises 1 neck sub-unit.

[0085] As shown in Figure 4 , the neck sub-unit comprises a first dynamic convolution layer, a second batch normalization layer, a second dynamic convolution layer, a third batch normalization layer, a third dynamic convolution layer, a fourth batch normalization layer, a first addition point and a second activation function layer connected in sequence; the input end of the first dynamic convolution layer is also connected with the input end of the first addition point.

[0086] It should be noted that the backbone network is improved based on the ResNet50 neural network, the first 44 layers of the ResNet50 neural network are retained, and a full-dimensional dynamic convolution layer is introduced to replace the traditional convolution layer; wherein the first convolution layer is a 7x7 convolution layer, the first dynamic convolution layer is a 1x1 dynamic convolution layer, the second dynamic convolution layer is a 3x3 dynamic convolution layer, the third dynamic convolution layer is a 1x1 dynamic convolution layer, the first activation function layer and the second activation function layer are both ReLU activation function layers, and the dynamic convolution layers are all full-dimensional dynamic convolutions, which can be expressed by the following formula:

[0087] f=(a ω1 ⊙a f1 ⊙a c1 ⊙a s1 ⊙W1+…+a ωn ⊙a fn ⊙a cn ⊙a sn ⊙W n )*f i

[0088] wherein, and are input features and output features respectively, is the i-th convolution kernel composed of C out filter, is an attention scalar of the convolution kernel, The three scalars of interest are the newly introduced spatial dimension, input channel dimension, and output channel dimension, respectively. ⊙ represents element-wise multiplication in the newly introduced three-dimensional kernel space, and * represents a convolution operation. The backbone network of this application tailors the ResNet50 neural network to the characteristics of small-target pests and introduces full-dimensional dynamic convolution. By trimming the network layers with the most parameters but the fewest extracted features, the backbone network training difficulty is reduced and its feature extraction capability for small-target pests is enhanced.

[0089] like Figure 5 As shown, the feature fusion network includes a first CBS block, a first upsampling layer, a second summing point, a second convolutional layer, a third convolutional layer, a fourth convolutional layer, a second CBS block, a second upsampling layer, a third summing point, a fifth convolutional layer, a sixth convolutional layer, a seventh convolutional layer, a third CBS block, a fourth summing point, an eighth convolutional layer, a ninth convolutional layer, a tenth convolutional layer, a fourth CBS block, a fifth summing point, an eleventh convolutional layer, a twelfth convolutional layer, and a thirteenth convolutional layer, which are connected in sequence;

[0090] The input end of the first CBS block is connected to the output end of the fourth feature extraction unit, and the output end of the first CBS block is also connected to the input end of the fifth summing point; the input end of the second summing point is also connected to the output end of the third feature extraction unit; the output end of the second CBS block is also connected to the input end of the fourth summing point; the input end of the third summing point is also connected to the output end of the second feature extraction unit;

[0091] The output ends of the seventh convolutional layer, the tenth convolutional layer, and the thirteenth convolutional layer are all connected to the input end of the detection head network.

[0092] It should be noted that the first CBS block, the first upsampling layer, the second summing point, the second convolutional layer, the third convolutional layer, the fourth convolutional layer, the second CBS block, the second upsampling layer, and the third summing point form a pyramid feature fusion network structure, which is used to preliminarily fuse the feature information extracted by the second feature extraction unit, the third feature extraction unit, and the fourth feature extraction unit, and transmit the fused feature information from top to bottom; the fifth convolutional layer, the sixth convolutional layer, the seventh convolutional layer, the third CBS block, the fourth summing point, the eighth convolutional layer, the ninth convolutional layer, the tenth convolutional layer, the fourth CBS block, the fifth summing point, the eleventh convolutional layer, the twelfth convolutional layer, and the thirteenth convolutional layer form a path aggregation network structure, which is used to receive the fused feature information transmitted by the pyramid feature fusion network structure, and transmit the feature information from bottom to top, and add and connect.

[0093] like Figure 6As shown, the detection head network includes the first decoupling head unit, the second decoupling head unit and the third decoupling head unit arranged side by side, and the input ends of the first decoupling head unit, the second decoupling head unit and the third decoupling head unit are connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer.

[0094] As shown in Figure 7 The first decoupling head unit, the second decoupling head unit and the third decoupling head unit have the same structure and each include the classification task decoupling head branch unit, the positioning task decoupling head branch unit and the confidence decoupling head branch unit arranged side by side.

[0095] The classification task decoupling head branch unit includes the first reshaping layer, the first full connection layer, the second full connection layer, the third full connection layer and the second reshaping layer connected in sequence, and the input end of the first reshaping layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer.

[0096] The positioning task decoupling head branch unit includes the fourteenth convolutional layer, the fifteenth convolutional layer and the sixteenth convolutional layer connected in sequence, and the input end of the fourteenth convolutional layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer.

[0097] The confidence decoupling head branch unit includes the third reshaping layer, the fourth full connection layer, the fifth full connection layer and the fourth reshaping layer connected in sequence, and the input end of the third reshaping layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer.

[0098] It should be noted that the classification task decoupling head branch unit is used to obtain the classification result of the small target pest in the crop image, the positioning task decoupling head branch unit is used to obtain the positioning result of the small target pest in the crop image, and the confidence decoupling head branch unit is used to obtain the confidence result. The detection head network adopts three parallel decoupling head structures, decouples the classification and positioning tasks, provides better bounding box information and more accurate loss evaluation for the small target pest, and improves the detection accuracy of the small target pest. The decoupling head structure reduces the number of parameters and the amount of calculation of the model, greatly speeds up the training and inference speed of the model, improves the perception ability of the model to target features of different scales, and thus improves the robustness and accuracy of the model and reduces the occurrence of overfitting.

[0099] S4: inputting the preprocessed crop pest data set into the small target pest detection model, setting a total loss function for training, and obtaining a trained small target pest detection model when the total loss function value is the smallest;

[0100] The total loss function includes three parts, namely a classification loss function, a confidence loss function and a positioning loss function, and is expressed as:

[0101]

[0102] wherein, Loss represents a total loss function, N represents a number of detection layers, L cls represents a classification loss function, L obj represents a confidence loss function, L box represents a positioning loss function, λ1, λ2, λ3 represent a first weight, a second weight and a third weight respectively;

[0103] The classification loss function adopts a binary cross-entropy loss function, which is represented as:

[0104]

[0105] wherein, L cls represents a classification loss function, M represents a total number of pest categories, y j represents a probability of being predicted as the jth category, represents a true value of the jth category, which is 0 or 1, x i is a current category prediction value;

[0106] The positioning loss function is an NMIoU function which combines NWD loss and MPDIoU loss, which is represented as:

[0107] L box = αL NWD +(1-α)L MPDIoU

[0108] L NWD = 1-NWD

[0109]

[0110] L MPDIoU = 1-MPDIoU

[0111]

[0112] wherein, L box represents a positioning loss function, L NWD represents a first bounding box similarity loss function, L MPDIoU represents a second bounding box similarity loss function, α represents a weight, NWD represents a normalized Wasserstein distance between a predicted bounding box and a real bounding box, x, y respectively represent horizontal and vertical coordinates of a center point of the predicted bounding box, w, h respectively represent width and height of the predicted bounding box, x gt , y gt respectively represent horizontal and vertical coordinates of a center point of the real bounding box, w gt , h gtrespectively represent the width and height of the real bounding box, C represents a constant; MPDIoU represents minimizing the distance between the top-left corner and the bottom-right corner of the predicted bounding box and the real bounding box, IoU represents calculating the intersection over union of the predicted bounding box and the real bounding box, w p ,h p respectively represent the width and height of the crop pest image, d1 represents the Euclidean distance between the top-left corner of the predicted bounding box and the top-left corner of the real bounding box, and d2 represents the Euclidean distance between the bottom-right corner of the predicted bounding box and the bottom-right corner of the real bounding box;

[0113] The present application improves the positioning loss function, combines the NWD loss and the MPDIoU loss, reduces the sensitivity of the MPDIoU loss to small target objects, and is more suitable for small target pest detection tasks. After the combination of the two, not only the factors such as overlapping or non-overlapping area, center point distance, width and height deviation are considered, but also the small target distribution similarity is measured with the assistance of the Wasserstein distance measurement, the small target pest detection accuracy is improved, and the detection accuracy of the detection model is further improved.

[0114] S5: Obtain the crop image to be detected, input the trained small target pest detection model, and obtain the detection result and the positioning result of all pests in the crop image to be detected;

[0115] S6: Perform NMS non-maximum suppression on the detection result and the positioning result of all pests to obtain the final pest detection result of the crop image to be detected.

[0116] In actual use, during model training, after the preprocessed crop pest dataset is input into the small target pest detection model, N crop pest images are randomly extracted and sequentially pass through the backbone network, the feature fusion network and the detection head network to obtain preliminary prediction results. The prediction results are compared with the pest labels, the total loss function value is calculated, and the model parameters are updated by backpropagation gradient according to the total loss function value. The above process is repeated until the total loss function value no longer decreases, the final model parameters are saved, and the trained small target pest detection model is obtained. Then, N crop pest images are randomly extracted and input into the trained small target pest detection model to obtain the pest detection result, and the evaluation index mAP of the model is calculated according to the pest detection result and the pest label. When testing the model performance, the evaluation index mAP is used to measure the average precision of the model in multi-class target detection. The higher the value, the higher the overall precision of the algorithm. The mAP is represented as:

[0117]

[0118] Wherein, c represents the number of categories; AP jThe average accuracy of each category can be obtained by calculating the area surrounded by the different classification accuracy-recall rate curves and the coordinate axes, and is represented as:

[0119] AP j =∫0 1 p(r)dr

[0120] where p(r) is a classification accuracy-recall rate PR curve function controlled by a preset prediction bounding box and an intersection over union IoU threshold value; by using different IoU settings, different PR curves can be drawn to calculate the mAP under different IoUs; the mAP when the IoU setting is 0.5, and the average mAP when the IoU setting is in the range from 0.5 to 0.95 (with a step of 0.05) are used as the final evaluation indicators.

[0121] In addition, the detection results of the method provided in the embodiment and other mainstream models are compared on a main vegetable pest data set. The main vegetable pest data set includes crop pest images and corresponding pest annotations, the annotation format is consistent with Pascal VOC, and the pest categories include: category 1: Linnaeus, category 2: Gennadius, category 3: Coquillett, category 4: Fabricius, and category 5: Frankliniella occidentalis Pergande. FPS is the number of pictures processed per second, and the detection results are as shown in the following table:

[0122]

[0123] It can be seen that compared with other mainstream models, the method provided in the embodiment achieves the highest detection accuracy in the pest categories other than the Fabricius category.

[0124] At the same time, the embodiment also performs verification experiments on the effectiveness of different improvement strategies, where A represents the use of the backbone network described in the embodiment, B represents the use of the detection head network described in the embodiment, and C represents the use of the positioning loss function NMIoU described in the embodiment. The comparison results are as shown in the following table:

[0125]

[0126] It can be seen that, by improving the backbone network for feature extraction, the detection head network for detection, and the positioning loss function at the same time, the classification and positioning tasks are more focused on the respective targets, the branches are calculated independently, mutual interference is avoided, the accuracy and efficiency of detection are improved, the decoupling head structure reduces the number of parameters and the amount of calculation in the model, greatly speeds up the training and inference speed of the model, improves the perception ability of the model to target features of different scales, thereby improving the robustness and accuracy of the model, and reducing the occurrence of overfitting.

[0127] Embodiment 3

[0128] The embodiment provides a small target pest detection system for crops, which is used for implementing the small target pest detection method for crops in the embodiments 1 or 2, and as shown in the accompanying drawings, comprises: Figure 8

[0129] A data acquisition module is configured to acquire a crop pest data set, wherein the crop pest data set comprises a plurality of crop pest images with pest annotations;

[0130] A data preprocessing module is configured to preprocess the crop pest data set to obtain a preprocessed crop pest data set;

[0131] A model construction module is configured to construct a small target pest detection model, which comprises a backbone network, a feature fusion network and a detection head network connected in sequence;

[0132] A model training module is configured to input the preprocessed crop pest data set into the small target pest detection model, set a total loss function for training, and obtain a trained small target pest detection model when the total loss function value is the smallest;

[0133] A pest detection unit is configured to acquire a crop image to be detected, input the crop image to be detected into the trained small target pest detection model, and obtain detection results and positioning results of all pests in the crop image to be detected;

[0134] A final detection unit is configured to perform NMS (Non-Maximum Suppression) on the detection results and the positioning results of all pests to obtain final pest detection results of the crop image to be detected.

[0135] The embodiment also provides a computer device, as shown in the accompanying drawings, comprising at least one processor 01, at least one communication interface 02, at least one memory 03 and at least one communication bus 04. Figure 9

[0136] ​​In the embodiments of the present application, the number of the processor 01, the communication interface 02, the memory 03 and the communication bus 04 is at least one, and the processor 01, the communication interface 02 and the memory 03 complete the communication with each other through the communication bus 04.

[0137] The processor 01 can include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 01 can be implemented in at least one of a hardware form of a Digital Signal Processor (DSP), a Field-Programmable Gate Array (FPGA), and a Programmable Logic Array (PLA). The processor 01 can also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a Central Processing Unit (CPU); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 01 can be integrated with a Graphics Processing Unit (GPU), which is used to render and draw the content required to be displayed by the display screen. In some embodiments, the processor 01 can also include an Artificial Intelligence (AI) processor, which is used to process computing operations related to machine learning.

[0138] The memory 03 can include one or more computer-readable storage media, which can be non-transitory. The memory 03 can also include a high-speed random access memory, and a nonvolatile memory such as one or more disk storage devices, flash storage devices.

[0139] The memory 03 stores a program, and the processor 01 can call the program stored in the memory 03. The program is used to execute the steps of the crop-oriented small target pest detection method in embodiments 1 or 2.

[0140] The same or similar reference numerals correspond to the same or similar components;

[0141] The terms describing the positional relationship in the drawings are only used for exemplary illustration, and cannot be understood as a limitation to the present patent;

[0142] Obviously, the above embodiments of the present application are merely exemplary but not intended to limit the embodiments of the present application. Based on the above description, any other variations or changes can be made by those skilled in the art without departing from the spirit and principles of the present application. It is not necessary to list all the embodiments here. Any modifications, equivalent replacements, and improvements made within the spirit and principles of the present application should be included in the protection scope of the claims of the present application.

Claims

1. A method for detecting small target pests in crops, characterized by, The method comprises the following steps: S1: obtaining a crop pest data set comprising a plurality of crop pest images with pest annotations; S2: preprocessing the crop pest data set to obtain a preprocessed crop pest data set; S3: constructing a small target pest detection model comprising a backbone network, a feature fusion network, and a detection head network connected in sequence; The backbone network comprises a first convolutional layer, a first batch normalization layer, a first activation function layer, a max pooling layer, a first feature extraction unit, a second feature extraction unit, a third feature extraction unit, and a fourth feature extraction unit connected in sequence; the output ends of the second, third, and fourth feature extraction units are connected to the input end of the feature fusion network; Each of the first, second, third, and fourth feature extraction units comprises a plurality of neck subunits connected in sequence; The neck subunit comprises a first dynamic convolutional layer, a second batch normalization layer, a second dynamic convolutional layer, a third batch normalization layer, a third dynamic convolutional layer, a fourth batch normalization layer, a first addition point, and a second activation function layer connected in sequence; the input end of the first dynamic convolutional layer is also connected to the input end of the first addition point; S4: inputting the preprocessed crop pest data set into the small target pest detection model, setting a total loss function for training, and obtaining a trained small target pest detection model when the total loss function value is the smallest; S5: obtaining a crop image to be detected and inputting it into the trained small target pest detection model to obtain detection results and positioning results of all pests in the crop image to be detected; S6: performing NMS non-maximum suppression on the detection results and positioning results of all pests to obtain the final pest detection results of the crop image to be detected.

2. The crop-oriented small target pest detection method according to claim 1, characterized by, The preprocessing includes any one or more of horizontal flipping, vertical flipping, random rotation, random cropping, deformation scaling, HSV transformation, and mosaic enhancement.

3. The crop-oriented small target pest detection method according to claim 1, characterized by, The feature fusion network comprises a first CBS block, a first upsampling layer, a second addition point, a second convolutional layer, a third convolutional layer, a fourth convolutional layer, a second CBS block, a second upsampling layer, a third addition point, a fifth convolutional layer, a sixth convolutional layer, a seventh convolutional layer, a third CBS block, a fourth addition point, an eighth convolutional layer, a ninth convolutional layer, a tenth convolutional layer, a fourth CBS block, a fifth addition point, an eleventh convolutional layer, a twelfth convolutional layer, and a thirteenth convolutional layer connected in sequence; The input end of the first CBS block is connected to the output end of the fourth feature extraction unit, and the output end of the first CBS block is also connected to the input end of the fifth addition point; the input end of the second addition point is also connected to the output end of the third feature extraction unit; the output end of the second CBS block is also connected to the input end of the fourth addition point; and the input end of the third addition point is also connected to the output end of the second feature extraction unit; The output ends of the seventh, tenth, and thirteenth convolutional layers are connected to the input end of the detection head network.

4. The crop-oriented small target pest detection method according to claim 3, characterized by, The detection head network comprises the first decoupling head unit, the second decoupling head unit and the third decoupling head unit arranged side by side; the input ends of the first decoupling head unit, the second decoupling head unit and the third decoupling head unit are connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer; The first decoupling head unit, the second decoupling head unit and the third decoupling head unit are of the same structure and each comprises the classification task decoupling head branch unit, the positioning task decoupling head branch unit and the confidence decoupling head branch unit arranged side by side; The classification task decoupling head branch unit comprises the first reshaping layer, the first full connection layer, the second full connection layer, the third full connection layer and the second reshaping layer connected in sequence; the input end of the first reshaping layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer; The positioning task decoupling head branch unit comprises the fourteenth convolutional layer, the fifteenth convolutional layer and the sixteenth convolutional layer connected in sequence; the input end of the fourteenth convolutional layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer; The confidence decoupling head branch unit comprises the third reshaping layer, the fourth full connection layer, the fifth full connection layer and the fourth reshaping layer connected in sequence; the input end of the third reshaping layer is connected with the output ends of the seventh convolutional layer, the tenth convolutional layer and the thirteenth convolutional layer.

5. The crop-oriented small target pest detection method according to claim 1, wherein The total loss function comprises: In the formula, Loss represents a total loss function, N represents a number of detection layers, L cls represents a classification loss function, L obj represents a confidence loss function, L box represents a positioning loss function, λ1, λ2, and λ3 represent a first weight, a second weight, and a third weight, respectively.

6. The crop-oriented small target pest detection method according to claim 5, wherein The classification loss function comprises: In the formula, L cls represents a classification loss function, M represents the total number of pest categories, y j represents the probability of being predicted as the jth category, represents the true value of the jth category.

7. The crop-oriented small target pest detection method according to claim 5, wherein The positioning loss function comprises: L box = aL NWD + (1 - a)L MPDIoU In the formula, L box represents the positioning loss function, L NWD represents the first bounding box similarity loss function, L MPDIoU represents the second bounding box similarity loss function, and a represents a weight; wherein: L NWD = 1 - NWD Where NWD represents the normalized Wasserstein distance between the predicted bounding box and the true bounding box, x, y represent the horizontal and vertical coordinates of the center point of the predicted bounding box, w, h represent the width and height of the predicted bounding box, and x gt ,y gt Respectively represent the horizontal and vertical coordinates of the center point of the real bounding box, w gt ,h gt Represent the width and height of the real bounding box respectively, and C represents a constant; L MPDIoU = 1-MPDIoU where MPDIoU represents minimizing the distance between the left upper corner vertex and the right lower corner vertex of the prediction bounding box and the real bounding box, IoU represents calculating the intersection over union of the prediction bounding box and the real bounding box, w p ,h p respectively represent the width and height of the crop pest image, d1 represents the Euclidean distance between the left upper corner vertex of the prediction bounding box and the left upper corner vertex of the real bounding box, and d2 represents the Euclidean distance between the right lower corner vertex of the prediction bounding box and the right lower corner vertex of the real bounding box.

8. A crop-oriented small target pest detection system for implementing the crop-oriented small target pest detection method according to any one of claims 1 to 7, characterized by, comprises: The data acquisition module is used to acquire a crop pest data set, and the crop pest data set comprises a plurality of crop pest images with pest annotations; The data preprocessing module is used to preprocess the crop pest data set to obtain a preprocessed crop pest data set; The model construction module is used to construct a small target pest detection model, comprising a backbone network, a feature fusion network and a detection head network connected in sequence; The model training module is used to input the preprocessed crop pest data set into the small target pest detection model, set a total loss function for training, and obtain a trained small target pest detection model when the total loss function value is the smallest; The pest detection unit is used to acquire a crop image to be detected, input the trained small target pest detection model, and obtain detection results and positioning results of all pests in the crop image to be detected; The final detection unit is used to perform NMS non-maximum suppression on the detection results and the positioning results of all pests to obtain final pest detection results of the crop image to be detected. 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The processor executes the computer program to implement the steps of the crop-oriented small target pest detection method in any one of claims 1-7.

Citation Information

Patent Citations

  • Forestry pest detection method and system based on multi-scale feature enhancement and fusion

    CN117671655A

  • Rice pest detection method based on Detr model

    CN118298164A