Corn pest detection method

By constructing a backbone network, a Transformer hybrid encoding head and a decoding prediction network, and combining multi-scale feature fusion and loss function optimization, the problems of high computing resource consumption and low recognition accuracy of existing corn pest detection algorithms are solved, and efficient and accurate corn pest detection is achieved.

CN120808388APending Publication Date: 2025-10-17ZHEJIANG FORESTRY UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510686862.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-26
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

The existing end-to-end corn pest detection algorithm based on convolutional neural networks has high computing resource consumption and low recognition accuracy, which limits its feasibility and universality in field applications.

Method used

A corn pest detection method is adopted, including the backbone network, Transformer hybrid encoding head and decoding prediction network. The deformation information is captured by the DCNv2-Block module. The AIFI multi-head attention module and multi-scale feature fusion module are combined to enhance feature extraction and global spatial information. The FocalLoss and GioU loss functions are used to optimize the model.

Benefits of technology

The accuracy and recall rate of corn pest detection are improved, the consumption of computing resources is reduced, the corn pest species can be detected quickly and accurately, the pest deformation is adapted to different periods, and the computational workload and memory overhead are reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120808388A_ABST
    Figure CN120808388A_ABST
Patent Text Reader

Abstract

The invention discloses a corn pest detection method. The method comprises the following steps: obtaining corn pest images, manually labeling the corn pest images, establishing a corn pest image data set, and dividing the corn pest image data set into a training set and a test set; constructing a corn pest detection model, wherein the corn pest detection model comprises a backbone network, a Transfomer hybrid coding head and a decoding prediction network; the training set is adopted to train the corn pest detection model, and the test set is adopted to evaluate the performance of the trained corn pest detection model; and inputting a to-be-detected corn pest image into the trained corn pest detection model, and outputting a pest category by the corn pest detection model. According to the method, the types of the corn pests can be rapidly and accurately detected, the detection precision is improved, and the computing resource consumption is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of crop pest detection, and in particular to a corn pest detection method. BACKGROUND

[0002] As the highest yield crop in China, corn has the largest planting area and yield among many crops. In 2023, the corn planting area in China was about 44,219 thousand hectares, accounting for about 40% of the total grain output in China. However, during the growth of corn, various pests often become an important factor affecting output and quality, not only causing yield decline, but also causing the entire crop to be absolutely lost in severe cases. Common corn pests include aphids, Spodoptera exigua, Agonosoma pistillum, and corn borer, which have a profound impact on the overall efficiency and quality of corn production.

[0003] In order to achieve precise control and scientific decision-making, it is particularly important to ensure that pests are identified in a timely and accurate manner. Currently, most research in the field of crop pest identification at home and abroad is still based on convolutional neural networks. These studies mostly use traditional target detection model structures, but such algorithms based on convolutional neural networks still have shortcomings in completing end-to-end detection of pests. Although existing end-to-end detection frameworks can theoretically simplify the detection process and model structure, they face high computational resource consumption and relatively low recognition accuracy in practical applications. These problems limit the feasibility and universality of end-to-end detection algorithms in field applications. SUMMARY

[0004] The present application provides a corn pest detection method that can quickly and accurately detect the type of corn pest, improving detection accuracy and reducing computational resource consumption.

[0005] To solve the above problems, the present application adopts the following technical solutions:

[0006] The corn pest detection method of the present application comprises the following steps:

[0007] S1: Obtain a corn pest image, manually label the corn pest image, establish a corn pest image dataset, and divide the corn pest image dataset into a training set and a test set;

[0008] S2: Construct a corn pest detection model, the corn pest detection model comprising a backbone network, a Transformer hybrid encoding head, and a decoding prediction network;

[0009] S3: Train the corn pest detection model using the training set and evaluate the performance of the trained corn pest detection model using the test set;

[0010] S4: inputting the image of the corn pest to be detected into the trained corn pest detection model, and outputting a pest category by the corn pest detection model.

[0011] Preferably, the step S1 comprises the following steps: obtaining original images of different kinds of corn pests, manually labeling the corn pests on the original images by using an image labeling tool to obtain a corn pest image dataset, and dividing the corn pest image dataset into a training set and a test set.

[0012] Preferably, the backbone network comprises a first ConvNormLayer module, a second ConvNormLayer module, a third ConvNormLayer module, a MaxPool2d module, a first BasicBlock module, a second BasicBlock module, a first DCNv2-Block module and a second DCNv2-Block module connected in sequence, and the backbone network is used for feature extraction processing on the input corn pest image, and outputs a feature map S1 from the second BasicBlock module, a feature map S2 from the first DCNv2-Block module, and a feature map S3 from the second DCNv2-Block module.

