Crop pest larva detection method based on YOLOv7-SV

By constructing the SGNet lightweight network and VoVGSCSP module in YOLOv7-SV, combined with the MPDIoU loss function, the problems of the existing pest detection methods in natural scenarios are solved, and efficient and accurate crop pest larvae are achieved Test.

CN119049024APending Publication Date: 2024-11-29GUILIN UNIVERSITY OF TECHNOLOGY
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411116441.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-14
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

The existing pest detection methods have shortcomings in accuracy and reliability, especially in natural scenarios, and traditional methods require a lot of manual intervention, while deep learning-based methods are difficult to apply on mobile devices due to the large amount of parameters. The detection effect is not ideal.

Method used

The lightweight network model based on YOLOv7-SV is adopted, and the SGNet lightweight network is built, the YOLOv7 backbone network is replaced, the calculation amount is reduced, and the E-ELAN module is replaced with VoVGSCSP module, and the MPDIoU loss function is used to optimize the detection effect.

Benefits of technology

It realizes efficient and accurate detection of crop pest larvae on mobile devices, improves detection accuracy and model adaptability, and reduces model complexity and computing resource requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119049024A_ABST
    Figure CN119049024A_ABST
Patent Text Reader

Abstract

The invention discloses a crop pest larva detection method based on YOLOv7-SV, and relates to the technical field of target detection. Comprising the following steps: 1) classifying and labeling different crop pest larva images, and constructing a data set; 2) dividing the data set into a training set and a test set; 3) constructing a YOLOv7-SV network model: constructing an SGNet lightweight network, taking the SGNet lightweight network as a YOLOv7 backbone network, replacing a head E-ELAN module with VoVGSCSP, and optimizing a loss function based on MPDIOU; 4) training the YOLOV7-SV model to obtain an optimal model weight; 5, the optimal model weight is loaded, crop pest larva images are input, and a final detection result is obtained.According to the constructed network model, the parameter quantity and the calculation quantity can be effectively reduced, the higher convergence speed and the more accurate regression result are achieved, and an effective technical scheme is provided for crop pest larva detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of target detection technology, specifically to a method for detecting crop pest larvae based on YOLOv7-SV. Background Technology

[0002] Crops are constantly threatened by pests during their growth, leading to reduced yield and quality. In particular, larvae feed on plant leaves, affecting plant growth; they sever the stems of seedlings and young plants, causing lodging or death; and they feed on flower buds, severely damaging plant growth and reducing fruit quality. When populations are large, larvae spread in large numbers, like an army, posing a serious threat to crop growth. To address this, real-time monitoring is needed to provide early warning of crop pest occurrences, offering crucial technical support for crop production monitoring and providing a foundation for developing plant protection prescriptions and automated, precise pesticide application.

[0003] Traditional pest detection methods typically rely on manually designed feature extractors and classifiers, resulting in low accuracy and reliability. They require significant manual intervention and adjustments and struggle to adapt to complex and changing natural environments. While deep learning-based pest detection methods can automatically extract features and classify pests, offering higher accuracy and robustness, they require substantial labeled data and computational resources, and their numerous model parameters hinder their application on mobile devices. Therefore, addressing the issues of large model parameters and unsatisfactory detection performance in natural scene images, designing an efficient and accurate lightweight network model for detecting crop pest larvae is essential for pest monitoring, the development of precise control measures, and deployment on mobile devices. Summary of the Invention

[0004] This invention proposes a method for detecting crop pest larvae based on YOLOv7-SV.

[0005] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows:

[0006] A method for detecting crop pest larvae based on YOLOv7-SV includes the following steps:

[0007] Step 1, construct a dataset of crop pest larvae:

[0008] Images were collected and the samples were augmented using data augmentation methods. Images of different larvae were classified and labeled to construct a dataset of multiple types of crop pest larvae.

[0009] Step 2, segment the crop pest larvae dataset:

[0010] The dataset of crop pest larvae was divided into a training set and a test set.

[0011] Step 3: Construct the YOLOv7-SV network model for detecting crop pest larvae:

