A lightweight rice pest detection method and electronic device based on GAFNet

By employing the lightweight rice pest detection method GAFNet, combined with global attention fusion and spatial pyramid pooling modules, C3 efficient feature selection attention module, and FECIoU loss function, the accuracy and efficiency issues of pest detection in paddy field environments are resolved, achieving efficient and accurate identification of small pests.

CN120912872BActive Publication Date: 2025-12-02JILIN AGRICULTURAL UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511431289.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-09
Publication Date
2025-12-02
Estimated Expiration
2045-10-09

AI Technical Summary

Technical Problem

Traditional methods are difficult to efficiently and accurately detect small pests in complex rice paddy environments, especially when image quality deteriorates and background interference is severe under low light conditions, leading to missed detections and false detections. Furthermore, the wide variety of pests and their small differences in appearance make classification difficult.

Method used

We adopted the lightweight rice pest detection method GAFNet, which optimizes feature extraction and target localization by introducing global attention fusion and spatial pyramid pooling modules, C3 efficient feature selection attention module, enhanced Ghost detection head and FECIoU loss function, and combined with data augmentation technology to simulate complex environment.

Benefits of technology

It improves the accuracy and efficiency of rice pest detection, reduces computational resource consumption, enhances the ability to identify complex backgrounds and small targets, and ensures rapid and accurate detection in complex environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120912872B_ABST
    Figure CN120912872B_ABST
Patent Text Reader

Abstract

This invention discloses a lightweight rice pest detection method and electronic device based on GAFNet. A global attention fusion and spatial pyramid pooling module is designed to capture global context and aggregate multi-scale features. Based on this, a C3-EFSA is proposed, which optimizes feature representation through depthwise separable convolution and a lightweight channel attention mechanism, thereby improving discriminative ability in complex backgrounds. An enhanced Ghost detection head is constructed, integrating enhanced Ghost convolution (EGConv), an SE module, and the SiLU activation function to reduce redundancy and further enhance the lightweight structure. Finally, an enhanced loss function FECIoU, optimized for complex pest detection scenarios, is proposed. This function is based on CIoU and introduces a numerically stable term and a hard sample weighting mechanism to further optimize the robustness of occluded pest localization. This lightweight target detection model can detect different types of rice pests and is suitable for practical deployment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to a lightweight rice pest detection method and electronic device based on GAFNet. Background Technology

[0002] With the increasing demand for efficient and accurate pest monitoring in agricultural production, traditional manual inspections and outdated pest detection methods are no longer sufficient to meet the challenges of modern agriculture, especially in rice pest control. Rice pests are diverse and have complex life habits, often leading to farmers' inability to detect and treat pests in a timely manner, thus affecting rice yield and quality. The detection of some small pests is particularly difficult; traditional methods are inaccurate and inefficient, and are prone to missed or false detections. These problems not only increase production costs but also result in significant economic losses.

[0003] In recent years, with the development of artificial intelligence technology, especially computer vision and deep learning, automated pest detection has gradually become an important tool in agricultural production. Deep learning models, especially object detection algorithms, have been widely used in crop pest and disease monitoring, demonstrating significant advantages. Using deep neural networks for pest identification and classification can greatly improve the accuracy and efficiency of pest detection, reduce human error, and enable real-time monitoring of pest occurrence, thereby achieving precise control. However, the complex and variable environment of rice paddies, including factors such as light, weather, background, and pest size, poses challenges to the performance of existing deep learning models.

[0004] When applying deep learning technology in rice pest detection, there are still several challenges, mainly including the following aspects: (1) The rice field environment is complex and changeable, and the lighting conditions are unstable, especially in low light conditions such as cloudy days or early morning and evening, which leads to a decrease in the image quality captured by the camera, thus affecting the recognition accuracy; (2) Rice pests are small in size, their posture changes frequently, and the background environment is complex. Traditional deep learning models are easily affected by background interference, which leads to recognition difficulties and is prone to misidentification or missed detection; (3) There are many types of pests in rice fields, and the appearance differences between similar pests are small, which brings great difficulty to the classification of existing deep learning models, resulting in a decrease in classification accuracy. Summary of the Invention

[0005] The technical solution of this invention to solve the above-mentioned technical problems is to provide a lightweight rice pest detection method based on GAFNet, comprising the following steps:

[0006] S1. Obtain an image dataset containing multiple categories of rice pests, and preprocess and augment the image dataset to construct a training set, a validation set, and a test set;

[0007] S2. Construct a lightweight object detection model GAFNet. The GAFNet model is based on the YOLO11n network and integrates the following modules:

[0008] A global attention fusion and spatial pyramid pooling module is used to replace the SPPF module in the original network to capture global contextual information and aggregate multi-scale features;

