Method and system for small target pest detection based on channel and spatial cooperative attention

By improving the YOLOv8 model, adding a small target detection layer and a channel and spatial collaborative attention module, the problem of low detection accuracy of small target pests in real field environments was solved, achieving higher detection accuracy and a lower false negative rate.

CN118038428BActive Publication Date: 2026-06-26XI AN JIAOTONG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
XI AN JIAOTONG UNIV
Filing Date
2024-02-29
Publication Date
2026-06-26

Smart Images

  • Figure CN118038428B_ABST
    Figure CN118038428B_ABST
Patent Text Reader

Abstract

The application relates to the field of target detection and discloses a small-target pest detection method and system based on channel and space cooperative attention, the method comprising the following steps: acquiring a target data set; dividing the target data set into a training set, a verification set and a test set according to a proportion of 8:1:1; taking a YOLOv8 model as a basic model, improving the YOLOv8 model and constructing a small-target pest detection model CSCA-YOLO; training and adjusting the CSCA-YOLO model by using the training set and the verification set respectively until the loss function of the model converges, so that a trained CSCA-YOLO model is obtained; inputting test set images into the trained CSCA-YOLO model for target detection and outputting the detection result of a pest target. The system comprises an acquisition module, a construction module, a training module and a detection module. The application analyzes the characteristics of small-target pests, improves the YOLOv8 model based on the characteristics, constructs the CSCA-YOLO model which can be applied to the detection of small targets such as pests, uses the CSCA-YOLO model for pest target detection, reduces the missed detection rate of small-target pests at a lower calculation cost, improves the detection capability of small targets and further improves the detection precision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of target detection, specifically relating to a method and system for detecting small target pests based on channel and spatial collaborative attention. Background Technology

[0002] Due to the wide variety of pests and the large area of ​​farmland, manual identification and location of pests is time-consuming, labor-intensive, subjective, and prone to errors. Therefore, it is imperative to conduct technical research on accurate and efficient pest detection.

[0003] Currently, deep learning-based pest detection technologies can be divided into two main categories: two-stage pest detection methods and single-stage pest detection methods. Two-stage detection methods primarily consist of convolutional neural networks and region proposal networks, such as R-CNN, Faster R-CNN, and Mask R-CNN. While offering high detection accuracy, they suffer from slow detection speed, large parameter count, and high storage and computational costs. Single-stage detection methods, such as the YOLO series, SSD, and RetinaNet, directly perform classification and regression after extracting convolutional features, without region proposal networks. This significantly improves detection speed, but results in lower accuracy. Subsequent researchers have made considerable efforts to improve single-stage detection accuracy while maintaining speed, including employing lightweight network models, introducing scale feature fusion, and optimizing loss functions. However, most existing pest detection algorithms are primarily applied to simple, controlled environments such as monitoring lights, and their ability to detect crop pests in real field environments has not yet been explored. The detection of small-target crop pests in complex backgrounds presents unique challenges. Therefore, exploring the detection of small-target pests in real field environments remains a challenging task.

[0004] In summary, existing research has made some progress in pest detection under simple controlled environments, but pest detection for small targets in real field environments still faces the following challenges:

[0005] (1) In images of pests taken in the field, the size of the pest targets is very small, usually only a few dozen pixels or even a few pixels in size, accounting for less than 1% of the entire image. Deep learning detection algorithms usually extract information of interest by stacking a large number of convolutional layers. As the downsampling rate increases, a lot of detailed information of small target features is lost.

[0006] (2) Small-scale pests in the field often exhibit aggregation characteristics. For example, aphids and whiteflies, a large number of pests gather in local areas of crops, with high density and high overlap. Conventional pest detection methods are difficult to achieve high detection accuracy and have a high rate of missed detection. Summary of the Invention

[0007] The purpose of this invention is to provide a method and system for detecting small target pests based on channel and spatial collaborative attention, so as to improve the detection accuracy of small target pests.

[0008] The present invention is achieved using the following technical solution:

[0009] Small-target pest detection methods based on channel and spatial collaborative attention include:

[0010] Obtain the target dataset and divide it into a training set, a validation set, and a test set in an 8:1:1 ratio;

[0011] Using the YOLOv8 model as the base model, the YOLOv8 model is improved to construct a small target pest detection model, which is referred to as the CSCA-YOLO model.

[0012] The CSCA-YOLO model is trained and its parameters are tuned using the training set and validation set respectively until the loss function of the CSCA-YOLO model converges, thus obtaining the trained CSCA-YOLO model.

[0013] The test set images are input into the trained CSCA-YOLO model for target detection, and the detection results of pest targets are output.

[0014] A further improvement of the present invention lies in the improvement of the YOLOv8 model, including:

[0015] The output of the P2 layer was added to the Neck and Prediction networks of the YOLOv8 model as a small object detection layer;