[0012] (3a) Construct a lightweight SGNet network: containing one 3×3 convolutional layer, three Shuffle Unit modules, three Global Attention (GAM) modules, and three 1×1 convolutional layers;

[0013] (3b) Replace the YOLOv7 backbone network with the SGNet lightweight network to reduce the computational cost of the model;

[0014] (3c) Replace the E-ELAN module in the YOLOv7 model header with the VoVGSCSP module to reduce model complexity;

[0015] (3d) Optimize the original loss function using the MPDIoU loss function:

[0016] Step 4, train the YOLOv7-SV network model:

[0017] The training set images are input into the YOLOv7-SV network, and the network parameters are iteratively updated using stochastic gradient descent (SGD) until the loss function converges.

[0018] Step 5, Detection of crop pest larvae based on the YOLOv7-SV model:

[0019] The image to be detected is input into the pre-trained YOLOv7-SV network model to obtain the detection results, including the location, category, and confidence level of the larvae.

[0020] In step 1, the following method is used to construct a dataset of crop pest larvae:

[0021] A total of 2,929 images of larvae of eight crop pests, including the fall armyworm, were collected from natural scene photography and web searches. Data augmentation methods including mirroring, rotation, brightness adjustment, and Gaussian noise enhancement were used to obtain a dataset of 10,460 images of crop pest larvae. The larvae were then labeled as follows: fall armyworm (AWL), corn borer (CBL), cutworm (GBL), beet armyworm (BAL), cotton bollworm (FAL), rice leaf roller (RLFL), white grub (GL), and wireworm (WL).

[0022] In step 2, the following method is used to segment the crop pest larvae dataset:

[0023] 8368 images (80%) were randomly selected from the dataset to build the training set, and the remaining 20% ​​were used to build the test set.

[0024] In step (3a), the Shuffle unit module consists of two branches: the left branch consists of one ChannelSplit sub-module, two 1×1 convolutional layer sub-modules, one 3×3 depthwise separable convolutional layer sub-module, one Concat sub-module, and one Channel Shuffle sub-module; the right branch consists of three 1×1 convolutional layer sub-modules, two 3×3 depthwise separable convolutional layer sub-modules, one Concat sub-module, and one Channel Shuffle sub-module.

[0025] The Channel Shuffle submodule consists of one channel grouping, one channel permutation, and one channel concatenation.

[0026] In step (3a), the GAM module consists of a Channel Attention Sub-module and a Spatial Attention Sub-module. When the GAM module is given an input feature map... intermediate state and output status Represented as:

[0027]

[0028]

[0029] in, and These are channel and spatial attention maps, respectively. This represents element-wise multiplication;

[0030] The channel attention submodule consists of a dimension converter, a multilayer perceptron (MLP), a dimension reducer, and a sigmoid function.

[0031] The spatial attention submodule consists of a 7×7 convolution operation to reduce the number of channels, a spatial information fusion unit, a 7×7 convolution operation to restore the consistency of the number of channels, and a sigmoid function.

[0032] In step (3b), the YOLOv7 backbone network is replaced with the SGNet lightweight network using the following method:

[0033] The three Shuffle unit modules are connected to the GAM module, and then each module is passed through a 1×1 convolutional layer to adjust the dimension of the feature map. The output of each feature map is then connected to the head of the YOLOv7 module to ensure seamless information transfer in the network.

[0034] In step (3c), the E-ELAN module is replaced with the VoVGSCSP module using the following method:

[0035] Replace all four E-ELAN modules in the YOLOv7 header with VoVGSCSP modules;

[0036] The VoVGSCSP module consists of three 1x1 convolutional layers, one gated shortcut connection (GSCSP) module, and one Concat module.

[0037] The gated shortcut connection (GSCSP) module consists of one 3x3 convolutional layer and two GSConv modules;

[0038] The GSConv module consists of a 1x1 convolutional layer, a 3x3 depthwise separable convolutional layer, a Concat module, and a shuffle module.

[0039] In step (3d), the MPDIoU loss function is defined as:

[0040]

[0041]