[0009] The C3 efficient feature selection attention module optimizes feature representation through depthwise separable convolution (DWConv) and lightweight channel attention mechanism to improve feature discrimination in complex backgrounds;

[0010] The enhanced Ghost detection head EGDetect is used to replace the standard detection head in the original network. EGDetect integrates the enhanced Ghost convolution (EGConv), Squeeze and Excitation (SE) modules and SiLU activation function to reduce computational redundancy.

[0011] S3. The GAFNet model is trained using the training set. During the training process, the enhanced loss function FECIoU is used. The FECIoU loss function introduces a numerical stability term and a hard sample weighting mechanism based on the CIoU loss function to optimize the robustness of locating occluded pests.

[0012] S4. Use the trained GAFNet model to detect pests in the input rice image and output the pest category and location information.

[0013] Furthermore, the execution process of the Global Attention Fusion and Spatial Pyramid Pooling Module (GAM-SPP) includes:

[0014] Channel compression is achieved by performing a 1×1 convolution on the input feature map;

[0015] The compressed feature maps are input into max pooling layers with kernel sizes of 5×5, 9×9, and 13×13 respectively for multi-scale feature extraction, and the extracted features are concatenated with the original input features in the channel dimension.

[0016] The concatenated features are subjected to 1×1 convolution to fuse multi-scale information and compress the number of channels;

[0017] The fused features are sequentially input into the Channel Attention (CA) submodule and the Spatial Attention (SA) submodule for weighted processing. The CA submodule adopts an SE structure, and the SA submodule obtains a spatial mapping map through max pooling and average pooling in the channel direction. After convolution and Sigmoid activation, spatial attention weights are generated.

[0018] Furthermore, the C3 efficient feature selection attention module (C3-EFSA) adopts a three-way parallel branch structure:

[0019] The first branch includes, in sequence, 1×1 convolution, 3×3 depthwise separable convolution, batch normalization (BN), and SiLU activation function;

[0020] The second branch includes, in sequence, 1×1 convolution, 5×5 depthwise separable convolution, batch normalization (BN), and SiLU activation function;

[0021] The third branch includes 3×3 grouped convolution, batch normalization (BN), and SiLU activation function in sequence;

[0022] The output features of the three branches are concatenated along the channel dimension;

[0023] The concatenated features are fused by performing 1×1 convolution, batch normalization (BN), and SiLU activation function.

[0024] An efficient channel attention (ECA) mechanism is applied to the fused features, which adaptively adjusts the channel attention through one-dimensional convolution;

[0025] When the number of input and output channels is the same, the module's output and input are residually connected.

[0026] Furthermore, the execution process of the Efficient Channel Attention (ECA) mechanism includes:

[0027] Perform global average pooling on the input features to obtain the global response scalar for each channel;

[0028] The obtained scalar vector is subjected to cross-channel interaction using one-dimensional convolution, with a kernel size of k, where k is determined by an adaptive function for the number of channels;

[0029] The output of the one-dimensional convolution is passed through the Sigmoid activation function to generate channel attention weights;

[0030] The generated weights are multiplied by the original input features to complete the recalibration of channel attention.

[0031] Furthermore, the execution process of the enhanced Ghost convolution (EGConv) module includes:

[0032] A partial output feature map is generated using a standard convolutional layer;

[0033] The aforementioned portion of the output feature map is fed into a depthwise separable convolution layer to generate the remaining output channels;

[0034] The feature map generated by standard convolution and the feature map generated by depthwise separable convolution are concatenated along the channel dimension to form a complete output feature.

[0035] The concatenated features are input into the SqueezeandExcitation (SE) module for channel attention weighting.

[0036] In the EGConv module, the SiLU activation function is used instead of the ReLU activation function.

[0037] Furthermore, the enhanced Ghost detection head (EGDetect) is implemented by replacing all the 3×3 and 1×1 standard convolutions in the original YOLO11n detection head with EGConv modules.

[0038] Furthermore, the calculation formula for the enhanced loss function FECIoU is as follows:

[0039] .

[0040] Furthermore, the data augmentation operations include one or more of random brightness adjustment, motion blur, random rectangular occlusion, and salt-and-pepper noise addition, used to simulate the complex environment of rice paddies.

[0041] To address the aforementioned technical problems, the present invention also proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method described above.

[0042] Compared with the prior art, the advantages of the present invention are as follows:

[0043] (1) The GAFNet network effectively improves the accuracy and efficiency of rice pest detection by introducing the Global Attention Fusion (GAM) module and Spatial Pyramid Pooling (SPP) module. Traditional pest detection methods struggle to handle small-sized, high-density, or occluded pest targets. The combination of GAM and SPP modules enhances the model's ability to perceive pest targets at different scales. The GAM module optimizes feature fusion, enabling the model to efficiently extract features of fine-grained targets in complex backgrounds. The SPP module, through multi-scale pooling strategies, enhances the model's spatial perception of pest targets, avoiding information loss and misidentification. This optimization significantly improves overall detection accuracy, especially in complex environments, ensuring rapid and accurate identification of pest targets in rice paddies.

[0044] (2) The GAFNet network introduces the C3-EFSA module, which combines depthwise separable convolution with a lightweight channel attention mechanism, enabling the model to more accurately identify small targets in complex backgrounds. Traditional pest detection methods are prone to missed or false detections when faced with occlusion, complex backgrounds, or small targets. The C3-EFSA module, by introducing multi-scale receptive field modeling and ECA mechanism, can effectively improve the model's target recognition ability. Especially in complex environments such as rice paddies, the C3-EFSA module can improve the accuracy of pest targets through detailed feature extraction and adaptive weighting, ensuring accurate detection of small pests on rice leaves, thereby enhancing the practicality and robustness of the system.

[0045] (3) To reduce computational burden and improve processing speed, the GAFNet network introduces the Enhanced Ghost Convolutional Module (EGConv). This module combines the advantages of standard convolution and depthwise separable convolution, effectively reducing computational resource consumption while ensuring high-precision detection. By using the lightweight GhostConv module, EGConv not only optimizes the network structure but also significantly improves processing speed, making the model more advantageous in real-time monitoring and pest early warning systems. In addition, the addition of the channel attention mechanism further enhances the model's ability to identify key regions while maintaining efficient utilization of computational resources. This design ensures efficient pest detection even with limited resources.

[0046] (4) The FECIoU loss function of the GAFNet network is optimized to address the limitations of traditional CIoU in handling small targets and occluded objects. By introducing a minimal positive number ϵ to correct the aspect ratio difference term and adopting a hard sample weighting mechanism, FECIoU can more accurately handle small targets and occluded pest targets in rice pest detection. Traditional loss functions are prone to numerical instability or large errors when facing pests with irregular shapes or severe occlusion. The optimization strategy of FECIoU allows the model to focus on difficult-to-detect samples during training, improving detection accuracy and model stability. This improvement enables GAFNet to effectively handle complex field environments and improves the ability to locate small or occluded pests. Attached Figure Description

[0047] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.

[0048] Figure 1Examples of enhanced rice pest training set samples from this invention are shown below (a is an enhanced image of Curculionidae; b is an enhanced image of Delphacidae; c is an enhanced image of Cicadellidae; d is an enhanced image of Phlaeothripidae; e is an enhanced image of Cecidomyiidae; f is an enhanced image of Crobidae).

[0049] Figure 2 This is a schematic diagram of the GAM-SPP structure principle of the present invention;

[0050] Figure 3 This is a schematic diagram of the C3-EFSA module structure of the present invention;

[0051] Figure 4 This is a schematic diagram of the EGConv module structure of the present invention. Detailed Implementation

[0052] This invention proposes a lightweight rice pest detection method and electronic device based on GAFNet, aiming to improve the detection accuracy and efficiency of rice pests, reduce production costs, and ensure high-quality rice production.

[0053] The lightweight rice pest detection method based on GAFNet proposed in this invention will be described below in specific embodiments:

[0054] Example 1: In the technical solution of this example, a lightweight rice pest detection method based on GAFNet includes the following steps:

[0055] S1. Obtain an image dataset containing multiple categories of rice pests, and preprocess and augment the image dataset to construct a training set, a validation set, and a test set;

[0056] S2. Construct a lightweight object detection model GAFNet. The GAFNet model is based on the YOLO11n network and integrates the following modules:

[0057] A global attention fusion and spatial pyramid pooling module is used to replace the SPPF module in the original network to capture global contextual information and aggregate multi-scale features;

[0058] The C3 efficient feature selection attention module optimizes feature representation through depthwise separable convolution (DWConv) and lightweight channel attention mechanism to improve feature discrimination in complex backgrounds;

[0059] The enhanced Ghost detection head EGDetect is used to replace the standard detection head in the original network. EGDetect integrates the enhanced Ghost convolution (EGConv), Squeeze and Excitation (SE) modules and SiLU activation function to reduce computational redundancy.

[0060] S3. The GAFNet model is trained using the training set. During the training process, the enhanced loss function FECIoU is used. The FECIoU loss function introduces a numerical stability term and a hard sample weighting mechanism based on the CIoU loss function to optimize the robustness of locating occluded pests.

