Lightweight pest image detection method based on dynamic adaptive scanning and attention mechanism joint optimization

The lightweight pest image detection method optimized by dynamic adaptive scanning and attention mechanism solves the problems of insufficient accuracy and high computational complexity of lightweight models in pest detection, and achieves efficient and real-time pest detection results.

CN120808397APending Publication Date: 2025-10-17ANHUI UNIV +1
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202510973444.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-15
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

Existing pest detection technologies struggle to maintain high detection accuracy in lightweight models, particularly in identifying small-scale pests. Meanwhile, high-parameter schemes are computationally complex and difficult to deploy on edge devices, failing to achieve a balance between high accuracy and low computational requirements.

Method used

A lightweight pest image detection method is proposed, which is jointly optimized by dynamic adaptive scanning and attention mechanism. By constructing a lightweight pest image detection network, including dynamic adaptive scanning feature extraction, hole space compression excitation attention optimization, multi-scale pest feature perception aggregation and multi-category pest classification and localization modules, and training it with AdamW optimization algorithm, the method achieves efficient collaboration between feature extraction and detection.

Benefits of technology

It significantly improves the accuracy and robustness of pest detection, effectively detects small-scale pests, reduces computational complexity, achieves a balance between real-time performance and high accuracy, and is suitable for edge devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120808397A_ABST
    Figure CN120808397A_ABST
Patent Text Reader

Abstract

The invention relates to a light-weight pest image detection method based on dynamic adaptive scanning and attention mechanism joint optimization, and solves the problems that a light-weight model sacrifices a feature modeling capability during parameter compression, so that missing detection is more, small-scale pest information is difficult to extract, and the detection precision is low. And although small-scale features can be extracted by a high-parameter-quantity scheme, the calculation complexity is high, the high-parameter-quantity scheme is difficult to deploy to edge equipment, and the unification of high detection precision and low calculation power requirements cannot be realized. The method comprises the following steps: constructing a multi-category crop pest data set; constructing a lightweight pest image detection network; training a lightweight pest image detection network; acquiring a pest image to be detected; and obtaining a pest image detection result. Target features are extracted through the dynamic self-adaptive scanning module, long-distance dependency relationships in different directions are captured by utilizing the features of a state space model, and meanwhile, the calculation efficiency is kept; meanwhile, the detection network is optimized based on the attention mechanism, the detection precision and robustness of the pest target are remarkably improved, and the real-time performance of pest detection is achieved through light-weight design.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of pest image detection, in particular to a lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism. BACKGROUND

[0002] In recent years, pest detection technology based on computer vision has gradually been applied, but the existing scheme still has significant defects. The current intelligent detection field of agricultural pests generally uses a deep learning model based on static images, which partially solves the problem of poor environmental robustness of traditional image processing methods, but faces two major bottlenecks: first, existing lightweight models sacrifice feature modeling capability when compressing parameters, resulting in more missed detections for pest images in real agricultural environments and difficulty in extracting small-scale pest information, leading to low model detection accuracy; second, high-parameter schemes can extract small-scale pest features, but have high computational complexity and are difficult to deploy to edge devices. The existing pest detection technology has not achieved the unification of high detection accuracy and low power requirements, which restricts the engineering application of real-time pest detection.

[0003] The representative technology in the current field of agricultural pest detection has significant limitations: two-stage methods such as Faster R-CNN can extract certain features, but have limited detection accuracy and slow speed, making them difficult to adapt to edge devices; single-stage models such as SSD are faster but have lower accuracy, with severe missed detection of small-scale pests; YOLO series such as YOLOv5 have improved speed and accuracy, but still cannot effectively balance the two, and lack the ability to capture pest features in complex scenarios; DETR series have high accuracy, but the speed and lightweight degree still do not meet the real-time deployment requirements, and the core contradiction between high accuracy and low power has not been solved. SUMMARY

[0004] The purpose of the present application is to solve the defects in the prior art that lightweight models sacrifice feature modeling capability when compressing parameters, resulting in more missed detections, difficulty in extracting small-scale pest information, and low detection accuracy, while high-parameter schemes can extract small-scale features but have high computational complexity and are difficult to deploy to edge devices, and fail to achieve the unification of high detection accuracy and low power requirements. The present application provides a lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism to solve the above problems.

[0005] To achieve the above purpose, the technical solution of the present application is as follows:

[0006] A lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism, comprising the following steps:

[0007] Constructing a multi-class crop pest dataset;

[0008] Constructing a lightweight pest image detection network: constructing a lightweight pest image detection network based on dynamic adaptive scanning and attention mechanism combined optimization;

[0009] Training of the lightweight pest image detection network;

[0010] Acquisition of the pest image to be detected;

[0011] Obtaining of the pest image detection result: inputting the pest image to be detected into the trained lightweight pest image detection network to obtain the pest image detection result.

[0012] The construction of the lightweight pest image detection network comprises the following steps:

[0013] Setting the lightweight pest image detection network comprising a dynamic adaptive scanning feature extraction network, a hollow space extrusion excitation attention optimization module, a multi-scale pest feature perception aggregation module and a multi-class pest classification and positioning module;

[0014] Setting the dynamic adaptive scanning feature extraction network;

[0015] Setting the hollow space extrusion excitation attention optimization module;

