A forestry pest identification method and system
By combining the shared feature attention module and the global query attention module, the problems of insufficient sample diversity and recognition accuracy in complex scenarios in forestry pest image recognition are solved, and efficient pest type recognition is achieved.
Patent Information
- Application Number
- CN202510450568.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-11
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2045-04-11
AI Technical Summary
Existing forestry pest image recognition technologies suffer from insufficient sample diversity and inaccurate recognition in complex scenarios. In particular, they are affected by factors such as significant differences in pest species and morphology in different regions, changes in light, leaf obstruction, and rainwater pollution, resulting in low recognition accuracy.
By employing a shared feature attention module and a global query attention module, the model's learning ability is enhanced in training scenarios with insufficient sample diversity and complex scenes by capturing and fusing similar features between different sample images. Feature extraction and processing are performed using ResNet-18 neural network and techniques such as self-attention module, spatial awareness attention module, and 3D convolutional layer.
It significantly improves the accuracy of forest pest image recognition, and has good adaptability and robustness in complex and diverse forestry scenarios, thereby enhancing the model's recognition accuracy.
Smart Images

Figure CN120339881B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of forest pest image recognition technology, specifically relating to a method and system for identifying forest pests. Background Technology
[0002] In the field of forestry, pest identification has always been a hot topic of research for botanists. In the past, identification relied mainly on the observation and analysis of pest characteristics by professionals. However, due to the limited number of experts and their varying levels of experience, misidentification of forest pest types was common. With the development of image recognition and data analysis technologies in the field of artificial intelligence, more and more fields are using these technologies to identify and analyze different types of images. In the field of forestry pest identification, image recognition technology can efficiently identify the types, quantities, and distribution of forest pests. This technology can also quickly detect pests by analyzing images taken by drones or on the ground, replacing traditional manual identification methods and significantly improving the work efficiency of forest rangers.
[0003] Although image recognition technology has been applied to forestry pest identification and achieved significant results, some problems still need to be addressed. First, the diversity of forestry pest data samples is insufficient. Due to significant differences in pest species and morphology across different regions, existing identification models may struggle to recognize unfamiliar pest types. Second, in complex, multi-scene environments, factors such as variations in lighting, leaf shading, and rainwater contamination can affect the accuracy of pest identification.
[0004] Therefore, this invention proposes a forest pest identification method to solve the problem of low identification accuracy caused by the small number of pest image samples and the large number of forest pest scenarios in the existing forest pest image identification process. Summary of the Invention
[0005] To address the aforementioned problems, this invention provides a method and system for identifying forest pests.
[0006] To achieve the above objectives, the present invention employs the following technical solution:
[0007] This invention provides a method for identifying forest pests, comprising the following steps:
[0008] S1. Obtain forest pest identification query images and sample images Constructing a forestry pest sample dataset ; Identify and query images related to forestry pests Forestry pest sample dataset Each sample image in The images are input into the feature capture module for image analysis to obtain the initial features of the query image. and the initial feature map of each sample ;
[0009] S2. Construct a shared feature attention module, which uses the initial feature map of each sample. The image is input into the shared feature attention module for image analysis to obtain the attention-shared features. ;
[0010] S3. Construct a global query attention module to process the initial features of the query image. Features shared with attention The input is aggregated into the global query attention module to obtain the global query fusion attention feature. ;
[0011] S4. Construct a shared feature processing module to extract attention-shared features from dataset samples. Enhanced sample features are obtained by fusing with sample images from the dataset. ,use Operations to extract enhanced sample features Regions are categorized using a parameter generator in the shared feature processing module. weight and bias ,in This represents the total number of classes in the samples in the dataset;
[0012] S5. Construct a pest target identifier by fusing global queries with attention features. Perform a flattening operation and combine it with the weights of the dataset sample classes obtained from the shared feature processing module. and bias Combined, calculate the final probability of all categories. ;
[0013] S6. Output the forest pest identification results. After calculating the probability of all categories, output the label corresponding to the probability with the highest value to obtain the forest pest query image identification results.
[0014] Furthermore, step S1 specifically includes:
[0015] The feature capture module is a ResNet-18 neural network, which removes the fully connected layer at the output end;
[0016] Forestry pest query image The initial features are obtained by inputting them into the feature capture module. The formula is expressed as follows:
[0017] ,
[0018] in, Indicates the height of the queried image. Indicates the width of the query image. This indicates the number of channels in the queried image. Indicates the height of the initial feature. Indicates the width of the initial feature. The function represents the processing procedure of the ResNet-18 neural network; the forestry pest sample dataset is... Forestry pest sample dataset Each sample image in The input is fed into the feature capture module to obtain the initial feature map for each sample. The formula is expressed as follows:
[0019] ,
[0020] in, This represents the total number of samples in the sample dataset. Indicates the first One sample, , These represent forestry pest sample datasets. The height and width of each sample image in the dataset. yes The corresponding category label.
[0021] Furthermore, step S2 specifically includes:
[0022] The shared feature attention module includes a self-attention module and a spatial awareness attention module;
[0023] S21. Initialize the feature map for each sample. By concatenating the data along the dimension of sample size, a four-dimensional tensor is obtained. The formula is expressed as follows:
[0024] ,
[0025] in, This represents the feature concatenation and stacking operation; it involves concatenating and stacking four-dimensional tensors. The input is fed into the shared feature attention module, which converts the four-dimensional tensor into a single input. In spatial dimension and width Flattened into a two-dimensional matrix The formula is expressed as follows:
[0026] ,
[0027] in, Represents vector flattening operation; calculates query features. Key features Sum value characteristics The formula is expressed as follows:
[0028] ,
[0029] in, The learnable parameters representing the query features. Learnable parameters representing key features Learnable parameters representing value features, , This indicates the use of linear mapping operations to transform a two-dimensional matrix. passage Mapped to the dimensions required for a self-attention mechanism; the self-attention module contains There are 1 attention head, and each attention head has 1 dimension. Query features Key features Sum value characteristics Divided into Attention head features:
[0030]
[0031] in, Indicates the first A query, key, and value vector for each attention head. Using attention head features Calculate the correlation of features among all samples in the dataset to obtain the correlation features for each attention head. The formula is expressed as follows:
[0032] ,
[0033] in, This represents the Softmax activation function. This indicates the scaling factor parameter that is set. Key feature vector The transpose of the vector; the similarity score will be calculated. With the value vector of each attention head Multiply to obtain the output features of each attention head. and will The output features of each attention head are concatenated in the last dimension to obtain the final refined features. Finally, refine the features By restoring to the original dimensions, we obtain the recovered features. The formula is expressed as follows:
[0034] ,
[0035] ,
[0036] ,
[0037] in, This indicates a feature concatenation operation. This indicates a re-flattening and restoration operation, restoring features. ;
[0038] S22. Restore features The input is fed into the spatial awareness attention module, using a convolution kernel size of [size missing]. A 3D convolutional layer of varying size processes the input features to obtain feature sets. ,in For the number of channels in a single group, The number of groups is expressed by the following formula:
[0039] ,
[0040] in, This represents the activation function. This indicates a batch normalization operation. Indicates the feature 3D convolutional layers for processing; for feature groups Processing the spatiotemporal information dimension, in The statistical vector is obtained by calculating the average value along the time axis. Then through a fully connected layer and Activation function operations generate spatial attention vectors The formula is expressed as follows:
[0041] ,
[0042] ,
[0043] in, Indicates a fully connected layer. express Activation function;
[0044] S23. Transfer the spatial attention vector With recovery characteristics Multiply to obtain attention-sharing features The formula is expressed as follows:
[0045] ,
[0046] in, This indicates the Hadamard product operation.
[0047] Furthermore, step S3 specifically includes:
[0048] S31. Initial features are transformed through linear transformation. Mapping to a new space yields query features Attention-sharing features are achieved through linear transformation. Mapping to a new space yields supporting features The formula is expressed as follows:
[0049] ,
[0050] ,
[0051] in, This represents a learnable query feature mapping matrix. This represents a learnable support feature mapping matrix, which is obtained during model training through gradient descent and backpropagation. After mapping, the features are queried. The dimension is Support features The dimension is ;
[0052] S32. Query features With supporting features Using the dot product, we obtain the attention scores between features. Attention score Attention weights are obtained by normalization using the Softmax activation function. And the attention weight With supporting features The weighted summation is then concatenated with the query features to obtain the global query fusion attention feature. The formula is expressed as follows:
[0053] ,
[0054] ,
[0055] ,
[0056] in, To support features transpose, This represents the activation function. This indicates a feature splicing operation.
[0057] Furthermore, step S4 specifically includes:
[0058] Attention-shared features extracted from all samples in the dataset Forest pest sample dataset By splicing and merging, enhanced sample features are obtained. The formula is expressed as follows:
[0059] ,
[0060] Strengthen sample features Use convolution kernel size of The 3D convolutional layer process yields the enhanced sample feature map. Then, the ROI features are extracted using the ROIAlign operation to obtain the region features. Then, for regional features The dataset is flattened into a one-dimensional vector. A fully connected layer is then used to generate the weights and biases for each class based on the total number of classes in the dataset. The formulas are as follows:
[0061] ,
[0062] ,
[0063] ,
[0064] in, Indicates the kernel size as 3D convolutional layers, This indicates a feature region alignment operation. Indicate category The weight, Indicate category Bias, category , The total number of classes in the dataset. This indicates a fully connected operation. This represents the vector flattening operation.
[0065] Furthermore, step S5 specifically includes:
[0066] The global query obtained in step S3 is fused with attention features. Flatten it into a one-dimensional vector and combine it with the weights of each class of the dataset samples obtained in step S4. and bias Forestry pest query images are computed using fully connected layers and activation functions. The predicted probability score for each category is expressed by the following formula:
[0067] ,
[0068] in, This indicates that the category obtained from calculating forestry pest query images is... The predicted probability score, , The total number of categories in the sample; This represents the Sigmoid activation function; This indicates a fully connected operation. This represents the vector flattening operation.
[0069] Furthermore, step S6 specifically includes:
[0070] Forestry pest query image The combined vector of predicted probabilities for each category The label output corresponding to the highest probability value in the given values, assuming a predicted probability combination score. The maximum probability value in is This indicates that the pest identification classification of the forestry pest query image is as follows: The formula for this process is as follows:
[0071] ,
[0072] in, This indicates an operation to iterate through the maximum value index.
[0073] The present invention also provides a forest pest identification system, which executes the aforementioned forest pest identification method, including:
[0074] Data acquisition unit: used to acquire forest pest identification query images and sample images, and construct a forest pest sample dataset; input each sample image in the forest pest identification query images and forest pest sample dataset into the feature capture module for image analysis to obtain the initial features of the query image and the initial feature map of each sample;
[0075] Shared Feature Attention Module Construction Unit: Used to construct the shared feature attention module. The initial feature map of each sample is input into the shared feature attention module for image analysis to obtain the attention-shared features.
[0076] Global Query Attention Module Construction Unit: Used to construct the global query attention module. The initial features of the query image and the attention-shared features are input into the global query attention module for aggregation to obtain the global query fusion attention features.
[0077] Shared Feature Processing Module Building Unit: Used to build the shared feature processing module. Attention-shared features extracted from dataset samples are fused with dataset sample images to obtain enhanced sample features. Operations to extract enhanced sample features The region obtains the class weights and biases through the parameter generator in the shared feature processing module;
[0078] Pest Target Identifier Building Unit: Used to build a pest target identifier. It flattens the global query fusion attention features and combines them with the weights and biases of the dataset sample categories obtained from the shared feature processing module to calculate the final probability of all categories.
[0079] Forest pest identification result output unit: Used to output forest pest identification results. After calculating the probability of all categories, it outputs the label corresponding to the probability with the highest value, thus obtaining the forest pest query image identification result.
[0080] The advantages of this invention are:
[0081] This invention designs a forest pest identification method. It utilizes images of different pests in a forest pest dataset, and captures similarity features between different sample images through a shared feature attention module in the model. Furthermore, it designs a global query attention module to fuse and match the similarity features extracted from different images with the features of the query image, thereby enhancing the model's learning ability in situations with insufficient training sample diversity and complex scenarios. This effectively improves the accuracy of the model in identifying forest pest images. Attached Figure Description
[0082] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.
[0083] Figure 1 This is a flowchart of the steps of the method of the present invention;
[0084] Figure 2 This is a comparison of the pest image recognition performance of the method of the present invention with that of existing technologies. Detailed Implementation
[0085] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0086] Example 1
[0087] In this embodiment, as Figure 1 As shown, this invention provides a method for identifying forest pests, the specific steps of which include:
[0088] S1. Obtain forest pest identification query images and sample images Constructing a forestry pest sample dataset ; Identify and query images related to forestry pests Forestry pest sample dataset Each sample image in The images are input into the feature capture module for image analysis to obtain the initial features of the query image. and the initial feature map of each sample ;
[0089] Specifically, the feature capture module is a ResNet-18 neural network, which removes the fully connected layer at the output end;
[0090] Forestry pest query image The initial features are obtained by inputting them into the feature capture module. The formula is expressed as follows:
[0091] ,
[0092] in, Indicates the height of the queried image. Indicates the width of the query image. This indicates the number of channels in the queried image. Indicates the height of the initial feature. Indicates the width of the initial feature. The function represents the processing procedure of the ResNet-18 neural network; the forestry pest sample dataset is... Forestry pest sample dataset Each sample image in The input is fed into the feature capture module to obtain the initial feature map for each sample. The formula is expressed as follows:
[0093] ,
[0094] in, This represents the total number of samples in the sample dataset. Indicates the first One sample, , These represent forestry pest sample datasets. The height and width of each sample image in the dataset. yes The corresponding category label.
[0095] S2. Construct a shared feature attention module, which uses the initial feature map of each sample. The image is input into the shared feature attention module for image analysis to obtain the attention-shared features. ;
[0096] Specifically, the shared feature attention module includes a self-attention module and a spatial awareness attention module;
[0097] S21. Initialize the feature map for each sample. By concatenating the data along the dimension of sample size, a four-dimensional tensor is obtained. The formula is expressed as follows:
[0098] ,
[0099] in, This represents the feature concatenation and stacking operation; it involves concatenating and stacking four-dimensional tensors. The input is fed into the shared feature attention module, which converts the four-dimensional tensor into a single input. In spatial dimension and width Flattened into a two-dimensional matrix The formula is expressed as follows:
[0100] ,
[0101] in, Represents vector flattening operation; calculates query features. Key features Sum value characteristics The formula is expressed as follows:
[0102] ,
[0103] in, The learnable parameters representing the query features. Learnable parameters representing key features Learnable parameters representing value features, , This indicates the use of linear mapping operations to transform a two-dimensional matrix. passage Mapped to the dimensions required for a self-attention mechanism; the self-attention module contains There are 1 attention head, and each attention head has 1 dimension. Query features Key features Sum value characteristics Divided into Attention head features:
[0104]
[0105] in, Indicates the first A query, key, and value vector for each attention head. Using attention head features Calculate the correlation of features among all samples in the dataset to obtain the correlation features for each attention head. The formula is expressed as follows:
[0106] ,
[0107] in, This represents the Softmax activation function. This indicates the scaling factor parameter that is set. Key feature vector The transpose of the vector; the similarity score will be calculated. With the value vector of each attention head Multiply to obtain the output features of each attention head. and will The output features of each attention head are concatenated in the last dimension to obtain the final refined features. Finally, refine the features By restoring to the original dimensions, we obtain the recovered features. The formula is expressed as follows:
[0108] ,
[0109] ,
[0110] ,
[0111] in, This indicates a feature concatenation operation. This indicates a re-flattening and restoration operation, restoring features. ;
[0112] S22. Restore features The input is fed into the spatial awareness attention module, using a convolution kernel size of [size missing]. A 3D convolutional layer of varying size processes the input features to obtain feature sets. ,in For the number of channels in a single group, The number of groups is expressed by the following formula:
[0113] ,
[0114] in, This represents the activation function. This indicates a batch normalization operation. Indicates the feature 3D convolutional layers for processing; for feature groups Processing the spatiotemporal information dimension, in The statistical vector is obtained by calculating the average value along the time axis. Then through a fully connected layer and Activation function operations generate spatial attention vectors The formula is expressed as follows:
[0115] ,
[0116] ,
[0117] in, Indicates a fully connected layer. express Activation function;
[0118] S23. Transfer the spatial attention vector With recovery characteristics Multiply to obtain attention-sharing features The formula is expressed as follows:
[0119] ,
[0120] in, This indicates the Hadamard product operation.
[0121] S3. Construct a global query attention module to process the initial features of the query image. Features shared with attention The input is aggregated into the global query attention module to obtain the global query fusion attention feature. ;
[0122] Specifically, S31. The initial features are transformed through linear transformation. Mapping to a new space yields query features Attention-sharing features are achieved through linear transformation. Mapping to a new space yields supporting features The formula is expressed as follows:
[0123] ,
[0124] ,
[0125] in, This represents a learnable query feature mapping matrix. This represents a learnable support feature mapping matrix, which is obtained during model training through gradient descent and backpropagation. After mapping, the features are queried. The dimension is Support features The dimension is ;
[0126] S32. Query features With supporting features Using the dot product, we obtain the attention scores between features. Attention score Attention weights are obtained by normalization using the Softmax activation function. And the attention weight With supporting features The weighted summation is then concatenated with the query features to obtain the global query fusion attention feature. The formula is expressed as follows:
[0127] ,
[0128] ,
[0129] ,
[0130] in, To support features transpose, This represents the activation function. This indicates a feature splicing operation.
[0131] S4. Construct a shared feature processing module to extract attention-shared features from dataset samples. Enhanced sample features are obtained by fusing with sample images from the dataset. ,use Operations to extract enhanced sample features Regions are categorized using a parameter generator in the shared feature processing module. weight and bias ,in This represents the total number of classes in the samples in the dataset;
[0132] Specifically, the attention-shared features extracted from all samples in the dataset Forest pest sample dataset By splicing and merging, enhanced sample features are obtained. The formula is expressed as follows:
[0133] ,
[0134] Strengthen sample features Use convolution kernel size of The 3D convolutional layer process yields the enhanced sample feature map. Then, the ROI features are extracted using the ROIAlign operation to obtain the region features. Then, for regional features The dataset is flattened into a one-dimensional vector. A fully connected layer is then used to generate the weights and biases for each class based on the total number of classes in the dataset. The formulas are as follows:
[0135] ,
[0136] ,
[0137] ,
[0138] in, Indicates the kernel size as 3D convolutional layers, This indicates a feature region alignment operation. Indicate category The weight, Indicate category Bias, category , The total number of classes in the dataset. This indicates a fully connected operation. This represents the vector flattening operation.
[0139] S5. Construct a pest target identifier by fusing global queries with attention features. Perform a flattening operation and combine it with the weights of the dataset sample classes obtained from the shared feature processing module. and bias Combined, calculate the final probability of all categories. ;
[0140] Specifically, the global query obtained in step S3 is fused with attention features. Flatten it into a one-dimensional vector and combine it with the weights of each class of the dataset samples obtained in step S4. and bias Forestry pest query images are computed using fully connected layers and activation functions. The predicted probability score for each category is expressed by the following formula:
[0141] ,
[0142] in, This indicates that the category obtained from calculating forestry pest query images is... The predicted probability score, , The total number of categories in the sample; This represents the Sigmoid activation function; This indicates a fully connected operation. This represents the vector flattening operation.
[0143] S6. Output the forest pest identification results. After calculating the probability of all categories, output the label corresponding to the probability with the highest value to obtain the forest pest query image identification results.
[0144] Specifically, the forestry pest query image The combined vector of predicted probabilities for each category The label output corresponding to the highest probability value in the given values, assuming a predicted probability combination score. The maximum probability value in is This indicates that the pest identification classification of the forestry pest query image is as follows: The formula for this process is as follows:
[0145] ,
[0146] in, This indicates an operation to iterate through the maximum value index.
[0147] Example 2
[0148] This invention proposes a forestry pest identification method, which is compared with existing image recognition technologies used in forestry pest identification. Under unified experimental conditions, the comparative results are obtained to demonstrate the effectiveness of the proposed method. Currently, several models applied to forestry pest image recognition are selected for comparison in the experiment, such as: 1. DeepFeature: This model extracts image features using traditional machine learning methods and combines them with classification algorithms to classify and identify forestry pest images; 2. FR-ResNet: This model is based on a feature residual network and enhances its classification performance by introducing feature capture methods; 3. SaliencyEnsemble: This model combines GoogleNet and DenseNet neural networks, enhancing its classification performance based on multi-dimensional feature fusion; 4. YOLOv7: YOLOv7 enhances its ability to extract image features by introducing an extended ELAN module, improving its gradient calculation data flow and feature fusion capabilities; 5. YOLOv8: This network uses an improved CSPNet architecture and incorporates more lightweight network modules, making the model's image feature extraction more efficient.
[0149] In the comparative experiment of the proposed forestry pest identification method, four evaluation metrics were used to illustrate the effectiveness of the method: accuracy, precision, recall, and F1 score. Accuracy represents the proportion of correctly predicted samples out of the total number of samples. Precision represents the proportion of correctly predicted samples of a certain class out of all predicted samples of that class. Recall represents the proportion of correctly identified forestry pest images out of all actual images of that class. The F1 score represents the trade-off between precision and recall and is an indicator of the overall performance of the model.
[0150] The forestry pest identification method proposed in this invention was experimentally tested on the IP102 dataset, a large-scale dataset for identifying forestry and agricultural pests. This dataset contains images of pests in various complex scenarios and covers different life stages of the pests, such as eggs, larvae, pupae, and adults. The dataset contains images of 102 pest categories, totaling 75,222 images. The number of images for each category is unbalanced, exhibiting a long-tailed distribution. In the experiment, the images for each category in the dataset were divided into training, validation, and test sets in an 8:1:1 ratio.
[0151] The proposed small-sample, multi-scenario forest pest identification method based on adaptive features was validated on the IP102 dataset. The experimental results are shown in Table 1.
[0152] Table 1. Comparison of experimental results between the method of the present invention and the prior art.
[0153]
[0154] This method outperforms other image recognition models for forestry pests in comparison results. Specifically, in the pest recognition task on the IP102 dataset, it achieves the best performance in all four metrics: accuracy, precision, recall, and F1-score. The accuracy reaches 83.25%, significantly outperforming other image recognition models. The proposed method achieves a precision of 75.35%, a recall of 74.97%, and an overall F1-score of 75.16%, all higher than the current mainstream model YOLOv8. Specifically, precision and F1-score are improved by 4.53% and 3.83% respectively compared to YOLOv8. Figure 2 The experiment used images of the leafminer moth to detect pests. Comparing the actual detection results of the proposed method with existing technologies, the accuracy of the proposed method is significantly better than other existing comparative models, reaching 85%. Experimental results show that the small-sample, multi-scene forest pest identification method based on adaptive features proposed in this invention can significantly improve the accuracy of forest pest image identification and has good adaptability and robustness in complex and diverse forestry scenarios.
[0155] Example 3
[0156] This embodiment provides a forest pest identification system, which implements a forest pest identification method as described in Embodiment 1, including:
[0157] Data acquisition unit: used to acquire forest pest identification query images and sample images, and construct a forest pest sample dataset; input each sample image in the forest pest identification query images and forest pest sample dataset into the feature capture module for image analysis to obtain the initial features of the query image and the initial feature map of each sample;
[0158] Shared Feature Attention Module Construction Unit: Used to construct the shared feature attention module. The initial feature map of each sample is input into the shared feature attention module for image analysis to obtain the attention-shared features.
[0159] Global Query Attention Module Construction Unit: Used to construct the global query attention module. The initial features of the query image and the attention-shared features are input into the global query attention module for aggregation to obtain the global query fusion attention features.
[0160] Shared Feature Processing Module Building Unit: Used to build the shared feature processing module. Attention-shared features extracted from dataset samples are fused with dataset sample images to obtain enhanced sample features. Operations to extract enhanced sample features The region obtains the class weights and biases through the parameter generator in the shared feature processing module;
[0161] Pest Target Identifier Building Unit: Used to build a pest target identifier. It flattens the global query fusion attention features and combines them with the weights and biases of the dataset sample categories obtained from the shared feature processing module to calculate the final probability of all categories.
[0162] Forest pest identification result output unit: Used to output forest pest identification results. After calculating the probability of all categories, it outputs the label corresponding to the probability with the highest value, thus obtaining the forest pest query image identification result.
[0163] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for identifying forest pests, characterized in that, Includes the following steps: S1. Obtain forest pest identification query images and sample images Constructing a forestry pest sample dataset ; Forestry pest identification query image Forestry pest sample dataset Each sample image in The images are input into the feature capture module for image analysis to obtain the initial features of the query image. and the initial feature map of each sample ; S2. Construct a shared feature attention module, which combines the initial feature maps of each sample. The image is input into the shared feature attention module for image analysis to obtain the attention-shared features. ; S3. Construct a global query attention module to process the initial features of the query image. Features shared with attention The input is aggregated into the global query attention module to obtain the global query fusion attention feature. ; S4. Construct a shared feature processing module to extract attention-shared features from dataset samples. Enhanced sample features are obtained by fusing with sample images from the dataset. ,use Operations to extract enhanced sample features Regions are categorized using a parameter generator in the shared feature processing module. weight and bias ,in This represents the total number of classes in the samples in the dataset; S5. Construct a pest target identifier by fusing global queries with attention features. Perform a flattening operation and combine it with the weights of the dataset sample classes obtained from the shared feature processing module. and bias Combined, calculate the final probability of all categories. ; S6. Output the forest pest identification results. After calculating the probability of all categories, output the label corresponding to the probability with the highest value to obtain the forest pest query image identification results.
2. The method for identifying forest pests according to claim 1, characterized in that, Step S1 specifically includes: The feature capture module is a ResNet-18 neural network, which removes the fully connected layer at the output end; Forestry pest query image The initial features are obtained by inputting them into the feature capture module. The formula is expressed as follows: , in, Indicates the height of the queried image. Indicates the width of the query image. This indicates the number of channels in the queried image. Indicates the height of the initial feature. Indicates the width of the initial feature. The function represents the processing procedure of the ResNet-18 neural network; the forestry pest sample dataset is... Forestry pest sample dataset Each sample image in The input is fed into the feature capture module to obtain the initial feature map for each sample. The formula is expressed as follows: , in, This represents the total number of samples in the sample dataset. Indicates the first One sample, , These represent forestry pest sample datasets. The height and width of each sample image in the dataset. yes The corresponding category label.
3. The method for identifying forest pests according to claim 2, characterized in that, Step S2 specifically includes: The shared feature attention module includes a self-attention module and a spatial awareness attention module; S21. Initialize the feature map for each sample. By concatenating the data along the dimension of sample size, a four-dimensional tensor is obtained. The formula is expressed as follows: , in, This represents the feature concatenation and stacking operation; it involves concatenating and stacking four-dimensional tensors. The input is fed into the shared feature attention module, which converts the four-dimensional tensor into a single input. In spatial dimension and width Flattened into a two-dimensional matrix The formula is expressed as follows: , in, Represents vector flattening operation; calculates query features. Key features Sum value characteristics The formula is expressed as follows: , in, The learnable parameters representing the query features. Learnable parameters representing key features Learnable parameters representing value features, , This indicates the use of linear mapping operations to transform a two-dimensional matrix. passage Mapped to the dimensions required by the self-attention mechanism; the self-attention module contains There are 1 attention head, and each attention head has 1 dimension. Query features Key features Sum value characteristics Divided into Attention head features: in, Indicates the first A query, key, and value vector for each attention head. Using attention head features Calculate the correlation of features among all samples in the dataset to obtain the correlation features for each attention head. The formula is expressed as follows: , in, This represents the Softmax activation function. This indicates the scaling factor parameter that is set. Key feature vector The transpose of the vector; the similarity score will be calculated. With the value vector of each attention head Multiply to obtain the output features of each attention head. and will The output features of each attention head are concatenated in the last dimension to obtain the final refined features. Finally, refine the features By restoring to the original dimensions, we obtain the recovered features. The formula is expressed as follows: , , , in, This indicates a feature concatenation operation. This indicates a re-flattening and restoration operation, restoring features. ; S22. Restore features The input is fed into the spatial awareness attention module, using a convolution kernel size of [size missing]. A 3D convolutional layer of varying size processes the input features to obtain feature sets. ,in For the number of channels in a single group, The number of groups is expressed by the following formula: , in, This represents the activation function. This indicates a batch normalization operation. Indicates the feature 3D convolutional layers for processing; for feature groups Processing the spatiotemporal information dimension, in The statistical vector is obtained by calculating the average value along the time axis. Then through a fully connected layer and Activation function operations generate spatial attention vectors The formula is expressed as follows: , , in, Indicates a fully connected layer. express Activation function; S23. Transfer the spatial attention vector With recovery characteristics Multiply to obtain attention-sharing features The formula is expressed as follows: , in, This indicates the Hadamard product operation.
4. The method for identifying forest pests according to claim 3, characterized in that, Step S3 specifically includes: S31. Initial features are transformed through linear transformation. Mapping to a new space yields query features Attention-sharing features are achieved through linear transformation. Mapping to a new space yields supporting features The formula is expressed as follows: , , in, This represents a learnable query feature mapping matrix. This represents a learnable support feature mapping matrix, which is obtained during model training through gradient descent and backpropagation. After mapping, the features are queried. The dimension is Support features The dimension is ; S32. Query features With supporting features Using the dot product, we obtain the attention scores between features. Attention score Attention weights are obtained by normalization using the Softmax activation function. And the attention weight With supporting features The weighted summation is then concatenated with the query features to obtain the global query fusion attention feature. The formula is expressed as follows: , , , in, To support features transpose, This represents the activation function. This indicates a feature splicing operation.
5. The method for identifying forest pests according to claim 4, characterized in that, Step S4 specifically includes: Attention-shared features extracted from all samples in the dataset Forest pest sample dataset By splicing and merging, enhanced sample features are obtained. The formula is expressed as follows: , Strengthen sample features Use convolution kernel size of The 3D convolutional layer process yields the enhanced sample feature map. Then, the ROI features are extracted using the ROIAlign operation to obtain the region features. Then, for regional features The dataset is flattened into a one-dimensional vector. A fully connected layer is then used to generate the weights and biases for each class based on the total number of classes in the dataset. The formulas are as follows: , , , in, Indicates the kernel size as 3D convolutional layers, This indicates a feature region alignment operation. Indicates category The weight, Indicates category Bias, category , The total number of classes in the samples in the dataset. Indicates a fully connected operation. This indicates the vector flattening operation.
6. The method for identifying forest pests according to claim 5, characterized in that, Step S5 specifically includes: The global query obtained in step S3 is fused with attention features. Flatten it into a one-dimensional vector and combine it with the weights of each class of the dataset samples obtained in step S4. and bias Forestry pest query images are computed using fully connected layers and activation functions. The predicted probability score for each category is expressed by the following formula: , in, This indicates that the category obtained from calculating forestry pest query images is... The predicted probability score, , The total number of categories in the sample; This represents the Sigmoid activation function; Indicates a fully connected operation. This indicates the vector flattening operation.
7. The method for identifying forest pests according to claim 6, characterized in that, Step S6 specifically includes: Forestry pest query image The combined vector of predicted probabilities for each category The label output corresponding to the highest probability value in the given values, assuming a predicted probability combination score. The maximum probability value in is This indicates that the pest identification classification of the forestry pest query image is as follows: The formula for this process is as follows: , in, This indicates an operation to iterate through the maximum value index.
8. A forest pest identification system, implementing the forest pest identification method as described in claim 1, characterized in that, include: Data acquisition unit: used to acquire forest pest identification query images and sample images, and to construct a forest pest sample dataset; The forest pest identification query image and each sample image in the forest pest sample dataset are input into the feature capture module for image analysis to obtain the initial features of the query image and the initial feature map of each sample. Shared Feature Attention Module Construction Unit: Used to construct the shared feature attention module. The initial feature map of each sample is input into the shared feature attention module for image analysis to obtain the attention-shared features. Global Query Attention Module Construction Unit: Used to construct the global query attention module. The initial features of the query image and the attention-shared features are input into the global query attention module for aggregation to obtain the global query fusion attention features. Shared Feature Processing Module Building Unit: Used to build the shared feature processing module. Attention-shared features extracted from dataset samples are fused with dataset sample images to obtain enhanced sample features. Operations to extract enhanced sample features The region obtains the class weights and biases through the parameter generator in the shared feature processing module; Pest Target Identifier Building Unit: Used to build a pest target identifier. It flattens the global query fusion attention features and combines them with the weights and biases of the dataset sample categories obtained from the shared feature processing module to calculate the final probability of all categories. Forest pest identification result output unit: Used to output forest pest identification results. After calculating the probability of all categories, it outputs the label corresponding to the probability with the highest value, thus obtaining the forest pest query image identification result.
Citation Information
Patent Citations
Insect pest fine granularity identification method based on OfficienNetV2S
CN117876773A
Disease and pest identification method based on improved residual network of multi-head self-attention mechanism
CN119540718A