[0061] S4. Use the trained GAFNet model to detect pests in the input rice image and output the pest category and location information.

[0062] Furthermore, the execution process of the Global Attention Fusion and Spatial Pyramid Pooling Module (GAM-SPP) includes:

[0063] Channel compression is achieved by performing a 1×1 convolution on the input feature map;

[0064] The compressed feature maps are input into max pooling layers with kernel sizes of 5×5, 9×9, and 13×13 respectively for multi-scale feature extraction, and the extracted features are concatenated with the original input features in the channel dimension.

[0065] The concatenated features are subjected to 1×1 convolution to fuse multi-scale information and compress the number of channels;

[0066] The fused features are sequentially input into the Channel Attention (CA) submodule and the Spatial Attention (SA) submodule for weighted processing. The CA submodule adopts an SE structure, and the SA submodule obtains a spatial mapping map through max pooling and average pooling in the channel direction. After convolution and Sigmoid activation, spatial attention weights are generated.

[0067] Specifically, the Global Attention Fusion and Spatial Pyramid Pooling (GAM-SPP) module significantly improves the accuracy and efficiency of rice pest detection by replacing the SPPF module in the YOLO11n model. This module targets fine-grained targets in rice pest detection, addressing the difficulty of traditional models in accurately extracting key features when faced with small-sized, high-density, and severely occluded pests. By introducing multi-scale pyramid pooling (SPP), GAM-SPP enhances the ability to perceive pest targets at different scales. Channel attention (CA) and spatial attention (SA) mechanisms optimize feature selectivity, helping the model focus on pest areas on rice leaves and filter out irrelevant information. This design, while optimizing feature fusion, improves the accuracy and robustness of pest detection in complex backgrounds by adaptively adjusting the weights of channel and spatial features.

[0068] Furthermore, the C3 efficient feature selection attention module (C3-EFSA) adopts a three-way parallel branch structure:

[0069] The first branch includes, in sequence, 1×1 convolution, 3×3 depthwise separable convolution, batch normalization (BN), and SiLU activation function;

[0070] The second branch includes, in sequence, 1×1 convolution, 5×5 depthwise separable convolution, batch normalization (BN), and SiLU activation function;

[0071] The third branch includes 3×3 grouped convolution, batch normalization (BN), and SiLU activation function in sequence;

[0072] The output features of the three branches are concatenated along the channel dimension;

[0073] The concatenated features are fused by performing 1×1 convolution, batch normalization (BN), and SiLU activation function.

[0074] An efficient channel attention (ECA) mechanism is applied to the fused features, which adaptively adjusts the channel attention through one-dimensional convolution;

[0075] When the number of input and output channels is the same, the module's output and input are residually connected.

[0076] Specifically, the C3 efficient feature selection attention module, combined with multi-scale receptive field modeling and ECA mechanism, effectively reduces false negatives and false negatives, enhancing the ability to express pest features. C3-EFSA employs a three-way parallel branch design, extracting information at different scales through depthwise separable convolutions and grouped convolutions, then fusing features through 1×1 convolutions, and introducing an ECA mechanism to strengthen the model's focus on salient regions. The ECA mechanism adaptively adjusts channel attention through one-dimensional convolutions, avoiding excessive computational overhead and improving the ability to identify small targets. The preserved residual connection structure ensures the transmission of low-level feature information, enhancing training stability and accelerating convergence. This design will significantly improve the detection accuracy of rice pests in complex environments, especially under occlusion and complex background conditions.

[0077] Furthermore, the execution process of the Efficient Channel Attention (ECA) mechanism includes:

[0078] Perform global average pooling on the input features to obtain the global response scalar for each channel;

[0079] The obtained scalar vector is subjected to cross-channel interaction using one-dimensional convolution, with a kernel size of k, where k is determined by an adaptive function for the number of channels;

[0080] The output of the one-dimensional convolution is passed through the Sigmoid activation function to generate channel attention weights;

[0081] The generated weights are multiplied by the original input features to complete the recalibration of channel attention.

[0082] Specifically, the Enhanced Ghost Convolutional Module (EGConv) improves the robustness and accuracy of rice pest detection by introducing a lightweight GhostConv module and a channel attention mechanism (SE) module. EGConv combines standard convolution with depthwise separable convolution, reducing computational overhead and enhancing feature representation. The main branch extracts core features, while a cheaper branch forges remaining features, thereby optimizing the ability to identify key regions. The SE module adjusts channel weights through a channel attention mechanism, enhancing the model's focus on pest-affected areas. The SiLU activation function is used instead of ReLU, improving non-linear expression capabilities, especially in complex environments, effectively improving the accuracy of small target detection while maintaining the network's lightweight nature.