[0042] In the formula, IoU is the intersection-union ratio of the ground truth bounding box and the predicted bounding box, and the coordinates of the top-left and bottom-right corners of the predicted bounding box are respectively... and The coordinates of the top left and bottom right corners of the actual bounding box are respectively and , For the actual bounding box, To predict the bounding box, and This represents the actual width and height of the bounding box. and This is used to calculate the Euclidean distance between the predicted bounding box and the actual bounding box's top-left and bottom-right corners.

[0043] Compared with existing technologies, the beneficial effects of this invention are as follows: This invention proposes a method for detecting crop pest larvae based on YOLOv7-SV. Specifically, this invention replaces the YOLOv7 backbone network with a lightweight SGNet network, improving the network's ability to refine features, enhancing useful features, and suppressing useless features. Furthermore, it replaces the YOLOv7 head E-ELAN module with a VoVGSCSP module, reducing model complexity. Simultaneously, it employs the minimum point distance IoU loss (MPDIoU) to address the problems of existing loss functions, achieving faster convergence speed and more accurate regression results. The lightweight YOLOv7-SV network model proposed in this invention provides an effective technical solution for detecting crop pest larvae. Attached Figure Description

[0044] Figure 1 This is a flowchart of the YOLOv7-SV-based method for detecting crop pest larvae in Example 1.

[0045] Figure 2 Enhanced images of part of Example 1

[0046] Figure 3 The number of categories and labels for Example 1

[0047] Figure 4 This is a structural diagram of the SGNet lightweight network module in Example 1.

[0048] Figure 5 This is a structural diagram of the attention mechanism (GAM) module in Example 1.

[0049] Figure 6 This is a diagram showing the overall structure of the YOLOv7-SV network model in Example 1.

[0050] Figure 7 This is a structural diagram of the VoVGSCSP module in Example 1.

[0051] Figure 8 Anchor block diagram of MPDIoU loss function in Example 1

[0052] Figure 9 The image shows the detection results of Example 1.

[0053] Figure 10 This is a visualization of the system terminal in Example 1. Detailed Implementation

[0054] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0055] Reference Figure 1 The implementation steps of the present invention will be described in further detail.

[0056] Example 1

[0057] Step 1, construct a dataset of crop pest larvae:

[0058] Collect images, classify and label images of different larvae, and construct datasets of various types of crop pest larvae;

[0059] (1a) Image acquisition:

[0060] A total of 2,929 images of larvae of eight crop pests, including the fall armyworm larvae, were collected from natural scene photography and web searches.

[0061] (1b) Data augmentation:

[0062] A dataset of crop pest larvae containing 10,460 images was obtained through data augmentation methods including mirroring, rotation, brightness adjustment, and Gaussian noise. Some of the augmented images are shown below. Figure 2 As shown, the specific number of categories and labels are as follows: Figure 3 As shown;

[0063] (1c) Image sample annotation:

[0064] The LabelImg annotation tool was used to label different types of larvae. The fall armyworm was labeled as "AWL", the corn borer as "CBL", the cutworm as "GBL", the beet armyworm as "BAL", the cotton bollworm as "FAL", the rice leaf roller as "RLFL", the white grub as "GL", and the wireworm as "WL".

[0065] Step 2, segment the crop pest larvae dataset:

[0066] The dataset was divided into training and test sets in an 8:2 ratio. Specifically, 8368 images (80%) were randomly selected from the dataset to build the training set, and the remaining 20% ​​were used to build the test set.

[0067] Step 3: Construct the YOLOv7-SV network model for detecting crop pest larvae:

[0068] (3a) Construct the SGNet lightweight network, the network structure diagram of which is as follows: Figure 4 As shown, it contains one 3×3 convolutional layer, three Shuffle Unit modules, three Global Attention (GAM) modules, and three 1×1 convolutional layers;