[0016] Setting the multi-scale pest feature perception aggregation module;

[0017] Setting the multi-class pest classification and positioning module.

[0018] The training of the lightweight pest image detection network comprises the following steps:

[0019] Initializing the parameters of the lightweight pest image detection network, including the weight parameters of the dynamic adaptive scanning feature extraction network, the hollow space extrusion excitation attention optimization module, the multi-scale pest feature perception aggregation module and the multi-class pest classification and positioning module;

[0020] Setting the training hyperparameters, including the learning rate, the batch size, the training round number, and defining the classification loss function, the positioning loss function and the auxiliary loss for optimizing feature fusion;

[0021] Inputting the training set image into the dynamic adaptive scanning feature extraction network, sequentially through the cascaded coding module, the dynamic adaptive scanning block and the visual fusion module, and outputting the feature map containing multi-direction long-distance dependence features;

[0022] Inputting the feature map output by the dynamic adaptive scanning feature extraction network into the hollow space extrusion excitation attention optimization module, capturing multi-scale context information through convolution operation with different hole rates, and outputting enhanced feature map after channel attention calibration;

[0023] The enhanced feature map is input into a multi-scale pest feature perception aggregation module, based on a path aggregation feature pyramid network design, different level features are fused through horizontal connection and up-sampling operation to generate a multi-scale feature map set;

[0024] The multi-scale feature map set is input into a multi-class pest classification and positioning module, each detection layer outputs target class probability, bounding box coordinates and segmentation mask based on the corresponding scale feature map, and the weighted sum of classification loss, positioning loss and segmentation loss is calculated as the total loss;

[0025] The AdamW optimization algorithm is used to back-propagate the total loss and update the network parameters, realizing the joint optimization of the dynamic adaptive scanning module, attention module, feature aggregation module and classification and positioning module, and saving the optimal parameters of the lightweight pest image detection network.

[0026] The dynamic adaptive scanning feature extraction network includes the following steps:

[0027] The dynamic adaptive scanning feature extraction network includes a pest image cascade coding module, a dynamic adaptive scanning block and a visual fusion module.

[0028] The pest image cascade coding module is constructed as follows:

[0029] The original crop pest images in the multi-class crop pest data set are input, and a convolution operation with a convolution kernel size of 3 and a step size of 2 is used to perform initial coding on the image features;

[0030] The feature map after initial coding is again coded using a convolution layer with a convolution kernel size of 3 and a step size of 2 to reduce the feature map scale and obtain the segmented pest feature map.

[0031] The dynamic adaptive scanning block is constructed as follows:

[0032] The dynamic adaptive scanning module is designed, and the input is the segmented pest feature map. Two information streams are generated through the convolution layer: one stream is refined through depth convolution and Silu activation function to capture complex patterns; the other stream is directly processed through Silu activation function.

[0033] The two information streams are input into the core dynamic adaptive scanning mechanism to model all feature dimension information, and then output through convolution fusion.

[0034] The output features of the dynamic adaptive scanning module are normalized by layer.

[0035] The normalized features are input into the efficient feedforward network and processed by the following operations: Convolution maps the features to a high-dimensional space, depth convolution combines with the gating mechanism to process hidden layer features, and then uses a ​Convolution maps the features back to the original dimension, resulting in high-quality feature maps;

[0036] The dynamic adaptive scanning module includes five functional sub-modules: scanning expansion module, direction state space model processing module, direction attention generation module, dynamic fusion module and scanning merging module. The specific processing flow is as follows:

[0037] The scanning expansion module expands the input feature map into a one-dimensional sequence along the main diagonal from the top left to the bottom right, the secondary diagonal from the top right to the bottom left, the vertical row first, and the horizontal column first. Cover the full direction structure information, denoted as ;

[0038] The direction state space model processing module applies the state space model independently to each direction sequence , discretizes the state transition matrix and the input matrix based on the zero-order hold method, and the discretization formula is:

[0039] ,

[0040] ,

[0041] where is the state transition matrix corresponding to the direction , which describes the transition relationship of the state over time; is the input matrix corresponding to the direction , which represents the influence of the input on the state; is the time scale parameter, which is used to control the discretization accuracy of the state transition matrix; is the unit matrix, which recursively calculates the state sequence:

[0042] ,

[0043] ,

[0044] where and represent the discretized state transition matrix and input matrix, respectively; represents the hidden state sequence of the direction at time ; is the input sequence of the direction , is the output matrix that maps the hidden state to the output feature , Combining in order, finally get the direction feature ;

[0045] The direction attention generation module performs global average pooling on the input feature to obtain the channel-level global feature , the formula is:

[0046] ,

[0047] wherein, is the height of the feature map, is the width of the feature map, represents selecting the value of all batches and all channels at a specific spatial position from the input feature , and then mapping the channel number to 4 through convolution and performing Softmax normalization to generate four-direction attention weights , which represents the importance of the direction , realizing adaptive selection and fusion of the direction feature:

[0048] ,

[0049] wherein, represents convolution operation, which is used for dimension reduction and feature transformation, satisfying ;

[0050] The dynamic fusion module pads each direction feature to the maximum length, and performs weighted sum according to the attention weight to obtain the fusion feature , the formula is:

[0051] ,

[0052] wherein, represents padding the direction feature to a unified length;