[0083] Furthermore, the execution process of the enhanced Ghost convolution (EGConv) module includes:

[0084] A partial output feature map is generated using a standard convolutional layer;

[0085] The aforementioned portion of the output feature map is fed into a depthwise separable convolution layer to generate the remaining output channels;

[0086] The feature map generated by standard convolution and the feature map generated by depthwise separable convolution are concatenated along the channel dimension to form a complete output feature.

[0087] The concatenated features are input into the SqueezeandExcitation (SE) module for channel attention weighting.

[0088] In the EGConv module, the SiLU activation function is used instead of the ReLU activation function.

[0089] Furthermore, the enhanced Ghost detection head (EGDetect) is implemented by replacing all the 3×3 and 1×1 standard convolutions in the original YOLO11n detection head with EGConv modules.

[0090] Specifically, the Enhanced Ghost Detector (EGDetect) replaces the standard 3×3 and 1×1 convolutional modules in the original YOLO11n Detect module with a new EGDetect module to improve the model's capabilities in feature generation, attention fusion, and activation function optimization. EGDetect leverages the lightweight nature of the GhostConv module to reduce computational costs while improving the ability to identify key regions of rice pests. This optimizes performance while maintaining the network's lightweight design.

[0091] Furthermore, the calculation formula for the enhanced loss function FECIoU is as follows:

[0092] .

[0093] Specifically, the enhanced loss function FECIoU improves upon the CIoU loss function in the original YOLO11n model by introducing an optimization mechanism to adapt to the detection of small targets, occluded objects, and irregularly shaped pests. Addressing the numerical instability of traditional CIoU in rice pest detection when handling extremely small targets or those with extreme proportions (such as slender pests), FECIoU proposes a scheme to correct for aspect ratio differences by introducing a minimal positive number ϵ. Furthermore, FECIoU enhances the model's ability to fit small targets, occluded objects, or samples with large prediction biases by introducing a hard sample weighting mechanism similar to Focal Loss, thereby improving accuracy during training. This loss function smooths gradient fluctuations by adjusting the weight term α, improving the model's training stability in complex environments.

[0094] Traditional CIoU loss function As shown in formula (1):

[0095]

[0096] in, This represents the squared Euclidean distance between the center point of the predicted bounding box and the center point of the ground truth bounding box; This represents the square of the diagonal length of the smallest bounding box; , used to measure the difference in aspect ratio; , is the dynamic weight of the aspect ratio penalty term; It is the width of the ground truth box; It is the height of the ground truth box; It is the width of the predicted box; It is the height of the predicted box. However, in the aspect ratio consistency modeling part, the original CIoU uses A function is used to measure the shape difference between the predicted bounding box and the ground truth bounding box. In rice pest detection, many targets are extremely small or have extreme proportions (e.g., elongated pests), which can cause the height of the ground truth bounding box to be significantly different. Approaching zero. At this point, The function's value can become extremely large, leading to numerical instability or gradient explosion. Such instability can severely impact the training process, especially when dealing with these extreme targets, resulting in poorer model convergence.

[0097] To solve the problem, a very small positive number is introduced into the calculation. The aspect ratio difference of CIoU Improvements can be made, as shown in formula (2):

[0098]

[0099] In fact, the weighting term in formula (1) When the IoU is at its minimum, drastic gradient fluctuations can easily occur. Therefore, to smooth gradient changes, [the following is omitted as it is not explicitly stated]. The definition is as shown in equation (3).

[0100]

[0101] Furthermore, to further enhance the model's ability to fit the samples, a hard sample weighting mechanism similar to FocalLoss is introduced into the loss function. This mechanism utilizes a simple IoU exponential weighting term. This is to improve the gradient influence of low-quality predictions, thereby making the model pay more attention to small targets, occluded samples, or samples with large prediction bias during training. Here, To focus on parameters and control the intensity of this adjustment, in the experiment, to appropriately enhance the contribution of difficult samples without excessively perturbing the training of normal samples, the following settings were implemented: Finally, the FECIoU loss function is expressed as shown in equation (4):

[0102]

[0103] In rice pest detection, FECIoU helps improve the accuracy of detecting small pests that are difficult to detect. It can significantly improve the model's localization ability, thereby improving detection accuracy and robustness in complex rice field environments.

[0104] Furthermore, the data augmentation operations include one or more of random brightness adjustment, motion blur, random rectangular occlusion, and salt-and-pepper noise addition, used to simulate the complex environment of rice paddies.