[0069] In step (3a), the Shuffle unit module consists of two branches, left and right. The left branch consists of one ChannelSplit sub-module, two 1×1 convolutional layer sub-modules, one 3×3 depthwise separable convolutional layer sub-module, one Concat sub-module, and one Channel Shuffle sub-module. The right branch consists of three 1×1 convolutional layer sub-modules, two 3×3 depthwise separable convolutional layer sub-modules, one Concat sub-module, and one Channel Shuffle sub-module.

[0070] The Channel Split submodule groups the channels of the input feature map, allowing each group to be processed independently. A 1×1 convolutional layer is used to adjust the number of channels and dimensions. A 3×3 depthwise separable convolutional layer performs depthwise convolution on the segmented channels. The Concat submodule concatenates the feature map processed by depthwise convolution with the feature map processed by 1×1 convolution. The Channel Shuffle submodule rearranges the channels of the concatenated feature map to ensure effective information exchange between different channels.

[0071] In step (3a), the GAM module consists of a channel attention sub-module and a spatial attention sub-module, such as... Figure 5 As shown, when the GAM module provides an input feature map intermediate state and output status Represented as:

[0072]

[0073]

[0074] and These are channel and spatial attention maps, This represents element-wise multiplication;

[0075] The channel attention submodule consists of a dimension converter, a multilayer perceptron (MLP), a dimension reducer, and a sigmoid function. The dimension converter is used to reduce the dimension of the input feature map and extract global channel information. The multilayer perceptron (MLP) is used to capture the relationships and dependencies between channels in the feature map. The dimension reducer restores the vector processed by the MLP to have the same number of channels as the input feature map. Finally, the sigmoid function is used to map the generated channel weights to the range [0, 1], thereby adjusting the importance of each channel in the input feature map.

[0076] The spatial attention submodule consists of a 7×7 convolution operation, a spatial information fusion unit, a 7×7 convolution operation, and a sigmoid function. The 7×7 convolution operation is used to reduce the number of channels while preserving spatial information. The spatial information fusion unit is used to fuse the spatial information in the feature map after the number of channels has been reduced. The 7×7 convolution operation is used to restore the number of channels to maintain consistency with the number of input channels. Finally, after processing by the sigmoid function, a spatial weight map in the range [0, 1] is obtained.

[0077] (3b) Replace the YOLOv7 backbone network with the SGNet lightweight network to reduce the computational cost of the model;

[0078] The YOLOv7 network uses the lightweight SGNet network as its backbone. Three Shuffle unit modules are connected to the GAM module, and then 1×1 convolutional layers are used to adjust the dimension of the feature maps. The outputs are then connected to the YOLOv7 head to ensure seamless information transfer within the network. The overall structure of the YOLOv7-SV network model is shown below. Figure 6 As shown;

[0079] (3c) Replace the E-ELAN module in the YOLOv7 model header with the VoVGSCSP module to reduce model complexity;

[0080] In step (3c), the VoVGSCSP module contains two branches, such as... Figure 7 As shown, the upper branch first goes through a 1x1 convolutional layer to adjust the number of channels; then the gated shortcut connection (GSCSP) module selectively allows or suppresses information transmission; the lower branch goes through a 1x1 convolutional layer for channel compression; finally, the two branches are concatenated and fused by Concat, and then go through a 1x1 convolutional layer to adjust the number of output channels and output the feature map.

[0081] The Gated Shortcut Connection (GSCSP) module divides the input feature map into two branches. The upper branch extracts spatial features through a 3x3 convolutional layer, while the lower branch consists of two GSConv modules to achieve grouped convolution and channel compression.

[0082] The GSConv module consists of one 1x1 convolutional layer, one 3x3 depthwise separable convolutional layer, one Concat module, and one shuffle module, as follows: Figure 7 As shown, a 1x1 convolutional layer is used to adjust the number of channels, followed by a 3x3 depthwise separable convolutional layer to extract spatial features. Then, the feature map is fused through the Concat module, and finally, the channels are rearranged through the shuffle module so that the network can better learn and fuse information from different channels.

[0083] (3d) Optimize the original loss function using the MPDIoU loss function;