[0016] In the feature enhancement stage of the neck, the small target detection layer performs multi-scale feature fusion with the feature maps output by layers P3-P5 to obtain an enhanced feature map of size 160×160×64, which is then input to the Prediction detection head.

[0017] A further improvement of the present invention lies in the improvement of the YOLOv8 model, including:

[0018] In the Neck network, a channel- and spatially coordinated attention module, hereinafter referred to as the CSCA module, is added after the C2f module;

[0019] The CSCA module consists of three parallel branches. The first branch is responsible for capturing the feature dependencies in spatial dimension W, the second branch is responsible for capturing the feature dependencies in spatial dimension H, and the third branch is used to capture the feature dependencies between channels C.

[0020] The first branch, the second branch, and the third branch each include a squeeze transformation module, an excitation transformation module, and a feature aggregation module connected in sequence.

[0021] The squeeze transformation module consists of two parallel branches: the first branch is a global average pooling, and the second branch is a global standard deviation pooling. The feature maps output by the two branches are then weighted and summed before being fed into the excitation transformation module.

[0022] The excitation transformation module consists of convolutional kernels with a kernel size of (1,K). For the first and second branches, the kernel size is 7. For the third branch, the kernel size is adaptively determined by the number of channels, and is expressed as kernel size. Where C is the number of channels, and γ and τ are two hyperparameters, set to 1.5 and 1 respectively. It refers to the nearest odd number less than or equal to ε;

[0023] The feature aggregation module performs a weighted fusion of the enhanced feature maps generated independently from the three branches, represented as follows: Where F″ is the aggregated feature, F″ W ,F″ H ,F″ C These are the outputs of the first branch, the second branch, and the third branch, respectively. λ1, λ2, and λ3 are floating-point parameters, ranging from (0,1), which are the summation weights of the three branches.

[0024] The feature map input to the CSCA module is enhanced through the first branch, the second branch, and the third branch, respectively.

[0025] The feature maps output from the first, second, and third branches are subjected to feature aggregation processing to obtain a fused feature map, which is then transmitted to the next module.

[0026] A further improvement of the present invention is that, before inputting the images of the dataset to be detected into the CSCA-YOLO model for object detection, the method further includes:

[0027] Convert the .xml format tag files in the dataset to be tested into .txt format tag files.

[0028] A further improvement of this invention is that the expression for the loss function of the CSCA-YOLO model is as follows:

[0029] Loss=β1L cls +β2L obj +β3L loc

[0030] Among them, L cls L represents the classification loss.obj L represents the confidence loss. loc β1, β2, and β3 represent the positioning loss, and β1, β2, and β3 are the balance coefficients corresponding to the losses of each component.

[0031] A small-target pest detection system based on channel and spatial collaborative attention includes:

[0032] The acquisition module is used to acquire the target dataset and divide the target dataset into a training set, a validation set, and a test set in a ratio of 8:1:1.

[0033] The building module is used to improve the YOLOv8 model as a base model and build a small target pest detection model, which is referred to as the CSCA-YOLO model.

[0034] The training module is used to train and tune the CSCA-YOLO model using the training set and validation set respectively, until the loss function of the CSCA-YOLO model converges, thus obtaining the trained CSCA-YOLO model.

[0035] The detection module is used to input test set images into the trained CSCA-YOLO model for target detection and output the detection results of pest targets.

[0036] A further improvement of the present invention is that the YOLOv8 model is improved in the construction module, including:

[0037] The output of the P2 layer was added to the Neck and Prediction networks of the YOLOv8 model as a small object detection layer;

[0038] In the feature enhancement stage of the neck, the small target detection layer performs multi-scale feature fusion with the feature maps output by layers P3-P5 to obtain an enhanced feature map of size 160×160×64, which is then input to the Prediction detection head.

[0039] A further improvement of the present invention is that the YOLOv8 model is improved in the construction module, including:

[0040] In the Neck network, a channel- and spatially coordinated attention module, hereinafter referred to as the CSCA module, is added after the C2f module;

[0041] The CSCA module consists of three parallel branches. The first branch is responsible for capturing the feature dependencies in spatial dimension W, the second branch is responsible for capturing the feature dependencies in spatial dimension H, and the third branch is used to capture the feature dependencies between channels C.

[0042] The first branch, the second branch, and the third branch each include a squeeze transformation module, an excitation transformation module, and a feature aggregation module connected in sequence.

[0043] The squeeze transformation module consists of two parallel branches: the first branch is a global average pooling, and the second branch is a global standard deviation pooling. The feature maps output by the two branches are then weighted and summed before being fed into the excitation transformation module.

[0044] The excitation transformation module consists of convolutional kernels with a kernel size of (1,K). For the first and second branches, the kernel size is 7. For the third branch, the kernel size is adaptively determined by the number of channels, and is expressed as kernel size. Where C is the number of channels, and γ and τ are two hyperparameters, set to 1.5 and 1 respectively. It refers to the nearest odd number less than or equal to ε;

