Rice disease and insect pest detection method and system
By embedding the Optimize SPPF module and C2f-faster neural network in the YOLOv8n model, the problems of insufficient feature extraction capability and high computational complexity in rice pest recognition in the prior art are solved, and more efficient feature extraction and recognition accuracy are achieved.
Patent Information
- Application Number
- CN202411566771.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-03-28
Smart Images

Figure CN119723323A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of target detection, in particular to a method and system for detecting rice pests and diseases. Background Art
[0002] Rice occupies an important position among my country's food crops, and its yield is closely related to my country's food security issues, but it often encounters the threat of pests during its growth. Affected by various environmental factors, the occurrence of rice pests has increased year by year, causing serious damage to rice yield and safety, and pest control has become the primary issue in rice growth. Traditional pest control methods are mainly through manual identification and trapping, which is not only time-consuming and labor-intensive, but also causes further reduction in rice production due to improper pesticide spraying. Therefore, it is crucial to accurately identify rice pests in complex field environments. Only by accurately killing pests can rice yields be guaranteed. With the continuous development of artificial intelligence technology, deep learning methods have been widely used in the field of crop disease and pest detection. Existing target detection algorithms have made some progress in the identification of pests in complex environments, but the interference caused by the messy background in the field and the small target volume to crop pest detection has not been solved. Summary of the invention
[0003] Purpose of the invention: The purpose of the present invention is to provide a method and system for detecting rice pests and diseases that enhances feature extraction capability, expands feature extraction receptive field, and reduces computational complexity.
[0004] Technical solution: The rice pest and disease detection method of the present invention comprises the following steps:
[0005] Obtain rice pictures, input them into the trained detection model, and obtain the category information and location information of rice pests and diseases in the rice pictures;
[0006] The detection model is a YOLOv8n model, and the SPPF module in YOLOv8n is replaced by the Optimize SPPF module, and the C2f module in YOLOv8n is replaced by the C2f-faster module; the Optimize SPPF is to connect a convolution unit after the second pooling layer of the SPPF module, and fuse it with the output of the SPPF module to obtain the output of the Optimize SPPF module; the C2f-faster module is to replace the Bottleneck of the C2f module with the FasterNet module;
[0007] The training method of the detection model comprises: obtaining rice images containing rice diseases and insect pests and annotating them to obtain a data set, and using the data set to train the detection model.
[0008] Furthermore, the C2f-faster module is used to replace the C2f module in the Neck part of YOLOv8n.
[0009] Furthermore, after obtaining the rice images containing rice pests and diseases and annotating them to obtain the data set, the method further includes dividing the data set into a training set, a test set and a validation set.
[0010] Furthermore, the category information of rice pests and diseases includes brown spot disease, rice blast disease and bacterial leaf blight disease.
[0011] Furthermore, obtaining the category information and location information of rice pests and diseases in the rice picture includes marking the location of the rice pests and diseases with a rectangular frame on the rice picture, and marking the category information and the confidence value.
[0012] The rice pest and disease detection system of the present invention comprises:
[0013] A data acquisition unit, used for acquiring rice images;
[0014] A detection unit is used to input a rice picture into a trained detection model to obtain category information and location information of rice pests and diseases in the rice picture; the detection model is a YOLOv8n model, the SPPF module in YOLOv8n is replaced by the Optimize SPPF module, and the C2f module in YOLOv8n is replaced by the C2f-faster module; the OptimizeSPPF is to connect a convolution unit after the second pooling layer of the SPPF module, and obtain the output of the Optimize SPPF module after fusing it with the output of the SPPF module; the C2f-faster module is to replace the Bottleneck of the C2f module with the FasterNet module;
[0015] The training unit is used to train the detection model, obtain rice images containing rice diseases and insect pests and annotate them to obtain a data set, and use the data set to train the detection model.
[0016] Furthermore, in the detection unit, the C2f-faster module is used to replace the C2f module of the Neck part in YOLOv8n.
[0017] Furthermore, in the detection unit, a rectangular frame is used to mark the location of rice pests and diseases on the rice picture, and the category information and confidence value are marked. The category information of rice pests and diseases includes brown spot disease, rice blast and bacterial leaf blight. In the training unit, after obtaining a rice image containing rice pests and diseases and annotating it to obtain a data set, it also includes dividing the data set into a training set, a test set and a validation set.
[0018] The electronic device described in the present invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the computer program implements the rice pest and disease detection method when loaded into the processor.
[0019] The computer-readable storage medium of the present invention stores a computer program, and when the computer program is executed by a processor, the rice pest and disease detection method is implemented.
[0020] Beneficial effects: Compared with the prior art, the advantages of the present invention are: (1) The present invention embeds the Optimize SPPF module and the C2f-faster neural network in YOLOv8n, which can simultaneously perceive surrounding targets in a larger range, reduce computational redundancy and memory access, and perform multi-scale feature fusion to fully utilize their complementarity and capture important information in rice pest and disease images through high-performance neural networks; (2) The present invention achieves a significant improvement in computing speed after streamlining the number and size of pooling kernels by designing the Optimize SPPF module, can effectively fuse feature information from different scales, enhance the adaptability and robustness of the model to object scale changes, and reduce the memory usage of the model at runtime; (3) In order to reduce computational redundancy and memory access, the present invention designs the C2f-faster neural network to achieve the most advanced performance in classification, detection and segmentation tasks, while having lower latency and higher throughput. The Pconv and PWConv layers are used at the same time to fully and effectively utilize information from all channels to help the model find small target rice pests and diseases that are difficult to capture more quickly, thereby better utilizing the computing power on the device and improving the accuracy of rice pest and disease detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 The present invention is a flow chart of the rice pest detection method;
[0022] Figure 2 It is a schematic diagram of the structure of the Optimize SPPF module of the present invention;
[0023] Figure 3 It is a schematic diagram of the network structure of the C2f-faster neural network of the present invention;
[0024] Figure 4 This is a schematic diagram of the structure of the rice pest and disease detection model of the present invention;
[0025] Figure 5 2 is a diagram showing the detection results of an embodiment of the present invention. DETAILED DESCRIPTION
[0026] The technical solution of the present invention is further described below in conjunction with the accompanying drawings.
[0027] like Figure 1 As shown, the rice pest and disease detection method comprises the following steps.
[0028] S1. Create an image dataset containing rice pests and diseases, annotate the dataset, and divide it into appropriate proportions.
[0029] Create an image dataset containing rice pests and diseases, annotate the dataset, and divide it according to an appropriate ratio; convert all images into jpg format; annotate all image datasets, use labelimg as the annotation tool, use a rectangle as the annotation box, and annotate rice pests and diseases; the requirement for the rectangular annotation box is the minimum rectangle that encloses a single target, and multiple targets are allowed to be annotated in one image; modify all image file names to match the corresponding label file names.
[0030] The created data set is divided into a training set, a test set, and a validation set in a ratio of 8:1:1. In this embodiment, 1158 training set images, 124 test set images, and 73 validation set images are obtained.
[0031] S2. Design the Optimize SPPF (OSPPF for short) module and the C2f-faster neural network and integrate them into YOLOv8n to replace the SPPF and C2f of the Neck part of YOLOv8n.
[0032] like Figure 2 As shown in the figure, the Optimize SPPF module includes an initial convolution block and multiple MaxPool2d pooling layers. The specific process of the Optimize SPPF module is as follows: first, the feature map is segmented. The SPP layer divides the input feature map into multiple grids of different sizes (such as 1x1, 2x2, 4x4, etc.); then three small pooling layers (such as three layers of 3x3 maximum pooling) are used to replace the pooling operation of a single large core to obtain the feature representation of each grid; after the second maximum pooling layer, the network introduces a concat operation to merge feature maps from different sources to enhance the feature expression ability of the model. This feature fusion can be from different layers of the same network, or from multiple parallel network structures. Finally, feature splicing is performed to splice the feature representations of all grids to form a feature vector of fixed length.
[0033] Compared with the traditional SPPF module, the Optimize SPPF module mainly adds a new conv branch introduced from the second pooling layer to further reduce the amount of calculation and strengthen feature fusion, improve detection efficiency and accuracy, help the model capture more semantic information of rice pests and diseases, and bring better results for feature extraction of rice pests and diseases.
[0034] like Figure 3 As shown in the figure, the C2f-faster neural network structure adopts a four-layer hierarchical strategy, and the beginning of each layer is equipped with two types of preprocessing layers: one is the embedding layer, which uses a standard 4x4 convolution kernel with a stride of 4 to achieve spatial downsampling; the other is the merging layer, which uses a standard 2x2 convolution kernel with a stride of 2 to expand the number of channels. These preprocessing layers provide the basis for dimensionality reduction and channel expansion for subsequent layers.
[0035] In each hierarchical stage, a series of FasterNet blocks are deployed to replace the original Bottlenec, which are the basic units for building the network. The network structure is further optimized by increasing the number of FasterNet blocks in the last two stages and allocating more computing resources to these stages accordingly. Such design decisions are intended to improve the overall performance of the network while maintaining the efficiency of memory access. Each FasterNet block of the C2f-faster neural network has a PConv layer followed by two PWConv (or Conv 1×1) layers. The following is a detailed explanation of the Pconv module:
[0036] PConv performs traditional convolution operations on only a subset of the input feature channels to extract spatial features, while keeping the other channels unchanged. Specifically, for continuous or regular memory access patterns, we select the first or last continuous channel (cp) as the representative of the entire feature map for calculation. Without losing generality, the input and output feature maps are usually assumed to have the same number of channels, and the FLOPs of PConv are only 1 / 16 of those of ordinary Conv.
[0037] The C2f-faster neural network reduces computational redundancy and the number of memory accesses, extracts spatial features more efficiently, and achieves higher running speeds than other neural networks on a wide range of devices without compromising the accuracy of various visual tasks.
[0038] Integrate the Optimize SPPF module and C2f-faster neural network structure into YOLOv8n, and build a model such as Figure 4As shown. Through the Optimize SPPF module, the number and size of pooling kernels are simplified to achieve a significant improvement in computing speed. It can effectively fuse feature information from different scales, enhance the adaptability and robustness of the model to object scale changes, and reduce the memory usage of the model at runtime. To reduce computational redundancy and memory access, the C2f-faster neural network enables it to achieve state-of-the-art performance in classification, detection, and segmentation tasks, while having lower latency and higher throughput. Using the Pconv and PWConv layers at the same time, the information from all channels is fully and effectively used to help the model find small, hard-to-catch rice pests and diseases more quickly, thereby making better use of the computing power on the device and improving the accuracy of rice pests and diseases.
[0039] S3. Use the training set and the test set to train the built model and obtain the training results. The specific implementation process is as follows:
[0040] The data set is input into the built model for training. Each batch of 16 images is trained. One round of training is when all the images in the training set are trained once. A total of 200 rounds of training are conducted. The initial learning rate is set to 0.01, and the final learning rate is 0.001. The training uses a variety of data enhancement strategies such as random splicing, random mixing, and random left-right flipping. The usage rate of random splicing is 100%, the usage rate of random left-right flipping is 50%, the usage rate of random mixing is 15%, and the usage rate of random copy and paste is 50%. The total video memory used for model training is 32G, which consists of two GPUs with 16G video memory. The GPU model is TealaV100. The detailed information of the training environment is shown in Table 1.
[0041] Table 1 Training environment information table
[0042] parameter Configuration GPU TeslaV100-SXM2-16GB Programming language version Python 3.8 Deep learning framework version PyTorch 1.8.0 CUDA Version 10.2.89 Numpy version 1.21.6 OpenCV version 4.7.0.72
[0043] During training, the image size is uniformly adjusted to 640×640. The model will continuously extract features and downsample the input image by two times until the feature map size reaches 20×20. The prediction head will make predictions on feature maps of 80×80, 40×40, and 20×20. The prediction will generate a rectangular box to mark the target location and predict the category, which includes brown spot disease, rice blast disease, and bacterial leaf blight disease. After reaching the specified training round, the best result of all rounds is selected and saved to obtain the training weight file Train_Result.pt. The training results are shown in Table 2.
[0044] Table 2 Training results
[0045]
[0046] In Table 2, map@.5 represents the mean average precision when the IoU threshold is 0.5, and map@.5.95 represents the mean average precision at different IoU thresholds [0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95].
[0047] Compared with YOLOv8n, the rice pest and disease detection method based on Optimize SPPF and C2f-faster neural network shows good precision, recall rate and map@.5. The specific data are shown in Table 3.
[0048] Table 3 Effect comparison
[0049]
[0050] S4. Use the training results to detect rice pests and diseases. The specific steps are as follows:
[0051] Use the above Train_Result.pt to detect the pictures in the test set; the detection results are marked with a rectangular box, and the category information and confidence value are marked, such as Figure 5 shown.
[0052] The rice pest and disease detection system of the present invention comprises:
[0053] A data acquisition unit, used for acquiring rice images;
[0054] A detection unit is used to input a rice picture into a trained detection model to obtain category information and location information of rice pests and diseases in the rice picture; the detection model is a YOLOv8n model, the SPPF module in YOLOv8n is replaced by the Optimize SPPF module, and the C2f module in YOLOv8n is replaced by the C2f-faster module; the OptimizeSPPF is to connect a convolution unit after the second pooling layer of the SPPF module, and obtain the output of the Optimize SPPF module after fusing it with the output of the SPPF module; the C2f-faster module is to replace the Bottleneck of the C2f module with the FasterNet module;
[0055] The training unit is used to train the detection model, obtain rice images containing rice diseases and insect pests and annotate them to obtain a data set, and use the data set to train the detection model.
[0056] The electronic device described in the present invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the computer program implements the rice pest and disease detection method when loaded into the processor.
[0057] The computer-readable storage medium of the present invention stores a computer program, and when the computer program is executed by a processor, the rice pest and disease detection method is implemented.
[0058] The computer-readable storage media may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, flash memory, or any other medium that can be used to store program code in the form of instructions or data structures and that can be accessed by a computer.
[0059] The processor is used to execute the computer program stored in the memory to implement each step of the method involved in the above embodiment.
Claims
1. A method for detecting rice pests and diseases, characterized in that: The steps include: Obtain rice pictures, input them into the trained detection model, and obtain the category information and location information of rice pests and diseases in the rice pictures; The detection model is a YOLOv8n model, and the SPPF module in YOLOv8n is replaced by the Optimize SPPF module, and the C2f module in YOLOv8n is replaced by the C2f-faster module; the Optimize SPPF is to connect a convolution unit after the second pooling layer of the SPPF module, and fuse it with the output of the SPPF module to obtain the output of the Optimize SPPF module; the C2f-faster module is to replace the Bottleneck of the C2f module with the FasterNet module; The training method of the detection model comprises: obtaining rice images containing rice diseases and insect pests and annotating them to obtain a data set, and using the data set to train the detection model.
2. The rice pest and disease detection method according to claim 1, characterized in that: Use the C2f-faster module to replace the C2f module in the Neck part of YOLOv8n.
3. The rice pest detection method according to claim 1, characterized in that: After obtaining the rice images containing rice pests and diseases and annotating them to obtain the data set, the method further includes dividing the data set into a training set, a test set and a validation set.
4. The rice pest and disease detection method according to claim 1, characterized in that: Category information of rice pests and diseases includes brown spot disease, rice blast and bacterial leaf blight.
5. The rice pest detection method according to claim 1, characterized in that: The obtaining of the category information and location information of rice pests and diseases in the rice picture includes marking the location of the rice pests and diseases with a rectangular frame on the rice picture, and marking the category information and the confidence value.
6. A rice pest and disease detection system, characterized in that: include: A data acquisition unit, used for acquiring rice images; A detection unit is used to input a rice picture into a trained detection model to obtain category information and location information of rice pests and diseases in the rice picture; the detection model is a YOLOv8n model, the SPPF module in YOLOv8n is replaced by the Optimize SPPF module, and the C2f module in YOLOv8n is replaced by the C2f-faster module; the OptimizeSPPF is to connect a convolution unit after the second pooling layer of the SPPF module, and obtain the output of the Optimize SPPF module after fusing it with the output of the SPPF module; the C2f-faster module is to replace the Bottleneck of the C2f module with the FasterNet module; The training unit is used to train the detection model, obtain rice images containing rice diseases and insect pests and annotate them to obtain a data set, and use the data set to train the detection model.
7. The rice pest and disease detection system according to claim 6, characterized in that: In the detection unit, the C2f-faster module is used to replace the C2f module of the Neck part in YOLOv8n.
8. The rice pest and disease detection system according to claim 6, characterized in that: In the detection unit, a rectangular frame is used to mark the location of rice pests and diseases on the rice picture, and the category information and confidence value are marked. The category information of rice pests and diseases includes brown spot disease, rice blast and bacterial leaf blight. In the training unit, after obtaining a rice image containing rice pests and diseases and annotating it to obtain a data set, the data set is also divided into a training set, a test set and a validation set.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the computer program is loaded into a processor, the rice disease and insect pest detection method according to any one of claims 1 to 5 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the rice disease and insect pest detection method according to any one of claims 1 to 5 is implemented.
Citation Information
Cited By
Method for detecting plant diseases and insect pests of open field vegetables
CN120689683A
Lightweight corn disease detection method and system
CN122023779A