[0084] To accelerate the convergence speed of the network model and improve detection accuracy, MPDIoU is introduced to enhance the performance and efficiency of bounding box regression. Its anchor diagram is shown below. Figure 8 As shown, MPDIoU is a bounding box similarity comparison metric based on minimum point distance. It incorporates factors such as overlapping or non-overlapping regions, center point distance, and width / height deviation. The MPDIoU loss function is defined as:

[0085]

[0086]

[0087] In the formula, IoU is the intersection-union ratio of the ground truth bounding box and the predicted bounding box, and the coordinates of the top-left and bottom-right corners of the predicted bounding box are respectively... and The coordinates of the top left and bottom right corners of the actual bounding box are respectively and , For the actual bounding box, To predict the bounding box, and This represents the actual width and height of the bounding box. and This is used to calculate the Euclidean distance between the predicted bounding box and the actual bounding box's top-left and bottom-right corners.

[0088] Step 4, train the YOLOv7-SV network model:

[0089] The training set images are input into the YOLOv7-SV network, and the network parameters are iteratively updated using stochastic gradient descent (SGD) until the loss function converges. The final model parameters and optimal model weights are then saved.

[0090] Step 5, Detection of crop pest larvae based on the YOLOv7-SV model:

[0091] The image to be detected is input into a pre-trained YOLOv7-SV network model to obtain the detection results, including the location, category, and confidence score of the larvae. Figure 9 As shown.

[0092] The specific experimental environment and parameters for this embodiment were set as follows: all experiments were conducted on a computer configured with an Intel(R) Silver4210R@2.40GHz 2.39GHz, an RTX 3060Ti (12GB) GPU, and a Windows 10 system. A YOLOv7-SV network model was built 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 cosine annealing was used for tuning. The model was trained for 300 epochs, and the model performance was evaluated at the end of each epoch. The optimal model weights were saved, as shown in Table 1.

[0093] Table 1 Experimental Environment and Parameter Settings

[0094]

[0095] To better illustrate the technical effects of the present invention, in this embodiment, the performance of the method proposed in this invention is compared with that of existing target detection algorithms.

[0096] Table 2 Performance comparison of YOLOv7-SV with existing object detection models

[0097] Model P(%) R (%) mAP@0.5(%) mAP@0.5:0.95(%) Params(M) GFLOPs Faster R-CNN 75.10 73.24 76.25 53.66 136.50 402.00 SSD 77.91 76.50 83.82 71.33 26.33 62.80 YOLOv3 80.60 76.51 84.11 73.59 61.90 155.30 YOLOv4 84.61 81.46 85.40 73.89 52.60 119.90 YOLOv5l 87.91 85.40 87.55 74.08 48.00 115.40 YOLOv8l 86.83 89.73 89.77 75.54 43.60 165.20 YOLOv7 87.22 88.08 91.13 78.10 37.20 105.20 YOLOv7-SV 90.96 92.14 94.03 78.90 28.90M 78.95

[0098] Table 2 compares YOLOv7-SV with SSD, Faster R-CNN, YOLOv3, YOLOv4, YOLOv5l, YOLOv7, and YOLOv8l object detection models in terms of precision (P), recall (R), mAP, number of parameters (Params), and floating-point operations (FLOPs), where GFLOPs=10. 9 FLOPs.

[0099] As shown in Table 2, compared with other object detection algorithms, the method proposed in this invention achieves the highest precision (P), recall (R), and mAP value. Furthermore, the method of this invention has a lower number of model parameters and computational cost.

[0100] Considering the practicality of the YOLOv7-SV model, this embodiment designs a crop pest larvae detection system based on PyQt5. After loading weights and initializing the model, the system allows users to select an input image, video, or capture an image from a camera. Running the detection system outputs the location, category, and confidence score of the crop pest larvae. The system's visualization of the detection results is shown below. Figure 10 As shown.

