Pest identification method, device and equipment, and storage medium
By combining target detection and feature extraction with attention aggregation and angular interval measurement classification, the problems of dense occlusion and morphological similarity of closely related species in the identification of pests by insect-prevention lamps are solved, thus improving the accuracy of pest identification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- WUHAN JIAHE TECH CO LTD
- Filing Date
- 2026-03-13
- Publication Date
- 2026-06-26
AI Technical Summary
When existing insect monitoring lamps are used to identify pests in the field, there are problems of missed detection and confusion caused by dense occlusion and similar morphological characteristics of closely related species. The identification accuracy is difficult to meet the needs of refined monitoring.
The target detection model is used to locate the insect body region, perform region cropping and feature extraction, and combine attention aggregation and angular interval measurement for classification to eliminate background noise interference and increase the feature distance of similar pests.
It improves the accuracy of pest identification, effectively solves the problems of dense occlusion and easy confusion between similar pests, and achieves higher identification accuracy.
Smart Images

Figure CN122290169A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image recognition technology, and in particular to a method, apparatus, device, and storage medium for identifying pests using an insect-monitoring lamp. Background Technology
[0002] In the field of intelligent agricultural monitoring, insect monitoring lamps trap pests and capture images. Combined with computer vision technology, this enables pest species identification and quantity statistics, providing crucial data support for pest and disease control. However, in actual field environments, pests trapped by insect monitoring lamps are often densely packed, accompanied by background noise interference such as light reflection and grid obstruction. Furthermore, many closely related species among pests exhibit highly similar morphologies, and the appearance of the same species varies significantly at different growth stages. This leads to existing detection algorithms easily missing detections in dense environments and prone to confusion in fine-grained classification, making it difficult to meet the requirements of refined monitoring in terms of identification accuracy. Therefore, improving the accuracy of pest identification remains a problem that needs to be solved.
[0003] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention
[0004] The main objective of this application is to provide a method, device, equipment, and storage medium for identifying pests using an insect-monitoring lamp, aiming to solve the technical problem of how to improve the accuracy of pest identification.
[0005] To achieve the above objectives, this application proposes a method for identifying pests using insect-infesting lamps, the method comprising:
[0006] Acquire target insect images collected by insect infestation lamps, perform target detection on the target insect images, and obtain a set of candidate insect bounding boxes and detection confidence scores; The target insect image is cropped based on the candidate insect bounding box set to obtain the insect image; Feature extraction is performed on the insect image to obtain an image patch feature sequence; Attention aggregation is performed on the feature sequence of the image patch to obtain the insect body embedding feature vector; The insect body embedded feature vector is subjected to angular interval-based metric classification to obtain pest category labels and classification confidence scores; The final identification result of each insect is determined based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score.
[0007] In one embodiment, the step of performing target detection on the target insect infestation image to obtain a set of candidate insect bounding boxes and detection confidence scores includes: The target insect infestation image is input into the target detection model to obtain the predicted bounding box and the confidence of the predicted bounding box. The target detection model includes an encoder-decoder ensemble prediction structure. The predicted bounding boxes are filtered based on the confidence level to obtain a set of candidate insect bounding boxes and a detection confidence level.
[0008] In one embodiment, the step of cropping the target insect infestation image based on the candidate insect bounding box set to obtain the insect image includes: Based on each candidate bounding box in the candidate insect body bounding box set, the corresponding initial insect body sub-image is cropped from the target insect infestation image; The scaling ratio is determined based on the original width and original height of the initial worm body sub-image; The initial insect sub-image is scaled proportionally according to the scaling ratio to obtain the insect image.
[0009] In one embodiment, the step of extracting features from the insect image to obtain an image patch feature sequence includes: The insect image is divided into multiple image blocks; Each of the image blocks is linearly projected into a label vector; The marker vector is input into the DINOv3 feature extractor to obtain the image patch marker sequence.
[0010] In one embodiment, the step of performing attention aggregation on the image patch feature sequence to obtain the insect body embedding feature vector includes: Define a set of learnable query vectors; Calculate the attention weight between each query vector and each image patch feature in the image patch feature sequence; The image patch features are weighted and summed according to the attention weights to obtain the aggregated features corresponding to each query vector; The aggregated features are concatenated to obtain the insect body embedding feature vector.
[0011] In one embodiment, the step of performing angular interval-based metric classification on the insect body embedded feature vector to obtain the pest category label and classification confidence includes: Obtain a pre-trained metric classification head, which includes weight vectors, scale factors, and preset angular intervals for each category; The insect body embedding feature vector and the weight vector are normalized respectively to obtain normalized features and normalized weights; The initial cosine similarity between the normalized feature and the normalized weight is calculated. The target cosine similarity is calculated based on the initial cosine similarity and the preset angle interval. Multiply the target cosine similarity by the scaling factor to obtain the classification score for each category; The pest category label and classification confidence level are obtained based on the classification score.
[0012] In one embodiment, the step of determining the final identification result of each insect based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score includes: Obtain the cosine similarity difference for each insect, wherein the cosine similarity difference is the difference between the cosine similarity corresponding to the highest classification confidence and the cosine similarity corresponding to the second highest classification confidence for each insect. Valid insects are determined based on the detection confidence level, the classification confidence level, and the cosine similarity difference. The classification confidence scores corresponding to the effective insect bodies are normalized to obtain the final identification scores of the effective insect bodies. The candidate insect bounding box, the pest category label, and the final identification score of the valid insect are associated to obtain the final identification result.
[0013] Furthermore, to achieve the above objectives, this application also proposes a device for identifying pests using an insect infestation lamp, the device comprising: The detection module is used to acquire target insect images collected by the insect infestation lamp, perform target detection on the target insect images, and obtain a set of candidate insect bounding boxes and detection confidence scores. The cropping module is used to crop the target insect image based on the candidate insect bounding box set to obtain an insect image. The extraction module is used to extract features from the insect image to obtain an image block feature sequence; The aggregation module is used to perform attention aggregation on the feature sequence of the image patch to obtain the insect body embedding feature vector; The classification module is used to perform angular interval-based metric classification on the insect's embedded feature vector to obtain pest category labels and classification confidence scores. The identification module is used to determine the final identification result of each insect based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score.
[0014] In addition, to achieve the above objectives, this application also proposes an identification device for insect pests in insect-infested lamps, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the insect pest identification method described above.
[0015] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the insect identification method for insect pests as described above.
[0016] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the insect identification method for insect pests as described above.
[0017] This application provides a method for identifying pests using insect-infesting lamps. The method involves acquiring target insect images collected by the lamps, performing target detection on the target insect images to obtain a set of candidate insect bounding boxes and detection confidence scores; cropping regions from the target insect images based on the candidate insect bounding boxes to obtain insect images; extracting features from the insect images to obtain image patch feature sequences; performing attention aggregation on the image patch feature sequences to obtain insect embedding feature vectors; performing angular interval-based metric classification on the insect embedding feature vectors to obtain pest category labels and classification confidence scores; and determining the final identification result for each insect based on the candidate insect bounding box set, the pest category labels, the detection confidence scores, and the classification confidence scores. This application first locates insect regions from complex insect infestation images through object detection, eliminating background noise interference and providing clean input for subsequent classification. Then, feature extraction and attention aggregation are performed on the cropped insect images to capture fine-grained features of the insects at the image patch level. Finally, angular interval-based metric classification is performed in hyperspherical space, increasing the feature distance between similar pests. This two-stage design effectively solves the problems of missed detection due to dense occlusion and easy confusion between similar pests, thereby improving the accuracy of pest identification. Attached Figure Description
[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A flowchart illustrating the method for identifying pests using insect-infesting lamps in this application (Example 1). Figure 2 This is a schematic diagram of the RF-DETR detection results provided in Embodiment 1 of the insect pest identification method of this application; Figure 3 This is a flowchart illustrating the second embodiment of the method for identifying pests using insect-infesting lamps in this application. Figure 4 A simplified flowchart illustrating the insect identification method using an insect-monitoring lamp provided in Embodiment 1 of this application; Figure 5 This is a schematic diagram of the module structure of the insect identification device of the insect-prevention lamp according to an embodiment of this application; Figure 6 This is a schematic diagram of the hardware operating environment of the pest identification method using insect-infesting lamps in this application embodiment.
[0021] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0022] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0023] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0024] This application acquires target insect images collected by insect infestation lamps, performs target detection on the target insect images to obtain a set of candidate insect bounding boxes and detection confidence scores; performs region cropping on the target insect images based on the candidate insect bounding box set to obtain insect images; extracts features from the insect images to obtain image patch feature sequences; performs attention aggregation on the image patch feature sequences to obtain insect embedding feature vectors; performs angular interval-based metric classification on the insect embedding feature vectors to obtain pest category labels and classification confidence scores; and determines the final identification result for each insect based on the candidate insect bounding box set, the pest category labels, the detection confidence scores, and the classification confidence scores.
[0025] In the field of intelligent agricultural monitoring, insect monitoring lamps trap pests and capture images. Combined with computer vision technology, this enables pest species identification and quantity statistics, providing crucial data support for pest and disease control. However, in actual field environments, pests trapped by insect monitoring lamps are often densely packed, accompanied by background noise interference such as light reflection and grid obstruction. Furthermore, many closely related species among pests exhibit highly similar morphologies, and the appearance of the same species varies significantly at different growth stages. This leads to existing detection algorithms easily missing detections in dense environments and prone to confusion in fine-grained classification, making it difficult to meet the requirements of refined monitoring in terms of identification accuracy. Therefore, improving the accuracy of pest identification remains a problem that needs to be solved.
[0026] This application first locates insect regions from complex insect infestation images through object detection, eliminating background noise interference and providing clean input for subsequent classification. Then, feature extraction and attention aggregation are performed on the cropped insect images to capture fine-grained features of the insects at the image patch level. Finally, angular interval-based metric classification is performed in hyperspherical space, increasing the feature distance between similar pests. This two-stage design effectively solves the problems of missed detection due to dense occlusion and easy confusion between similar pests, thereby improving the accuracy of pest identification.
[0027] Based on this, embodiments of this application provide a method for identifying pests using insect-infesting lamps, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the insect identification method using insect-infesting lamps in this application.
[0028] In this embodiment, the method for identifying pests using the insect-spreading lamp includes steps S10 to S60: Step S10: Obtain the target insect image collected by the insect infestation lamp, perform target detection on the target insect image, and obtain the candidate insect body bounding box set and detection confidence. It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device capable of performing the above functions, such as an insect pest identification device. The following description uses an insect pest identification device as an example to illustrate this embodiment and the subsequent embodiments.
[0029] It should be noted that the first step is image acquisition and preprocessing. The original insect infestation images are acquired by the insect infestation lamp camera module. These original images undergo illumination normalization, noise suppression, and size standardization to obtain the target insect infestation image. Then, a target detection model can be used to identify the set of candidate insect bounding boxes and the detection confidence level in the target insect infestation image.
[0030] In one feasible approach, the target insect infestation image is input into a target detection model to obtain predicted bounding boxes and the confidence scores of the predicted bounding boxes. The target detection model includes an encoder-decoder ensemble prediction structure. The predicted bounding boxes are then filtered based on the confidence scores to obtain a set of candidate insect bounding boxes and detection confidence scores.
[0031] It should be noted that the target detection model can use the Roboflow Real-Time Detection Transformer (RF-DETR). The RF-DETR target detection model in this embodiment employs an ensemble prediction structure based on a Transformer encoder-decoder, which can generate a fixed number of predictions based on the input target insect infestation image. Predictions for each object query The RF-DETR algorithm achieves a one-to-one correspondence between the predicted set and the ground truth annotation set through optimal one-to-one matching, thereby obtaining the predicted bounding boxes and their confidence scores. Then, the predicted bounding boxes are filtered based on their confidence scores, removing detection results with excessively low confidence scores to obtain a set of candidate insect bounding boxes and their detection confidence scores. Furthermore, the training loss function of RF-DETR in this embodiment... satisfy:
[0032] in, For the actual target quantity, This is the optimal assignment obtained from a one-to-one optimal matching. The category prediction result of the σ(i)th prediction query output that matches the i-th true target. For classifying losses, For the true frame, For the prediction box, , These are the weighting coefficients. It is an L1 norm. This refers to a generalized intersection, union, and comparison. (For reference only.) Figure 2 , Figure 2 This is a schematic diagram of the RF-DETR detection results.
[0033] Step S20: Crop the target insect image according to the candidate insect bounding box set to obtain the insect image; It should be noted that, based on the candidate bounding boxes, the target insect image can be cropped and padded while maintaining its aspect ratio to obtain a standard-sized insect image.
[0034] In one feasible approach, the step of cropping the target insect infestation image based on the candidate insect bounding box set to obtain an insect image includes: cropping a corresponding initial insect sub-image from the target insect infestation image based on each candidate bounding box in the candidate insect bounding box set; determining a scaling ratio based on the original width and original height of the initial insect sub-image; and scaling the initial insect sub-image proportionally according to the scaling ratio to obtain the insect image.
[0035] It should be noted that the original image is cropped based on the bounding box set to obtain a single insect body sub-image; the single insect body sub-image is then scaled while maintaining its aspect ratio and filled to a preset size to obtain an aligned insect body image; the specific formula is as follows:
[0036] in, For preset size, , represents the width and height of the protozoan subgraph, and r is the scaling factor.
[0037] Step S30: Extract features from the insect image to obtain an image patch feature sequence; It should be noted that after obtaining a single insect image, it needs to be converted into a mathematical form that a computer can understand and process. In this embodiment, the insect image is input into a powerful feature extractor. This feature extractor divides the image into many small, fixed-size image patches, such as 16x16 pixel squares. Then, these patches are converted into sets of numerical vectors, forming an image patch feature sequence. This image patch feature sequence completely preserves the local details of the insect image, such as the texture of the wings and the shape of the antennae.
[0038] In one feasible approach, the step of extracting features from the insect image to obtain an image block feature sequence includes: dividing the insect image into multiple image blocks; linearly projecting each image block into a label vector; and inputting the label vector into a DINOv3 feature extractor to obtain an image block label sequence.
[0039] It should be noted that, firstly, following the standard processing flow of a Vision Transformer (ViT), the entire image is uniformly divided into multiple fixed-size, non-overlapping image patches. Each image patch is essentially a three-dimensional array of pixel values. Each image patch needs to be mapped to a high-dimensional vector space; this output vector is called the label vector. This process transforms the raw pixel information into an initial feature representation rich in semantic information that the model can process. This embodiment uses a self-supervised visual transformer model (Distillation with NO Labelsv3, DINOv3) as the core feature extractor. DINOv3 consists of multiple cascaded transformer layers. Each layer uses a self-attention mechanism to allow information interaction between different label vectors, so that the features of each image patch not only represent itself but also incorporate information from its surroundings and even the entire image context. DINOv3 ultimately outputs a deeply encoded sequence of image patch tokens containing rich contextual information. The DINOv3 feature extractor used in this embodiment is frozen during classification training, and its parameters do not participate in gradient updates.
[0040] Step S40: Perform attention aggregation on the image patch feature sequence to obtain the insect body embedding feature vector; It's important to note that after obtaining the image patch feature sequence, an attention aggregation mechanism can be used to dynamically determine which image patches are more critical. For example, when identifying a moth, the model automatically focuses on the feature image patches of the wing markings and head antennae using an attention mechanism, assigning them higher weights; while less critical parts of the background or body are assigned lower weights. By integrating all image patch features in this weighted manner, a highly condensed one-dimensional vector representing the entire pest—the insect body embedding feature vector—is ultimately formed.
[0041] Step S50: Perform angular interval-based metric classification on the insect body embedded feature vector to obtain pest category labels and classification confidence scores; It's important to note that once we have the insect's feature vector, classification can be performed. Specifically, a refined metric classification method can be employed. The core idea is to pre-define a standard orientation or position for each known pest category within a high-dimensional hyperspherical space. The feature vector of the insect to be identified is also mapped into this hyperspherical space, and then the angle between this vector and the standard orientation for each category is calculated. The category with the smallest angle is the one to which the insect is most likely to belong.
[0042] In one feasible approach, the step of performing angular interval-based metric classification on the insect body embedding feature vector to obtain pest category labels and classification confidence includes: obtaining a pre-trained metric classification head, which includes weight vectors for each category, a scaling factor, and a preset angular interval; normalizing the insect body embedding feature vector and the weight vector respectively to obtain normalized features and normalized weights; calculating the initial cosine similarity between the normalized features and the normalized weights; calculating the target cosine similarity based on the initial cosine similarity and the preset angular interval; multiplying the target cosine similarity by the scaling factor to obtain classification scores for each category; and obtaining pest category labels and classification confidence based on the classification scores.
[0043] It should be noted that this embodiment uses the Additive Angular Margin Loss (ArcFace) as the classification head. The ArcFace classification head performs L2 normalization on the embedded features and class weights, and then calculates the cosine of the angle between the normalized worm embedding feature vector and each class normalized weight vector. The closer the cosine value is to 1, the closer the directions of the two vectors are, and the higher the probability that the worm belongs to that class. These cosine values are called the initial cosine similarity. Then, for the worm's true class (known during training and the target class during inference), a preset angular margin m is added to the angle θ corresponding to its initial cosine similarity, resulting in θ+m. The cosine value of this new angle, cos(θ+m), is then calculated as the target cosine similarity for that class. For other non-true classes, the initial cosine similarity is used directly. This step is equivalent to forcing the feature direction of the correct class to a more extreme position in the hyperspherical space, thereby increasing the distance to other similar classes. Then, the calculated cosine similarities for each category are multiplied by a large scaling factor to obtain the final classification score. The scaling factor amplifies the differences between scores, making the probability distribution generated by the Softmax function sharper, which helps with model training and convergence. Finally, the classification scores for each category are input into a Softmax function, converting it into a probability distribution that sums to 1. Each value in this probability distribution represents the classification confidence of the corresponding category. The category with the highest confidence is selected as the final pest category label output. The specific formula includes:
[0044]
[0045]
[0046]
[0047] in, To embed feature vectors, For the first Class weight vector, For category indexing, For the true category index, For embedding feature vectors With the Class weight vector The angle between them For embedding feature vectors Compared to the real category Corresponding weight vector The angle between them The embedded feature vector With the Class weight vector Normalized cosine similarity, The target category angle response obtained after introducing an angle interval m to the true category. For non-real category number The class output score, For the real category The output score, For angular intervals, is the scale factor.
[0048] Fine-grained classification uses the focus loss function ,satisfy:
[0049] in, Let be the Softmax probability of the target class. To focus parameters, For category weights.
[0050] Step S60: Determine the final identification result of each insect based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score.
[0051] It should be noted that the final judgment is made by combining the target detection results with the fine classification results. For example, a recognition result is considered reliable only when both the detection confidence and classification confidence of a certain insect are high enough. After screening and verification, a final recognition result containing its specific location, specific species, and a final comprehensive score will be output for each confirmed pest in the image.
[0052] In one feasible approach, the step of determining the final identification result of each insect based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score includes: obtaining the cosine similarity difference for each insect, wherein the cosine similarity difference is the difference between the cosine similarity corresponding to the highest classification confidence score and the cosine similarity corresponding to the second highest classification confidence score for each insect; determining valid insects based on the detection confidence score, the classification confidence score, and the cosine similarity difference; normalizing the classification confidence score corresponding to the valid insect to obtain the final identification score of the valid insect; and associating the candidate insect bounding box, the pest category label, and the final identification score of the valid insect to obtain the final identification result.
[0053] It should be noted that during the classification measurement step, the cosine similarity between each classified insect and its class weight has already been calculated. These similarities are then sorted from highest to lowest, and the highest and second-highest cosine similarities are extracted. The difference between the two is then calculated, which is the cosine similarity difference.
[0054] It should be noted that, in conjunction with the first Detection confidence of candidate bounding boxes Dynamically determine the classification cosine threshold ; for satisfying , and The candidate worm body is bounded by the bounding box of the candidate worm body. With category labels Perform association, and according to the above Normalization yields the final recognition score. Output the final identification result for each insect. And count the number by category; among them, To detect the confidence threshold, This represents the difference between the highest and second-highest cosine similarity of the candidate insect. The corresponding difference threshold; The highest cosine similarity confidence value corresponding to the predicted category. The final recognition score obtained by normalization, and The larger, The larger.
[0055] This embodiment acquires target insect images collected by insect infestation lamps, performs target detection on the target insect images to obtain a set of candidate insect bounding boxes and detection confidence scores; crops the target insect images based on the candidate insect bounding boxes to obtain insect images; extracts features from the insect images to obtain image patch feature sequences; performs attention aggregation on the image patch feature sequences to obtain insect embedding feature vectors; performs angular interval-based metric classification on the insect embedding feature vectors to obtain pest category labels and classification confidence scores; and determines the final identification result for each insect based on the candidate insect bounding box set, the pest category labels, the detection confidence scores, and the classification confidence scores. This embodiment first locates insect regions from complex insect images through target detection, eliminating background noise interference and providing clean input for subsequent classification; then, it performs feature extraction and attention aggregation on the cropped insect images to capture fine-grained features of the insects at the image patch level; finally, it performs angular interval-based metric classification in hyperspherical space to increase the feature distance between similar pests. This two-stage design effectively solves the problems of missed detection due to dense occlusion and easy confusion between similar pests, thereby improving the accuracy of pest identification.
[0056] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 3 Step S40 also includes steps S401 to S404: Step S401: Define a set of learnable query vectors; It should be noted that this embodiment uses an efficient attention aggregation mechanism, such as EfficientProbing. First, a set of learnable query vectors of number Q is initialized.
[0057] Step S402: Calculate the attention weight between each query vector and each image patch feature in the image patch feature sequence; It should be noted that, next, the similarity between each query vector and the feature vectors of all image patches in the image patch label sequence is calculated. The higher the similarity of an image patch, the more relevant its information is to the visual pattern of interest to the query vector. These similarity scores are then normalized using a Softmax function to obtain the attention weight of each query vector for each image patch. This weight value is between 0 and 1, and sums to 1.
[0058] Step S403: Perform a weighted summation of the image patch features according to the attention weights to obtain the aggregated features corresponding to each query vector; It should be noted that the feature vectors of all image patches are summed in a weighted manner according to attention weights. Feature vectors of image patches with higher weights contribute more to the summation result, while those of image patches with lower weights contribute less. Relevant information is collected from all image patches and integrated into a single, information-focused feature vector, which is the aggregated feature corresponding to the query vector.
[0059] Step S404: Concatenate the aggregated features to obtain the insect body embedding feature vector.
[0060] It should be noted that Q aggregated features are ultimately obtained, each representing information obtained from observing the insect from different angles. To obtain a complete and comprehensive representation of the insect's features, these Q aggregated feature vectors are concatenated end-to-end to form a longer feature vector. This final concatenated vector is the information-rich insect embedding feature vector that can represent the entire pest. The specific calculation process of the EfficientProbing attention convergence module is as follows:
[0061]
[0062]
[0063] in, For the catch token matrix, For learnable query vector matrices, The number of patch tokens, The number of learnable query vectors, For the attention dimension, For the learnable query vector matrix With patchtoken matrix The calculated attention weight matrix, For the first The attention weight of each query to the nth patch token. For value projection matrix, For the patch token matrix Value projection matrix The value matrix obtained by linear projection To group the value matrix by the query dimension, the first... The query corresponding to the first The value subvector of each patch token The insect body embedding feature vector is obtained by concatenating the weighted aggregation results of each query.
[0064] This embodiment defines a set of learnable query vectors; calculates the attention weight between each query vector and each image patch feature in the image patch feature sequence; performs a weighted summation of the image patch features according to the attention weights to obtain the aggregated feature corresponding to each query vector; and concatenates the aggregated features to obtain the worm embedding feature vector. This embodiment, by performing attention aggregation on the image patch feature sequence based on learnable query vectors, can dynamically focus on the key discrimination regions of the worm, generating a more representative worm embedding feature vector, thereby improving the accuracy of subsequent classification.
[0065] For example, to help understand the implementation process of the insect pest identification method obtained by combining this embodiment with the above embodiment one, please refer to... Figure 4 , Figure 4 A simplified flowchart of a method for identifying insect pests using insect-infested lamps is provided. Specifically: Image acquisition and preprocessing: The insect-infested lamp camera module acquires raw images and performs illumination normalization, noise suppression, and size standardization. First-stage bounding box detection: The RF-DETR target detection model generates a set of candidate insect bounding boxes to address the issue of missed detections. Candidate region cropping and alignment: Regions are cropped based on the bounding box set, and the aspect ratio of individual insect sub-images is scaled and padded to a preset size. Second-stage fine classification: DINOv3 feature extraction uses patch tokens, EfficientProbing attention convergence generates embedded features, and the ArcFace classification head performs fine classification in hyperspherical space. Result fusion and output: The bounding box information from the first stage and the category information from the second stage are fused to output the final identification result. The number of results is counted by category, and the results are reported and stored.
[0066] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the method for identifying pests using the insect-infesting lamp in this application. Any simple modifications based on this technical concept are within the scope of protection of this application.
[0067] This application also provides a pest identification device for insect infestation lamps; please refer to [reference needed]. Figure 5 The insect identification device of the insect infestation lamp includes: Detection module 10 is used to acquire target insect images collected by insect infestation lamps, perform target detection on the target insect images, and obtain a set of candidate insect bounding boxes and detection confidence scores. The cropping module 20 is used to crop the target insect image based on the candidate insect bounding box set to obtain an insect image; Extraction module 30 is used to extract features from the insect image to obtain an image block feature sequence; Aggregation module 40 is used to perform attention aggregation on the image block feature sequence to obtain the insect body embedding feature vector; The classification module 50 is used to perform angular interval-based metric classification on the insect body embedded feature vector to obtain pest category labels and classification confidence. The identification module 60 is used to determine the final identification result of each insect based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score.
[0068] This application acquires target insect images collected by insect infestation lamps, performs target detection on the target insect images to obtain a set of candidate insect bounding boxes and detection confidence scores; crops the target insect images according to the candidate insect bounding box set to obtain insect images; extracts features from the insect images to obtain image patch feature sequences; performs attention aggregation on the image patch feature sequences to obtain insect embedding feature vectors; performs angular interval-based metric classification on the insect embedding feature vectors to obtain pest category labels and classification confidence scores; and determines the final identification result of each insect based on the candidate insect bounding box set, the pest category labels, the detection confidence scores, and the classification confidence scores. This application first locates insect regions from complex insect images through target detection, eliminating background noise interference and providing clean input for subsequent classification; then, it performs feature extraction and attention aggregation on the cropped insect images to capture fine-grained features of the insects at the image patch level; finally, it performs angular interval-based metric classification in hyperspherical space to increase the feature distance between similar pests. This two-stage design effectively solves the problems of missed detection due to dense occlusion and easy confusion between similar pests, thereby improving the accuracy of pest identification.
[0069] In one embodiment, the detection module 10 is further configured to input the target insect infestation image into a target detection model to obtain a predicted bounding box and a confidence level of the predicted bounding box, wherein the target detection model includes an encoder-decoder set prediction structure; and to filter the predicted bounding boxes according to the confidence level to obtain a set of candidate insect bounding boxes and a detection confidence level.
[0070] In one embodiment, the cropping module 20 is further configured to crop out a corresponding initial insect body sub-image from the target insect infestation image based on each candidate bounding box in the candidate insect body bounding box set; determine a scaling ratio based on the original width and original height of the initial insect body sub-image; and scale the initial insect body sub-image proportionally according to the scaling ratio to obtain an insect body image.
[0071] In one embodiment, the extraction module 30 is further configured to divide the insect image into multiple image blocks; linearly project each image block into a label vector; and input the label vector into a DINOv3 feature extractor to obtain an image block label sequence.
[0072] In one embodiment, the aggregation module 40 is further configured to define a set of learnable query vectors; Calculate the attention weight of each query vector and each image patch feature in the image patch feature sequence; perform a weighted summation of the image patch features according to the attention weight to obtain the aggregated feature corresponding to each query vector; concatenate the aggregated features to obtain the insect body embedding feature vector.
[0073] In one embodiment, the classification module 50 is further configured to acquire a pre-trained metric classification head, the metric classification head including weight vectors, scale factors, and preset angular intervals for each category; normalize the insect body embedding feature vector and the weight vector respectively to obtain normalized features and normalized weights; calculate the initial cosine similarity between the normalized features and the normalized weights; calculate the target cosine similarity based on the initial cosine similarity and the preset angular interval; multiply the target cosine similarity by the scale factor to obtain the classification score for each category; and obtain the pest category label and classification confidence based on the classification score.
[0074] In one embodiment, the identification module 60 is further configured to obtain the cosine similarity difference for each insect, wherein the cosine similarity difference is the difference between the cosine similarity corresponding to the highest classification confidence and the cosine similarity corresponding to the second highest classification confidence for each insect; determine valid insects based on the detection confidence, the classification confidence, and the cosine similarity difference; normalize the classification confidence corresponding to the valid insects to obtain the final identification score of the valid insects; and associate the candidate insect bounding box, the pest category label, and the final identification score of the valid insects to obtain the final identification result.
[0075] The insect-infested lamp pest identification device provided in this application, employing the insect-infested lamp pest identification method described in the above embodiments, can solve the technical problem of how to improve the accuracy of pest identification. Compared with the prior art, the beneficial effects of the insect-infested lamp pest identification device provided in this application are the same as those of the insect-infested lamp pest identification method provided in the above embodiments, and other technical features in the insect-infested lamp pest identification device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0076] This application provides a device for identifying insect pests in light-emitting lamps. The device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the insect pest identification method in Embodiment 1 described above.
[0077] The following is for reference. Figure 6 This document illustrates a structural schematic diagram of a device suitable for implementing the insect pest identification device in the embodiments of this application. The insect pest identification device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 6 The insect identification device shown in the insect lamp is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0078] like Figure 6 As shown, the insect pest identification device for the insect infestation lamp may include a processing unit 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in ROM (Read Only Memory) 1002 or a program loaded from storage device 1003 into RAM (Random Access Memory) 1004. The RAM 1004 also stores various programs and data required for the operation of the insect pest identification device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the insect pest identification device to communicate wirelessly or wiredly with other devices to exchange data. Although insect pest identification devices with various systems are shown in the figure, it should be understood that it is not required to implement or possess all the systems shown. More or fewer systems can be implemented alternatively.
[0079] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0080] The insect pest identification device provided in this application, employing the insect pest identification method described in the above embodiments, can solve the technical problem of how to improve the accuracy of pest identification. Compared with the prior art, the beneficial effects of the insect pest identification device provided in this application are the same as those of the insect pest identification method provided in the above embodiments, and other technical features in this insect pest identification device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0081] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0082] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0083] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, which are used to execute the insect identification method of the insect-infestation lamp in the above embodiments.
[0084] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0085] The aforementioned computer-readable storage medium may be included in the insect pest identification device; or it may exist independently and not assembled into the insect pest identification device.
[0086] The aforementioned computer-readable storage medium carries one or more programs. When these programs are executed by the insect pest identification device of the insect infestation lamp, the insect pest identification device performs the following actions: acquires a target insect image collected by the insect infestation lamp; performs target detection on the target insect image to obtain a set of candidate insect bounding boxes and a detection confidence score; performs region cropping on the target insect image based on the set of candidate insect bounding boxes to obtain an insect image; extracts features from the insect image to obtain an image patch feature sequence; performs attention aggregation on the image patch feature sequence to obtain an insect embedding feature vector; performs metric classification based on angular interval on the insect embedding feature vector to obtain an insect category label and a classification confidence score; and determines the final identification result for each insect based on the set of candidate insect bounding boxes, the insect category label, the detection confidence score, and the classification confidence score.
[0087] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0088] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0089] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0090] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described method for identifying insect pests using insect-infesting lamps, thereby solving the technical problem of how to improve the accuracy of pest identification. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the insect pest identification method provided in the above embodiments, and will not be repeated here.
[0091] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described method for identifying pests using an insect infestation lamp.
[0092] The computer program product provided in this application can solve the technical problem of how to improve the accuracy of pest identification. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the pest identification method using insect-monitoring lamps provided in the above embodiments, and will not be repeated here.
[0093] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A method for identifying pests using insect-infesting lamps, characterized in that, The method includes: Acquire target insect images collected by insect infestation lamps, perform target detection on the target insect images, and obtain a set of candidate insect bounding boxes and detection confidence scores; The target insect image is cropped based on the candidate insect bounding box set to obtain the insect image; Feature extraction is performed on the insect image to obtain an image patch feature sequence; Attention aggregation is performed on the feature sequence of the image patch to obtain the insect body embedding feature vector; The insect body embedded feature vector is subjected to angular interval-based metric classification to obtain pest category labels and classification confidence scores; The final identification result of each insect is determined based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score.
2. The method as described in claim 1, characterized in that, The step of performing target detection on the target insect infestation image to obtain a set of candidate insect bounding boxes and detection confidence scores includes: The target insect infestation image is input into the target detection model to obtain the predicted bounding box and the confidence of the predicted bounding box. The target detection model includes an encoder-decoder ensemble prediction structure. The predicted bounding boxes are filtered based on the confidence level to obtain a set of candidate insect bounding boxes and a detection confidence level.
3. The method as described in claim 1, characterized in that, The step of cropping the target insect infestation image based on the candidate insect bounding box set to obtain the insect image includes: Based on each candidate bounding box in the candidate insect body bounding box set, the corresponding initial insect body sub-image is cropped from the target insect infestation image; The scaling ratio is determined based on the original width and original height of the initial worm body sub-image; The initial insect sub-image is scaled proportionally according to the scaling ratio to obtain the insect image.
4. The method as described in claim 1, characterized in that, The step of extracting features from the insect image to obtain an image patch feature sequence includes: The insect image is divided into multiple image blocks; Each of the image blocks is linearly projected into a label vector; The marker vector is input into the DINOv3 feature extractor to obtain the image patch marker sequence.
5. The method as described in claim 1, characterized in that, The step of performing attention aggregation on the image patch feature sequence to obtain the insect body embedding feature vector includes: Define a set of learnable query vectors; Calculate the attention weight between each query vector and each image patch feature in the image patch feature sequence; The image patch features are weighted and summed according to the attention weights to obtain the aggregated features corresponding to each query vector; The aggregated features are concatenated to obtain the insect body embedding feature vector.
6. The method as described in claim 1, characterized in that, The step of performing angular interval-based metric classification on the insect body embedded feature vector to obtain the pest category label and classification confidence includes: Obtain a pre-trained metric classification head, which includes weight vectors, scale factors, and preset angular intervals for each category; The insect body embedding feature vector and the weight vector are normalized respectively to obtain normalized features and normalized weights; The initial cosine similarity between the normalized feature and the normalized weight is calculated. The target cosine similarity is calculated based on the initial cosine similarity and the preset angle interval. Multiply the target cosine similarity by the scaling factor to obtain the classification score for each category; The pest category label and classification confidence level are obtained based on the classification score.
7. The method as described in claim 1, characterized in that, The step of determining the final identification result of each insect based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score includes: Obtain the cosine similarity difference for each insect, wherein the cosine similarity difference is the difference between the cosine similarity corresponding to the highest classification confidence and the cosine similarity corresponding to the second highest classification confidence for each insect. Valid insects are determined based on the detection confidence level, the classification confidence level, and the cosine similarity difference. The classification confidence scores corresponding to the effective insect bodies are normalized to obtain the final identification scores of the effective insect bodies. The candidate insect bounding box, the pest category label, and the final identification score of the valid insect are associated to obtain the final identification result.
8. A device for identifying pests using an insect-prevention lamp, characterized in that, The device includes: The detection module is used to acquire target insect images collected by the insect infestation lamp, perform target detection on the target insect images, and obtain a set of candidate insect bounding boxes and detection confidence scores. The cropping module is used to crop the target insect image based on the candidate insect bounding box set to obtain an insect image. The extraction module is used to extract features from the insect image to obtain an image block feature sequence; The aggregation module is used to perform attention aggregation on the feature sequence of the image patch to obtain the insect body embedding feature vector; The classification module is used to perform angular interval-based metric classification on the insect's embedded feature vector to obtain pest category labels and classification confidence scores. The identification module is used to determine the final identification result of each insect based on the candidate insect bounding box set, the pest category label, the detection confidence score, and the classification confidence score.
9. A device for identifying pests using an insect-infestation lamp, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the method for identifying insect pests as described in any one of claims 1 to 7.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the method for identifying insect pests as described in any one of claims 1 to 7.