[0013] Preferably, the Transformer mixed encoding head comprises an AIFI multi-head attention module and a multi-scale feature fusion module, the AIFI multi-head attention module is used for global feature enhancement processing on the feature map S3 to obtain a feature map Y3 and output the feature map Y3, and the multi-scale feature fusion module is used for multi-scale feature fusion processing on the feature map Y3, the feature map S1 and the feature map S2 to obtain a feature map P17 and output the feature map P17 to the decoding prediction network.

[0014] Preferably, the multi-scale feature fusion module comprises a first CA attention module, a second CA attention module, a third CA attention module, a fourth CA attention module, a fifth CA attention module, a first conv convolution module, a second conv convolution module, a third conv convolution module, a first ConvTranspose2d inverse convolution module, a second ConvTranspose2d inverse convolution module, a first matrix addition module, a second matrix addition module, a first matrix multiplication module, a second matrix multiplication module, a first Fusion reparameterization module, a second Fusion reparameterization module and a Concat module.

[0015] The first CA attention module is used for coordinate attention enhancement processing on the feature map Y3 to obtain a feature map P1 and output the feature map P1 to the first conv convolution module and the Concat module.

[0016] The first conv convolution module is used for performing convolution processing on the feature map P1 to obtain a feature map P2 and output to a first ConvTranspose2d inverse convolution module;

[0017] The first ConvTranspose2d inverse convolution module performs inverse convolution processing on the feature map P2 to obtain a feature map P3 and output to a second ConvTranspose2d inverse convolution module, a first matrix addition module, and a fourth CA attention module;

[0018] The second ConvTranspose2d inverse convolution module performs inverse convolution processing on the feature map P3 to obtain a feature map P4 and output to a second matrix addition module and a fifth CA attention module;

[0019] The second CA attention module performs coordinate attention enhancement processing on the feature map S1 to obtain a feature map P5 and output to a second conv convolution module;

[0020] The second conv convolution module performs convolution processing on the feature map P5 to obtain a feature map P6 and output to the fourth CA attention module and a first matrix multiplication module;

[0021] The fourth CA attention module performs coordinate attention enhancement processing on the feature map P3 and the feature map P6 to obtain a feature map P7 and output to the first matrix multiplication module;

[0022] The first matrix multiplication module performs point-by-point multiplication processing on the feature map P6 and the feature map P7 to obtain a feature map P8 and output to the first matrix addition module;

[0023] The first matrix addition module performs point-by-point addition processing on the feature map P3 and the feature map P8 to obtain a feature map P9 and output to a first Fusion reparameterization module;

[0024] The first Fusion reparameterization module performs reparameterization processing on the feature map P9 to obtain a feature map P10 and output to a Concat module;

[0025] The third CA attention module performs coordinate attention enhancement processing on the feature map S2 to obtain a feature map P11 and output to a third conv convolution module;

[0026] The third conv convolution module performs convolution processing on the feature map P11 to obtain a feature map P12 and output to the fifth CA attention module and a second matrix multiplication module;

[0027] The fifth CA attention module performs coordinate attention enhancement processing on the feature map P4 and the feature map P12 to obtain a feature map P13 and output to the second matrix multiplication module.

[0028] The second matrix multiplication module performs point-by-point multiplication processing on the feature map P12 and the feature map P13 to obtain a feature map P14 and output to the second matrix addition module;

[0029] The second matrix addition module performs point-by-point addition processing on the feature map P4 and the feature map P14 to obtain a feature map P15 and output to the second Fusion reparameterization module;

[0030] The second Fusion reparameterization module performs reparameterization processing on the feature map P15 to obtain a feature map P16 and output to the Concat module;

[0031] The Concat module performs splicing processing on the feature map P1, the feature map P10, and the feature map P16 to obtain a feature map P17 and output to the decoding prediction network.

[0032] As a preferred, the coordinate attention enhancement processing includes the following steps:

[0033] Adaptive average pooling is performed on the input feature map in the height and width directions to generate a height feature map and a width feature map;

[0034] The height feature map and the width feature map are spliced, and 1x1 convolution, batch normalization and activation function processing are performed to generate an intermediate feature map;

[0035] The intermediate feature map is divided into a height part and a width part, the height part is processed by 1x1 convolution and sigmoid activation to generate a height attention weight map, and the width part is processed by 1x1 convolution and sigmoid activation to generate a width attention weight map;

[0036] The height attention weight map and the width attention weight map are multiplied point by point to generate an attention weight map with the same size as the input feature map;

[0037] The attention weight map is multiplied point by point with the input feature map to obtain an output feature map.

[0038] As a preferred, the decoding prediction network includes an Iou-based query selection module and a Transformer decoder;

[0039] The Iou-based query selection module is used to extract high-confidence initial queries from the received feature map and generate their corresponding reference bounding boxes;

[0040] The Transformer decoder is used to perform multi-layer iterative refinement on the initial queries to output the final bounding box coordinates and classification probabilities.