[0045] The feature aggregation module performs a weighted fusion of the enhanced feature maps generated independently from the three branches, represented as follows: Where F″ is the aggregated feature, F″ W ,F″ H ,F″ C These are the outputs of the first branch, the second branch, and the third branch, respectively. λ1, λ2, and λ3 are floating-point parameters, ranging from (0,1), which are the summation weights of the three branches.

[0046] The feature map input to the CSCA module is enhanced through the first branch, the second branch, and the third branch, respectively.

[0047] The feature maps output from the first, second, and third branches are subjected to feature aggregation processing to obtain a fused feature map, which is then transmitted to the next module.

[0048] A further improvement of this invention is that, in the training module, the expression for the loss function of the CSCA-YOLO model is as follows:

[0049] Loss=β1L cls +β2L obj +β3L loc

[0050] Among them, L cls L represents the classification loss. obj L represents the confidence loss. loc β1, β2, and β3 represent the positioning loss, and β1, β2, and β3 are the balance coefficients corresponding to the losses of each component.

[0051] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the small-target pest detection method based on channel and spatial collaborative attention.

[0052] Based on existing technologies, this invention focuses on the challenges of detecting small targets and designs a method for detecting small pests based on channel and spatial collaborative attention on the YOLOv8 model, which has at least the following beneficial technical effects:

[0053] (1) A small target detection layer is added to the original YOLOv8s network to capture detailed information of small target features. In the field images of pests, the size of the pest targets is very small, and a large amount of detailed information of small target features will be lost as the downsampling rate of the deep learning detection network increases. The feature extraction and feature fusion network is redesigned, a small target detection layer is added, and multi-scale feature fusion is performed to enrich the extracted feature information and reduce the loss of small target feature information;

[0054] (2) A channel- and spatial collaborative attention mechanism was designed. For feature enhancement, targeting the clustering characteristics of small-target pests, the proposed CSCA channel- and spatial collaborative attention mechanism simultaneously models complementary attention in the channel, height, and width dimensions without introducing almost any additional computation. This enhances the expressive power of learned features and accurately locates objects of interest, making the network focus more on the local regions where pests cluster. In the feature fusion stage, adaptive weighted feature weights and adaptive enhancement are used to derive a more refined pest information feature map, significantly improving the detection accuracy of small-target pests. Attached Figure Description

[0055] Figure 1 This is a block diagram of the network structure of the YOLOv8s model.

[0056] Figure 2 This is a network structure diagram of a small-target pest detection method based on channel and spatial collaborative attention.

[0057] Figure 3 This is a block diagram of the CSCA attention module.

[0058] Figure 4 This is a block diagram of the extrusion transformation module.

[0059] Figure 5 This is a block diagram of the excitation transformation module.

[0060] Figure 6 This is a block diagram of the feature aggregation module.

[0061] Figure 7(a) shows the results of the YOLOv8s baseline model on the test set, and (b) shows the results of the final training weights of the small target pest detection method based on channel and spatial collaborative attention on the test set.

[0062] Figure 8 (a) is a visualization of the pest detection results of YOLOv8s on the test set, and (b) is a visualization of the pest detection results of the small target pest detection method based on channel and spatial collaborative attention on the test set.

[0063] Figure 9 This is a flowchart of the small target pest detection method based on channel and spatial collaborative attention according to the present invention.

[0064] Figure 10 This is a structural block diagram of the small target pest detection system based on channel and spatial collaborative attention according to the present invention. Detailed Implementation

[0065] Exemplary embodiments of the present invention will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present invention and to fully convey the scope of the invention to those skilled in the art. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.

[0066] like Figure 9 As shown, the small-target pest detection method based on channel and spatial collaborative attention provided by the present invention includes:

[0067] Obtain the target dataset and divide it into a training set, a validation set, and a test set in an 8:1:1 ratio;

[0068] Using the YOLOv8 model as the base model, the YOLOv8 model is improved to construct a small target pest detection model, which is referred to as the CSCA-YOLO model.

[0069] The improvements to the YOLOv8 model include:

[0070] The output of the P2 layer was added to the Neck and Prediction networks of the YOLOv8 model as a small object detection layer;

[0071] In the feature enhancement stage of the neck, the small target detection layer performs multi-scale feature fusion with the feature maps output by layers P3-P5 to obtain an enhanced feature map of size 160×160×64, which is then input to the Prediction detection head.

[0072] The improvements to the YOLOv8 model also include:

[0073] In the Neck network, a channel- and spatially coordinated attention module, hereinafter referred to as the CSCA module, is added after the C2f module;

[0074] The CSCA module consists of three parallel branches. The first branch is responsible for capturing the feature dependencies in spatial dimension W, the second branch is responsible for capturing the feature dependencies in spatial dimension H, and the third branch is used to capture the feature dependencies between channels C.