[0053] The scanning and merging module restores the one-dimensional sequence after fusion to a two-dimensional feature map in row priority order, and outputs it for use by subsequent network layers;

[0054] Construct a visual fusion module:

[0055] Input the two-dimensional pest feature map output by the dynamic adaptive scanning block, and reorganize the spatial dimension information into the channel dimension through the reorganization operation, so that the feature block at each spatial position is expanded into a part of the channel dimension;

[0056] A 4x compressed convolutional layer is used to process the reorganized feature map. The number of channels is compressed by cross-channel weighted summation to achieve cross-channel information fusion and spatial dimension downsampling, and the downsampled fused feature map is output.

[0057] The setting of the hole space squeezing incentive attention optimization module includes the following steps:

[0058] The feature map output by the dynamic adaptive scanning feature extraction network is input, and four sets of dilated convolution operations are applied to the input feature map in parallel, as follows:

[0059] The void ratio is 1 Conventional convolution captures local features and generates feature maps ;

[0060] The void ratio is 2 Dilated convolution expands the receptive field to , capturing medium-scale context and generating feature maps ;

[0061] Using a void ratio of 4 Dilated convolution expands the receptive field to , capture large-scale environmental information and generate feature maps ;

[0062] The void ratio is 8 Dilated convolution expands the receptive field to , capture global context and generate feature maps ;

[0063] For each set of feature maps , , perform global average pooling to compress the spatial dimension;

[0064] A nonlinear incentive mechanism is used to generate channel weight coefficients:

[0065] The number of channels is compressed to one-fourth of the original number of channels through the first fully connected layer, and the activation function is ReLU;

[0066] The number of channels is restored to the original number through the second fully connected layer, the activation function is Sigmoid, and the weight vector is generated. ;

[0067] The weight vector And the corresponding feature map Channel-by-channel multiplication, recalibration feature map ;

[0068] The 4 groups of recalibrated feature maps 、 、 、 Spliced in the channel dimension, a temporary feature map is obtained

[0069] Convolutional dimension reduction is used on the temporary feature map , compress the channel number, eliminate redundant information, and output an enhanced feature map.

[0070] The set multi-scale pest feature perception aggregation module includes the following steps:

[0071] A dynamic adaptive scanning block is embedded in the feature fusion path of the multi-scale pest feature perception aggregation module to capture gradient-rich information flow and enhance the semantic association between different scale features.

[0072] The input of the multi-scale pest feature perception aggregation module is a multi-level feature map constructed by the feature map output by the dynamic adaptive scanning feature extraction network and the enhanced feature map output by the hollow space squeezing excitation attention optimization module, denoted as , ;

[0073] For the layer and the layer feature map, the layer feature map is upsampled using interpolation method.

[0074] Convolutional layers and batch normalization layers are used to process the feature map. In the convolutional layer, a convolutional kernel is used to extract features, and a batch normalization layer is used to normalize the features.

[0075] Starting from the bottom feature map, each layer is fused with the upper layer feature map, and after each fusion, convolution and normalization processing are performed.

[0076] Finally, a multi-scale feature map set is generated.

[0077] The set multi-class pest classification and positioning module includes the following steps:

[0078] Input the multi-scale feature map set output by the multi-scale pest feature perception aggregation module.

[0079] Three detection layers are constructed: a small size detection layer is used to detect small scale pests; a medium size detection layer is adapted to medium size pest detection; and a large size detection layer is used to identify large size pests. The feature map size of the small size detection layer is , the feature map size of the middle size detection layer is , the feature map size of the large size detection layer is ;

[0080] The cross-scale NMS processing is performed on the output results of the three detection layers, and finally the detection results containing the pest category, confidence and bounding box are output.

[0081] A computer readable storage medium, wherein the storage medium stores a computer program, when the computer program is executed by a processor, a lightweight pest image detection method based on dynamic adaptive scanning and attention mechanism combined optimization can be realized.

[0082] A computer device, characterized by comprising a memory, a processor and a computer program stored on the memory and executable on the processor, when the processor executes, a lightweight pest image detection method based on dynamic adaptive scanning and attention mechanism combined optimization can be realized.

[0083] Advantages

[0084] Compared with the prior art, the lightweight pest image detection method based on dynamic adaptive scanning and attention mechanism combined optimization of the application extracts target features through a dynamic adaptive scanning module, captures long-distance dependence in different directions while maintaining computational efficiency by using the characteristics of the state space model; at the same time, the detection network is optimized based on the attention mechanism, which significantly improves the detection accuracy and robustness of the pest target, and realizes the real-time performance of pest detection by using lightweight design.

[0085] The application enhances the direction sensitivity of image features and the efficient capture of long-distance dependence by designing a dynamic adaptive scanning module, and efficiently extracts pest features of different scales by combining the effects of the dynamic adaptive scanning module and the attention mechanism of the hollow space extrusion excitation, thereby enhancing the detection ability of mutually occluded pests and small target pests, effectively solving the problems of high difficulty and low precision in agricultural pest detection, and achieving good detection effect. BRIEF DESCRIPTION OF DRAWINGS

[0086] Figure 1 The method sequence diagram of the application;

[0087] Figure 2 The lightweight pest image detection network structure involved in the application;

[0088] Figure 3 The dynamic adaptive scanning block structure involved in the application;