[0041] As preferred, the Transformer decoder comprises 6 deformable Transformer decoder layers. Each deformable Transformer decoder layer comprises 8 attention heads and 4 sampling points.

[0042] As preferred, the calculation formula of the output feature map of the DCNv2-Block module is:

[0043]

[0044] wherein p0 is a position on the output feature map, y(p0) is an element at the p0 position on the output feature map, R is a position set of elements on the input feature map, p n is a position element in R, w(p n ) is a convolution kernel weight value at the p n position, Δp n is an offset, x(p0+p n +Δp n ) is an element at the p0+p n +Δp n position on the input feature map.

[0045] As preferred, the loss function of the corn pest detection model comprises a FocalLoss loss function for optimizing a classification task and a GioU loss function for optimizing a regression task.

[0046] The FocalLoss loss function is: FL(p t )=-α t (1-p t ) γ log(p t ),

[0047] The GioU loss function is:

[0048] wherein p t is a predicted probability of the corn pest detection model for a certain class, ɑ t is a balance factor, γ is a regulation factor, A inter is an intersection area between a predicted frame and a real frame, A union is a union area of the predicted frame and the real frame, and A c is a minimum rectangular frame capable of enclosing the predicted frame and the real frame.

[0049] The beneficial effects of the present invention are: (1) it can quickly and accurately detect the types of corn pests, improve detection accuracy, and reduce computing resource consumption. (2) The backbone network sets two DCNv2-Block modules to capture the deformation information of objects in the input feature map. According to the deformation of the objects in the input feature map, the shape and size of the convolution kernel can be adaptively adjusted, so that the corn pest detection model can better adapt to the changes in length, width and aspect ratio of corn pests in different periods, improve the feature extraction ability of pests with diverse geometric features, improve the model accuracy and reduce the amount of calculation. (3) The Transformer hybrid encoding head can capture richer global spatial information by performing horizontal pooling and vertical pooling on the input feature map; through activation function and channel scaling, the sensitivity to the target area is enhanced while ensuring that the amount of calculation is controllable; the output attention weight can finely weight the channel and spatial information, so that the network can better allocate channel attention, highlight the pest area, suppress background interference, improve the model recall rate and mAP50, and further reduce the model calculation amount and memory overhead. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 is a flow chart of this embodiment;

[0051] Figure 2 It is the structural parameter diagram of the backbone network;

[0052] Figure 3 It is a structural diagram of the multi-scale feature fusion module;

[0053] Figure 4 It is the original image of the corn pest;

[0054] Figure 5 This embodiment method is Figure 4 a detection result image obtained by performing the detection;

[0055] Figure 6 3 is a comparison diagram of the receptive fields of the corn pest detection model in this embodiment and the existing detection model.

[0056] In the figure: 1, the first CA attention module, 2, the second CA attention module, 3, the third CA attention module, 4, the fourth CA attention module, 5, the fifth CA attention module, 6, the first conv convolution module, 7, the second conv convolution module, 8, the third conv convolution module, 9, the first ConvTranspose2d inverse convolution module, 10, the second ConvTranspose2d inverse convolution module, 11, the first matrix addition module, 12, the second matrix addition module, 13, the first matrix multiplication module, 14, the second matrix multiplication module, 15, the first Fusion reparameterization module, 16, the second Fusion reparameterization module, 17, the Concat module. DETAILED DESCRIPTION

[0057] The technical solutions of the present application will be further specifically described below by examples in combination with the drawings.

[0058] Embodiment: A corn pest detection method of the embodiment, as shown in the figure, includes the following steps: Figure 1

[0059] S1: Obtain a corn pest image, manually label the corn pest image, establish a corn pest image dataset, and divide the corn pest image dataset into a training set and a test set;

[0060] S2: Construct a corn pest detection model, the corn pest detection model including a backbone network, a Transformer hybrid encoding head, and a decoding prediction network;

[0061] S3: Train the corn pest detection model using the training set and evaluate the performance of the trained corn pest detection model using the test set;

[0062] S4: Input the corn pest image to be detected into the trained corn pest detection model, and the corn pest detection model outputs the pest category.

[0063] Step S1 includes the following steps: obtaining original images of different types of corn pests from a public dataset IP102, each original image containing only one type of corn pest, uniformly scaling the original images to 640x640 pixel RGB images, manually labeling the corn pests on the original images using an image labeling tool Labelme (with their category information and their detection box information), obtaining a corn pest image dataset, and dividing the corn pest image dataset into a training set and a test set.

[0064] ​The pest images in the training set and the test set can also be subjected to a mirror operation, the images after the mirror operation are saved, and the original pest images and the images after the mirror operation are subjected to a counterclockwise rotation of 90° operation, the images after the rotation are saved, so as to expand the training set and the test set.