[0075] The first branch, the second branch, and the third branch each include a squeeze transformation module, an excitation transformation module, and a feature aggregation module connected in sequence.

[0076] The squeeze transformation module consists of two parallel branches: the first branch is a global average pooling, and the second branch is a global standard deviation pooling. The feature maps output by the two branches are then weighted and summed before being fed into the excitation transformation module.

[0077] The excitation transformation module consists of convolutional kernels with a kernel size of (1,K). For the first and second branches, the kernel size is 7. For the third branch, the kernel size is adaptively determined by the number of channels, and is expressed as kernel size. Where C is the number of channels, and γ and τ are two hyperparameters, set to 1.5 and 1 respectively. It refers to the nearest odd number less than or equal to ε;

[0078] The feature aggregation module performs a weighted fusion of the enhanced feature maps generated independently from the three branches, represented as follows: Where F″ is the aggregated feature, F″ W ,F″ H ,F″ C These are the outputs of the first branch, the second branch, and the third branch, respectively. λ1, λ2, and λ3 are floating-point parameters, ranging from (0,1), which are the summation weights of the three branches.

[0079] The feature map input to the CSCA module is enhanced through the first branch, the second branch, and the third branch, respectively.

[0080] The feature maps output from the first, second, and third branches are subjected to feature aggregation processing to obtain a fused feature map, which is then transmitted to the next module.

[0081] The CSCA-YOLO model is trained and its parameters are tuned using the training set and validation set respectively until the loss function of the CSCA-YOLO model converges, thus obtaining the trained CSCA-YOLO model.

[0082] The expression for the loss function of the CSCA-YOLO model is as follows:

[0083] Loss=β1L cls +β2L obj +β3L loc

[0084] Among them, L cls L represents the classification loss. obj L represents the confidence loss. loc β1, β2, and β3 represent the positioning loss, and β1, β2, and β3 are the balance coefficients corresponding to the losses of each component.

[0085] The test set images are input into the trained CSCA-YOLO model for target detection, and the detection results of pest targets are output. Before inputting the images of the dataset to be detected into the CSCA-YOLO model for target detection, the method further includes: converting the .xml format label files in the dataset to be detected into .txt format label files.

[0086] Example 1

[0087] This invention selects 12,654 images from the publicly available real-world field environment dataset AgriPest, covering four common crops (wheat, rice, rapeseed, and corn) and five small target pests (wheat spider mites, wheat aphids, rice planthoppers, rapeseed aphids, and corn aphids). This subset of the dataset is named smallAgriPest. A method for detecting small target pests based on channel and spatial collaborative attention is proposed, which can accurately and efficiently detect small target pests in real-world field environments.

[0088] The overall network diagram of the original YOLOv8s algorithm upon which this invention is based is as follows: Figure 1As shown, the YOLOv8 network consists of four parts: Input, Backbone, Neck, and Prediction head. The input module preprocesses the data, including adjusting the input image size and data augmentation. Data augmentation strategies primarily include mosaic enhancement, blending enhancement, spatial perturbation, and color perturbation. The backbone network, also known as the feature extraction network, references the CSPDarkNet-53 network structure, using the C2f module instead of the C3 module in YOLOv5 for further weight reduction, and employs the SPPF module to reduce redundant computation. The neck uses an FPN+PAN structure to construct the feature pyramid, enhancing the extracted features and enabling full fusion between multi-scale features. The detection head adopts a "decoupled head" structure, with two parallel branches performing classification and localization tasks respectively.

[0089] To address the characteristics of small-target pests in real-world field environments, two improvements were made to the YOLOv8s network structure. The overall network diagram is shown below. Figure 2 As shown. (1) To address the issue of small target pests being small in size, the feature extraction and feature fusion network was redesigned. A small target detection layer was added to the original network to enrich the fusion of information at different stages, significantly improving the accuracy of small target detection. (2) In terms of feature enhancement, a channel and spatial collaborative attention mechanism (CSCA) was proposed to address the aggregation characteristics of small target pests. This mechanism infers attention in the channel, height, and width dimensions simultaneously without introducing any additional computation. It considers the collaborative interaction between multidimensional space and channels, making the network more focused on the local areas where pests are clustered and reducing complex background interference. In the feature fusion stage, adaptive weighted feature weights and adaptive enhancement are adopted, making it more selective. A detailed introduction to the improvements is as follows:

[0090] 1. Small target detection layer

[0091] YOLOv8s network detection layer architecture as follows Figure 1 As shown in the Prediction section, feature maps output from layers P3, P4, and P5 are fed into the detection head for detection. If the normalized image size in the network input module is 640×640×3, the sizes of the output feature maps corresponding to layers P3-P5 are 80×80×128, 40×40×256, and 20×20×512, respectively, corresponding to small, medium, and large targets. Each pixel in the 80×80×128 feature map of layer P3 represents information from an 8×8 pixel region of the original image. However, many small targets are actually smaller in scale, leading to low accuracy and high false negative rates in small target detection.

