Cocoa pod disease and insect pest detection method based on Transform detection model
By improving the CGM-DETR model, optimizing the backbone network and feature fusion, combining data enhancement and lightweight processing, the deployment difficulties of the RT-DETR model on resource-constrained devices are solved, and efficient and real-time detection of cocoa pod pests is achieved.
Patent Information
- Application Number
- CN202510524910.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-24
- Publication Date
- 2025-08-05
AI Technical Summary
When the existing cocoa pod pest detection model based on RT-DETR is deployed on resource-constrained devices, the computing resource consumption is large, resulting in deployment difficulties and low pest identification efficiency in complex scenarios.
Build an improved CGM-DETR model, optimize the model structure by improving the backbone network, feature fusion and connection layer, combining data enhancement and annotation, reduce the amount of model parameters and calculation complexity, and perform lightweight processing on the mobile terminal.
While maintaining high detection accuracy, the model's computing resource consumption is reduced, real-time pest detection on resource-constrained devices is realized, and it is suitable for real-time monitoring in the field.
Smart Images

Figure CN120431050A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of agricultural pest and disease detection, and specifically relates to a cocoa pod pest and disease detection method based on improved RT-DETR, which is suitable for real-time identification and positioning of cocoa pod pests and diseases in complex scenarios. Background Art
[0002] Cocoa is one of the world's most important economic crops, widely used in the food industry and possessing unique value in medicine, health supplements, and skincare products. However, as a vital source of income for millions of farmers worldwide, cocoa production faces serious threats from pests and diseases. Therefore, detecting cocoa pod pests and diseases is crucial for ensuring the healthy growth of cocoa trees and maintaining stable cocoa yields. Traditional cocoa pest and disease detection methods rely on manual observation and diagnosis of lesions. While these methods have some practicality, they suffer from limitations in efficiency, accuracy, and real-time performance.
[0003] Over the past decade, machine learning has garnered widespread attention in the field of object detection, primarily due to its powerful capabilities in feature extraction and pattern recognition. However, the transformer-based RT-DETR series of models suffers from several issues, such as high computational resource consumption, which can become a bottleneck limiting their use in some applications. Model size and computational complexity are particularly important when deploying models on resource-constrained devices.
[0004] Therefore, a cocoa pod pest and disease detection method based on improved RT-DETR was developed, aiming to reduce model resource consumption without affecting accuracy by optimizing the network structure, which is of great value for achieving large-scale, efficient and accurate real-time detection of cocoa pod pests and diseases. Summary of the Invention
[0005] The main technical problem to be solved by the present invention is how to reduce the number of parameters, computational complexity and weight of the cocoa pod pest and disease detection model to facilitate its deployment on resource-constrained devices.
[0006] In order to achieve the above object, the present invention is implemented by adopting the following technical solutions: S1: Acquire images of cocoa pod pests and diseases in complex scenes and screen the images. The image types include pest and disease samples and healthy samples. S2: Perform data augmentation and annotation on the images. Divide the entire dataset into training set, validation set, and test set; S3: Build an improved CGM-DETR model, including backbone network improvement, feature fusion improvement, and connection layer improvement. The improved model is based on the improvement of RT-DETR. S4: Use the training set to train the improved cocoa pod pest and disease detection model; S5: Test the improved cocoa pod pest and disease detection model using the test set; S6: Deploy the trained model to mobile devices to achieve real-time field detection.
[0007] As a preferred technical solution, the steps of collecting images of cocoa pod pests and diseases are as follows: S101: Acquisition of cocoa pod pest and disease imagery. Determine the specific types and quantities of cocoa pod pests and diseases based on requirements, and collect images of cocoa pod pests and diseases, covering scenarios with varying lighting, occlusion, and overlap. S102: Image screening. Screen out images with suitable size, specifications, and angles according to requirements.
[0008] As a preferred technical solution, the steps for preparing a cocoa pod pest and disease dataset are as follows: S201: Data enhancement. Common data enhancement methods include rotation, flipping, cropping, scaling, and translation. Select the appropriate data enhancement method to process the image. S202: Data labeling. Use the labeling tool Labelimg to label the processed image and save the labeling file in the corresponding folder; S203: Dataset Partitioning. Shuffle the labeled images so that each sample's position in the dataset is randomized, eliminating any potential order effects. After the data is fully randomized, split the dataset into three independent parts: training, validation, and test sets, with a ratio of 8:1:1.
[0009] As a preferred technical solution, the CGM-DETR model is improved based on the RT-DETR model, and the specific improvement steps are as follows: S301: Backbone network improvement. Construct a Context Guided BasicBlock module, which consists of two ordinary convolutions and a Context Guided Block. The input data is processed in two branches. The upper branch first passes through a 3×3 convolution layer (Conv 3×3), then connects to a batch normalization layer (BN) and a ReLU activation function in sequence, and then is input into the "Context GuidedBlock" module, and finally passes through a batch normalization layer (BN) again; the lower branch directly passes through a 1×1 convolution layer (Conv 1×1), followed by a batch normalization layer (BN). The outputs of the two branches are concatenated and finally pass through a ReLU activation function to output the result. The constructed Context GuidedBasicBlock module replaces the BasicBlock part in the original network; S302: Feature Fusion Improvement. Construct the OREPANCSPELAN module. First, two ordinary convolutions form the OREPAN module. A residual link is added to the OREPAN module to create the OREPANBottleneck module. Features are extracted through two parallel convolutional layers and further processed in the OREPANBottleneck module, thus forming the OREPANCS module. Finally, the input is divided into different branches, and the OREPANCS module is used multiple times in each branch, combined with convolutional layers for feature processing. Finally, a concatenation operation is used to fuse all branch features, forming the more complex OREPANCSPELAN module. The OREPANCSPELAN module then replaces the RepC3 portion of the original network. S303: Connection layer improvements. The DSDI module is constructed. Each layer's feature map first passes through the SpatialAttention and ChannelAttention modules, followed by sampling and mapping, before being input into the dynamic snake convolution. Finally, the processed features at each layer are fused through a concatenation operation. The DSDI module then replaces the Concat part of the original network.
[0010] As a preferred technical solution, the trained and improved cocoa pod pest and disease detection model is specifically: S401: Select the PyTorch deep learning framework to train the cocoa pod pest and disease recognition model, set the image input size, select the optimizer, adjust the learning rate, and set the number of training rounds.
[0011] As a preferred technical solution, the improved cocoa pod pest and disease detection model is specifically: S501: Use the test set as input to test the performance of the improved cocoa pod pest and disease detection model. Four evaluation metrics are introduced: mean average precision (mAP), computational complexity (GFLOPs), number of parameters, and weight size.
[0012] As a preferred technical solution, the trained model is deployed to the mobile device, specifically: S601: Model optimization. Use pruning and quantization to lightweight the model, reducing the amount of computation and size to make it suitable for mobile device resource constraints. S602: Format conversion. Convert the trained model to ONNX format, and then use the coremltools library to further convert it to the Core ML format supported by the mobile terminal; S603: Application Integration. Embed the converted model into the mobile application code and select the framework interface to load the model. For Android, use TFLite, and for iOS, use Core ML. S604: Performance Tuning. Enable GPU and NPU hardware acceleration to optimize memory and computing efficiency, ensuring real-time inference and low power consumption. S605: Testing and debugging. Test functionality, speed, and stability on different devices and fix compatibility issues or accuracy loss. S606: Applying the debugged detection model that meets the actual working conditions to the actual working conditions to conduct actual detection of cocoa pod diseases and insect pests.
[0013] Compared with the prior art, the present invention has the following advantages and beneficial effects: Algorithm performance optimization: The original RT-DETR network model was optimized to reduce the model's consumption of computing resources, which is conducive to the deployment of the model on resource-constrained edge devices. It can demonstrate good detection results and real-time performance when identifying cocoa pod pests and diseases in various complex environments.
[0014] Strong image adaptability: The images collected in this invention cover scenes with different lighting, occlusion and overlap, and are processed using data enhancement methods such as rotation and cropping. They can adapt to images with different lighting, colors and angles, making the model more generalizable and applicable to a wider range of scenarios.
[0015] Convenient for large-scale application: Compared with the traditional identification method that relies on manual experience, the present invention can realize rapid and accurate identification of pests and diseases, and is convenient for large-scale application.
[0016] Wide range of application areas: By deploying the pest and disease identification model on mobile devices, real-time detection in the field can be easily achieved. It can also be applied to other fields such as agricultural research, crop planting management, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a flow chart of the method of the present invention; Figure 2 This is a structural diagram of the CGM-DETR model of the present invention; Figure 3 This is the module structure diagram of Context Guided BasicBlock of the present invention; Figure 4 This is a structural diagram of the OREPANCSPELAN module of the present invention; Figure 5 The structural diagram of the DSDI module of the present invention; DETAILED DESCRIPTION
[0018] To facilitate understanding of the present invention, the present invention will be described more fully below with reference to the relevant drawings.
[0019] like Figure 1 As shown, a cocoa pod pest and disease detection method based on the Transformer detection model includes: S1: Acquire images of cocoa pod pests and diseases in complex scenes and screen the images. The pest and disease types include black pod, frosty rot, mirid and healthy samples. S2: Perform data augmentation and annotation on the images. Divide the entire dataset into training set, validation set, and test set with a ratio of 8:1:1; S3: Build an improved CGM-DETR model, including backbone network improvement, feature fusion improvement, and connection layer improvement. The improved model is based on the improvement of RT-DETR. S4: Use the training set to train the improved cocoa pod pest and disease detection model; S5: Test the improved cocoa pod pest and disease detection model using the test set; S6: Deploy the trained model to mobile devices to achieve real-time field detection.
[0020] Furthermore, in step S1, an image of cocoa pod pests and diseases in a complex scene is obtained by: S101: Acquire images of cocoa pod pests and diseases. Determine the specific types and quantities of cocoa pod pests and diseases based on requirements. Collect images of cocoa pod pests and diseases, covering scenarios with varying lighting, occlusion, and overlap. In this embodiment, the pest types generally include black pod, frosty rot, mirid, and healthy samples. Black pod and frosty rot are fungal diseases, while mirid is caused by the cocoa stink bug. These three diseases are widespread and pose a serious threat to cocoa production yield and quality. These images can be collected from the following two aspects: Public websites: such as kaggle, roboflow, huggingface, MendeleyData and other public dataset websites.
[0021] On-site photography: If conditions permit, you can film directly on-site. This provides the most direct and realistic image data. The images in this paper were collected at the Treeco cocoa plantation in Wanning City, Hainan Province, covering scenes with varying lighting, occlusion, and overlap.
[0022] The images collected from public websites and on-site photography mentioned above need to be as diverse as possible, including different lighting, angles, backgrounds, and other factors, so as to improve the generalization ability of the model.
[0023] S102: Image screening. Check each collected image and select images with suitable size, specifications and angles according to requirements.
[0024] Furthermore, in step S2, the cocoa pod pest and disease dataset is prepared, specifically: S201: Data augmentation. Data augmentation is primarily used to alleviate data shortages, improve model generalization, and prevent overfitting. Common data augmentation methods include rotation, flipping, cropping, scaling, and translation. In the above process, rotation and cropping are primarily used to augment the data.
[0025] S202: Data Labeling. Use the labeling tool Labelimg to label the processed images. During the labeling process, the images are divided into four categories: BLACK POD, FROSTY ROT, MIRID, and healthy samples. The labeling information and images are saved in the corresponding folders.
[0026] S203: Dataset Partitioning. Shuffle the labeled images so that each sample's position in the dataset is randomized, eliminating any potential order effects. After the data is fully randomized, split the dataset into three independent parts: training, validation, and test sets, with a ratio of 8:1:1.
[0027] Furthermore, in step S3, the improved CGM-DETR model is constructed. Specifically, the improvements are as follows: in the backbone network, the original BasicBlock part is replaced by the Context Guided BasicBlock module; in the neck network, the RepC3 part is replaced by the OREPANCSPELAN module; and the original Concat part is replaced by the DSDI module. The CGM-DETR model structure diagram is shown below. Figure 2 shown.
[0028] The Context Guided BasicBlock module structure diagram is as follows Figure 3 As shown, it consists of two standard convolutional layers and a Context Guided Block. Input data is processed in two branches. The upper branch first passes through a 3×3 convolutional layer (Conv 3×3), followed by a batch normalization layer (BN) and a ReLU activation function, before being input into the Context Guided Block module and finally passing through a batch normalization layer (BN). The lower branch directly passes through a 1×1 convolutional layer (Conv 1×1), followed by a batch normalization layer (BN). The outputs of the two branches are concatenated and finally passed through a ReLU activation function to produce the output.
[0029] OREPANCSPELAN module structure diagram is as follows Figure 4 As shown, the RepNCSPELAN4 module is optimized using an online convolutional reparameterization method. First, the OREPAN module is constructed from two standard convolutions. A residual link is added to the OREPAN module to create the OREPANBottleneck module. Features are extracted through two parallel convolutional layers and further processed in the OREPANBottleneck module, forming the OREPANCS module. Finally, the input is divided into different branches, each of which uses the OREPANCS module multiple times. These branches are then combined with convolutional layers for feature processing. Finally, a concatenation operation (concat) fuses the features of all branches to form the more complex OREPANCSPELAN module.
[0030] DSDI module structure diagram as shown below Figure 5As shown in Figure 1, it consists of spatial attention, channel attention, and dynamic snake convolution (DSConv). It contains four layers, from l=1 to l=4, each processing feature maps at different scales. The feature maps of each layer first pass through the spatial attention and channel attention modules, then undergo sampling and mapping before being input into the dynamic snake convolution. Finally, the processed features of each layer are fused through a concatenation operation.
[0031] Furthermore, in step S4, the training of the improved cocoa pod pest and disease detection model is specifically as follows: S401: Use the PyTorch deep learning framework to train a cocoa pod pest and disease recognition model. Input the processed data from S2 and train the model using the training set. Set the image input size to 640×640, select the AdamW optimizer, adjust the learning rate to 0.0001, and set the number of training rounds to 200. During training, the model gradually learns how to identify pest and disease components of the cocoa pod through forward and backpropagation based on the labeled information. Then, the model parameters are continuously adjusted to improve recognition accuracy.
[0032] Furthermore, in step S5, the improved cocoa pod pest and disease detection model is tested, specifically: S501: The performance of the improved cocoa pod pest and disease detection model is tested using the test set as input. The test set is a subset of the original dataset used to test the model's effectiveness. This data was not previously used in training and is therefore completely new to the model. Four evaluation metrics, namely mean average precision (mAP), computational complexity (GFLOPs), number of parameters, and weight size, are used to evaluate the performance of the cocoa pod pest and disease recognition model. mAP is the average prediction accuracy for different categories and is generally used for multi-target detection. GFLOPs, parameters, and weight size are metrics used to assess model size and resource consumption. In this example, comparative experiments show that the improved CGM-DETR model achieves a mean average precision (mAP) of 87.2%, with a 33.9% reduction in parameters, a 40.0% reduction in computational complexity, and a 27.7% reduction in weight file size. The improved model significantly reduces both model size and resource consumption.
[0033] Furthermore, in step S6, the trained model is deployed to the mobile device, specifically: S601: Model Optimization. Pruning and quantization are used to lightweight the model, reducing computational effort and size to make it suitable for mobile device resource constraints. In this embodiment, pruning is used to remove redundant parameters or layers in the model, further reducing model size and resource consumption.
[0034] S602: Format conversion. Convert the trained model to ONNX format. Use the coremltools library to further convert it to the Core ML format supported by mobile devices, making the model more suitable for mobile device deployment.
[0035] S603: Application Integration: Embed the converted model into the mobile application code and select the framework interface to load the model. For Android, use TFLite, and for iOS, use Core ML.
[0036] S604: Performance Tuning. Enable GPU and NPU hardware acceleration to optimize memory and computational efficiency. Process large inputs in chunks to avoid memory overflows. Ensure real-time inference and low power consumption.
[0037] S605: Testing and Debugging. Deploy the model on different devices, test its functionality, speed, and stability, check the model path and format compatibility, and confirm that quantization and pruning do not destroy the high-sensitivity features of the lesion area.
[0038] S606: Applying the debugged detection model that meets the actual working conditions to the actual working conditions to conduct actual detection of cocoa pod diseases and insect pests.
[0039] Those skilled in the art will appreciate that all or part of the steps of the methods described in the above embodiments can be implemented via hardware associated with computer program instructions. The program can be stored in a computer-readable storage medium. When the program is executed, the processes described in the above method embodiments can be executed. The storage medium includes, but is not limited to, a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0040] It should be noted that the detailed description of the technical solutions in the preferred embodiments of the present invention is for illustrative purposes only and is not intended to be limiting. After reading this specification, those skilled in the art may modify the technical solutions in the embodiments or replace some of the technical features with equivalents. Such modifications or replacements should not deviate from the essence of the technical solutions and the technical spirit and scope of the embodiments of the present invention.
Claims
1. A cocoa pod pest and disease detection method based on the Transformer detection model, characterized in that The following steps are involved: S1: Acquire images of cocoa pod pests and diseases in complex scenes and screen the images. The image types include pest and disease samples and healthy samples. S2: Perform data augmentation and annotation on the images. Divide the entire dataset into training set, validation set, and test set; S3: Build an improved CGM-DETR model, including backbone network improvement, feature fusion improvement, and connection layer improvement. The improved model is based on the improvement of RT-DETR. S4: Use the training set to train the improved cocoa pod pest and disease detection model; S5: Test the improved cocoa pod pest and disease detection model using the test set; S6: Deploy the trained model to mobile devices to achieve real-time field detection.
2. The cocoa pod pest and disease detection method based on the Transformer detection model according to claim 1, characterized in that: In S1, the images of cocoa pod pests and diseases are collected in the following steps: S101: Acquisition of cocoa pod pest and disease imagery. Determine the specific types and quantities of cocoa pod pests and diseases based on requirements, and collect images of cocoa pod pests and diseases, covering scenarios with varying lighting, occlusion, and overlap. S102: Image screening. Screen out images with suitable size, specifications, and angles according to requirements.
3. The cocoa pod pest and disease detection method based on the Transformer detection model according to claim 1, characterized in that: In S2, the cocoa pod pest and disease dataset is generated by the following steps: S201: Data enhancement. Common data enhancement methods include rotation, flipping, cropping, scaling, and translation. Select the appropriate data enhancement method to process the image. S202: Data labeling. Use the labeling tool Labelimg to label the processed image and save the labeling file in the corresponding folder; S203: Dataset Partitioning. Shuffle the labeled images so that each sample's position in the dataset is randomized, eliminating any potential order effects. After the data is fully randomized, split the dataset into three independent parts: training, validation, and test sets, with a ratio of 8:1:
1.
4. The cocoa pod pest and disease detection method based on the Transformer detection model according to claim 1, characterized in that: In S3, the CGM-DETR model is improved based on the RT-DETR model. The specific improvement steps are as follows: S301: Backbone network improvement. Construct a Context Guided BasicBlock module, which consists of two ordinary convolutions and a Context Guided Block. The input data is processed in two branches. The upper branch first passes through a 3×3 convolution layer (Conv 3×3), then connects to a batch normalization layer (BN) and a ReLU activation function in sequence, and then is input into the "Context GuidedBlock" module, and finally passes through a batch normalization layer (BN) again. The lower branch directly passes through a 1×1 convolution layer (Conv 1×1), followed by a batch normalization layer (BN). The outputs of the two branches are concatenated and finally pass through a ReLU activation function to output the result. The constructed Context GuidedBasicBlock module replaces the BasicBlock part of the original network; S302: Feature Fusion Improvement. Construct the OREPANCSPELAN module. First, two ordinary convolutions form the OREPAN module. A residual link is added to the OREPAN module to create the OREPANBottleneck module. Features are extracted through two parallel convolutional layers and further processed in the OREPANBottleneck module, thus forming the OREPANCS module. Finally, the input is divided into different branches, and the OREPANCS module is used multiple times in each branch, combined with convolutional layers for feature processing. Finally, a concatenation operation is used to fuse all branch features, forming the more complex OREPANCSPELAN module. The OREPANCSPELAN module then replaces the RepC3 portion of the original network. S303: Connection layer improvements. The DSDI module is constructed. Each layer's feature map first passes through the SpatialAttention and ChannelAttention modules, followed by sampling and mapping, before being input into the dynamic snake convolution. Finally, the processed features at each layer are fused through a concatenation operation. The DSDI module then replaces the Concat part of the original network.
5. The cocoa pod pest and disease detection method based on the Transformer detection model according to claim 1, characterized in that: In S4, the improved cocoa pod pest and disease detection model is trained, specifically: S401: Select the PyTorch deep learning framework to train the cocoa pod pest and disease recognition model, set the image input size, select the optimizer, adjust the learning rate, and set the number of training rounds.
6. The cocoa pod pest and disease detection method based on the Transformer detection model according to claim 1, characterized in that: In S5, the improved cocoa pod pest and disease detection model is tested, specifically: S501: Convert the test set image data into tensor format and convert the corresponding annotation file into a tensor sequence containing the ground-truth labels. Then, perform normalization on the image tensors to generate normalized test set input data, which is used as input to test the performance of the improved cocoa pod pest and disease detection model. Four evaluation metrics, namely mean average precision (mAP), computational complexity (GFLOPs), number of parameters, and weight size, are introduced to evaluate the performance of the cocoa pod pest and disease recognition model.
7. The cocoa pod pest and disease detection method based on the Transformer detection model according to claim 1, characterized in that: In S6, the trained model is deployed to the mobile device, specifically: S601: Model optimization. Use pruning and quantization to lightweight the model, reducing the amount of computation and size to make it suitable for mobile device resource constraints. S602: Format conversion. Convert the trained model to ONNX format, and then use the coremltools library to further convert it to the Core ML format supported by the mobile terminal; S603: Application Integration. Embed the converted model into the mobile application code and select the framework interface to load the model. For Android, use TFLite, and for iOS, use Core ML. S604: Performance Tuning. Enable GPU and NPU hardware acceleration to optimize memory and computing efficiency, ensuring real-time inference and low power consumption. S605: Testing and debugging. Test functionality, speed, and stability on different devices and fix compatibility issues or accuracy loss. S606: Applying the debugged detection model that meets the actual working conditions to the actual working conditions to conduct actual detection of cocoa pod diseases and insect pests.