Lightweight multi-species insect detection method and device based on computer vision
By introducing cascaded receptive field modules, improved upsamplers, and C2f structures into the YOLOv8n model, combined with image data enhancement, the problem of low detection accuracy for multiple types of pests was solved, achieving efficient and accurate pest identification.
Patent Information
- Application Number
- CN202511118367.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-11
- Publication Date
- 2025-11-14
AI Technical Summary
Existing pest detection algorithms struggle to improve detection accuracy when dealing with complex features such as small-scale, multi-scale, similar appearance, and dense distribution, especially in detecting pests from multiple crops.
The SPPF module in the YOLOv8n backbone network is replaced with a cascaded receptive field module. A novel upsampler and an improved C2f structure are introduced, and combined with image data enhancement technology, feature fusion and detection accuracy are improved.
It significantly improves the accuracy and efficiency of detecting various crop pests, especially excelling in handling small targets and high-density pests, providing a flexible pest monitoring tool.
Smart Images

Figure CN120954056A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of agricultural pest monitoring, and in particular to a lightweight multi-species insect detection method and device based on computer vision. Background Technology
[0002] Pest damage to crops seriously threatens global food security and sustainable agricultural development. Early field pest monitoring relied primarily on manual identification by entomologists or technicians, which was highly susceptible to environmental interference and inefficient. With the rapid development of artificial intelligence technology, deep learning has provided a new solution for pest detection. This technology, through learning from image data, can automatically extract key features, significantly improving the accuracy and speed of pest detection. In the complex and ever-changing field environment, deep learning technology can quickly and accurately identify and classify pest species, providing agricultural managers with real-time monitoring data to help them formulate timely control strategies and effectively reduce crop losses.
[0003] Currently, although deep learning algorithms have been widely applied in the field of pest detection, some problems still exist. The small size of pests, the similarity in appearance between different classes, and the subtle differences within a class make it difficult to effectively improve detection accuracy.
[0004] In recent years, various algorithms have been developed to achieve high-performance real-time target detection. Among them, the YOLO (You Only Look Once) series of algorithms occupies a pivotal position in the field of target detection due to its excellent balance between detection speed and accuracy.
[0005] Feature fusion plays a crucial role in object detection networks, directly impacting the efficiency of feature information flow and the integration of multi-scale semantic information. The YOLO series of models has continuously optimized this aspect, from the C3 module in YOLOv5 to the C2f module in YOLOv8, demonstrating the ongoing evolution of model structure in fusion strategies. The C3 module employs a bottleneck structure, enhancing contextual modeling capabilities through multi-layer convolutions and residual connections, making it particularly suitable for handling complex backgrounds and large object detection tasks. The C2f module focuses more on achieving efficient feature information flow and preserving spatial details, effectively fusing low-level and high-level features through branching structures and shortcut connections, significantly improving the perception of small targets. Despite the advantages of each module, existing fusion structures mostly emphasize local modeling, making it difficult to fully capture long-distance dependencies. Currently, no effective algorithm has been proposed to solve the task of detecting multiple types of crop pests. Summary of the Invention
[0006] This invention provides a lightweight multi-species insect detection method and device based on computer vision. This invention solves the problem of poor detection results in existing methods for crop pests due to their complex characteristics such as small scale, multi-scale, similar appearance, and dense distribution. It improves the detection accuracy of various crop pests, as detailed below:
[0007] A first aspect is a lightweight multi-species insect detection method based on computer vision, the method comprising:
[0008] Collect and label cotton pest image data to obtain a labeled cotton pest image dataset.
[0009] Image data augmentation was performed on the labeled cotton pest image dataset, and the augmented image data was used as the preprocessed dataset.
[0010] The YOLOv8n object detection model is improved in three steps to obtain the final improved object detection model.
[0011] Based on the final improved target detection model, combined with the preprocessed dataset, pests are detected, and the detection and identification results of pests are output.
[0012] The three-step improvement to the YOLOv8n object detection model is as follows:
[0013] The SPPF module in the YOLOv8n backbone network is replaced with a self-designed cascaded receptive field module.
[0014] In the upsampling phase, a novel upsampler is introduced to improve network transmission efficiency.
[0015] The C2f structure is improved using MBlockLiteV to form a new C2f_MV structure, which is used to improve the feature fusion effect.
[0016] The image data augmentation of the labeled cotton pest image dataset includes:
[0017] From the original labeled cotton pest image dataset, the bounding box coordinates and category information of each pest target are parsed, and image fragments of each pest target are cropped based on these bounding box coordinates.
[0018] Analyze the dataset, identify the categories with significantly fewer samples, and calculate the number of new samples needed to be added for each minority category based on the preset category balance target.
[0019] For each of the few categories that need supplementary samples, the paste operation is performed cyclically according to the calculated number to generate new enhanced image samples: at the same time, the extracted target image fragments are randomly scaled before pasting;
[0020] The target image fragments, after being scaled and rotated, are then composited onto the verified locations.
[0021] Only targets completely contained within the window are retained. For each image that meets the conditions, it is sliced and saved as a new training image. At the same time, a corresponding VOC format XML annotation file is generated to form a new training sample set. The training sample set is used as the preprocessed dataset.
[0022] The scaling and pasting rules include: position rules and transformation rules. The position rules require that the distance between the pasting and the existing target be ≥50 pixels and that the pasting does not exceed the effective edge of the sticky trap. The transformation rules require that random scaling and rotation be applied.
[0023] Specifically, the replacement of the SPPF module in the YOLOv8n backbone network with a self-designed cascaded receptive field module is as follows:
[0024] Multi-receptive field cascade mechanism: By cascading convolutional modules with different receptive fields, multi-level and multi-scale features are integrated within a single network layer. The receptive fields are expanded through different convolutional kernel sizes, strides, and dilation, enabling the network to process feature information of different scales in the same layer and achieve coarse-to-fine feature extraction.
[0025] Feature fusion: A simplified spatial pyramid pooling module is introduced to capture spatial features at different scales and fuse multi-scale information;
[0026] An ECA attention mechanism is introduced to adaptively adjust the weights of each channel, combining global average pooling with one-dimensional convolution.
[0027] The ECA attention mechanism is as follows:
[0028] The kernel size k of the one-dimensional convolution is adaptively calculated based on the number of channels;
[0029]
[0030] Where k is the calculated convolution kernel size, C is the number of channels of the input feature, and γ and b are hyperparameters;
[0031] [out=Conv1D k (in)]
[0032] Among them, Conv1D k This represents a one-dimensional convolution operation with a kernel size of k;
[0033] By employing residual connections, input features are directly passed to the output via skip connections.
[0034] The novel upsampler is as follows:
[0035] Upsampling can be viewed as performing a lightweight prediction of the sampled coordinates at each output position, and then using PyTorch's built-in standard functions to complete the resampling in one go.
[0036] The improvement of the C2f structure using MBlockLiteV to form a new C2f_MV structure is as follows:
[0037] The input features are first extracted spatially using a 3×3 depthwise convolution, followed by batch normalization and SiLU activation; then, 1×1 pointwise convolution is used to compress or expand the channels, followed by batch normalization; finally, the input enters the ECAV attention module.
[0038] First, global average pooling is used to compress the spatial dimension into a channel vector. Then, one-dimensional convolution with an adaptive kernel size is used to learn the channel weights. The weights are then multiplied by the original features channel by channel after passing through the Sigmoid function to complete the weighting. Finally, the input is directly added to the output in a residual manner.
[0039] The C2f_MV module builds upon MBlockLiteV, using depthwise separable convolutions and pointwise convolutions to adjust channels, and lightweight ECAV attention to capture channel dependencies.
[0040] MBlockLiteV includes: a standard convolution and activation part; a depthwise separable convolution part; a pointwise convolution part; and an ECAV attention mechanism.
[0041] The ECAV attention mechanism is as follows:
[0042]
[0043] Here, γ and b are hyperparameters used to dynamically adjust the kernel size to ensure that the kernel size is an odd number;
[0044] The final output is calculated as follows:
[0045] X out =X×σ(Conv1D K (GAP(X))
[0046] Where X is the input feature map, and the weights obtained by GAP and Conv1D are multiplied with the input feature map channel by channel after Sigmoid activation to generate the final output; GAP is global average pooling, which performs mean pooling on the spatial dimension H×W to obtain the channel-level statistical vector [B,C,1,1]; Conv1D_k is a one-dimensional convolution with C input channels and C output channels; σ(·) is the Sigmoid activation function, which compresses the Conv1D output to the (0,1) interval to generate the weight coefficients of each channel.
[0047] In a second aspect, a lightweight multi-species insect detection device based on computer vision is provided, the device comprising: a processor and a memory, the memory storing program instructions, the processor calling the program instructions stored in the memory to cause the device to perform the method described in any of the first aspects.
[0048] The beneficial effects of the technical solution provided by this invention are:
[0049] 1. This invention provides an intelligent pest detection framework, which makes pest detection more accurate and efficient, especially when dealing with small targets and high-density pest challenges; this invention adopts a cascaded receptive field module, which gets rid of the problem of low detection accuracy caused by target overlap in existing target detection algorithms;
[0050] 2. This invention employs a feature extraction and fusion module, which effectively enhances the model's ability to express details of small targets through multi-scale convolutional branches and attention mechanisms; this invention also uses the DySample upsampling method, which can accurately recover spatial structure information with low computational overhead.
[0051] 3. Compared with other algorithms, this invention improves the YOLO algorithm through the design of modules, thereby designing a new detection model that can distinguish different kinds of pests, providing a powerful and flexible tool for pest monitoring; this invention improves the detection accuracy of multiple types of crop pests. Attached Figure Description
[0052] Figure 1 This is a flowchart of a lightweight, multi-species insect detection method based on computer vision.
[0053] Figure 2 This is a schematic diagram of the overall structure of a lightweight multi-species insect detection system based on computer vision.
[0054] Figure 3 Here is a structural diagram of ECMRFO (Cascaded Receptive Field Module);
[0055] Figure 4 The structure diagram of MBlockLiteV (Lightweight Convolutional Module);
[0056] Figure 5 Flowchart for data enhancement. Detailed Implementation
[0057] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be described in further detail below.
[0058] Example 1
[0059] A lightweight multi-species insect detection method based on computer vision, see [link to relevant documentation]. Figure 1 and Figure 2 The method includes the following steps:
[0060] S11: Collect cotton pest image data and label it to obtain the labeled cotton pest image dataset;
[0061] The annotated cotton pest image data will be used to form a cotton pest image dataset for subsequent steps.
[0062] S12: Perform image data augmentation on the labeled cotton pest image dataset, and obtain the augmented image data as the preprocessed dataset;
[0063] The enhanced and labeled cotton pest image data obtained through the above processing is used as the preprocessed dataset.
[0064] S13: Replace the SPPF module in the YOLOv8n backbone network with a self-designed cascaded receptive field module;
[0065] This module fuses receptive field features of different scales through a cascading strategy, significantly improving the feature extraction capability of the backbone network while maintaining the model's lightweight nature. The improved backbone network, combined with the cascaded receptive field module, can extract multi-scale features from preprocessed data more efficiently.
[0066] The YOLO object detection model includes a backbone network as the main network and cascaded receptive field modules. This invention improves the performance of both the backbone network and the cascaded receptive field modules through their interaction and cooperation, thus achieving the first step in improving the object detection model.
[0067] S14: In the upsampling stage, a new type of upsampler is introduced to improve the transmission efficiency of the network.
[0068] The target detection model also includes an upsampler. This embodiment of the invention improves the upsampler, which significantly improves the transmission efficiency of the network, thereby achieving the second step of improvement to the target detection model.
[0069] S15: The C2f structure is improved using MBlockLiteV to form a new C2f_MV structure, thereby improving the feature fusion effect;
[0070] The target detection model also includes a C2f structure. In this embodiment, the C2f structure is improved using MBlockLiteV to form a new C2f_MV structure to enhance feature fusion performance, thereby achieving the third step of improvement to the target detection model. Therefore, this embodiment achieves a three-step improvement to the target detection model through the above steps S13-S15, obtaining the final improved target detection model as a lightweight multi-species insect detection model.
[0071] See Figure 2 The input image, 640×640×3, is processed through three Conv layers to obtain 160×160 features, which are then fed into the Backbone network. In the backbone network, a C2f module first downsamples the 160×160 to 80×80, followed by two consecutive C2f modules maintaining the 80×80 scale. Then, a Conv module compresses the 80×80 to 40×40, followed by two more C2f modules maintaining the 40×40 scale, and finally another Conv module compresses the 40×40 to 20×20. At this point, the original YOLOv8n SPPF module is replaced with an ECMRFO module to enhance the multi-scale feature extraction capability at the 20×20 scale. Next, the network proceeds to the Neck: 20×20 features are upsampled using the novel Dysample upsampler and then fused with 40×40 features. The fused 40×40 features are then upsampled again using Dysample and fused with 80×80 features. At all fusion nodes, the original C2f structure is replaced with a lightweight C2f_MV to improve feature fusion efficiency and reduce the number of parameters. Finally, the Head outputs detection results at three scales: 80×80, 40×40, and 20×20, achieving accurate detection of multiple pests. The entire network is EMDNet, which significantly improves the detection accuracy of multiple insect species with extremely low parameter requirements.
[0072] In optimizing the YOLOv8n architecture, this embodiment of the invention adopted several improvements: First, the SPPF module was replaced with the ECMRFO module to enhance feature extraction capabilities; second, at the network neck, the original C2f structure was replaced with the C2f_MV module to improve feature fusion performance; finally, from the perspective of point sampling, a novel upsampling device was introduced. Through these improvements, this embodiment of the invention successfully developed the EMDNet network. This network significantly improves the detection accuracy for multiple types of pest targets while maintaining a low parameter count.
[0073] S16: Detect pests based on the final improved target detection model and output the detection and identification results of pests.
[0074] In summary, this invention, through steps S11-S16, proposes a lightweight multi-species insect detection model based on computer vision, building upon the existing target detection model YOLOv8n. The detection model designed in this invention has achieved optimal results on both self-built datasets and publicly available pest datasets, improving the detection accuracy of various crop pests.
[0075] Example 2
[0076] The scheme in Example 1 will be further described below with reference to specific experimental data and calculation formulas. See the following description for details:
[0077] S21: Collect cotton pest image data and label it to obtain the labeled cotton pest image dataset;
[0078] The process included: data collection was conducted from June to October 2024 at Huaxing Farm. This study aimed to monitor various pests, including thrips and aphids. Given the pests' strong attraction to yellow, yellow sticky traps were used as collection tools. Traps were placed in cotton fields at 0.25-meter intervals, and data was collected every 2-3 days. Image data was collected using a Huawei nova 12 Pro smartphone (3072×4096 pixels) and a Raspberry Pi camera (3264×2448 pixels). Initially, smartphones were used primarily for field photography; later, Raspberry Pi was used indoors. Furthermore, to ensure sufficient diversity in the collected dataset, a combination of natural and artificial lighting was used during photography. The collected cotton pest images were then labeled to obtain a labeled cotton pest image dataset.
[0079] S22: Perform image data augmentation on the labeled cotton pest image dataset, and obtain the augmented image data as the preprocessed dataset;
[0080] In step S22, the specific method for image data enhancement is as follows:
[0081] (1) Target extraction and pasting
[0082] To address the issue of insufficient sample numbers for certain categories in the labeled cotton pest image dataset (i.e., the original dataset), an oversampling enhancement strategy based on target pasting was first implemented. The specific process is as follows:
[0083] 1) Target Extraction: First, from the original labeled cotton pest image dataset, the bounding box coordinates and category information of each pest target are parsed. Based on these bounding boxes, image segments of each pest target (containing the target and a small amount of surrounding background) are accurately cropped.
[0084] 2) Determine the categories and quantities that need to be augmented: Analyze the dataset to identify categories with significantly under-represented sample sizes (e.g., ladybugs, flying ants, flies, etc.). Based on preset category balance goals (e.g., making the minority class sample size close to that of the majority class or reaching a specific threshold), automatically calculate the number of new samples that need to be added to each minority class.
[0085] 3) Perform target pasting to generate enhanced images: For each of the few categories that require supplementary samples, perform the following pasting operation cyclically according to the calculated number to generate new enhanced image samples: Select pasting location: Randomly select a location in one of the original images (or another suitable background image). Verify pasting location: Check that the location meets specific rules to ensure that the newly pasted target looks natural and is reasonably positioned: The bounding box of the new target must maintain a minimum distance of at least 50 pixels from the bounding boxes of all existing targets in the image; the bounding box of the new target must not exceed the valid edge area of any existing target on the sticky trap (to prevent the target from appearing in physically unreasonable locations, such as outside the trap edge).
[0086] 4) Apply transformations: Before pasting, randomly scale (e.g., scaling ratio between 0.8 and 1.2) and randomly rotate (e.g., rotation angle between -30 degrees and 30 degrees) the extracted target image fragments to increase the visual diversity of the samples and alleviate the homogenization problem.
[0087] 5) Perform pasting: The scaled and rotated target image fragment is composited onto the verified location. If the location is on the original image, the original image is modified; if it is a new background, a completely new composite image is generated. The image generated by these operations is the enhanced image. Specific categories include ladybugs, flying ants, and flies, which have relatively few samples.
[0088] The scaling and pasting rules include: position rules and transformation rules. Position rules require a minimum of 50 pixels of spacing from the existing target and must not exceed the effective edge of the sticky trap. Transformation rules apply random scaling and rotation to enhance versatility.
[0089] (2) After performing oversampling enhancement, in order to further improve the detection model's ability to detect small targets in large image scenes, a sliding window approach is used for image cropping. The specific method is as follows:
[0090] 1) Window parameter settings: Set the window size (640×640 pixels) and step size (600 pixels) to ensure that there is a certain overlap between image patches, thereby enhancing the model's ability to learn targets in edge regions.
[0091] 2) Complete target selection: Only retain targets that are completely contained within the window to avoid inaccurate labeling or training noise caused by target cutting.
[0092] 3) Generate new training samples: For each image that meets the conditions, cut it into pieces and save it as a new training image. At the same time, generate the corresponding VOC format XML annotation file to form a new training sample set. Use the training sample set as the preprocessed dataset.
[0093] Finally, the preprocessed dataset was divided into training, testing, and validation sets in an 8:1:1 ratio, as detailed in Table 1. This series of data augmentation strategies effectively improved the model's ability to identify small sample classes and enhanced the diversity and balance of the training data.
[0094] S23: As Figure 2 As shown, the original SPPF module of the 9th layer of the YOLOv8n backbone is replaced with the ECMRFO module proposed in this embodiment of the invention. Figure 3 (As shown). The data is first mapped from the input channels to the intermediate channels through pointwise convolution-batch normalization-activation. Then, it is divided into three branches, each using depthwise convolution-batch normalization. Different kernel sizes and dilation coefficients are used to obtain three receptive fields: 5×5, 9×9, and 13×13. The results from the three branches are concatenated and then fed into simplified spatial pyramid pooling: using 5, 9, and 13 pooling kernels to fuse multi-scale information and unify the size, followed by another depthwise convolution-batch normalization for refinement. The refined features enter the efficient channel attention module: first, global average pooling is performed to compress the channel vectors, then one-dimensional convolution with an adaptive kernel size k is used to complete the interaction between channels. After obtaining the weights through sigmoid, they are multiplied with the input channel by channel. Finally, the original features are added back in a residual manner, preserving details while strengthening important channels. The entire module inherits the core function of spatial pyramid multi-scale while completing context modeling with fewer parameters and lower computational cost through cascaded receptive fields, lightweight pooling, and attention mechanisms, providing more efficient features for subsequent pest detection.
[0095] The ECMRFO module is a cascaded receptive field module that extracts and fuses information from different scales by combining multiple receptive fields, improving the model's ability to perceive diverse targets. It explores the features of different receptive fields through a cascading approach and improves target detection accuracy by processing features from multiple different receptive fields. Furthermore, the designed LiteSPPF (Simplified Spatial Pyramid Pooling) and the introduction of the ECA Attention mechanism further enhance the detection capability of multi-scale targets. This module helps YOLOv8 effectively extract rich feature information from input images, providing a good feature representation for subsequent pest detection tasks.
[0096] In step S23, the specific design method of the ECMRFO module is as follows:
[0097] 1) Multi-Receptive Field Cascade Mechanism: This module continues to capture different scale features of the target through a multi-receptive field strategy. By cascading convolutional modules with different receptive fields, the ECMRFO module can integrate multi-level and multi-scale features within a single network layer, thereby enhancing the model's ability to distinguish complex backgrounds and targets. The receptive field is expanded through operations such as different convolutional kernel sizes, stride, and dilation, enabling the network to process feature information of different scales within the same layer, thus achieving coarse-to-fine feature extraction.
[0098] 2) Efficient Feature Fusion: The designed LiteSPPF (Simplified Spatial Pyramid Pooling) module is introduced, which can effectively capture spatial features at different scales and fuse multi-scale information. Compared with traditional Spatial Pyramid Pooling (SPPF), LiteSPPF fuses multi-scale information through pooling with three different receptive fields (5×5, 9×9, and 13×13), thereby better enhancing the perception and recognition capabilities of multi-scale targets.
[0099] 3) An ECA attention mechanism is introduced to adaptively adjust the weights of each channel. By combining global average pooling with one-dimensional convolution, the ECA attention mechanism provides precise channel weighting, enhancing the expressive power of important features while suppressing unimportant features. This mechanism improves the accuracy of feature representation and detection capability without increasing additional computational overhead.
[0100] The core idea of the ECA module is to capture the dependencies between channels through one-dimensional convolution. Compared with traditional attention mechanisms, the ECA module avoids complex dimensionality reduction and expansion processes, thus achieving high efficiency and lightweight characteristics.
[0101] Specifically, the ECA module first adaptively calculates the kernel size k of the one-dimensional convolution based on the number of channels. The formula for calculating the kernel size is as follows:
[0102]
[0103] Where k is the calculated kernel size, C is the number of input feature channels, and γ and b are hyperparameters. Taking the absolute value and rounding down to the nearest odd number ensures that the kernel size is odd.
[0104] After obtaining the kernel size k, the ECA module applies one-dimensional convolution to the input features to learn the importance of each channel relative to other channels. This process can be represented by the following formula:
[0105] [out=Conv1D k (in)] (2)
[0106] Among them, Conv1D k This represents a one-dimensional convolution operation with a kernel size of k.
[0107] Finally, to improve model stability and avoid information loss, residual connections are used in the module. This design allows input features to be directly passed to the output through skip connections, thus preserving the original information of the input and avoiding the information decay problem in deep networks.
[0108] S24: Neck upsampling was performed using DySample (see...) Figure 2 DySample redesigns the upsampler from a "point sampling" perspective. It treats upsampling as a lightweight prediction of the sampling coordinates at each output position, then uses PyTorch's built-in standard functions to complete the resampling all at once. This strategy eliminates the need for custom CUDA kernels, resulting in significantly lower parameter count, floating-point number, memory usage, and latency compared to traditional dynamic upsamplers based on learnable convolutional kernels. It is both efficient and easy to implement in native PyTorch.
[0109] S25: via Figure 2 As shown in the process, the 640×640×3 image first outputs features from the backbone. After these feature maps are sent into the neck, they are first upsampled by DySample and stitched together with Contact. Then, the C2f_MV module completes the cross-scale features, thereby providing the detection head with multi-level information that combines details and semantics.
[0110] In step S24, the C2f_MV module is proposed based on MBlockLiteV. The MBlockLiteV module combines various efficient convolutional and lightweight attention mechanisms, and its design particularly emphasizes a balance between computational efficiency and feature representation capability (see [link to relevant documentation]). Figure 4The input features are first extracted spatially using a 3×3 depthwise convolution (DwConv), followed by batch normalization and SiLU activation. Then, 1×1 pointwise convolutions are used to compress or expand channels, followed by batch normalization. The input then enters the ECAV attention module: first, global average pooling compresses the spatial dimension into channel vectors; then, one-dimensional convolutions with adaptive kernel size (kernel size determined by the number of channels and hyperparameters) learn channel weights. These weights are then multiplied by the original features channel-wise using a Sigmoid function for weighting. Finally, the input is added directly to the output as a residual, preserving the original information while enhancing the response of key channels. The entire C2f_MV module, based on MBlockLiteV, uses depthwise separable convolutions to reduce computation, pointwise convolutions to flexibly adjust channels, and lightweight ECAV attention to accurately capture channel dependencies, balancing efficiency and expressive power to provide refined and powerful features for subsequent pest detection. The specific design method of MBlockLiteV is as follows:
[0111] 1) Standard Convolution and Activation (Conv + BatchNorm + SiLU): Conv: Basic convolution operation, responsible for extracting features from the input; BatchNorm: Accelerates the training process and reduces the risk of gradient vanishing or exploding by batch normalizing the features after convolution; SiLU activation function: SiLU (Sigmoid Linear Unit) is a smooth non-linear activation function that can retain a certain linearity while increasing non-linearity, making the gradient smoother during training and improving the performance of the model.
[0112] 2) Depthwise Separable Convolution (DWConv): This technique reduces computational complexity. In this type of convolution, each input channel is convolved independently, rather than using a shared kernel. Compared to standard convolution, depthwise separable convolution reduces computation, making the model more efficient.
[0113] 3) Pointwise Convolution: Used to adjust the number of channels in a feature map. Pointwise convolution can improve information flow and fuse features from different channels without increasing computational cost. It is mainly used for channel compression or expansion to improve computational efficiency.
[0114] 4) ECAV Attention Mechanism: ECAV is an optimized module of ECA, designed to further improve computational efficiency and feature representation capabilities, especially in situations with limited computational resources, to efficiently model channel attention. Compared to the original ECA module, ECAV maintains efficiency while further optimizing the attention mechanism, enabling it to more accurately capture inter-channel dependencies in the model. Specifically, ECAV's kernel size calculation method is more flexible; it not only depends on the number of channels but also controls the kernel size ratio through hyperparameters γ and b. This allows ECAV to finely adjust the kernel size to capture more complex channel dependencies. The kernel size calculation formula is as follows:
[0115]
[0116] Here, γ and b are hyperparameters used to dynamically adjust the kernel size to ensure that the kernel size is an odd number.
[0117] In ECAV, the final output is weighted by multiplying the input feature map with adaptively computed channel weights channel by channel. Unlike traditional attention mechanisms, ECAV uses one-dimensional convolutions instead of fully connected layers, which can more efficiently capture the dependencies between channels.
[0118] The final output is calculated as follows:
[0119] X out =X×σ(Conv1D K (GAP(X)) (4)
[0120] Where X is the input feature map, the weights obtained by GAP and Conv1D are multiplied with the input feature map channel by channel after Sigmoid activation to generate the final output; GAP global average pooling is used to perform mean pooling on the spatial dimension H×W to obtain the channel-level statistical vector [B,C,1,1]; Conv1D_k is a one-dimensional convolution (kernel_size=k, k is an odd number and usually takes 3 or 5), with C input channels and C output channels, used to model the inter-channel dependencies (i.e. "channel attention") across channels; σ(·) is the Sigmoid activation function, which compresses the Conv1D output to the (0,1) interval to generate the weight coefficients of each channel.
[0121] The BlockLiteV2 module effectively replaces the backbone module in the C2f structure of YOLOv8 by fusing depthwise separable convolutions, pointwise convolutions, a lightweight ECAV attention mechanism, and residual connections, significantly improving the network's performance in lightweight object detection. This module not only optimizes computational efficiency but also enhances the ability to perceive multi-scale targets, making it particularly suitable for performing efficient and accurate object detection tasks in computationally limited scenarios.
[0122] S26: Output the identification results for each type of pest.
[0123] In summary, this invention, through steps S21-S26, proposes a lightweight multi-species insect detection model based on computer vision, building upon the existing target detection model YOLOv8n. The detection model designed in this invention has achieved optimal results on both self-built datasets and publicly available pest datasets, improving the detection accuracy of various crop pests.
[0124] Example 3
[0125] To evaluate the performance of the proposed network model, the following metrics were used in this embodiment: mean precision (mAP@0.5) at a threshold of 0.5, mean precision (mAP@0.5~0.95) at a threshold between 0.5 and 0.95, F1-Score, precision, recall, parameter counts, and GFLOPs. The F1-Score, a weighted average of precision and recall, is a balanced performance metric. Precision represents the proportion of correctly predicted positive samples, while recall is the proportion of correctly predicted positive samples. A higher F1 score indicates a better balance between accurate target identification and comprehensive target coverage, suggesting a well-trained model. The precision-recall (PR) curve illustrates the trade-off between precision and recall; a larger area under the PR curve indicates a higher mean precision (AP). The above metrics are defined as follows:
[0126]
[0127] Furthermore, the primary metric used to evaluate the accuracy of object detection models is mean precision (mAP). It is calculated as the average of the mean precision (AP) values for different classes, as shown below:
[0128]
[0129] Here, AP represents average precision, and N represents the number of object classes. Typically, AP is the average precision (P) of different recall (R) values within the range R∈[0,1].
[0130] To illustrate the accuracy of the method, prediction results were compared with other models on the Yellow Sticky Traps pest dataset and a self-built dataset, resulting in the model prediction results shown in Table 1-2. The last row presents the experimental results of the model proposed in this embodiment, while the others show experimental results of some common and recent network models. Considering all evaluation metrics, it can be seen that the model proposed in this embodiment has a significant overall performance advantage, exhibiting higher performance in mAP50 and F1. This indicates that the model proposed in this embodiment has better detection accuracy in pest detection tasks, can more accurately identify pests, and maintain a low false detection rate.
[0131] Table 1
[0132]
[0133] Table 2
[0134]
[0135]
[0136] Example 4
[0137] A lightweight multi-species insect detection device based on computer vision includes a processor and a memory. The memory stores program instructions, and the processor calls the program instructions stored in the memory to cause the device to perform the following method steps in Embodiment 1:
[0138] Collect and label cotton pest image data to obtain a labeled cotton pest image dataset.
[0139] Image data augmentation was performed on the labeled cotton pest image dataset, and the augmented image data was used as the preprocessed dataset.
[0140] The YOLOv8n object detection model is improved in three steps to obtain the final improved object detection model.
[0141] Based on the final improved target detection model, combined with the preprocessed dataset, pests are detected, and the detection and identification results of pests are output.
[0142] The three-step improvement to the YOLOv8n object detection model is as follows:
[0143] The SPPF module in the YOLOv8n backbone network is replaced with a self-designed cascaded receptive field module.
[0144] In the upsampling phase, a novel upsampler is introduced to improve network transmission efficiency.
[0145] The C2f structure is improved using MBlockLiteV to form a new C2f_MV structure, which is used to improve the feature fusion effect.
[0146] The image data augmentation of the labeled cotton pest image dataset includes:
[0147] From the original labeled cotton pest image dataset, the bounding box coordinates and category information of each pest target are parsed, and image fragments of each pest target are cropped based on these bounding box coordinates.
[0148] Analyze the dataset, identify the categories with significantly fewer samples, and calculate the number of new samples needed to be added for each minority category based on the preset category balance target.
[0149] For each of the few categories that need supplementary samples, the paste operation is performed cyclically according to the calculated number to generate new enhanced image samples: at the same time, the extracted target image fragments are randomly scaled before pasting;
[0150] The target image fragments, after being scaled and rotated, are then composited onto the verified locations.
[0151] Only targets completely contained within the window are retained. For each image that meets the conditions, it is sliced and saved as a new training image. At the same time, a corresponding VOC format XML annotation file is generated to form a new training sample set. The training sample set is used as the preprocessed dataset.
[0152] The scaling and pasting rules include: position rules and transformation rules. The position rules require that the distance between the pasting and the existing target be ≥50 pixels and that the pasting does not exceed the effective edge of the sticky trap. The transformation rules require that random scaling and rotation be applied.
[0153] Specifically, the replacement of the SPPF module in the YOLOv8n backbone network with a self-designed cascaded receptive field module is as follows:
[0154] Multi-receptive field cascade mechanism: By cascading convolutional modules with different receptive fields, multi-level and multi-scale features are integrated within a single network layer. The receptive fields are expanded through different convolutional kernel sizes, strides, and dilation, enabling the network to process feature information of different scales in the same layer and achieve coarse-to-fine feature extraction.
[0155] Feature fusion: A simplified spatial pyramid pooling module is introduced to capture spatial features at different scales and fuse multi-scale information;
[0156] An ECA attention mechanism is introduced to adaptively adjust the weights of each channel, combining global average pooling with one-dimensional convolution.
[0157] The ECA attention mechanism is as follows:
[0158] The kernel size k of the one-dimensional convolution is adaptively calculated based on the number of channels;
[0159]
[0160] Where k is the calculated convolution kernel size, C is the number of channels of the input feature, and γ and b are hyperparameters;
[0161] [out=Conv1D k (in)]
[0162] Among them, Conv1D k This represents a one-dimensional convolution operation with a kernel size of k;
[0163] By employing residual connections, input features are directly passed to the output via skip connections.
[0164] The novel upsampler is as follows:
[0165] Upsampling can be viewed as performing a lightweight prediction of the sampled coordinates at each output position, and then using PyTorch's built-in standard functions to complete the resampling in one go.
[0166] The improvement of the C2f structure using MBlockLiteV to form a new C2f_MV structure is as follows:
[0167] The input features are first extracted spatially using a 3×3 depthwise convolution, followed by batch normalization and SiLU activation; then, 1×1 pointwise convolution is used to compress or expand the channels, followed by batch normalization; finally, the input enters the ECAV attention module.
[0168] First, global average pooling is used to compress the spatial dimension into a channel vector. Then, one-dimensional convolution with an adaptive kernel size is used to learn the channel weights. The weights are then multiplied by the original features channel by channel after passing through the Sigmoid function to complete the weighting. Finally, the input is directly added to the output in a residual manner.
[0169] The C2f_MV module builds upon MBlockLiteV, using depthwise separable convolutions and pointwise convolutions to adjust channels, and lightweight ECAV attention to capture channel dependencies.
[0170] MBlockLiteV includes: a standard convolution and activation part; a depthwise separable convolution part; a pointwise convolution part; and an ECAV attention mechanism.
[0171] The ECAV attention mechanism is as follows:
[0172]
[0173] Here, γ and b are hyperparameters used to dynamically adjust the kernel size to ensure that the kernel size is an odd number;
[0174] The final output is calculated as follows:
[0175] X out =X×σ(Conv1D K (GAP(X)
[0176] Where X is the input feature map, and the weights obtained by GAP and Conv1D are multiplied with the input feature map channel by channel after Sigmoid activation to generate the final output; GAP is global average pooling, which performs mean pooling on the spatial dimension H×W to obtain the channel-level statistical vector [B,C,1,1]; Conv1D_k is a one-dimensional convolution with C input channels and C output channels; σ(·) is the Sigmoid activation function, which compresses the Conv1D output to the (0,1) interval to generate the weight coefficients of each channel.
[0177] It should be noted that the device descriptions in the above embodiments correspond to the method descriptions in the embodiments, and the embodiments of the present invention will not be repeated here.
[0178] The execution entities of the aforementioned processor and memory can be devices with computing functions such as computers, microcontrollers, and single-chip microcomputers. In specific implementations, the embodiments of the present invention do not limit the execution entities and can select them according to the needs of actual applications.
[0179] Data signals are transmitted between the memory and the processor via a bus, which will not be elaborated upon in this embodiment of the invention.
[0180] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium, the storage medium including a stored program, which, when the program is running, controls the device where the storage medium is located to execute the method steps in the above embodiments.
[0181] The computer-readable storage medium includes, but is not limited to, flash memory, hard disk, solid-state drive, etc.
[0182] It should be noted that the description of the readable storage medium in the above embodiments corresponds to the description of the method in the embodiments, and the embodiments of the present invention will not be repeated here.
[0183] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of the present invention is generated.
[0184] A computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions can be stored in or transmitted through a computer-readable storage medium. A computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be magnetic or semiconductor, etc.
[0185] Unless otherwise specified, the model numbers of the various devices in this embodiment of the invention are not limited, and any device that can perform the above functions is acceptable.
[0186] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of a preferred embodiment, and the sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0187] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A lightweight multi-species insect detection method based on computer vision, characterized in that, The method includes: Collect and label cotton pest image data to obtain a labeled cotton pest image dataset. Image data augmentation was performed on the labeled cotton pest image dataset, and the augmented image data was used as the preprocessed dataset. The YOLOv8n object detection model is improved in three steps to obtain the final improved object detection model. Based on the final improved target detection model, combined with the preprocessed dataset, pests are detected, and the detection and identification results of pests are output.
2. The lightweight multi-species insect detection method based on computer vision according to claim 1, characterized in that, The three-step improvement to the YOLOv8n object detection model is as follows: The SPPF module in the YOLOv8n backbone network is replaced with a self-designed cascaded receptive field module. In the upsampling phase, a novel upsampler is introduced to improve network transmission efficiency. The C2f structure is improved using MBlockLiteV to form a new C2f_MV structure, which is used to improve the feature fusion effect.
3. The lightweight multi-species insect detection method based on computer vision according to claim 1, characterized in that, The image data augmentation of the labeled cotton pest image dataset is as follows: From the original labeled cotton pest image dataset, the bounding box coordinates and category information of each pest target are parsed, and image fragments of each pest target are cropped based on these bounding box coordinates. Analyze the dataset, identify the categories with significantly fewer samples, and calculate the number of new samples needed to be added for each minority category based on the preset category balance target. For each of the few categories that need supplementary samples, the paste operation is performed cyclically according to the calculated number to generate new enhanced image samples: at the same time, the extracted target image fragments are randomly scaled before pasting; The target image fragments, after being scaled and rotated, are then composited onto the verified locations. Only targets completely contained within the window are retained. For each image that meets the conditions, it is sliced and saved as a new training image. At the same time, a corresponding VOC format XML annotation file is generated to form a new training sample set. The training sample set is used as the preprocessed dataset.
4. The lightweight multi-species insect detection method based on computer vision according to claim 3, characterized in that, The scaling and pasting rules include: position rules and transformation rules. The position rules require that the distance between the pasting and the existing target be ≥50 pixels and that the pasting does not exceed the effective edge of the sticky trap. The transformation rules require that random scaling and rotation be applied.
5. The lightweight multi-species insect detection method based on computer vision according to claim 1, characterized in that, The replacement of the SPPF module in the YOLOv8n backbone network with a self-designed cascaded receptive field module is as follows: Multi-receptive field cascade mechanism: By cascading convolutional modules with different receptive fields, multi-level and multi-scale features are integrated within a single network layer. The receptive fields are expanded through different convolutional kernel sizes, strides, and dilation, enabling the network to process feature information of different scales in the same layer and achieve coarse-to-fine feature extraction. Feature fusion: A simplified spatial pyramid pooling module is introduced to capture spatial features at different scales and fuse multi-scale information; An ECA attention mechanism is introduced to adaptively adjust the weights of each channel, combining global average pooling with one-dimensional convolution.
6. The lightweight multi-species insect detection method based on computer vision according to claim 1, characterized in that, The ECA attention mechanism is as follows: The kernel size k of the one-dimensional convolution is adaptively calculated based on the number of channels; Where k is the calculated convolution kernel size, C is the number of channels of the input feature, and γ and b are hyperparameters; [out=Conv1D k (in)] Among them, Conv1D k This represents a one-dimensional convolution operation with a kernel size of k; By employing residual connections, input features are directly passed to the output via skip connections.
7. The lightweight multi-species insect detection method based on computer vision according to claim 1, characterized in that, The novel upsampler is: Upsampling can be viewed as performing a lightweight prediction of the sampled coordinates at each output position, and then using PyTorch's built-in standard functions to complete the resampling in one go.
8. The lightweight multi-species insect detection method based on computer vision according to claim 1, characterized in that, The C2f structure is improved using MBlockLiteV to form a new C2f_MV structure as follows: The input features are first extracted spatially using a 3×3 depthwise convolution, followed by batch normalization and SiLU activation; then, 1×1 pointwise convolution is used to compress or expand the channels, followed by batch normalization; finally, the input enters the ECAV attention module. First, global average pooling is used to compress the spatial dimension into a channel vector. Then, one-dimensional convolution with an adaptive kernel size is used to learn the channel weights. The weights are then multiplied by the original features channel by channel after passing through the Sigmoid function to complete the weighting. Finally, the input is directly added to the output in a residual manner. The C2f_MV module builds upon MBlockLiteV, using depthwise separable convolutions and pointwise convolutions to adjust channels, and lightweight ECAV attention to capture channel dependencies.
9. A lightweight multi-species insect detection method based on computer vision according to claim 8, characterized in that, The MBlockLiteV includes: a standard convolution and activation part; a depthwise separable convolution part; a pointwise convolution part; and an ECAV attention mechanism. The ECAV attention mechanism is as follows: Here, γ and b are hyperparameters used to dynamically adjust the kernel size to ensure that the kernel size is an odd number; The final output is calculated as follows: X out =X×σ(Conv1D K (GAP(X) Where X is the input feature map, and the weights obtained by GAP and Conv1D are multiplied with the input feature map channel by channel after Sigmoid activation to generate the final output; GAP is global average pooling, which performs mean pooling on the spatial dimension H×W to obtain the channel-level statistical vector [B,C,1,1]; Conv1D_k is a one-dimensional convolution with C input channels and C output channels; σ(·) is the Sigmoid activation function, which compresses the Conv1D output to the (0,1) interval to generate the weight coefficients of each channel.
10. A lightweight multi-species insect detection device based on computer vision, characterized in that, The device includes a processor and a memory, the memory storing program instructions, the processor invoking the program instructions stored in the memory to cause the device to perform the method according to any one of claims 1-9.