[0089] Figure 4 The dynamic adaptive scanning module structure in the application;

[0090] Figure 5 A schematic diagram of the operation principle of the dynamic adaptive scanning module in the application;

[0091] Figure 6 A structure diagram of the cavity space extrusion attention optimization module involved in the application;

[0092] Figure 7 A practical pest detection effect diagram. DETAILED DESCRIPTION

[0093] In order to have a further understanding and recognition of the structural features and effects achieved by the application, the following detailed description is given in combination with preferred embodiments and the accompanying drawings:

[0094] As shown in Figure 1 , the light-weight pest image detection method based on dynamic adaptive scanning and attention mechanism combined optimization comprises the following steps:

[0095] First, build a multi-class crop pest dataset. Use an automatic image acquisition device to capture agricultural pest images in a real scene. The dataset built by the application contains a total of 25,378 images, including 24 different pest categories collected on 8 crops. The dataset is divided into training set, validation set and test set according to the ratio of 5:3:2 for training and evaluating the model.

[0096] Second, build a light-weight pest image detection network: as shown in Figure 2 , a light-weight pest image detection network based on dynamic adaptive scanning and attention mechanism combined optimization is built.

[0097] Under the light-weight framework, the deep collaboration of dynamic adaptive scanning mechanism and attention mechanism is realized. Not only the multi-direction long-distance dependence features are effectively captured through the dynamic adaptive scanning block, but also the multi-scale context information is accurately aggregated with the help of the cavity space extrusion attention module. At the same time, the parameter scale of each module is coordinated to balance the feature extraction ability and the calculation efficiency, so as to solve the feature modeling problem of small-scale and occluded pests. The network integrates dynamic adaptive scanning feature extraction, cavity space extrusion attention optimization, multi-scale feature aggregation and classification positioning module. Through dynamic scanning, the direction sensitivity and long-distance feature capture are enhanced, the attention mechanism optimizes the multi-scale context, and the multi-module collaboration realizes the organic unity of light-weight design and high-precision detection.

[0098] (1) Set the light-weight pest image detection network to include a dynamic adaptive scanning feature extraction network, a cavity space extrusion attention optimization module, a multi-scale pest feature perception aggregation module, and a multi-class pest classification and positioning module.

[0099] (2) Set the dynamic adaptive scanning feature extraction network.

[0100] A1) Set up a dynamic adaptive scanning feature extraction network including a pest image cascade coding module, a dynamic adaptive scanning block, and a visual fusion module;

[0101] A2) Construct a pest image cascade coding module to realize initial image segmentation while balancing the performance and efficiency of the pest detection model:

[0102] A21) Input the original crop pest images in the multi-class crop pest data set, and use a convolution operation with a kernel size of 3 and a step size of 2 to initially encode the image features;

[0103] A22) Use a convolution layer with a kernel size of 3 and a step size of 2 to reduce the feature map scale and obtain the segmented pest feature map;

[0104] A3) As shown in Figure 3 , construct a dynamic adaptive scanning block to realize feature embedding and model information flow in the global domain:

[0105] A31) Design a dynamic adaptive scanning module, which inputs the segmented pest feature map and generates two information streams through a convolution layer: one stream is refined through deep convolution and Silu activation function to capture complex patterns; the other stream is directly processed through Silu activation function;

[0106] A32) Input the two information streams into the core dynamic adaptive scanning mechanism to model all feature dimension information, and then output through convolution fusion;

[0107] A33) Normalize the output features of the dynamic adaptive scanning module to reduce pattern collapse;

[0108] A34) Input the normalized features into an efficient feedforward network and process them through the following operations: Convolution maps the features to a high-dimensional space; deep convolution combines with a gating mechanism to process hidden layer features; then use a convolution to map the features back to the original dimension to obtain high-quality feature maps;

[0109] A35) The dynamic adaptive scanning module realizes the enhancement of direction sensitivity and efficient capture of long-distance dependence of image features by introducing a dynamic attention mechanism and collaborative modeling with a multi-direction state space model. The core innovation is as follows: the two-dimensional features are decomposed into one-dimensional sequences in four directions, and the long-range dependence of each direction is modeled independently, solving the problem of insufficient representation of directional structure by fixed scanning; the direction attention weight is generated by global semantics to adaptively adjust the contribution of each direction feature and strengthen the semantic information of key directions; while introducing a lightweight attention mechanism, the linear complexity characteristic of the state space model is inherited to ensure real-time performance of the model.

[0110] As shown in Figure 4 , the dynamic adaptive scanning module includes five functional sub-modules: scanning expansion module, directional state space model processing module, directional attention generation module, dynamic fusion module, and scanning merging module. The specific processing flow is as follows:

[0111] The scanning expansion module expands the input feature map into one-dimensional sequences in four directions along the main diagonal from the top left to the bottom right, the secondary diagonal from the top right to the bottom left, vertical row first, and horizontal column first. The specific scanning method is shown in Figure 5 , covering all directional structure information, denoted as .

[0112] The directional state space model processing module independently applies a state space model to each directional sequence . The state transition matrix and the input matrix are discretized based on the zero-order hold method, and the discretization formula is:

[0113] ,

[0114] ,