[0092] Based on this, the feature extraction and feature fusion network was redesigned, and a new P2 layer output was added as a small target detection layer adapted for pest detection, realizing the capture of tiny targets. The corresponding output feature map size is 160×160×64. In the neck feature enhancement stage, the feature maps of 80×80×128, 40×40×256, and 20×20×256 are combined with the feature maps of PAN to achieve bidirectional flow of deep and shallow semantic information through the FPN+PAN structure, realizing multi-scale feature fusion and significantly improving the accuracy of small target detection.

[0093] 2. Attention Mechanisms of Channel and Spatial Coordination (CSCA)

[0094] Attention mechanisms don't introduce complex structures into the network. Instead, they reference the human eye's attention mechanism, shifting the network's attention to the most meaningful parts of an image while ignoring unnecessary areas. In visual recognition, attention mechanisms can be viewed as a dynamic weight adjustment process based on the importance of input image features, telling the network "what" and "where" to focus on. Since pests in field environments often cluster densely, the goal is for the network to focus on localized areas of pest concentration, ignoring complex background information—a concept aligned with the principles of attention mechanisms.

[0095] Among existing attention mechanism algorithms, the SE attention mechanism initially proposed using a multilayer perceptron (MLP) with a hidden layer to capture inter-channel correlations and demonstrated the effectiveness of this operation. Following this idea, CBAM and CA also independently adopted it in their channel attention modules. However, this operation involving dimensionality reduction not only makes the correspondence between channels and their weights indirect, leading to the loss of inter-channel relationships, but also the nonlinear global cross-channel dependencies it captures are inefficient and redundant for channel attention.

[0096] To overcome the aforementioned challenges, a channel- and spatial collaborative attention mechanism, CSCA, is designed. Unlike previous methods that either develop attention only in the channel or spatial dimensions, or compute channel and spatial attention separately, inevitably leading to the loss of valuable information, this paper's CSCA focuses on simultaneously modeling complementary attention in the channel, height, and width dimensions to enhance the expressive power of learned features and accurately locate objects of interest.

[0097] CSCA module, such as Figure 3As shown, it consists of three parallel branches. The top two branches are responsible for capturing the feature dependencies in spatial dimensions W and H, respectively, while the last branch is mainly used to capture inter-channel interactions. From a framework perspective, the CSCA structure can be divided into three parts: a squash transformation module, an excitation transformation module, and a feature aggregation module. Clearly, CSCA can be viewed as a computational unit that expresses a specific transformation from the input tensor to an exact output tensor of the same shape.

[0098] Specifically, let This is the output of the convolutional layer, i.e., the input feature map of the CSCA module. Taking the first branch as an example, the input feature map is first rotated 90° counterclockwise along the H-axis to obtain the rotated feature map. To model the long-term dependency between C and H, the feature map is rotated. The data is input into the squeeze transformation module to obtain aggregated features. Then, The information is input into the excitation transformation module to capture the interaction of features on W, and thus... Attention weights are then generated along the W dimension using the sigmoid activation function. Next, Applying a matrix to element-wise multiplication This generates an enhanced feature mapping matrix. Then rotate 90° clockwise along the H-axis to obtain a feature map with the same shape as the original input. The above process can be summarized by the following equation:

[0099]

[0100]

[0101]

[0102] Among them, PM H (·) indicates a 90° counterclockwise rotation along the H-axis. T represents rotation in the opposite direction, σ(·) represents the activation function, and T sq (·) and T ex (·) refers to squeeze transformation and activation transformation, respectively.

[0103] Similarly, the second branch first rotates F counterclockwise by 90° along the W axis to obtain the rotated feature map. The interdependence between channel dimension C and spatial dimension W is modeled, and the interaction between spatial dimensions H is further captured by rotating the feature map. The data are sequentially input into the extrusion transformation module and the excitation transformation module to derive the aggregated feature map. and H feature direction weights Attention weights are then generated in the H dimension using the sigmoid activation function. Next, Recalibrate This generates an enhanced feature mapping matrix. Then rotate 90° clockwise along the H-axis to obtain a feature map with the same shape as the original input. The above process can be summarized by the following equation:

[0104]

[0105]

[0106]

[0107] Among them, PM W (·) indicates a 90° counterclockwise rotation along the H-axis. It indicates rotation in the opposite direction.

[0108] The third branch primarily models the interdependencies between spaces (H and W) and captures the interactions between channels. This will be achieved through identity mapping. Then The data are sequentially input into the extrusion transformation module and the excitation transformation module to obtain the aggregated feature map. and channel-level feature orientation weights Channel attention weights are then generated using the sigmoid activation function. Next, Recalibrate This generates an enhanced feature mapping matrix F′. C ∈R H×C×W Then, through a mapping function, a feature map with the same shape as the original input is obtained. The above process can be summarized by the following equation:

[0109]

[0110]

[0111]

[0112] Wherein, IM refers to the identity mapping function.

[0113] Finally, in the feature aggregation module, a strategy of simple averaging plus adaptive weight perturbation is used to aggregate all the outputs of the three branches that have been recalibrated by the attention weights generated in different dimensions, which can lead to a more refined feature map of pest information.

[0114]

[0115] Where λ1, λ2, and λ3 are floating-point parameters, ranging from (0, 1), meaning the weights of the three branches are automatically learned through gradient descent. Each module is described in detail below:

[0116] (1) Extrusion Transformation Module

[0117] Existing algorithms have demonstrated the effectiveness of global average pooling, global max pooling, and global standard deviation pooling in aggregating cross-dimensional feature responses. To balance performance and computational cost, average and standard deviation pooling are used simultaneously to better aggregate cross-dimensional feature responses, rather than combining multiple pools (three or more). Since the credit values ​​of average pooling features and standard deviation pooling features differ at different stages of image feature extraction, an adaptive mechanism called squeeze transform is designed to effectively combine average pooling features and standard deviation pooling features, significantly improving the representation of feature descriptors.

[0118] The diagram of the extrusion transformation module is shown below. Figure 4 As shown. Specifically, taking the third branch as an example, the input features... First, global average pooling and global standard deviation pooling are used to generate two different channel-oriented features. and Then and The input is fed into the adaptive composition mechanism of the design, from which channel-oriented feature descriptors can be generated. Here, α1 and α2 are floating-point parameters (0,1), i.e., weights, which are automatically learned with gradient descent. The adaptive mechanism inherently introduces input-conditional dynamics, which can assign different weights to average pooling and standard deviation pooling features at different stages of image feature extraction, thereby enhancing the discriminability of the output feature descriptor.

[0119] (2) Excitation Transformation Module

[0120] Existing attention mechanisms often use multilayer perceptrons (MLPs) with a hidden layer to capture inter-channel correlations. However, this dimensionality reduction operation is not only inefficient and redundant, but also results in the indirect correspondence between channels and their weights, losing the inter-channel relationships. To overcome this problem, inspired by the ECA attention mechanism, an excitation transformation module that adaptively determines the coverage of channel interactions is designed, such as... Figure 5 As shown.

[0121] Specifically, in the third branch, the input features are For the channel with index m, only consider each channel and its K. C The interaction between adjacent channels, and the channel feature weights can be calculated as follows:

[0122]

[0123] get in, K represents the relationship between the m-th channel and the K-th channel. C The feature descriptor set of adjacent channels, ω ξ This represents shared learnable parameters that are not specific to that channel. This transformation can be performed using a kernel size of (1, K). C Two-dimensional convolution operations can be easily implemented.

[0124] Given that different levels of features can be learned at different stages of image feature extraction, it is reasonable to assume that the coverage range K is different at different stages. C Different. To determine K C The value of K was taken into consideration. C Mapping relationship with channel dimension C: ①K C ① The correlation between the channel number and the channel dimension C should be positive, meaning that higher-dimensional channels cover a wider range; ② To avoid limitations, this correlation should be non-linear; ③ In deep learning networks, the number of channels C is usually a power of 2. Therefore, the mapping relationship between them can be written as:

[0125]

[0126] Here, γ and τ are two hyperparameters, taking into account the kernel size K. C Always set to odd, given C, K C It can be approximated as follows:

[0127]

[0128] Here, It refers to the nearest odd number less than or equal to ε. In all experiments, γ and τ were empirically set to 1.5 and 1, respectively.

[0129] In the first and second branches, the input features are respectively and The corresponding feature weights are calculated as follows:

[0130]

[0131]

[0132] The convolution kernel K W ,K H Empirically set to 7 respectively, the feature weights in the W direction are obtained respectively. and feature weights in the H direction

[0133] (3) Feature aggregation module

[0134] The enhanced feature maps generated independently by the three branches are input into, for example... Figure 6 The feature aggregation module shown can derive a more detailed feature map of pest information:

[0135]

[0136] in:

[0137]

[0138]

[0139]

[0140] Where λ1, λ2, and λ3 are floating-point parameters, ranging from (0,1), which are the summation weights of the three branches. They are automatically learned with gradient descent and can adaptively assign different weights to the enhanced features in the H, W, and C dimensions during the image feature aggregation stage.