[0065] The backbone network comprises a first ConvNormLayer module, a second ConvNormLayer module, a third ConvNormLayer module, a MaxPool2d module, a first BasicBlock module, a second BasicBlock module, a first DCNv2-Block module and a second DCNv2-Block module connected in sequence, and is used for performing feature extraction processing on an input corn pest image (with a size of 640x640x3) and outputting a feature map S1 from the second BasicBlock module, a feature map S2 from the first DCNv2-Block module and a feature map S3 from the second DCNv2-Block module. A structure parameter diagram of the backbone network is shown in Figure 2 .

[0066] The backbone network is obtained by the following method: constructing a Resnet18 network, replacing ordinary convolution in the last two basic blocks in the Resnet18 network with deformable convolution, and obtaining the backbone network.

[0067] The specific process of the feature extraction processing of the backbone network on the input corn pest image (with a size of 640x640x3) is as follows:

[0068] The first ConvNormLayer module performs convolution operation on the input corn pest image with a size of 640x640x3, adopts a 3x3 convolution kernel, a stride of 2, and an output channel number of 32, generates a feature map with a size of 320x320x32, and extracts low-level features such as edges and textures;

[0069] The second ConvNormLayer module further processes the feature map output by the first ConvNormLayer module with a stride of 1, outputs a feature map with an output channel number of 32 and a size of 320x320x32;

[0070] The third ConvNormLayer module further processes the feature map output by the second ConvNormLayer module with a stride of 1, outputs a feature map with an output channel number of 64 and a size of 320x320x64;

[0071] The MaxPool2d module adopts a 3x3 pooling kernel, a stride of 2, a padding of 1, and an output channel number of 64, and down-samples the feature map output by the third ConvNormLayer module to 160x160x64;

[0072] The first BasicBlock module includes two residual units, and the output channel number is 64, and the feature map output by the MaxPool2d module is processed, and a feature map of 160x160x64 is output;

[0073] The second BasicBlock module includes two residual units, and the stride is 2, the output channel number is 128, and a feature map of 80x80x128 is generated S1, which is used to capture the local mode of the pest;

[0074] The first DCNv2-Block module adopts deformable convolution, includes two residual units, the stride is 2, the output channel number is 256, and a feature map of 40x40x256 is generated S2, which enhances the adaptability to the shape and position changes of the pest;

[0075] The second DCNv2-Block module adopts deformable convolution, includes two residual units, the stride is 2, the output channel number is 512, and a feature map of 20x20x512 is generated S3, which captures global and complex target features.

[0076] The feature maps S1, S2 and S3 have multi-scale characteristics, and respectively represent low, medium and high level semantic information, which are used for subsequent corn pest detection tasks.

[0077] The corn pest has different shapes, and the pests in different periods have great differences in appearance, and the length, width and aspect ratio show diversity. The Resnet18 network uses ordinary convolution, and the feature extraction effect of the corn pest image under complex background is not good. The backbone network in the embodiment sets two DCNv2-Block modules, replaces the ordinary convolution in the last two basic blocks of the Resnet18 network with deformable convolution, to capture the deformation information of the object in the input feature map, and adaptively adjust the shape and size of the convolution kernel according to the deformation of the object in the input feature map, so that the corn pest detection model better adapts to the changes of the corn pest in length, width and aspect ratio in different periods, improves the feature extraction capability of the pests with diverse geometric features, improves the model precision while reducing the calculation amount.

[0078] The Transformer hybrid encoding head includes an AIFI multi-head attention module and a multi-scale feature fusion module. The AIFI multi-head attention module is used for global feature enhancement processing on the feature map S3 to obtain a feature map Y3 and output. The multi-scale feature fusion module is used for multi-scale feature fusion processing on the feature map Y3, the feature map S1 and the feature map S2 to obtain a feature map P17 and output to the decoding prediction network.

[0079] The AIFI multi-head attention module is used for global feature enhancement processing on the feature map S3 to obtain a feature map Y3 and output the specific steps as follows:

[0080] The channel number of the 20x20x512 feature map S3 is adjusted from 512 to 256 through 1x1 convolution to generate a 20x20x256 intermediate feature map;

[0081] The intermediate feature map is flattened and rearranged into a sequence form, converted from [B, 256, 20, 20] to [B, 400, 256], wherein B is the batch size and 400 is the number of spatial positions;

[0082] A 2D sine-cosine position encoding is generated to add position information to each spatial position;

[0083] The sequence is processed using a multi-head self-attention mechanism (with 8 attention heads and an embedding dimension of 1024) to enhance the global context information of the pest target in the feature map;

[0084] The processed sequence is reshaped back to [B, 256, 20, 20] and a 20x20x256 feature map Y3 is generated through 1x1 convolution and output.

