Maize pest detection method based on MM-YOLOv8
By improving the multi-scale fine-grained feature extraction and multi-path coordinate attention mechanism of the YOLOv8 model, the complex environment and morphological changes in corn pest detection problems were solved, and the accuracy and efficiency of detection were improved.
Patent Information
- Application Number
- CN202510703253.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-29
- Publication Date
- 2025-09-23
AI Technical Summary
Existing technologies for corn pest detection have problems such as complex detection environments, variable pest morphologies, different scales, and similar colors and textures, which lead to false detections and missed detections, affecting recognition accuracy.
A multi-scale fine-grained feature extraction module (MFE) and a multi-path coordinate attention mechanism (MBCA) are designed to improve the YOLOv8 model and enhance feature extraction capabilities. The traditional convolution is replaced by MFE, and MBCA attention is added to enhance the focus on key area features. The feature pyramid and path aggregation network are combined for multi-scale fusion.
The accuracy and efficiency of corn pest detection are improved, the ability to focus on features in key areas is enhanced, and the false detection and missed detection rates are reduced.
Smart Images

Figure CN120689718A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of target detection technology, and in particular to a corn pest detection method based on MM-YOLOv8. Background Art
[0002] Corn is one of the world's most important food crops and industrial raw materials, but it faces constant threats from pests and diseases throughout its growth process, leading to reduced yield and quality. To prevent this, rigorous visual monitoring is required to detect crop pests and diseases early. Traditional pest detection relies on on-site identification of plant pests and diseases by agricultural experts or farmers based on their experience. This method is not only time-consuming and labor-intensive, but also prone to misjudgment due to subjective factors, leading to the indiscriminate use of pesticides. This situation not only pollutes the environment but also causes unnecessary economic losses. With advances in artificial intelligence, the use of computer vision for pest identification offers a new approach to pest monitoring.
[0003] Previous research on pest identification has primarily focused on traditional machine learning methods. However, these methods rely on manually designed features for classification, and manual feature extraction relies on expertise and experience. Manual feature extraction struggles to capture high-level features and complex patterns in images. Furthermore, crop pest images are typically captured in natural, real-world agricultural environments, often containing complex backgrounds and varying lighting conditions, which can affect the detection and identification accuracy of traditional machine learning algorithms.
[0004] In recent years, methods based on deep convolutional neural networks have demonstrated outstanding performance in various visual tasks, including image classification, object detection, and object tracking. In pest detection applications, deep learning-based methods can effectively learn target features from training data, overcoming the shortcomings of traditional machine learning methods that rely on manually extracted features. This approach also significantly improves accuracy and detection efficiency. However, the following challenges remain in corn pest detection: 1. When detecting pests in complex farmland environments, pest images are not only affected by background factors but also by the variable morphology and scale of the pests, which can easily lead to false or missed detections. 2. The appearance and shape of the same pest species vary significantly across different life stages. 3. Different pest species can exhibit indistinguishable similarities in color, texture, and shape, thus affecting recognition accuracy. To address these challenges, a corn pest detection algorithm based on a modified YOLOv8 was designed to enhance the model's feature extraction capabilities. Summary of the Invention
[0005] The present invention proposes a corn pest detection method based on MM-YOLOv8.
[0006] In order to solve the above technical problems, the technical solutions of the present invention are as follows:
[0007] A corn pest detection method based on MM-YOLOv8, comprising the following steps:
[0008] Step 1: Collect different types of corn pest image data;
[0009] Step 2: preprocess the collected corn pest data to construct a corn pest dataset;
[0010] Step 3: Build the MM-YOLOv8 corn pest detection network model:
[0011] (3a) Design a multi-scale fine-grained feature extraction module (MFE): The MFE consists of two branch paths, a convolutional layer, and a feature addition layer. The two branches are the feature scaling path and the dynamic receptive field path. The output of the dynamic receptive field path is reduced in dimension by the convolutional layer and then added to the output of the feature scaling path to form the output of the MFE module.
[0012] (3b) Use the MFE module to replace the traditional convolution in the YOLOv8 model to enhance the model's ability to extract features;
[0013] (3c) Improve the coordinate attention mechanism (CA) to the multi-path coordinate attention mechanism (MBCA);
[0014] (3d) Adding MBCA attention to the YOLOv8 model enhances the model’s ability to focus on key area features;
[0015] Step 4: Use the preprocessed data set to train the MM-YOLOv8 model to obtain a trained MM-YOLOv8 model;
[0016] Step 5: Corn pest detection based on the MM-YOLOv8 model:
[0017] The image to be detected is input into the trained MM-YOLOv8 network model to obtain the detection results, including the location, category and confidence of the pests.
[0018] In step 2, the preprocessing includes image rotation, horizontal flipping, spatial translation, brightness adjustment, adding Gaussian noise, and data label format conversion;
[0019] In step (3a), the feature scaling path consists of one interval sampling operation, one Concat submodule, and one 3×3 convolutional layer submodule;
[0020] In step (3a), the dynamic receptive field path consists of a 3×3 convolutional layer, three dilated convolutional layers with different dilation rates (1, 3, and 5, respectively), a Concat submodule, a 1×1 convolutional layer, and an Addition layer;
[0021] In step (3b), the following method is used to replace the traditional convolution in the YOLOv8 model with the MFE module:
[0022] Replace the Conv modules except the first layer of the YOLOv8 model with the MFE module;
[0023] In step (3c), the multi-path coordinate attention mechanism (MBCA) consists of three global average pooling layers along different directions (width X direction, height Y direction and channel ch direction), two 1×1 convolutional layers, one 3×1 convolutional layer, one Concat module, one Mean module, two Split functions, and four Sigmoid functions;
[0024] In step (3d), the following method is used to add MBCA attention to the YOLOv8 model:
[0025] After adding MBCA attention to the backbone network, the features extracted by the backbone network are enhanced and its output is connected to the neck of YOLOv8 to ensure seamless transmission of information in the network;
[0026] The step 4 comprises:
[0027] Step 4.1: Use the preprocessed image dataset as the input of the MM-YOLOv8 model, and perform mosaic data enhancement and adaptive image scaling in sequence;
[0028] Step 4.2: Extract features in the feature extraction backbone network through the Conv module, MFE module, C2f module and MBCA attention;
[0029] Step 4.3: In the neck network Neck module, a combination of feature pyramid FPN and path aggregation network PAN is used to perform multi-scale fusion of different feature maps;
[0030] Step 4.4: Use CIoU loss function to calculate the score of the target proposal box;
[0031] Step 4.5: Use non-maximum suppression (NMS) to suppress the suggestion boxes smaller than the threshold and retain the suggestion boxes larger than the threshold.
[0032] Step 4.6: Set the number of training rounds. When the maximum number of training rounds is reached, the trained network model is obtained.
[0033] Compared with the prior art, the beneficial effects of the present invention are as follows: the present invention proposes a corn pest detection method based on MM-YOLOv8. Specifically, the present invention designs a multi-scale fine-grained feature extraction module (MFE) and uses the MFE module to replace the traditional convolution in the YOLOv8 model, thereby achieving the unity of fine-grained feature retention and multi-scale semantic perception during the model downsampling process, and enhancing the model's ability to extract features. In addition, the coordinate attention mechanism (CA) is improved to a multi-path coordinate attention mechanism (MBCA), and the MBCA attention is added to the YOLOv8 model to enhance important features, suppress unimportant features, and strengthen the model's ability to focus on features in key areas. The MM-YOLOv8 network model proposed in the present invention provides an effective technical solution for the detection of corn pests. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 Flowchart of the corn pest detection method based on MM-YOLOv8 in Example 1
[0035] Figure 2 Part of the data enhancement picture of Example 1
[0036] Figure 3 The number of categories and labels in Example 1
[0037] Figure 4 The MFE module structure diagram of Example 1
[0038] Figure 5 This is the characteristic scaling path structure diagram of Example 1
[0039] Figure 6 This is the dynamic receptive field path structure diagram of Example 1
[0040] Figure 7 This is the CA attention mechanism network structure diagram of Example 1
[0041] Figure 8 This is the MBCA attention mechanism network structure diagram of Example 1
[0042] Figure 9 This is the overall structure diagram of the MM-YOLOv8 network model of Example 1
[0043] Figure 10 Part of the test results of Example 1 DETAILED DESCRIPTION
[0044] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0045] Reference Figure 1 The implementation steps of the present invention are described in further detail.
[0046] Example 1
[0047] Step 1: Collect different types of corn pest image data:
[0048] The corn pest image data collected comes from the IP102 dataset, which contains images of 11 corn pest species: grub, mole cricket, wireworm, black cutworm, large cutworm, yellow cutworm, red spider, corn borer, army worm, aphid, Potosiabre vitarsis, and peach borer.
[0049] Step 2: Preprocess the collected corn pest data to construct a corn pest dataset. The preprocessing includes image rotation, horizontal flipping, spatial translation, brightness adjustment, Gaussian noise addition, and data label format conversion.
[0050] The original dataset was randomly divided into training set, validation set and test set in a ratio of 7:2:1. The original training set was augmented using data augmentation technology, while the validation set and test set were not processed. Specific operations included image rotation, horizontal flipping, spatial translation, brightness adjustment and adding Gaussian noise. The amplified dataset is the final dataset IP11-Corn, which contains 7,875 corn pest images. Finally, the data labels were converted from XML format to TXT format suitable for YOLO. Some data augmentation images are shown below. Figure 2 As shown, the specific number of categories and labels are as follows Figure 3 As shown;
[0051] Step 3: Build the MM-YOLOv8 corn pest detection network model:
[0052] (3a) Design a multi-scale fine-grained feature extraction module (MFE), whose network structure is shown in the following diagram: Figure 4 As shown in the figure, MFE consists of two branch paths, a convolutional layer, and a feature addition layer. The two branches are the feature scaling path and the dynamic receptive field path. The output of the dynamic receptive field path is reduced in dimension by the convolutional layer and then added to the output of the feature scaling path to form the output of the MFE module.
[0053] In step (3a), the feature scaling path consists of an interval sampling operation, a Concat submodule and a 3×3 convolutional layer submodule. The network structure is shown in the following figure: Figure 5 As shown;
[0054] Among them, the interval sampling operation splits the original feature map (H×W×C) into 4 sub-maps (H / 2×W / 2×C) in a 2×2 grid by taking a slice of one pixel every other pixel, and then splices them in the channel dimension. The feature values of the four adjacent positions (i,j), (i,j+1), (i+1,j), and (i+1,j+1) in the original feature map are assigned to four different channels at the same spatial position (i / / 2, j / / 2) of the output feature map. The size of the spliced feature map is H / 2×W / 2×4C. This operation converts spatial information to the channel dimension, downsampling while retaining the fine-grained information of the input features to the maximum extent, avoiding the problem of fine-grained information loss caused by traditional downsampling operations. Finally, a convolution is used to extract features to achieve cross-channel feature fusion and adjust the number of channels;
[0055] In step (3a), the dynamic receptive field path consists of a 3×3 convolutional layer, three dilated convolutional layers with different dilation rates (1, 3, and 5), a Concat submodule, a 1×1 convolutional layer, and an Addition residual connection layer. The network structure is shown in the figure below. Figure 6 As shown;
[0056] Its structure consists of an initial 3×3 convolution compression channel to reduce the number of parameters. It is then divided into three branches, which use different dilation rates (1, 3, and 5) for convolution to obtain multi-scale feature maps with receptive fields of 3×3, 7×7, and 11×11, respectively. Finally, they are concatenated and adjusted through 1x1 convolution channels, and then a residual connection is added. The multi-scale processing of this path is to capture information of different receptive fields through convolution layers with different dilation rates, thereby capturing multi-scale features. Residual connections retain more detailed information while preventing gradient vanishing and spatial information degradation.
[0057] (3b) Use the MFE module to replace the traditional convolution in the YOLOv8 model to enhance the model's ability to extract features;
[0058] Replace the Conv modules except the first layer of the YOLOv8 model with the MFE module;
[0059] (3c) Improve the coordinate attention mechanism (CA) to the multi-path coordinate attention mechanism (MBCA);
[0060] In step (3c), the CA network structure diagram is as follows Figure 7As shown in the figure, the multi-path coordinate attention mechanism (MBCA) consists of three global average pooling layers along different directions (width X direction, height Y direction and channel ch direction), two 1×1 convolutional layers, one 3×1 convolutional layer, one Concat module, one Mean module, two Split functions, and four Sigmoid functions. The network structure is shown in the figure. Figure 8 As shown;
[0061] Specifically, the MBCA module mainly consists of two stages: information encoding and attention weight generation. Given the input features Figure X (W×H×C), MBCA first encodes information through three parallel feature extraction paths: AdaptiveAvgPool2d is used to compress the feature map to 1×1 spatial dimensions, and then a 1×1 convolution is performed to generate the channel attention vector X pool_ch , mathematically expressed as:
[0062] X pool_ch =Conv(GAP(X))
[0063] At the same time, adaptive average pooling is performed along the vertical direction (H dimension) to generate X pool_h (1×H×C), generates X along the horizontal direction (W dimension) pool_w (W×1×C), the calculation process can be formalized as:
[0064]
[0065] Then X pool_h Concatenate with Xpool_w along the spatial dimension to form the joint feature X pool_hw ((H+W)×1×C), and apply 3×1 convolution to achieve cross-directional feature interaction:
[0066] X pool_hw =Conv 3×1 (Concat(X pool_h ,X pool_w ))
[0067] The transpose operation This is to ensure that the spatial dimensions are aligned. After convolution, the H and W dimensions are split and reconstructed into X′ pool_h and X′ pool_w .
[0068] The above is the process of MBCA encoding information. Attention weights are generated at the same time. Specifically, the fusion feature X pool_hw Perform convolution and use Sigmoid function to generate spatial attention weight W hw , mathematically expressed as:
[0069] W hw =σ(Conv(X pool_hw ))
[0070] Then the split weight is the vertical weight W h With the horizontal weight W w , and take the weight W hw The channel mean is used as the channel weight W ch , respectively for W h and X′ pool_h 、W w and X′ pool_w 、W ch and X pool_ch Perform element-wise multiplication to obtain the enhanced attention feature X″ pool_h 、X″ pool_w , and X′ pool_ch in:
[0071] X″ pool_h =X′ pool_h W h
[0072] X″ pool_w =X′ pool_w W w
[0073] X′ pool_ch =X pool_ch W ch
[0074] Finally, the three-way enhanced features are normalized by the Sigmoid function and multiplied with the original input features to perform multi-dimensional attention weighting to obtain the final output:
[0075] Y=X·σ(X″ pool_w )·σ(X″ pool_h )·σ(X′ pool_ch )
[0076] (3d) Adding MBCA attention to the YOLOv8 model enhances the model’s ability to focus on key area features;
[0077] After adding MBCA attention to the backbone network, the features extracted by the backbone network are enhanced and its output is connected to the neck of YOLOv8 to ensure seamless transmission of information in the network. The overall structure of the MM-YOLOv8 network model is shown in the figure below. Figure 9 As shown;
[0078] Step 4: Use the preprocessed dataset to train the MM-YOLOv8 model to obtain the trained MM-YOLOv8 model, including:
[0079] Step 4.1: Use the preprocessed image dataset as the input of the MM-YOLOv8 model, and perform mosaic data enhancement and adaptive image scaling in sequence;
[0080] Step 4.2: Extract features in the feature extraction backbone network through the Conv module, MFE module, C2f module and MBCA attention;
[0081] Step 4.3: In the neck network Neck module, a combination of feature pyramid FPN and path aggregation network PAN is used to perform multi-scale fusion of different feature maps;
[0082] Step 4.4: Use CIoU loss function to calculate the score of the target proposal box;
[0083] Step 4.5: Use non-maximum suppression (NMS) to suppress the suggestion boxes smaller than the threshold and retain the suggestion boxes larger than the threshold.
[0084] Step 4.6: Set the number of training rounds. When the maximum number of training rounds is reached, the trained network model is obtained.
[0085] In this implementation, a 640*640 image is input at the input end, and mosaic data enhancement and adaptive image scaling are performed in sequence. This is done in the feature extraction backbone network (Backbone), where the Conv module, MFE module, C2f module, and MBCA attention module are sequentially used to extract features. At the neck (Neck), a combination of feature pyramid (FPN) and path aggregation network (PAN) is used to perform multi-scale fusion of features. The CIoU loss function is then used to calculate the difference between the predicted bounding box and the actual bounding box to obtain the score of the target suggestion box. Non-maximum suppression (NMS) is then used to filter the scores of the target suggestion boxes, retaining those greater than the threshold and removing those less than the threshold.
[0086] Step 5: Corn pest detection based on MM-YOLOv8:
[0087] Input the image to be detected into the trained MM-YOLOv8 network model to obtain the detection results, including the location, category and confidence of the pests, such as Figure 10 As shown;
[0088] The specific experimental environment and parameter settings for this example are as follows: All experiments were conducted on a computer configured with an Intel(R) Xeon(R) Platinum 8362 CPU @ 2.80GHz, an RTX 3090 (24GB) GPU, and Windows 10. The MM-YOLOv8 network model was constructed based on the PyTorch framework and trained using the SGD optimizer. The image input size was 640×640, the batch size was 16, the learning rate was 0.01, and a cosine annealing strategy was used for adjustment. Training was performed for 150 epochs, and model performance was evaluated at the end of each epoch, with the optimal model weights saved. The details are shown in Table 1.
[0089] Table 1 Experimental environment and parameter settings
[0090]
[0091] In order to better illustrate the technical effects of the present invention, in this embodiment, the performance of the method proposed in the present invention is compared with the existing target detection algorithm.
[0092] Table 2 Performance comparison of MM-YOLOv8 and existing target detection models
[0093]
[0094] As shown in Table 2, MM-YOLOv8 is compared with SSD, Faster-R-CNN, YOLOv3, YOLOv5n, YOLOv6n, YOLOv7-tiny, YOLOv8n and YOLOv11n object detection models in terms of precision (P), recall (R), F1 score, and mAP value indicators.
[0095] It can be seen from Table 2 that compared with other object detection algorithms, the method proposed in this paper achieves the highest precision (P), recall (R), F1 score and mAP value.
[0096] The above description is merely a specific embodiment of the present invention and is not intended to limit the manner in which the present invention is to be practiced. However, those skilled in the art will recognize that any modification, equivalent substitution, or improvement that violates the spirit and principles of the present invention is prohibited. Any modification, equivalent substitution, or improvement that is within the spirit and principles of the present invention is intended to be within the scope of protection of the present invention.
Claims
1. A corn pest detection method based on MM-YOLOv8, characterized in that: The following steps are involved: Step 1: Collect different types of corn pest image data; Step 2: preprocess the collected corn pest data to construct a corn pest dataset; Step 3: Build the MM-YOLOv8 corn pest detection network model: (3a) Design a multi-scale fine-grained feature extraction module (MFE); (3b) Use the MFE module to replace the traditional convolution in the YOLOv8 model to enhance the model's ability to extract features; (3c) Improve the coordinate attention mechanism (CA) to the multi-path coordinate attention mechanism (MBCA); (3d) Adding MBCA attention to the YOLOv8 model enhances the model’s ability to focus on key area features; Step 4: Use the preprocessed data set to train the MM-YOLOv8 model to obtain a trained MM-YOLOv8 model; Step 5: Corn pest detection based on the MM-YOLOv8 model: The image to be detected is input into the trained MM-YOLOv8 network model to obtain the detection results, including the location, category and confidence of the pests.
2. The corn pest detection method based on MM-YOLOv8 according to claim 1, characterized in that: The preprocessing in step 2 includes image rotation, horizontal flipping, spatial translation, brightness adjustment, adding Gaussian noise and data label format conversion.
3. The corn pest detection method based on MM-YOLOv8 according to claim 1, characterized in that: The multi-scale fine-grained feature extraction module (MFE) in step (3a) comprises two branch paths, a convolutional layer, and a feature addition layer. The two branches are a feature scaling path and a dynamic receptive field path. The output of the dynamic receptive field path is reduced in dimension by the convolutional layer and then added to the output of the feature scaling path to form the output of the MFE module.
4. The corn pest detection method based on MM-YOLOv8 according to claim 1, characterized in that: In step (3b), the following method is used to replace the traditional convolution in the YOLOv8 model with the MFE module: Replace the Conv modules except the first layer of the YOLOv8 model with the MFE module.
5. The corn pest detection method based on MM-YOLOv8 according to claim 1, characterized in that: In step (3c), the following method is used to improve the coordinate attention mechanism (CA) to a multi-path coordinate attention mechanism (MBCA): Based on the original CA, after the input feature map is average pooled, stacked, convolved and split into features representing two directions in width and height, attention weights are no longer generated directly. Instead, dynamic attention weights are generated through convolution and Sigmoid activation function before splitting, and the weights are split into attention weights in height and width dimensions. Then, the split weights are multiplied with the corresponding outputs of different directions after the original split to strengthen and dynamically adjust the features in two directions. Subsequently, the strengthened attention features in two directions are subjected to Sigmoid activation function to generate attention weights in two directions; in addition, an attention branch in the channel dimension is added, and the original feature map is pooled and convolved to obtain a feature map in the channel dimension. The channel average of the attention weights in the height and width dimensions is used as the weight in the channel dimension and multiplied with it to obtain the attention feature of the channel branch. The attention feature is then subjected to Sigmoid activation function to generate attention weights in the channel dimension. Finally, the original input feature map is multiplied by the output weights of the three branches to obtain the final output of MBCA attention. The improved multi-path coordinate attention mechanism (MBCA) consists of three global average pooling layers along different directions (width X direction, height Y direction and channel ch direction), two 1×1 convolutional layers, one 3×1 convolutional layer, one Concat module, one Mean module, two Split functions, and four Sigmoid functions.
6. The corn pest detection method based on MM-YOLOv8 according to claim 1, characterized in that: In step (3d), the following method is used to add MBCA attention to the YOLOv8 model: After adding MBCA attention to the backbone network, the features extracted by the backbone network are enhanced and its output is connected to the neck of YOLOv8 to ensure seamless transfer of information in the network.
7. The corn pest detection method based on MM-YOLOv8 according to claim 1, characterized in that: The step 4 comprises: Step 4.1: Use the preprocessed image dataset as the input of the MM-YOLOv8 model, and perform mosaic data enhancement and adaptive image scaling in sequence; Step 4.2: Extract features in the feature extraction backbone network through the Conv module, MFE module, C2f module and MBCA attention; Step 4.3: In the neck network Neck module, a combination of feature pyramid FPN and path aggregation network PAN is used to perform multi-scale fusion of different feature maps; Step 4.4: Use CIoU loss function to calculate the score of the target proposal box; Step 4.5: Use non-maximum suppression (NMS) to suppress the suggestion boxes smaller than the threshold and retain the suggestion boxes larger than the threshold. Step 4.6: Set the number of training rounds. When the maximum number of training rounds is reached, the trained network model is obtained.