[0141] In the specific implementation, the hardware environment used in the experiment was an NVIDIA GeForce RTX2080 with 32GB of video memory, running Ubuntu 18.04, and using Python 3.8 as the programming language. The deep learning framework used was PyTorch 1.8 with CUDA 11.3. YOLOv8s pre-trained weights were used to initialize the network structure, the model input image size was 640×640, and the batch size was set to 32. The regression loss function used was DFL Loss + CIoU Loss. The model was trained for a total of 200 epochs, and a validation epoch was performed after each training epoch. Finally, the weight file with the highest accuracy on the validation set was used for testing.

[0142] In this embodiment, mAP (mean Average Precision) is used as the evaluation metric. The mAP@0.5 value (the mAP value obtained when the IoU threshold is set to 0.5) is calculated. The AP value is calculated from the precision P (Precision) and recall R (Recall). The calculation formulas for Precision, Recall, AP, and mAP are as follows:

[0143]

[0144]

[0145]

[0146]

[0147] Where Tp (True Positive) represents a true positive (i.e., a correct prediction), and Fp (False Positive) represents a false positive (i.e., a prediction that is not a small target is a small target). N (False Negative) indicates a false negative, meaning that the small object is predicted as another category. AP represents the accuracy of a single category. mAP is the result of integrating the area under the Precision-Recall curve, representing the mean of the accuracy of all categories. k is the number of categories.

[0148] Experimental results are as follows Figure 7 and Figure 8 As shown. Figure 7 The left side (a) shows the results of the YOLOv8s baseline model on the test set, and the right side (b) shows the results of the final training weights of the improved model CSCA-YOLO on the test set. Here, 11111, 11121, 12111, 13111, and 14111 are pest target labels, corresponding to five small target pests: wheat spider mites, wheat aphids, rice planthoppers, rapeseed aphids, and corn constrictor aphids. Figure 7 It can be seen that the improved CSCA-YOLO model has a significant improvement in the detection accuracy (mAP) of each type of small target pest on the test set compared with the original YOLOv8s. Figure 8 (a) is a visualization of the pest detection results of YOLOv8s on the test set, and (b) is a visualization of the pest detection results of the improved CSCA-YOLO model on the test set. It can be seen that the improved model reduces false detections and false negatives compared to the original YOLOv8.

[0149] Example 2

[0150] like Figure 10 As shown, the small-target pest detection system based on channel and spatial collaborative attention provided by the present invention includes:

[0151] The acquisition module is used to acquire the target dataset and divide the target dataset into a training set, a validation set, and a test set in a ratio of 8:1:1.

[0152] The building module is used to improve the YOLOv8 model as a base model and build a small target pest detection model, which is referred to as the CSCA-YOLO model.

[0153] The training module is used to train and tune the CSCA-YOLO model using the training set and validation set respectively, until the loss function of the CSCA-YOLO model converges, thus obtaining the trained CSCA-YOLO model.

[0154] The detection module is used to input test set images into the trained CSCA-YOLO model for target detection and output the detection results of pest targets.

[0155] The present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the small target pest detection method based on channel and spatial collaborative attention.

[0156] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0157] This application is described with reference to flowchart illustrations and / or block diagrams of methods, systems, and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A system that specifies functions in one or more boxes.

[0158] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0159] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0160] Although the present invention has been described in detail above with general descriptions and specific embodiments, modifications or improvements can be made to it, which will be obvious to those skilled in the art. Therefore, all such modifications or improvements made without departing from the spirit of the present invention fall within the scope of protection claimed by the present invention.

Claims

1. A method for detecting small-target pests based on channel and spatial collaborative attention, characterized in that, include: Obtain the target dataset and divide it into a training set, a validation set, and a test set in an 8:1:1 ratio; Using the YOLOv8 model as the base model, the YOLOv8 model is improved to construct a small target pest detection model, which is referred to as the CSCA-YOLO model. The YOLOv8 model is improved by including: In the Neck network, a channel- and spatially coordinated attention module, hereinafter referred to as the CSCA module, is added after the C2f module; The CSCA module consists of three parallel branches. The first branch is responsible for capturing the feature dependencies in spatial dimension W, the second branch is responsible for capturing the feature dependencies in spatial dimension H, and the third branch is used to capture the feature dependencies between channels C. The first branch, the second branch, and the third branch each include a compression transformation module and an excitation transformation module connected in sequence. The squeeze transformation module consists of two parallel branches: the first branch is a global average pooling, and the second branch is a global standard deviation pooling. The feature maps output by the two branches are then weighted and summed before being fed into the excitation transformation module. The excitation transformation module consists of convolutional kernels with a kernel size of (1, K). For the first and second branches, the kernel size is 7. For the third branch, the kernel size is adaptively determined by the number of channels and is expressed as kernel size. Where C is the number of channels. and These are two hyperparameters, set to 1.5 and 1 respectively. It means less than or equal to The nearest odd number; The feature aggregation module performs a weighted fusion of the enhanced feature maps generated independently from the three branches, represented as follows: ,in These are the features after aggregation. These are the outputs of the first branch, the second branch, and the third branch, respectively. These are floating-point parameters, ranging from (0,1), which represent the summation weights of the three branches; The feature map input to the CSCA module is enhanced through the first branch, the second branch, and the third branch, respectively. The feature maps output from the first, second, and third branches are subjected to feature aggregation processing to obtain a fused feature map, which is then transmitted to the next module. The CSCA-YOLO model is trained and its parameters are tuned using the training set and validation set respectively until the loss function of the CSCA-YOLO model converges, thus obtaining the trained CSCA-YOLO model. The test set images are input into the trained CSCA-YOLO model for target detection, and the detection results of pest targets are output.