[0085] As shown in Figure 3 , the multi-scale feature fusion module includes a first CA attention module 1, a second CA attention module 2, a third CA attention module 3, a fourth CA attention module 4, a fifth CA attention module 5, a first conv convolution module 6, a second conv convolution module 7, a third conv convolution module 8, a first ConvTranspose2d inverse convolution module 9, a second ConvTranspose2d inverse convolution module 10, a first matrix addition module 11, a second matrix addition module 12, a first matrix multiplication module 13, a second matrix multiplication module 14, a first Fusion reparameterization module 15, a second Fusion reparameterization module 16, and a Concat module 17.

[0086] The first CA attention module 1 is used for coordinate attention enhancement processing on the feature map Y3 (with a size of 20x20x256), generates attention weights in the height and width directions through adaptive pooling, obtains a feature map P1 (with a size of 20x20x256), and outputs to the first conv convolution module 6 and the Concat module 17;

[0087] The first conv convolution module 6 is used for convolution processing on the feature map P1 to obtain a feature map P2 (with a size of 20x20x256) and output to the first ConvTranspose2d inverse convolution module 9;

[0088] The first ConvTranspose2d inverse convolution module 9 performs inverse convolution processing on the feature map P2 to obtain a feature map P3 (with a size of 40x40x256) and output to the second ConvTranspose2d inverse convolution module 10, the first matrix addition module 11, and the fourth CA attention module 4.

[0089] The second ConvTranspose2d inverse convolution module 10 performs inverse convolution processing on the feature map P3 to obtain a feature map P4 (with a size of 80x80x256) and output to the second matrix addition module 12 and the fifth CA attention module 5.

[0090] The second CA attention module 2 performs coordinate attention enhancement processing on the feature map S1 (with a size of 80x80x128) to obtain a feature map P5 (with a size of 80x80x128) and output to the second conv convolution module 7.

[0091] The second conv convolution module 7 performs convolution processing on the feature map P5 to obtain a feature map P6 (with a size of 80x80x256) and output to the fourth CA attention module 4 and the first matrix multiplication module 13.

[0092] The fourth CA attention module 4 performs coordinate attention enhancement processing on the feature map P3 and the feature map P6 to generate attention weights by fusing the feature map P3 and the feature map P6 (after down-sampling and addition fusion), and obtain a feature map P7 (with a size of 80x80x256) and output to the first matrix multiplication module 13.

[0093] The first matrix multiplication module 13 performs point-by-point multiplication processing on the feature map P6 and the feature map P7 to obtain a feature map P8 (with a size of 80x80x256) and output to the first matrix addition module 11.

[0094] The first matrix addition module 11 performs point-by-point addition processing on the feature map P3 and the feature map P8 to obtain a feature map P9 (with a size of 80x80x256) and output to the first Fusion reparameterization module 15.

[0095] The first Fusion reparameterization module 15 performs reparameterization processing on the feature map P9 to obtain a feature map P10 (with a size of 80x80x256) and output to the Concat module 17.

[0096] The third CA attention module 3 performs coordinate attention enhancement processing on the feature map S2 (with a size of 40x40x256) to generate attention weights in the height and width directions, and obtain a feature map P11 (with a size of 40x40x256) and output to the third conv convolution module 8.

[0097] The third convolutional module 8 performs convolutional processing on the feature map P11 to obtain a feature map P12 (40x40x256 in size) and output to the fifth CA attention module 5 and the second matrix multiplication module 14;

[0098] The fifth CA attention module 5 performs coordinate attention enhancement processing on the feature map P4 and the feature map P12, generates attention weights by fusing the feature map P4 and the feature map P6, obtains a feature map P13 (40x40x256 in size) and outputs to the second matrix multiplication module 14;

[0099] The second matrix multiplication module 14 performs point-by-point multiplication processing on the feature map P12 and the feature map P13 to obtain a feature map P14 (40x40x256 in size) and output to the second matrix addition module 12.

[0100] The second matrix addition module 12 performs point-by-point addition processing on the feature map P4 and the feature map P14 to obtain a feature map P15 (40x40x256 in size) and output to the second Fusion reparameterization module 16.

[0101] The second Fusion reparameterization module 16 performs reparameterization processing on the feature map P15 to obtain a feature map P16 (40x80x256 in size) and output to the Concat module 17.

[0102] The Concat module 17 performs splicing processing on the feature map P1, the feature map P10 and the feature map P16 to obtain a feature map P17 (40x40x256 in size) and output to the decoding prediction network.

[0103] The coordinate attention enhancement processing includes the following steps:

[0104] Perform adaptive average pooling in the height and width directions on the input feature map to generate a height feature map and a width feature map;

[0105] Splice the height feature map and the width feature map, and process through 1x1 convolution, batch normalization and activation function to generate an intermediate feature map;