[0101] The above description is merely one specific embodiment of the present invention and is not intended to limit the implementation of the present invention. However, those skilled in the art should not make any modifications, equivalent substitutions, or improvements that violate the spirit and principles of the present invention. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for detecting crop pest larvae based on YOLOv7-SV, characterized in that: The following steps are involved: Step 1: Build a crop pest larvae dataset: Collect images, expand samples through data augmentation methods, classify and annotate different larvae images, and construct a dataset of larvae of various types of crop pests; Step 2: Divide the crop pest larvae dataset: Divide the crop pest larvae dataset into training and testing sets; Step 3: Build the YOLOv7-SV crop pest larvae detection network model: (3a) Build the SGNet lightweight network; (3b) Replace the YOLOv7 backbone network with the SGNet lightweight network to reduce the amount of model calculation; (3c) Replace the E-ELAN module in the YOLOv7 model head with the VoVGSCSP module to reduce the model complexity; (3d) Using MPDIoU to optimize the original loss function; Step 4: Train the YOLOv7-SV network model: The training set images are input into the YOLOv7-SV network, and the network parameters are iteratively updated using stochastic gradient descent (SGD) until the loss function converges; Step 5, crop pest larvae detection based on YOLOv7-SV model: The image to be detected is input into the trained YOLOv7-SV network model to obtain the detection results, including the location, category and confidence of the larvae.

2. A crop pest larvae detection method based on YOLOv7-SV according to claim 1, characterized in that: In step 1, the following method is used to construct a crop pest larvae dataset: A total of 2929 images of eight kinds of crop pest larvae, including the fall armyworm larvae, were collected from natural scene photography and Web searches. Through mirroring, rotation, brightness adjustment and Gaussian noise data enhancement methods, a crop pest larvae dataset containing a total of 10460 images was obtained, and the pest larvae were labeled. Among them, the fall armyworm was labeled as "AWL", the corn borer was labeled as "CBL", the cutworm was labeled as "GBL", the beet armyworm was labeled as "BAL", the fall armyworm was labeled as "FAL", the rice leaf folder was labeled as "RLFL", the white grub was labeled as "GL", and the wireworm was labeled as "WL".

3. A crop pest larvae detection method based on YOLOv7-SV according to claim 1, characterized in that: In step 2, the crop pest larvae dataset is divided using the following method: 8368 images (80%) are randomly selected from the dataset to construct the training set, and the remaining 20% ​​are used to construct the test set.

4. A crop pest larvae detection method based on YOLOv7-SV according to claim 1, characterized in that: The SGNet network in step (3a) comprises one 3×3 convolutional layer, three Shuffle Unit modules, three global attention mechanism (GAM) modules, and three 1×1 convolutional layers.

5. The crop pest larvae detection method based on YOLOv7-SV according to claim 1, characterized in that: In the step (3b), the SGNet lightweight network is replaced by the YOLOv7 backbone network using the following method: The three Shuffle unit modules are connected to the GAM module respectively, and then pass through a 1×1 convolution layer to adjust the dimension of the feature map, and their outputs are connected to the head of YOLOv7 to ensure seamless transmission of information in the network.

6. A crop pest larvae detection method based on YOLOv7-SV according to claim 1, characterized in that: In the step (3c), the E-ELAN module is replaced with the VoVGSCSP module by the following method: Replace all four E-ELAN modules in the YOLOv7 header with VoVGSCSP modules.

7. A crop pest larvae detection method based on YOLOv7-SV according to claim 1, characterized in that: In the step (3d), the following method is used to define MPDIoU and optimize the original loss function: The MPDIoU loss function is defined as: Where IoU is the intersection over union of the real box and the predicted box, and the coordinates of the upper left and lower right corners of the predicted bounding box are and The coordinates of the upper left and lower right corners of the actual bounding box are and B gt is the actual bounding box, B prd is the predicted bounding box, w gt and h gt represents the width and height of the actual bounding box, and is the Euclidean distance between the coordinates of the upper left corner and lower right corner of the predicted bounding box and the actual bounding box.

Citation Information

Cited By

  • Dam underwater multi-class disease intelligent detection method and system under weak computing power condition

    CN119762957A

  • Semantic segmentation-based high-throughput analysis method for starch grains in wheat grains

    CN120088783A

  • A high-throughput analysis method for starch granules in wheat grains based on semantic segmentation

    CN120088783B