[0105] These improvements optimize the overall network, enabling the method to effectively handle small-sized, high-density, and occluded pest targets, enhancing its ability to identify complex backgrounds and tiny targets. The optimized network structure not only reduces computational burden but also increases attention to pest-affected areas. By improving the loss function and weighting mechanism, the model exhibits stronger fitting capabilities when handling difficult samples, particularly in detecting extremely small targets, occlusions, and irregularly shaped pests. This method provides strong support for rice pest detection in complex environments.

[0106] Example 2: A lightweight rice pest detection method based on GAFNet, comprising the following steps:

[0107] Step 1, as follows Figure 1The dataset shown is the dataset used for model training. This dataset contains samples from 10 pest families: weevils (Curculionidae), planthoppers (Delphacidae), leafhoppers (Cicadellidae), thrips (Phlaeothripidae), gall midges (Cecidomyiidae), butterflies (Hesperiidae), grass moths (Crambidae), stem flies (Chloropidae), water flies (Ephydridae), and noctuid moths (Noctuidae). After deduplication, cleaning, and manual review by experts from the College of Plant Protection of our university, 4226 valid samples were ultimately retained. The dataset was divided into a training set of 3375 images, a validation set of 424 images, and a test set of 427 images in an 8:1:1 ratio, ensuring that the distribution ratio of each pest class in the three subsets was approximately the same to support effective model training and fair evaluation. To improve the model's generalization and robustness, four data augmentation methods were applied to the training set: random brightness, motion blur, random rectangular occlusion, and salt-and-pepper noise. These methods simulate complex lighting changes in rice paddies, plant swaying and camera shake, leaf occlusion, and imaging noise, respectively. Specifically: random brightness simulates the changes in light and shadow before and after sunrise, overexposure at noon, and low light in the evening; motion blur reproduces the blurring and trailing caused by equipment shake or wind blowing through rice plants; random rectangular occlusion simulates partial or large-area occlusion of pests by rice leaves and ears; and salt-and-pepper noise simulates imaging equipment or environmental noise. By stacking the four augmentation operations, the number of samples in the training set was doubled to 6750, while the validation and test sets remained unchanged, thereby improving the model's generalization ability and robustness.

[0108] Step 2, the GAM-SPP module mainly consists of three parts: SPP branch, CA, and SA, as follows: Figure 2As shown, in the GAM-SPP module, a 1×1 convolution is first used to perform preliminary channel compression on the input feature map. Then, multi-scale pyramid pooling is performed, introducing three two-dimensional max pooling operations with different receptive fields, using kernel sizes of 5×5, 9×9, and 13×13 respectively, with stride=1 and corresponding padding set to ensure that the spatial size of the feature map remains unchanged after pooling. This design can effectively model multi-scale spatial context information, which helps to capture the salient regions of pest targets of different sizes. Secondly, feature fusion and channel compression are performed. The original feature map and the three pooling features are concatenated along the channel dimension, and a 1×1 convolution is used to compress the number of channels back to the input size, avoiding channel dimension expansion, reducing parameters and computational overhead, and simultaneously completing the fusion of multi-scale semantic features. Finally, CA guides the model to adaptively allocate the importance of different channels. CA uses a SE structure, specifically implemented by performing global 2D adaptive average pooling on the fused features, followed by two 1×1 2D convolutions. These convolutions are activated using ReLU and sigmoid respectively, resulting in a channel-dimensional weight map used to weight the channel responses of the input features. Furthermore, SA can be used to further model the saliency of spatial locations. SA is implemented by obtaining two spatial maps through max pooling and average pooling along the channel direction, concatenating them, and then inputting them into a 2D convolutional layer with 7×7 kernels. A spatial attention map is generated through sigmoid activation, which weights the feature map, allowing the model to focus more intently on potential insect-infested areas within rice leaves.

[0109] Step 3, the C3-EFSA module design focuses on lightweight multi-scale receptive field modeling and ECA mechanisms, aiming to enhance the model's ability to express insect features with limited computational resources. For example... Figure 3 As shown, the main module adopts a three-way parallel branch design, with each branch capturing structural information of different scales and spatial distributions from the input features. Two branches use 3×3 and 5×5 depthwise separable convolutions respectively after a 1×1 2D convolution to extract local and contextual texture information, balancing accuracy and computational efficiency. The third branch uses 3×3 grouped convolutions, reducing computational overhead while introducing cross-channel interaction, followed by Batch Normalization (BN) and SiLU activation functions to enhance non-linear expressiveness. The three features are concatenated along the channel dimension and then fused through a 1×1 2D convolution, followed by BN and SiLU activation functions to further enhance non-linear expressiveness.