[0106] Divide the intermediate feature map into a height part and a width part, generate a height attention weight map through 1x1 convolution and sigmoid activation for the height part, and generate a width attention weight map through 1x1 convolution and sigmoid activation for the width part;

[0107] Multiply the height attention weight map and the width attention weight map point by point to generate an attention weight map with the same size as the input feature map;

[0108] Multiply the attention weight map and the input feature map point by point to obtain an output feature map.

[0109] The transformer mixed encoding head can capture more rich global spatial information by horizontal and vertical pooling of the input feature map; through the activation function and channel scaling, the sensitivity to the target region is enhanced under the premise of controllable calculation amount; the output attention weight can finely weight the channel and spatial information, so that the network can better allocate channel attention, highlight the pest area, suppress background interference, improve the model recall rate and mAP50, and further reduce the model calculation amount and memory overhead.

[0110] The calculation formula of the output feature map of the DCNv2-Block module is:

[0111]

[0112] Wherein, p0 is the position on the output feature map, y(p0) is the element of p0 position on the output feature map, R is the position set of the element on the input feature map (R={(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)}), p n is the position element in R, w(p n ) is the convolution kernel weight value at p n position, Δp n is the offset, x(p0+p n +Δp n ) is the element of p0+p n +Δp n position on the input feature map.

[0113] The decoding prediction network is used for object detection processing on the feature map P17 to generate the bounding box and classification probability of the corn pest.

[0114] The decoding prediction network includes an Iou-based query selection module and a transformer decoder.

[0115] The Iou-based query selection module is used to extract high-confidence initial queries from the received feature map and generate the reference bounding box corresponding thereto.

[0116] The transformer decoder is used to perform multi-layer iterative refinement on the initial query to output the final bounding box coordinates and classification probability.

[0117] The transformer decoder includes 6 deformable transformer decoding layers. Each transformer deformable decoding layer includes 8 attention heads and 4 sampling points. The working process of the transformer decoder is as follows:

[0118] The initial query and the reference bounding box generated by the IoU-based query selection module are received, as well as the projected multi-scale feature map;

[0119] The self-attention mechanism (interaction between queries) and the cross-attention mechanism (interaction between queries and feature maps) are performed through 6 deformable Transformer decoding layers to gradually refine the feature representation of the query;

[0120] In each deformable Transformer decoding layer, the bounding box coordinates (including the center point coordinates, width and height) are predicted by a multi-layer perception, and the classification probability is predicted by a linear layer;

[0121] The refined query is output, each query containing normalized bounding box coordinates and classification probability, which is used to represent the detection result of the corn pest.

[0122] The decoding prediction network converts the multi-scale feature map P17 into a fixed number of detection results containing bounding boxes and classification probabilities through the above processing, which are used for subsequent post-processing and pest identification.

[0123] The loss function of the corn pest detection model includes the Focal Loss loss function for optimizing the classification task and the GioU loss function for optimizing the regression task;

[0124] The FocalLoss loss function is: FL(p t )=-α t (1-p t ) γ log(p t ),

[0125] The GioU loss function is:

[0126] where p t is the predicted probability of the corn pest detection model for a certain class, ɑ t is a balance factor, γ is a regulation factor, A innter is the intersection area between the predicted box and the real box, A union is the union area of the predicted box and the real box, and A c is the smallest rectangular box that can enclose the predicted box and the real box.

[0127] The Focal Loss loss function optimizes the classification task (pest class prediction), and the GioU loss function optimizes the regression task (pest bounding box prediction), and the targets of the two are independent. In the training process, the optimizer adjusts the model parameters through the total loss (the weighted sum of Focal Loss and GioU), and the convergence speeds of the Focal Loss loss function and the GioU loss function are different.

[0128] The scheme first establishes a corn pest image dataset, and divides it into a training set and a test set. A backbone network is used for feature extraction. A multi-head attention module is used to make the features of each scale have detailed context information. A multi-scale feature fusion module is designed to fuse multi-level features, thereby enhancing the subsequent classification and detection capabilities of the pests.

[0129] The method is used to identify 9 common corn pests, with an accuracy of 94.3%, a recall rate of 89.8%, and an mAP50 of 91.5%. The 9 common corn pests are aphids, army worms, black cutworms, corn borers, grubs, mole crickets, Potosia bre vitarsis, red spiders, and wireworms.

[0130] The method is used to identify 9 common corn pests, with an accuracy of 94.3%, a recall rate of 89.8%, and an mAP50 of 91.5%. The 9 common corn pests are aphids, army worms, black cutworms, corn borers, grubs, mole crickets, Potosia bre vitarsis, red spiders, and wireworms. Figure 4 The method is used to identify 9 common corn pests, with an accuracy of 94.3%, a recall rate of 89.8%, and an mAP50 of 91.5%. The 9 common corn pests are aphids, army worms, black cutworms, corn borers, grubs, mole crickets, Potosia bre vitarsis, red spiders, and wireworms. Figure 5 The detection results of the 9 corn pest images are shown in FIG. 9, and the corn pests in the 9 corn pest images are aphids, army worms, black cutworms, corn borers, grubs, mole crickets, Potosia bre vitarsis, red spiders, and wireworms. Figure 5 The values in each detection result represent the confidence of the corresponding pest. The confidence is a value between 0 and 1, reflecting the confidence level of the corn pest detection model for the detection result. The higher the confidence, the more confident the corn pest detection model is that the detection result is correct.