[0115] where is the state transition matrix corresponding to the direction , describing the transition relationship of the state over time; is the input matrix corresponding to the direction , representing the influence of the input on the state; is the time scale parameter used to control the discretization accuracy of the state transition matrix; is the identity matrix, and the state sequence is calculated recursively as:

[0116] ,

[0117] ,

[0118] wherein, and respectively represent the discretized state transition matrix and input matrix; denotes the direction of the hidden state sequence at time ; is the input sequence of the direction , is the output matrix mapping the hidden state to the output feature , all output features are sequentially combined to obtain the direction feature ;

[0119] The direction attention generation module performs global average pooling on the input feature to obtain the channel-level global feature , and the formula is:

[0120] ,

[0121] wherein, is the height of the feature map, is the width of the feature map, represents selecting the values of all batches and all channels at a specific spatial position from the input feature , and then mapping the channel number to 4 through convolution and performing Softmax normalization to generate four-direction attention weights , which represent the importance of the direction , realizing adaptive selection and fusion of direction features:

[0122] ,

[0123] wherein, represents convolution operation for dimension reduction and feature transformation, satisfying ;

[0124] The dynamic fusion module pads each direction feature to the maximum length, and then performs weighted summation according to the attention weight to obtain the fusion feature , and the formula is:

[0125] ,

[0126] wherein, represents the direction feature Padded to uniform length;

[0127] The scan merge module merges the one-dimensional sequence after fusion Restored to a two-dimensional feature map in row priority order, and output for subsequent network layers;

[0128] A4) Construct a visual fusion module to realize efficient feature down-sampling and information integration, and provide high-quality input for subsequent feature fusion and target detection:

[0129] A41) Input the two-dimensional pest feature map output by the dynamic adaptive scanning block, and reorganize the spatial dimension information to the channel dimension through reorganization, so that each spatial position feature block is expanded to part of the channel dimension;

[0130] A42) Use a 4-fold compression convolutional layer to process the reorganized feature map, compress the channel number through cross-channel weighted summation, realize cross-channel information fusion and spatial dimension down-sampling, and output the down-sampled fusion feature map.

[0131] (3) As shown in FIG. 6, a hollow space extrusion excitation attention optimization module is set.

[0132] B1) Input the feature map output by the dynamic adaptive scanning feature extraction network, and apply 4 groups of hollow convolution operations to the input feature map in parallel, as follows:

[0133] B11) Use a hollow rate of 1 Regular convolution, capture local features, and generate feature map ;

[0134] B12) Use a hollow rate of 2 Dilated convolution, expand the receptive field to , capture medium-scale context, and generate feature map ;

[0135] B13) Use a hollow rate of 4 Dilated convolution, expand the receptive field to , capture large-scale environmental information, and generate feature map ;

[0136] B14) Use a hollow rate of 8 Dilated convolution, expand the receptive field to , capture global context, and generate feature map ;

[0137] B2) Perform global average pooling on each group of feature maps , , compress the spatial dimension;

[0138] B3) Generate channel weight coefficients using nonlinear excitation mechanism:

[0139] B31) Compress the number of channels to one fourth of the original number of channels through the first full connection layer, and the activation function is ReLU;

[0140] B32) Restore the number of channels to the original number of channels through the second full connection layer, and the activation function is Sigmoid, to generate a weight vector ;

[0141] B4) Multiply the weight vector with the corresponding feature map channel by channel to recalibrate the feature map to obtain ;

[0142] B5) Concatenate the four groups of recalibrated feature maps , , , in the channel dimension to obtain a temporary feature map;

[0143] B6) Use convolution dimension reduction on the temporary feature map to compress the number of channels and eliminate redundant information, and output an enhanced feature map.

[0144] (4) Set a multi-scale pest feature perception aggregation module.

[0145] C1) Embed a dynamic adaptive scanning block in the feature fusion path to capture gradient-rich information flow and enhance the semantic association between different scale features;

[0146] C2) The input of this module is: the multi-level feature map constructed by the feature map output by the dynamic adaptive scanning feature extraction network and the enhanced feature map output by the hollow space squeezing excitation attention optimization module, denoted as , ;

[0147] C3) For the layer and the layer feature maps, the layer feature map is upsampled using the interpolation method;

[0148] C4) Design the internal processing structure of the network: use the alternating structure of convolution layers and batch normalization layers to process the feature map: in the convolution layer, use convolution kernel to extract features, and use batch normalization layer to normalize the features;

[0149] C5) Start from the bottom layer feature map, fuse with the upper layer feature map layer by layer, and after each fusion, process through convolution and normalization to enrich the feature expression;

[0150] C6) generating a final multi-scale feature map set .

[0151] (5) setting a multi-class pest classification and positioning module.

[0152] The multi-class pest classification and positioning module comprises the following steps:

[0153] D1) inputting the multi-scale feature map set output by the multi-scale pest feature perception aggregation module;

[0154] D2) constructing three detection layers: a small-size detection layer for detecting small-scale pests; a medium-size detection layer for adapting to medium-size pest detection; and a large-size detection layer for identifying large-size pests, wherein the feature map size of the small-size detection layer is , the feature map size of the medium-size detection layer is , and the feature map size of the large-size detection layer is ;

[0155] D3) performing cross-scale NMS processing on the output results of the three detection layers, and finally outputting detection results containing pest categories, confidence and bounding boxes.

