A method for detecting cotton pests with small samples
By constructing a small sample detection model and using random mixed enhancement processing and multi-scale dilated convolution combined with the cross-attention mechanism, the time-consuming and labor-intensive problems of traditional cotton pest detection are solved, and high-accuracy cotton pest identification is achieved, which is suitable for intelligent detection of cotton pests.
Patent Information
- Application Number
- CN202310021496.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-07
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2043-01-07
AI Technical Summary
Traditional cotton pest detection methods are time-consuming and labor-intensive, highly subjective, and lack real-time performance. They cannot meet the needs of intelligent detection, and farmers lack experience and find it difficult to accurately identify pest species.
A small sample detection method is adopted to enhance target detection capability and improve detection accuracy by constructing a detection model, including a backbone network model and a Faster RCNN structure model, combined with random hybrid enhancement processing, multi-scale hole convolution and cross attention mechanism.
The accuracy of cotton pest detection has been improved, especially when the key parts of the pests are blocked. The model has strong generalization ability and the accuracy rate is over 95%.
Smart Images

Figure CN116012711B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to a method for detecting cotton pest targets using a small sample size. Background Art
[0002] Cotton is one of the world's most important crops, boasting high yields and low production costs. However, its growth is susceptible to pests, resulting in varying degrees of reduction in both yield and quality. Therefore, accurate pest detection and diagnosis are essential. Cotton fields are home to a wide variety of pests, and targeted treatment of the main pests of cotton requires accurate classification of the pests currently in the local environment. Traditional cotton pest detection methods are time-consuming, labor-intensive, highly subjective, and lack real-time performance, failing to meet the needs of intelligent cotton pest detection.
[0003] In recent years, fields such as deep learning, computer vision, big data, artificial intelligence, and reinforcement learning have experienced rapid development, achieving remarkable results in a wide range of scenarios, including facial recognition, machine translation, vehicle detection, industrial intelligence, smart cities, and human-machine competition. These exciting research results are also providing new insights into the development of smart agriculture, promoting the modernization and informatization of agriculture. At the same time, many scholars and experts in academia and industry are continuously exploring the integration of artificial intelligence and modern agriculture.
[0004] As society steadily progresses, agriculture continues to develop. As one of my country's major cash crops, cotton's safe production is crucial to increasing agricultural efficiency and farmers' incomes in cotton-growing areas, as well as the healthy development of the nation's textile industry and textile export trade. It holds a crucial strategic position in my country's national economy. However, cotton pests cause cotton production to decline by 20% to 30% annually. Pests infest the cotton crop throughout its growth cycle, threatening both crop quality and yield. To minimize the economic losses caused by pests, timely and accurate early warning and identification of cotton pests are essential. However, due to the lack of comprehensive pest maps and the difficulty in collecting pest specimens, farmers lack experience and are unable to accurately identify pest species. Summary of the Invention
[0005] The problem solved by the present invention is how to accurately detect pests using a small number of samples.
[0006] To solve the above problems, the present invention provides a method for detecting cotton pests in a small sample, comprising:
[0007] Step 1: Collect images containing various types of cotton pests and divide the images into a base class dataset and a new class dataset; the base class dataset includes a base class training set and a base class test set; and form a small sample dataset from part of the base class dataset and the new class dataset, the small sample dataset including a small sample training set and a small sample test set;
[0008] Step 2: Build a detection model, which includes a backbone network model and a Faster RCNN structure model. The Faster RCNN structure model includes a region proposal network, a region of interest pooling layer, a fully connected layer, a classifier, and a regressor. First, use the COCO dataset and pre-train the backbone network model.
[0009] Step 3: pre-process the image collected in step 1, and perform random mixing enhancement processing on the pre-processed image;
[0010] Step 4: Input the base class training set processed in step 3 into the pre-trained backbone network model to obtain the feature information of the image;
[0011] Step 5: Perform multi-scale dilated convolution on the feature information, obtain different receptive fields by using dilated convolution with different dilated books, and then fuse the different receptive fields with the feature information to obtain the feature map S;
[0012] Step 6: Reduce the dimension of the feature map S to obtain the feature map T, and apply the cross attention mechanism to obtain a new feature map T' containing dense context information;
[0013] Step 7: Input the new feature map T' into the Faster RCNN structure model for classification and loss function calculation;
[0014] Step 8: Input the base class test set into the detection model for testing;
[0015] Step 9: Fix the parameters of the backbone network model, classifier, and regressor, and use the small sample training set to adjust the parameters of the detection model until the detection model converges. The converged detection model is the small sample detection model.
[0016] Step 10: Input the small sample test set into the small sample detection model for testing and verification, and initialize the internal parameters of the small sample detection model;
[0017] Step 11: Test the small sample detection model.
[0018] The beneficial effects of the present invention are: by performing random mixing enhancement processing on the image, the detection ability of other parts of the target is effectively enhanced, the detection accuracy of cotton pests is improved, and after obtaining feature information through the backbone network, a multi-scale feature map is obtained by using a dilated convolution operation with different numbers of holes to expand the receptive field of the convolution operation, and then the ability to extract local features is enhanced by applying an attention mechanism, so that more feature information of cotton pests in the image can be extracted, the generalization ability of the detection model is enhanced, and the accuracy of small sample target detection is improved.
[0019] Preferably, the pre-training of the backbone network using the COCO dataset in step 2 specifically includes:
[0020] Step 201: The backbone network is ResNet50, and a softmax layer and a fully connected layer are connected after the backbone network;
[0021] Step 202: A large number of cotton pest images are intercepted from the external network to form a COCO dataset, and multiple categories of images are selected from the COCO dataset as pre-training sets for the backbone network. The images are input into the backbone network in batches for training, and the parameter weights of the backbone network are updated at the same time. After the training is completed, the model parameters of the backbone network are included, and the softmax and fully connected layers are removed.
[0022] Preferably, the step 3 specifically includes:
[0023] Step 301: Generate a saliency map from the image by using saliency detection, and find the low-frequency area reflecting the outline of the image object in the saliency map. The saliency map is expressed as:
[0024] S vp =||I μ -I whc (p)||
[0025] Where, I μ Represents the average color feature of the image, I whc (p) represents the color feature of pixel P after Gaussian smoothing, ||·|| represents the L2 norm;
[0026] Step 302: The target key part is in the low-frequency area, and some areas in the low-frequency area are randomly selected. And cut out All pixel information within, x i ,y i Indicates the horizontal and vertical coordinates corresponding to the cropping center point, represented by x i ,y i =random(S vp ) obtain;
[0027] Step 303: Randomly crop the same size area of the image in another category corresponding to the same position of the original image to fill it for enhanced processing.
[0028] Preferably, the step 5 specifically includes:
[0029] Step 501: Perform dilated convolution operations on the feature information with dilated numbers of 2, 3, 4, 5, and 6, and then perform global pooling operations to extract multi-scale features to obtain features of different scale ranges. The equivalent convolution kernel after the dilated convolution operation is: k'=k+(k-1)×(d-1), where k is the dilated convolution kernel size and d is the number of dilated holes. The feature size after the dilated convolution is: Where p is the fill value and i is the input feature size;
[0030] Step 502: The feature information of the backbone network is combined with the multi-scale features to form a feature map to supplement the information.
[0031] Preferably, the step 6 specifically includes:
[0032] Step 601: quantize the feature map S to obtain normalized feature vectors K, Q, V;
[0033] Step 602: Apply a cross-attention mechanism to the normalized feature vector to obtain a new feature map T' containing long-range context information. The vector change formula is:
[0034] CrossAttention(K,Q,V)=Aggregation(Softmax(Affinity(Q,K)),V)
[0035] Where Affinity(·) represents the dot product operation between K and the set of vectors in K at the same position as each point in Q and Q; Aggregation(·) represents the final feature fusion.
[0036] Preferably, the step 7 specifically includes:
[0037] Step 701: The new feature map T' passes through the region proposal network, and generates a region proposal box through the anchor box mechanism of the region proposal network;
[0038] Step 702: Each suggestion box is mapped to a feature map according to its size and RoI pooling is performed to pool the features to a fixed size dimension.
[0039] Step 703: The fully connected layer performs fixed-dimensional RoI features;
[0040] Step 704: Use the classifier and regressor to perform classification and calculate the loss function. The loss function calculation includes classification loss and regression loss, and the calculation formula is:
[0041]
[0042] Where, represents the classification loss, p i is the true category value of each anchor box, is the predicted category of each anchor box, Represents regression loss, α is the balance loss function, and the regression loss function uses the smoothL1 function. The calculation formula is as follows:
[0043]
[0044]
[0045] The classification branch uses a similarity measure based on triple loss, and the triple loss function is defined as follows:
[0046]
[0047] Where N is the number of triplets, Represents the feature embedding of the anchor box sample, Represents the feature embedding of positive samples, represents the feature embedding of negative samples. α represents the minimum distance between anchor box samples and negative samples. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 This is a picture of the cotton pest detection effect;
[0049] Figure 2 This is the structural diagram of the detection model;
[0050] Figure 3 Blockout diagram for cotton pests;
[0051] Figure 4 Enhanced images for cotton pest data;
[0052] Figure 5 This is the accuracy chart of small sample cotton pests;
[0053] Figure 6 Flowchart for collecting small samples of cotton pests. DETAILED DESCRIPTION
[0054] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0055] A method for detecting cotton pests in a small sample size, comprising:
[0056] Step 1: collect images containing various types of cotton pests, and divide the images into a base class data set and a new class data set; the base class data set includes a base class training set and a base class test set; and a small sample data set is formed from part of the base class data set and the new class data set, the small sample data set includes a small sample training set and a small sample test set. In this specific embodiment, the number of samples of each class in the small sample data set does not exceed 30; in this specific embodiment, the images of cotton pests are collected using the following method: Figure 6 The collection system shown in the figure includes a 200W Intel D415 high-definition camera with a pixel resolution of 1920*1080, a processor equipped with a GPU Nvidia RTX3090, an impact screen, an insect attracting lamp, and an infrared insect body treatment chamber. By turning on the insect attracting lamp, cotton pests are attracted to hit the impact screen, and the insects fall into the insect killing chamber; the insects are killed by infrared rays; the camera captures the insect body image, and the camera is connected to the processor to upload the image;
[0057] Step 2: Build a detection model. The detection model includes a backbone network model and a Faster RCNN structure model. The Faster RCNN structure model includes a region proposal network, a region of interest pooling layer, a fully connected layer, a classifier, and a regressor. First, use the COCO dataset and pre-train the backbone network model. The pre-training process specifically includes:
[0058] Step 201: The backbone network is ResNet50, and a softmax layer and a fully connected layer are connected after the backbone network;
[0059] Step 202: A large number of cotton pest images are intercepted from the Internet to form a COCO dataset, and multiple categories of images are selected from the COCO dataset as pre-training sets for the backbone network. The images are input into the backbone network in batches for training, and the parameter weights of the backbone network are updated at the same time. After the training is completed, the model parameters of the backbone network are included, and the softmax and fully connected layers are removed;
[0060] Step 3: Preprocess the image collected in step 1. The preprocessing in this specific embodiment is to crop the image to a uniform size. The cropping size is 512*512. In addition, since there are too many cotton pest images collected, there may be a situation where the key parts are blocked by other pests, such as Figure 3 As shown, this affects the training effect and generalization of the detection model in the later stage. Therefore, this specific embodiment also performs random mixing enhancement processing on the pre-processed image; specifically, it includes:
[0061] Step 301: Generate a saliency map from the image by using saliency detection, and find the low-frequency area reflecting the outline of the image object in the saliency map. The saliency map is expressed as:
[0062]
[0063] Where, I μ Represents the average color feature of the image, I whc (p) represents the color feature of pixel P after Gaussian smoothing, ||·|| represents the L2 norm;
[0064] Step 302: The target key part is in the low-frequency area, and some areas in the low-frequency area are randomly selected. And cut out All pixel information within, x i ,y i Indicates the horizontal and vertical coordinates corresponding to the cropping center point, represented by x i ,y i =random(S vp ) obtain;
[0065] Step 303: Randomly crop the same size area of the image in another category corresponding to the same position of the original image to fill it In order to perform enhancement processing, we can get Figure 4 The enhanced image shown;
[0066] Step 4: Input the base class training set processed in step 3 into the pre-trained backbone network model to obtain the feature information of the image;
[0067] Step 5: Perform multi-scale dilated convolution on the feature information, obtain different receptive fields by using dilated convolution with different dilated books, and then fuse the different receptive fields with the feature information to obtain the feature map S; specifically, the following steps are included:
[0068] Step 501: Perform dilated convolution operations on the feature information with dilated numbers of 2, 3, 4, 5, and 6, and then perform global pooling operations to extract multi-scale features to obtain features of different scale ranges. The equivalent convolution kernel after the dilated convolution operation is: k'=k+(k-1)×(d-1), where k is the dilated convolution kernel size and d is the number of dilated holes. The feature size after the dilated convolution is: Where p is the fill value and i is the input feature size;
[0069] Step 502: The feature information of the backbone network is combined with the multi-scale features to form a feature map to supplement the information;
[0070] Step 6: Reduce the dimension of the feature map S to obtain the feature map T, and apply the cross-attention mechanism to obtain a new feature map T' containing dense context information; specifically,
[0071] Step 601: quantize the feature map S to obtain normalized feature vectors K, Q, V;
[0072] Step 602: Apply a cross-attention mechanism to the normalized feature vector to obtain a new feature map T' containing long-range context information. The vector change formula is:
[0073] CrossAttention(K,Q,V)=Aggregation(Softmax(Affinity(Q,K)),V)
[0074] Where Affinity(·) represents the dot product operation between K and the set of vectors in K that are at the same position as each point in Q and Q; Aggregation(·) represents the final feature fusion;
[0075] Step 7: Input the new feature map T' into the Faster RCNN structure model for classification and loss function calculation; specifically including:
[0076] Step 701: The new feature map T' passes through the region proposal network, and generates a region proposal frame through the anchor frame mechanism of the region proposal network, such as Figure 2 As shown;
[0077] Step 702: Each suggestion box is mapped to a feature map according to its size and RoI pooling is performed to pool the features to a fixed size dimension.
[0078] Step 703: The fully connected layer performs fixed-dimensional RoI features;
[0079] Step 704: Use the classifier and regressor to perform classification and calculate the loss function. The loss function calculation includes classification loss and regression loss, and the calculation formula is:
[0080]
[0081] Where, represents the classification loss, p i is the true category value of each anchor box, is the predicted category of each anchor box, Represents regression loss, α is the balance loss function, and the regression loss function uses the smoothL1 function. The calculation formula is as follows:
[0082]
[0083]
[0084] The classification branch uses a similarity metric based on triplet loss, and the triplet loss function is defined as follows:
[0085]
[0086] Where N is the number of triplets, Represents the feature embedding of the anchor box sample, Represents the feature embedding of positive samples, Represents the feature embedding of negative samples. α represents the minimum distance between anchor box samples and negative samples;
[0087] Step 8: Input the base class test set into the detection model for testing;
[0088] Step 9: Fix the parameters of the backbone network model, classifier, and regressor, and use the small sample training set to adjust the parameters of the detection model until the detection model converges. The converged detection model is the small sample detection model.
[0089] Step 10: Input the small sample test set into the small sample detection model for testing and verification, and initialize the internal parameters of the small sample detection model;
[0090] Step 11: Test the small sample detection model. The test results are as follows: Figure 1 shown.
[0091] The present invention has the following advantages and positive effects:
[0092] First, traditional data augmentation methods simply perform set transformation or pixel transformation on the image and cannot effectively modify the key features of the image. The present invention uses saliency detection to crop and repair key parts, effectively enhancing the detection ability of features in other parts of the target. The present invention is particularly effective when the key parts of pests are occluded, improving the detection effect of cotton pests and the accuracy of the model.
[0093] Second, the present invention uses the feature information obtained from the backbone network to generate multi-scale feature maps through dilated convolution operations with different dilation numbers. This expands the receptive field of the convolution operation and enhances the ability to extract local features by applying an attention mechanism. Finally, the images are fed into a detector for detection. This allows for the extraction of more feature information from cotton pest images, enhances model generalization, and improves the performance of small sample size object detection.
[0094] Third, the present invention has achieved a higher accuracy rate for cotton pests, such as Figure 5 As shown in the figure, the base class accuracy reaches 95%, and the small sample dataset accuracy reaches 65% in the 9-way-1-shot case. It has good pest detection performance and helps to solve the problem of cotton yield reduction caused by pests during growth.
[0095] Based on the above small sample cotton pest target detection method,
[0096] Although the present disclosure is disclosed as above, the protection scope of the present disclosure is not limited thereto. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the present disclosure, and these changes and modifications will fall within the protection scope of the present invention.
Claims
1. A method for detecting small-sample cotton pest targets, characterized in that: include: Step 1: Collect images containing various types of cotton pests and divide the images into a base class dataset and a new class dataset; The base class data set includes a base class training set and a base class test set; and a part of the base class data set and the new class data set are taken to form a small sample data set, and the small sample data set includes a small sample training set and a small sample test set; Step 2: Build a detection model, which includes a backbone network model and a Faster RCNN structure model. The Faster RCNN structure model includes a region proposal network, a region of interest pooling layer, a fully connected layer, a classifier, and a regressor. The backbone network model is pre-trained using the COCO dataset. Step 3: Preprocess the image collected in step 1 and perform random mixing enhancement processing on the preprocessed image; specifically, the process includes: Step 301: Generate a saliency map from the image by using saliency detection, and find the low-frequency area reflecting the outline of the image object in the saliency map. The saliency map is expressed as: ; Where, represents the average color feature of the image, Represents pixels Color features after Gaussian smoothing, The paradigm representing L2; Step 302: The target key part is in the low-frequency area, and some areas in the low-frequency area are randomly selected. , and cut out All pixel information within Indicates the horizontal and vertical coordinates corresponding to the cropping center point, Get; Step 303: Randomly crop the same size area of the image in another category corresponding to the same position of the original image to fill it in order to perform enhancement processing; Step 4: Input the base class training set processed in step 3 into the pre-trained backbone network model to obtain the feature information of the image; Step 5: Perform multi-scale dilated convolution on the feature information to obtain different receptive fields by using dilated convolution with different dilation numbers. Then, the different receptive fields are fused with the feature information to obtain the feature map S. Step 6: Reduce the dimension of the feature map S to obtain the feature map T, and apply the cross attention mechanism to obtain a new feature map T' containing dense context information; Step 7: Input the new feature map T' into the Faster RCNN structure model for classification and loss function calculation; Step 8: Input the base class test set into the detection model for testing; Step 9: Fix the parameters of the backbone network model, classifier, and regressor, and use the small sample training set to adjust the parameters of the detection model until the detection model converges. The converged detection model is the small sample detection model. Step 10: Input the small sample test set into the small sample detection model for testing and verification, and initialize the internal parameters of the small sample detection model; Step 11: Test the small sample detection model.
2. The method for detecting cotton pests with a small sample size according to claim 1, wherein: In step 2, the COCO dataset is used to pre-train the backbone network model, specifically including: Step 201: The backbone network is ResNet50, and a softmax layer and a fully connected layer are connected after the backbone network; Step 202: A large number of cotton pest images are intercepted from the external network to form a COCO dataset, and multiple categories of images are selected from the COCO dataset as pre-training sets for the backbone network. The images are input into the backbone network in batches for training, and the parameter weights of the backbone network are updated at the same time. After the training is completed, the model parameters of the backbone network are obtained, and the softmax and fully connected layers are removed.
3. The method for detecting cotton pests with a small sample size according to claim 1, wherein: The step 5 specifically includes: Step 501: Perform dilated convolution operations on the feature information with dilated numbers of 2, 3, 4, 5, and 6, and then perform global pooling operations to extract multi-scale features to obtain features of different scale ranges. The equivalent convolution kernel after the dilated convolution operation is: ,in, is the size of the dilated convolution kernel, is the number of holes; the feature size after hole convolution is: , where is the fill value, is the input feature size; Step 502: The feature information of the backbone network is combined with the multi-scale features to form a feature map.
4. The method for detecting cotton pests with a small sample size according to claim 1, wherein: The step 6 specifically includes: Step 601: quantize the feature map S to obtain normalized feature vectors K, Q, V; Step 602: Apply a cross-attention mechanism to the normalized feature vector to obtain a new feature map T' containing long-range context information. The vector change formula is: ; Where Affinity(·) represents the dot product operation between K and Q; Aggregation(·) represents the final feature fusion.
5. The method for detecting cotton pests with a small sample size according to claim 1, wherein: The step 7 specifically includes: Step 701: The new feature map T' generates a region proposal frame through the anchor frame mechanism of the region proposal network; Step 702: Each suggestion box is mapped to a feature map according to its size and RoI pooling is performed to pool the features to a fixed size dimension. Step 703: The fully connected layer extracts RoI features of fixed dimensions; Step 704: Use the classifier and regressor to perform classification and calculate the loss function. The loss function calculation includes classification loss and regression loss, and the calculation formula is: ; Where, represents the classification loss, is the true category value of each anchor box, is the predicted category of each anchor box, represents the regression loss, Represents the balance coefficient used to balance the loss. The regression loss function uses the smooth L1 function, and the calculation formula is as follows: ; ; The classification branch uses a similarity metric based on triplet loss, and the triplet loss function is defined as follows: ; Where N is the number of triplets, Represents the feature embedding of the anchor box sample, Represents the feature embedding of positive samples, Feature embedding representing negative samples; Represents the minimum distance between the anchor box sample and the negative sample.
Citation Information
Patent Citations
Small sample change detection method based on multi-scale feature extraction
CN112668494A
KR20190119261A