[0131] The receptive field comparison diagram of the corn pest detection model in this embodiment and the existing detection model is shown in FIG. 10. Figure 6The gradient-based effective receptive field visualization method is adopted. After the gradients of multiple input samples are accumulated and normalized, the results can be visualized as a heat map, thereby revealing the spatial distribution of the effective receptive field of the model in the input image. The values on the right side of the heat map (0.0 to 1.0) represent the size of the gradient value. After accumulation and normalization, these values reflect the contribution of the input image pixels to the response value of the center position of the feature map. The larger the value (closer to 1.0), the greater the influence of the region on the model output, that is, the model pays more attention to these regions. Conversely, the smaller the value (closer to 0.0), the smaller the contribution of the region to the model output. Figure 6 The high-contribution region (value close to 1.0) is represented by the medium green color, that is, the region where the effective receptive field of the model is mainly focused, and the model is most sensitive to the pixel changes in these regions.

[0132] From Figure 6 It can be seen that the receptive field of the existing detection model mainly concentrates on the center of the image, indicating that its capture of input features is relatively limited. The receptive field of the corn pest detection model in the embodiment presents a more dispersed and broad high-response region, which means that the corn pest detection model can more flexibly capture complex image features and spatial information by dynamically adjusting the position of the convolution sampling point, thereby forming an effective receptive field in a larger range and improving the adaptability and feature expression ability to diversified scenes.

Claims

1. A method for detecting corn pests, characterized in that: The following steps are involved: S1: Obtain corn pest images, manually label the corn pest images, establish a corn pest image dataset, and divide the corn pest image dataset into a training set and a test set; S2: Build a corn pest detection model, which includes a backbone network, a Transformer hybrid encoding head, and a decoding prediction network; S3: Use the training set to train the corn pest detection model, and use the test set to evaluate the performance of the trained corn pest detection model; S4: Input the corn pest image to be detected into the trained corn pest detection model, and the corn pest detection model outputs the pest category.

2. A corn pest detection method according to claim 1, characterized in that: The step S1 includes the following steps: obtaining original images of different types of corn pests, manually labeling the corn pests on the original images using an image annotation tool to obtain a corn pest image dataset, and dividing the corn pest image dataset into a training set and a test set.

3. A corn pest detection method according to claim 1, characterized in that: The backbone network includes a first ConvNormLayer module, a second ConvNormLayer module, a third ConvNormLayer module, a MaxPool2d module, a first BasicBlock module, a second BasicBlock module, a first DCNv2-Block module, and a second DCNv2-Block module, which are connected in sequence. The backbone network is used to perform feature extraction processing on the input corn pest image, and the second BasicBlock module outputs a feature map S1, the first DCNv2-Block module outputs a feature map S2, and the second DCNv2-Block module outputs a feature map S3.

4. A corn pest detection method according to claim 3, characterized in that: The Transformer hybrid encoding head includes an AIFI multi-head attention module and a multi-scale feature fusion module. The AIFI multi-head attention module is used to perform global feature enhancement processing on the feature map S3 to obtain and output the feature map Y3. The multi-scale feature fusion module is used to perform multi-scale feature fusion processing on the feature map Y3, the feature map S1, and the feature map S2 to obtain the feature map P17 and output it to the decoding prediction network.