[0110] After fusing the three feature paths, the C3-EFSA module further introduces an ECA mechanism. Unlike traditional attention mechanisms such as SE and CBAM, ECA is based on lightweight one-dimensional convolution, avoiding channel dimension compression and fully connected operations. This attention module first performs global two-dimensional adaptive average pooling on the fused feature map to obtain the global response vector for each channel. Then, it performs local channel information interaction through a one-dimensional convolution with a small kernel (usually 3). Finally, it generates attention coefficients for each channel through a sigmoid activation function and weights the original feature map accordingly. Therefore, the C3-EFSA module with ECA can significantly improve the module's ability to focus on salient areas of rice pests, while suppressing invalid background areas and enhancing the model's discrimination performance for small targets.

[0111] Furthermore, C3-EFSA retains the residual connection structure. When the number of input and output channels is equal, the module output is added element-wise to the input, thereby preserving low-level feature information and promoting stable gradient propagation in deep networks. This design will further improve the convergence speed and overall stability of the network during training.

[0112] Step 4: EGConv first uses a standard convolutional layer to perform preliminary feature extraction on the input, such as... Figure 4 As shown, the number of channels output by the main branch is a portion of the final output channels. This portion of the features is then fed into a depthwise separable convolution layer to generate the remaining output channels, achieving a richer representation. The outputs of the main branch and the low-cost branch are then concatenated along the channel dimension to form the complete output.

[0113] To further enhance the model's ability to focus on key target regions, a lightweight channel attention mechanism, the SE module, is introduced into the EGConv module. The SE module extracts the response statistics for each channel by performing global 2D adaptive average pooling on the feature map, and generates channel weights through two 1×1 2D convolutions to recalibrate the importance of each channel in the feature map. This mechanism effectively enhances salient features related to pest targets while suppressing background noise and irrelevant regions. The attention output applies to all concatenated channel features, and a truncation operation ensures that the final output channel count matches the expectation, maintaining full compatibility with the original Detect module.

[0114] Furthermore, to enhance the nonlinear expressive power of the network, all ReLU activation functions originally used in EGConv were replaced with SiLU activation functions. The SiLU activation function is shown in formula (5):

[0115]

[0116] in, It is each element of the input feature map. It uses the Sigmoid activation function. The SiLU activation function outperforms the traditional ReLU in terms of gradient continuity and expressive power, especially in target regression and small object detection tasks, where it delivers more stable performance. The advantage of replacing the activation function is that it positively impacts model optimization, convergence, and accuracy without changing the network structure size.

[0117] EGDetect replaces all the standard 3×3 and 1×1 convolutional modules in the original YOLO11n Detect with the new EGConv module to improve the model's enhanced features in feature generation, attention fusion, and activation function optimization.

[0118] The formula for calculating the enhanced loss function FECIoU is as follows:

[0119] .

[0120] The GAFNet model proposed in this invention demonstrates comprehensive advantages compared to existing models such as Faster R-CNN, SSD, RT-DETR, and the YOLO series. In terms of performance metrics, GAFNet achieves an accuracy of 89.8%, a recall of 85.6%, and a mAP of 90.1%, all of which outperform YOLO11n's 86.3%, 81.4%, and 88.5%, respectively, and are also superior to Faster R-CNN. The percentages for R-CNN are 47.1%, 71.4%, and 67.7%; for SSD, 78.1%, 58.6%, and 67.4%; for RT-DETR, 86.2%, 80.9%, and 83.7%; for YOLOv5n, 85.3%, 77.6%, and 85.2%; for YOLOv6n, 84.9%, 78.1%, and 85.5%; for YOLOv7-tiny, 83.4%, 75.1%, and 82.7%; for YOLOv8n, 85.6%, 78.5%, and 85.0%; for YOLOv10n, 87.0%, 82.4%, and 88.7%; and for YOLOv12n, 85.4%, 80.7%, and 86.0%. In terms of model efficiency, the GAFNet model requires only 2.45M parameters, a 5% reduction compared to YOLO11n's 2.58M parameters. Simultaneously, its computational cost is only 5.0 GFLOPs, a 21% reduction compared to YOLO11n's 6.3 GFLOPs. Furthermore, its parameter and computational costs are superior to Faster R-CNN (137.10M, 370.2 GFLOPs); SSD (23.75M, 60.9 GFLOPs); RT-DETR (32.00M, 103.5 GFLOPs); YOLOv5n (2.50M, 7.1 GFLOPs); YOLOv6n (4.23M, 11.8 GFLOPs); YOLOv7-tiny (6.03M, 13.1 GFLOPs); and YOLOv8n (3.01M, 8.1 GFLOPs). GFLOPs; YOLOv10n corresponds to 2.70M and 8.2 GFLOPs; YOLOv12n corresponds to 2.56M and 6.3 GFLOPs. Compared with other models, the GAFNet model proposed in this invention not only has significant improvements in accuracy and recall, but is also more lightweight.