2. The method for detecting small target pests based on channel and spatial collaborative attention according to claim 1, characterized in that, The YOLOv8 model is improved by including: A P2 layer output was added to the Neck and Prediction networks of the YOLOv8 model as a small object detection layer; In the feature enhancement stage of the neck, the small target detection layer performs multi-scale feature fusion with the feature maps output by layers P3-P5 to obtain an enhanced feature map of size 160×160×64, which is then input to the Prediction detection head.

3. The method for detecting small target pests based on channel and spatial collaborative attention according to claim 1, characterized in that, Before inputting the images of the target dataset into the CSCA-YOLO model for object detection, the method further includes: Convert the .xml format tag files in the target dataset to .txt format tag files.

4. The method for detecting small target pests based on channel and spatial collaborative attention according to claim 1, characterized in that, The expression for the loss function of the CSCA-YOLO model is as follows: in, Represents classification loss. Indicates confidence loss. Indicates location loss. These are the balance coefficients corresponding to the losses of each part.

5. A small-target pest detection system based on channel and spatial coordinated attention, characterized in that, include: The acquisition module is used to acquire the target dataset and divide the target dataset into a training set, a validation set, and a test set in a ratio of 8:1:

1. The building module is used to improve the YOLOv8 model as a base model and build a small target pest detection model, which is referred to as the CSCA-YOLO model. The YOLOv8 model is improved by including: In the Neck network, a channel- and spatially coordinated attention module, hereinafter referred to as the CSCA module, is added after the C2f module; The CSCA module consists of three parallel branches. The first branch is responsible for capturing the feature dependencies in spatial dimension W, the second branch is responsible for capturing the feature dependencies in spatial dimension H, and the third branch is used to capture the feature dependencies between channels C. The first branch, the second branch, and the third branch each include a compression transformation module and an excitation transformation module connected in sequence. The squeeze transformation module consists of two parallel branches: the first branch is a global average pooling, and the second branch is a global standard deviation pooling. The feature maps output by the two branches are then weighted and summed before being fed into the excitation transformation module. The excitation transformation module consists of convolutional kernels with a kernel size of (1, K). For the first and second branches, the kernel size is 7. For the third branch, the kernel size is adaptively determined by the number of channels and is expressed as kernel size. Where C is the number of channels. and These are two hyperparameters, set to 1.5 and 1 respectively. It means less than or equal to The nearest odd number; The feature aggregation module performs a weighted fusion of the enhanced feature maps generated independently from the three branches, represented as follows: ,in These are the features after aggregation. These are the outputs of the first branch, the second branch, and the third branch, respectively. These are floating-point parameters, ranging from (0,1), which represent the summation weights of the three branches; The feature map input to the CSCA module is enhanced through the first branch, the second branch, and the third branch, respectively. The feature maps output from the first, second, and third branches are subjected to feature aggregation processing to obtain a fused feature map, which is then transmitted to the next module. The training module is used to train and tune the CSCA-YOLO model using the training set and validation set respectively, until the loss function of the CSCA-YOLO model converges, thus obtaining the trained CSCA-YOLO model. The detection module is used to input test set images into the trained CSCA-YOLO model for target detection and output the detection results of pest targets.

6. The small-target pest detection system based on channel and spatial coordinated attention according to claim 5, characterized in that, The YOLOv8 model is improved in the building module, including: A P2 layer output was added to the Neck and Prediction networks of the YOLOv8 model as a small object detection layer; In the feature enhancement stage of the neck, the small target detection layer performs multi-scale feature fusion with the feature maps output by layers P3-P5 to obtain an enhanced feature map of size 160×160×64, which is then input to the Prediction detection head.

7. The small-target pest detection system based on channel and spatial coordinated attention according to claim 5, characterized in that, In the training module, the expression for the loss function of the CSCA-YOLO model is as follows: in, Represents classification loss. Indicates confidence loss. Indicates location loss. These are the balance coefficients corresponding to the losses of each part.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the small-target pest detection method based on channel and spatial collaborative attention as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Pomegranate fruit detection method before fruit thinning based on improved YOLOv8s

    CN116958962A

  • Disease and insect pest target detection method, device and equipment based on improved YOLOv8

    CN117115640A