5. A corn pest detection method according to claim 4, characterized in that: The multi-scale feature fusion module includes a first CA attention module (1), a second CA attention module (2), a third CA attention module (3), a fourth CA attention module (4), a fifth CA attention module (5), a first conv convolution module (6), a second conv convolution module (7), a third conv convolution module (8), a first ConvTranspose2d inverse convolution module (9), a second ConvTranspose2d inverse convolution module (10), a first matrix addition module (11), a second matrix addition module (12), a first matrix multiplication module (13), a second matrix multiplication module (14), a first Fusion reparameterization module (15), a second Fusion reparameterization module (16), and a Concat module (17); The first CA attention module (1) is used to perform coordinate attention enhancement processing on the feature map Y3 to obtain the feature map P1 and output it to the first conv convolution module (6) and the Concat module (17); The first conv convolution module (6) is used to perform convolution processing on the feature map P1 to obtain a feature map P2 and output it to the first ConvTranspose2d deconvolution module (9); The first ConvTranspose2d deconvolution module (9) performs deconvolution processing on the feature map P2 to obtain a feature map P3 and outputs it to the second ConvTranspose2d deconvolution module (10), the first matrix addition module (11), and the fourth CA attention module (4); the second ConvTranspose2d deconvolution module (10) performs deconvolution processing on the feature map P3 to obtain a feature map P4 and outputs it to the second matrix addition module (12) and the fifth CA attention module (5); The second CA attention module (2) performs coordinate attention enhancement processing on the feature map S1 to obtain a feature map P5 and outputs it to the second conv convolution module (7); The second conv convolution module (7) performs convolution processing on the feature map P5 to obtain a feature map P6 and outputs it to the fourth CA attention module (4) and the first matrix multiplication module (13); the fourth CA attention module (4) performs coordinate attention enhancement processing on the feature maps P3 and P6 to obtain a feature map P7 and outputs it to the first matrix multiplication module (13); the first matrix multiplication module (13) performs point-by-point multiplication processing on the feature maps P6 and P7 to obtain a feature map P8 and outputs it to the first matrix addition module (11); The first matrix addition module (11) performs point-by-point addition processing on the feature map P3 and the feature map P8 to obtain a feature map P9 and outputs it to the first Fusion reparameterization module (15); the first Fusion reparameterization module (15) performs reparameterization processing on the feature map P9 to obtain a feature map P10 and outputs it to the Concat module (17); The third CA attention module (3) performs coordinate attention enhancement processing on the feature map S2 to obtain a feature map P11 and outputs it to the third conv convolution module (8); The third conv convolution module (8) performs convolution processing on the feature map P11 to obtain a feature map P12 and outputs it to the fifth CA attention module (5) and the second matrix multiplication module (14); The fifth CA attention module (5) performs coordinate attention enhancement processing on the feature map P4 and the feature map P12 to obtain a feature map P13 and outputs it to the second matrix multiplication module (14); the second matrix multiplication module (14) performs point-by-point multiplication processing on the feature map P12 and the feature map P13 to obtain a feature map P14 and outputs it to the second matrix addition module (12); The second matrix addition module (12) performs point-by-point addition processing on the feature map P4 and the feature map P14 to obtain a feature map P15 and outputs it to the second Fusion reparameterization module (16); the second Fusion reparameterization module (16) performs reparameterization processing on the feature map P15 to obtain a feature map P16 and outputs it to the Concat module (17); The Concat module (17) performs concatenation processing on the feature map P1, the feature map P10, and the feature map P16 to obtain the feature map P17 and outputs it to the decoding prediction network.

6. A corn pest detection method according to claim 5, characterized in that: The coordinate attention enhancement process comprises the following steps: Perform adaptive average pooling in the height and width directions on the input feature map to generate a height feature map and a width feature map; Concatenate the height feature map and the width feature map, generate an intermediate feature map through 1×1 convolution, batch normalization and activation function processing; The intermediate feature map is divided into a height part and a width part. The height part generates a height attention weight map through 1×1 convolution and sigmoid activation, and the width part generates a width attention weight map through 1×1 convolution and sigmoid activation; Multiply the height attention weight map and the width attention weight map point by point to generate an attention weight map of the same size as the input feature map; The attention weight map is multiplied point by point with the input feature map to obtain the output feature map.

7. A corn pest detection method according to claim 4, characterized in that: The decoding prediction network includes an Iou-based query selection module and a Transformer decoder; The Iou-based query selection module is used to extract high-confidence initial queries from the received feature maps and generate corresponding reference bounding boxes; The Transformer decoder is used to perform multi-layer iterative refinement on the initial query and output the final bounding box coordinates and classification probability.

8. A corn pest detection method according to claim 7, characterized in that: The Transformer decoder includes 6 deformable Transformer decoding layers.

9. A corn pest detection method according to claim 1, characterized in that: The calculation formula of the output feature map of the DCNv2-Block module is: Among them, p0 is the position on the output feature map, y(p0) is the element at position p0 on the output feature map, R is the position set of elements on the input feature map, and p n is the position element in R, w(p n ) is the n The convolution kernel weight value of the position, Δp n is the offset, x(p0+p n +Δp n ) is p0+p on the input feature map n +Δp n Position element.

10. A corn pest detection method according to claim 1, characterized in that: The loss function of the corn pest detection model includes a FocalLoss loss function for optimizing the classification task and a GioU loss function for optimizing the regression task; The FocalLoss loss function is: FL(p t )=-α t (1-p t ) γ log(p t ), The GioU loss function is: Among them, p t is the predicted probability of a certain category by the corn pest detection model, ɑ t is the balance factor, γ is the adjustment factor, A inter is the intersection area between the predicted box and the real box, A union is the union area of ​​the predicted box and the true box, A c It is the minimum rectangular box that can surround the predicted box and the true box.