[0121] Example 3: An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to perform the steps of Example 1 above.

[0122] The above description is merely a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A lightweight rice pest detection method based on GAFNet, characterized in that, Includes the following steps: S1. Obtain an image dataset containing multiple categories of rice pests, and preprocess and augment the image dataset to construct a training set, a validation set, and a test set; S2. Construct a lightweight object detection model GAFNet. The GAFNet model is based on the YOLO11n network and integrates the following modules: A global attention fusion and spatial pyramid pooling module is used to replace the SPPF module in the original network to capture global contextual information and aggregate multi-scale features; The C3 efficient feature selection attention module optimizes feature representation through depthwise separable convolution and lightweight channel attention mechanism to improve feature discrimination ability in complex backgrounds; The enhanced Ghost detection head EGDetect is used to replace the standard detection head in the original network. EGDetect integrates enhanced Ghost convolution, SqueezeandExcitation modules and SiLU activation function to reduce computational redundancy. S3. The GAFNet model is trained using the training set. During the training process, the enhanced loss function FECIoU is used. The FECIoU loss function introduces a numerical stability term and a hard sample weighting mechanism based on the CIoU loss function to optimize the robustness of locating occluded pests. S4. Use the trained GAFNet model to detect pests in the input rice image and output the pest category and location information.

2. The method according to claim 1, characterized in that, The execution process of the global attention fusion and spatial pyramid pooling module includes: Channel compression is achieved by performing a 1×1 convolution on the input feature map; The compressed feature maps are input into max pooling layers with kernel sizes of 5×5, 9×9, and 13×13 respectively for multi-scale feature extraction, and the extracted features are concatenated with the original input features in the channel dimension. The concatenated features are subjected to 1×1 convolution to fuse multi-scale information and compress the number of channels; The fused features are sequentially input into the channel attention submodule and the spatial attention submodule for weighted processing. The channel attention submodule adopts an SE structure, and the spatial attention submodule obtains a spatial mapping map through max pooling and average pooling in the channel direction, and generates spatial attention weights after convolution and Sigmoid activation.

3. The method according to claim 1, characterized in that, The C3 high-efficiency feature selection attention module adopts a three-way parallel branch structure: The first branch includes, in sequence, 1×1 convolution, 3×3 depthwise separable convolution, batch normalization, and SiLU activation function; The second branch includes, in sequence, 1×1 convolution, 5×5 depthwise separable convolution, batch normalization, and SiLU activation function; The third branch includes, in sequence, 3×3 grouped convolution, batch normalization, and SiLU activation function; The output features of the three branches are concatenated along the channel dimension; The concatenated features are fused by performing 1×1 convolution, batch normalization, and SiLU activation function. An efficient channel attention mechanism is applied to the fused features, which adaptively adjusts the channel attention through one-dimensional convolution. When the number of input and output channels is the same, the module's output and input are residually connected.

4. The method according to claim 3, characterized in that, The execution process of the efficient channel attention mechanism includes: Perform global average pooling on the input features to obtain the global response scalar for each channel; The obtained scalar vector is subjected to cross-channel interaction using one-dimensional convolution, with a kernel size of k, where k is determined by an adaptive function for the number of channels; The output of the one-dimensional convolution is passed through the Sigmoid activation function to generate channel attention weights; The generated weights are multiplied by the original input features to complete the recalibration of channel attention.

5. The method according to claim 1, characterized in that, The enhanced Ghost detection head EGDetect execution process includes: A partial output feature map is generated using a standard convolutional layer; The aforementioned portion of the output feature map is fed into a depthwise separable convolution layer to generate the remaining output channels; The feature map generated by standard convolution and the feature map generated by depthwise separable convolution are concatenated along the channel dimension to form a complete output feature. The concatenated features are input into the SqueezeandExcitation module for channel attention weighting; In the enhanced Ghost convolution, the SiLU activation function is used instead of the ReLU activation function.

6. The method according to claim 5, characterized in that, The enhanced Ghost detection head is implemented by replacing all the 3×3 and 1×1 standard convolutions in the original YOLO11n detection head with the enhanced Ghost convolutions as described in claim 5.

7. The method according to claim 1, characterized in that, The formula for calculating the enhanced loss function FECIoU is as follows: 。 8. The method according to claim 1, characterized in that, The data augmentation operations include one or more of random brightness adjustment, motion blur, random rectangular occlusion, and salt and pepper noise addition, used to simulate the complex environment of rice paddies.

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 processor executes the program, it implements the steps of the method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Digital printing defect detection method based on lightweight network

    CN120411118A

  • Systems and methods for detecting bad telematics device installations

    US12367688B1