[0156] Thirdly, training of the lightweight pest image detection network. The joint optimization of the dynamic adaptive scanning module, the attention optimization module, the feature aggregation module and the classification and positioning module is realized. The parameter updating of each module is coupled, and the gradient propagation of different modules needs to be balanced to avoid local optimization. At the same time, a reasonable loss function weighting mechanism (weighting of classification loss, positioning loss and auxiliary loss) needs to be designed to solve the problems of insufficient feature learning, weak loss feedback of small-scale pests and other problems caused by parameter constraints of the lightweight network, so as to ensure that the model maintains lightweight characteristics and improves detection accuracy during the convergence process. The AdamW optimization algorithm is used to update the parameters of the multi-module joint backpropagation. The comprehensiveness of feature learning is strengthened through multi-loss weighting (including feature fusion auxiliary loss), and the training set and validation set are dynamically monitored to realize the precise optimization of network parameters in 300 training rounds. Finally, the optimal model parameters are obtained, which take into account lightweight deployment and high-precision detection, and are not simply single-module independent training or conventional loss function optimization.

[0157] (1) initializing the parameters of the lightweight pest image detection network, including the weight parameters of the dynamic adaptive scanning feature extraction network, the attention optimization module of the hollow space extrusion excitation, the multi-scale pest feature perception aggregation module and the multi-class pest classification and positioning module.

[0158] (2) setting training hyperparameters, including learning rate, batch size, training rounds, and defining classification loss function, positioning loss function and auxiliary loss for optimizing feature fusion.

[0159] (3) The training set image is input into a dynamic self-adaptive scanning feature extraction network, sequentially passes through a cascaded coding module, a dynamic self-adaptive scanning block and a visual fusion module, and outputs a feature map containing multi-direction long-distance dependent features.

[0160] (4) The feature map output by the dynamic self-adaptive scanning feature extraction network is input into a hollow space extrusion excitation attention optimization module, multi-scale context information is captured through convolution operation with different hole rates, and an enhanced feature map is output after channel attention calibration.

[0161] (5) The enhanced feature map is input into a multi-scale pest feature perception aggregation module, based on a path aggregation feature pyramid network design, different level features are fused through horizontal connection and up-sampling operation, and a multi-scale feature map set is generated.

[0162] (6) The multi-scale feature map set is input into a multi-class pest classification and positioning module, each detection layer outputs target class probability, bounding box coordinates and segmentation mask based on corresponding scale feature map, and the weighted sum of classification loss, positioning loss and segmentation loss is calculated as the total loss.

[0163] (7) The AdamW optimization algorithm is used to back-propagate the total loss, update the network parameters, realize the joint optimization of the dynamic self-adaptive scanning module, the attention module, the feature aggregation module and the classification and positioning module, and save the optimal parameters of the lightweight pest image detection network.

[0164] Step 4, obtaining the image of the pest to be detected.

[0165] Step 5, obtaining the pest image detection result: inputting the image of the pest to be detected into the trained lightweight pest image detection network to obtain the pest image detection result.

[0166] After 300 rounds of training, the present application is compared with the current mainstream target detection model. In the comparison test, nine representative algorithms are selected for comparison and analysis, which can comprehensively evaluate the performance of the model in the pest detection task. All models are trained and tested under the same data set and experimental environment to ensure fair comparison. The specific experimental results are shown in Table 1.

[0167] Table 1 Comparison of the present application and the conventional method

[0168] Methods mAP@0.5 Recall FPS Faster R-CNN 0.549 0.665 19 Cascade R-CNN 0.636 0.68 27 SSD 0.515 0.69 69 YOLOv3 0.609 0.69 78 YOLOv4 0.675 0.721 73 YOLOv5 0.679 0.68 75 YOLOv7 0.684 0.69 72 YOLOv8 0.685 0.667 78 RT-DETR-R101 0.692 0.803 70 Pest-Mamba(Ours) 0.703 0.81 179

[0169] From the experimental data, it can be seen that the Pest-Mamba model designed in the application performs outstandingly in the pest detection task. In terms of detection accuracy, the mAP@0.5 thereof is 0.703, which is higher than 0.549 of Faster R-CNN, 0.636 of Cascade R-CNN and models such as YOLO series and RT-DETR-R101, indicating that the model is more accurate in identifying pests and can effectively reduce false detection and missed detection. In terms of recall rate, the recall rate of Pest-Mamba is 0.81, which is also the highest among all models, meaning that it can more comprehensively detect pests in the image, which is crucial for early detection of pests. In addition, the frame per second (FPS) thereof is as high as 179, far exceeding other models, which can realize fast real-time detection and is suitable for efficient monitoring of large-area farmland.

[0170] In summary, the Pest-Mamba model proposed in the application has significant advantages in detection accuracy, recall rate and detection speed, can provide more reliable basis and more timely response for pest control, and the actual detection effect is as shown in Figure 7

[0171] The basic principles, main features and advantages of the application are shown and described above. It should be understood by those skilled in the art that the application is not limited by the above examples, and the above examples and descriptions in the specification are only the principles of the application. Without departing from the spirit and scope of the application, various changes and improvements can be made to the application, and these changes and improvements all fall within the scope of the claimed application. The scope of protection claimed by the application is defined by the appended claims and their equivalents.​

Claims

1. A lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism, characterized by: The following steps are involved: 11) Construct a multi-category crop pest dataset; 12) Building a lightweight pest image detection network: Build a lightweight pest image detection network based on the joint optimization of dynamic adaptive scanning and attention mechanism; 13) Training of lightweight pest image detection networks; 14) Acquisition of images of pests to be detected; 15) Obtaining pest image detection results: Input the pest image to be detected into the trained lightweight pest image detection network to obtain the pest image detection results.

2. The lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism according to claim 1 is characterized in that: The construction of a lightweight pest image detection network includes the following steps: 21) Design a lightweight pest image detection network including a dynamic adaptive scanning feature extraction network, a void space squeezing incentive attention optimization module, a multi-scale pest feature perception aggregation module, and a multi-category pest classification and positioning module; 22) Setting up a dynamic adaptive scanning feature extraction network; 23) Set up a void space squeezing incentive attention optimization module; 24) Set up a multi-scale pest feature perception aggregation module; 25) Set up a multi-category pest classification and positioning module.

3. The lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism according to claim 1 is characterized in that: The training of the lightweight pest image detection network includes the following steps: 31) Initialize the parameters of the lightweight pest image detection network, including the weight parameters of the dynamic adaptive scanning feature extraction network, the void space squeezing incentive attention optimization module, the multi-scale pest feature perception aggregation module, and the multi-category pest classification and localization module; 32) Set training hyperparameters, including learning rate, batch size, number of training rounds, and define classification loss function, localization loss function, and auxiliary loss for optimizing feature fusion; 33) Input the training set images into the dynamic adaptive scanning feature extraction network, which passes through the cascade encoding module, dynamic adaptive scanning block and visual fusion module in sequence, and outputs a feature map containing multi-directional long-distance dependent features; 34) The feature map output by the dynamic adaptive scanning feature extraction network is input into the dilated space squeeze-stimulated attention optimization module, which captures multi-scale contextual information through convolution operations with different dilation rates and outputs an enhanced feature map after channel attention calibration; 35) The enhanced feature map is input into the multi-scale pest feature perception aggregation module. Based on the path aggregation feature pyramid network design, the features of different levels are fused through lateral connection and upsampling operations to generate a multi-scale feature map set; 36) The multi-scale feature map set is input into the multi-class pest classification and localization module. Each detection layer outputs the target category probability, bounding box coordinates and segmentation mask based on the corresponding scale feature map, and calculates the weighted sum of the classification loss, localization loss and segmentation loss as the total loss; 37) The AdamW optimization algorithm is used to backpropagate the total loss, update the network parameters, realize the joint optimization of the dynamic adaptive scanning module, attention module, feature aggregation module and classification and positioning module, and save the lightweight pest image detection network under the optimal parameters.

4. The lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism according to claim 2 is characterized in that: The setting of the dynamic adaptive scanning feature extraction network comprises the following steps: 41) Set the dynamic adaptive scanning feature extraction network to include the pest image cascade encoding module, dynamic adaptive scanning block, and visual fusion module; 42) Constructing a cascade encoding module for pest images: 421) Input the original crop pest image in the multi-category crop pest dataset and perform the initial encoding of the image features using a convolution operation with a kernel size of 3 and a stride of 2; 422) The feature map after the initial encoding is again subjected to a convolution layer with a convolution kernel size of 3 and a stride of 2 to reduce the scale of the feature map and obtain a segmented pest feature map; 43) Build dynamic adaptive scanning blocks: 431) Design a dynamic adaptive scanning module whose input is the segmented pest feature map. It generates two information streams through the convolution layer: one stream is refined by deep convolution and Silu activation function to capture complex patterns; the other stream is directly processed by Silu activation function. 432) Input the two information streams into the core dynamic adaptive scanning mechanism, model all feature dimension information, and then Convolution fusion output; 433) Perform layer normalization on the output features of the dynamic adaptive scanning module; 434) The normalized features are fed into an efficient feedforward network and processed by the following operations: Convolution maps features to high-dimensional space, and deep convolution combines the gating mechanism to process hidden layer features, and then uses a Convolution maps the features back to the original dimension to obtain high-quality feature maps; 435) The dynamic adaptive scanning module includes five functional sub-modules: scanning expansion module, directional state space model processing module, directional attention generation module, dynamic fusion module, and scanning merging module. The specific processing flow is as follows: The scanning expansion module expands the input feature map into a one-dimensional sequence along the main diagonal from upper left to lower right, the secondary diagonal from upper right to lower left, vertical row priority, and horizontal column priority, covering all-directional structural information, which is recorded as ; The direction state space model processing module processes each direction sequence Independent application of the state space model, discretization of the state transfer matrix based on the zero-order hold method and the input matrix , the discretization formula is: , ; , ; in, For direction The corresponding state transfer matrix describes the state transfer relationship over time; For direction The corresponding input matrix represents the impact of the input on the state; is the time scale parameter, which is used to control the discretization accuracy of the state transfer matrix; is the identity matrix, and the state sequence is recursively calculated: , ; , ;in, and Represent the discretized state transfer matrix and input matrix respectively; Indicates direction In time The hidden state sequence of For direction The input sequence, is the output matrix, mapping the hidden state to the output feature , all output features Combine them in sequence and finally get the directional features ; Directional attention generation module for input features Perform global average pooling to obtain channel-level global features , the formula is: , ; in, is the height of the feature map, is the width of the feature map, Represents the input features Select all batches and all channels at a specific spatial location The value of Convolution maps the number of channels to 4 and normalizes them with Softmax to generate four-directional attention weights. , indicating direction The importance of , to achieve adaptive selection and fusion of directional features: , ; in, express Convolution operation, used for dimensionality reduction and feature transformation, satisfy ; The dynamic fusion module combines the features of each direction Zero padding to maximum length, by attention weight Weighted summation to obtain fusion features , the formula is: , ; in, Indicates that the direction feature Zero-padded to uniform length; The scanning and merging module merges the fused one-dimensional sequence Restore it to a two-dimensional feature map in row-priority order and output it for use in subsequent network layers; 44) Constructing a visual fusion module: 441) Input the two-dimensional pest feature map output by the dynamic adaptive scanning block, reorganize the spatial dimension information into the channel dimension through the reorganization operation, so that the feature block at each spatial position is expanded into a part of the channel dimension; 442) A 4x compressed convolutional layer is used to process the reorganized feature map. The number of channels is compressed by cross-channel weighted summation to achieve cross-channel information fusion and spatial dimension downsampling, and the downsampled fused feature map is output.

5. The lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism according to claim 2 is characterized in that: The setting of the hole space squeezing incentive attention optimization module The following steps are involved: 51) Input the feature map output by the dynamic adaptive scanning feature extraction network and apply four sets of dilated convolution operations to the input feature map in parallel, as follows: 511) Using a void ratio of 1 Conventional convolution captures local features and generates feature maps ; 512) Using a void ratio of 2 Dilated convolution expands the receptive field to , capturing medium-scale context and generating feature maps ; 513) Using a void ratio of 4 Dilated convolution expands the receptive field to , capture large-scale environmental information and generate feature maps ; 514) Using a void ratio of 8 Dilated convolution expands the receptive field to , capture global context and generate feature maps ; 52) For each set of feature maps , , perform global average pooling to compress the spatial dimension; 53) Use nonlinear incentive mechanism to generate channel weight coefficients: 531) The number of channels is compressed to one-fourth of the original number of channels through the first fully connected layer, and the activation function is ReLU; 532) The number of channels is restored to the original number through the second fully connected layer, the activation function is Sigmoid, and the weight vector is generated ; 54) The weight vector And the corresponding feature map Multiply channel by channel and recalibrate the feature map to obtain ; 55) The 4 sets of recalibrated feature maps 、 、 、 Splicing in the channel dimension to obtain a temporary feature map; 56) Use the temporary feature map Convolution reduces dimension, compresses the number of channels, eliminates redundant information, and outputs enhanced feature maps.

6. The lightweight pest image detection method based on dynamic adaptive scanning and attention mechanism joint optimization according to claim 2 is characterized in that: The setting of the multi-scale pest feature perception aggregation module comprises the following steps: 61) Embed a dynamic adaptive scanning block in the feature fusion path of the multi-scale pest feature perception aggregation module to capture gradient-rich information flow and enhance the semantic association between features at different scales; The input of the multi-scale pest feature perception aggregation module is a multi-level feature map constructed by combining the feature map output by the dynamic adaptive scanning feature extraction network and the enhanced feature map output by the void space squeezing incentive attention optimization module, denoted as , ; 62) For Layer and Layer feature map, for the The layer feature map is upsampled using interpolation; 63) The feature map is processed by alternating the convolution layer and the batch normalization layer. In the convolution layer, The convolution kernel extracts features and the batch normalization layer is used to normalize the features; 64) Starting from the bottom feature map, it is fused with the upper feature map layer by layer, and each fusion is processed by convolution and normalization; 65) Finally generate a multi-scale feature map set .

7. The lightweight pest image detection method based on joint optimization of dynamic adaptive scanning and attention mechanism according to claim 2 is characterized in that: The multi-category pest classification and positioning module includes the following steps: 71) Input the multi-scale feature map set output by the multi-scale pest feature perception aggregation module; 72) Construct three detection layers: the small-size detection layer is used to detect small-scale pests; the medium-size detection layer is adapted to detect medium-sized pests; the large-size detection layer is used to identify large-size pests. The feature map size of the small-size detection layer is , the feature map size of the medium-sized detection layer is , the feature map size of the large-size detection layer is ; 73) Perform cross-scale NMS processing on the output results of the three detection layers, and finally output the detection results including pest category, confidence level and bounding box.

8. A computer-readable storage medium, characterized in that The storage medium stores a computer program. When the computer program is executed by the processor, the lightweight pest image detection method based on the joint optimization of dynamic adaptive scanning and attention mechanism described in any one of claims 1 to 7 can be implemented.

9. A computer device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the program, the lightweight pest image detection method based on the joint optimization of dynamic adaptive scanning and attention mechanism described in any one of claims 1 to 7 can be implemented.

Citation Information

Cited By

  • Pest information acquisition system for smart agriculture

    CN121708470A

  • Crop disease and pest identification and classification method and system, storage medium and equipment

    CN121937886A

  • Crop disease and pest identification and classification method and system, storage medium and equipment

    CN121937886B

  • Steel bar detection model, method and system

    CN122073010A