Method and device for detecting pests and diseases
By constructing a multi-level fusion feature map and density map prediction mechanism, high-probability candidate regions are screened out and accurately located, solving the problems of time-consuming, labor-intensive, and low-accuracy traditional pest and disease detection, and realizing efficient and accurate monitoring of small target pests in agricultural scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INST OF AUTOMATION CHINESE ACAD OF SCI
- Filing Date
- 2026-06-24
- Publication Date
- 2026-07-21
AI Technical Summary
Traditional pest and disease detection methods are time-consuming, labor-intensive, and have high labor costs. Their accuracy is also affected by subjective factors, making it difficult to meet the real-time monitoring needs of large-scale agricultural production. Complex background noise also affects detection efficiency and accuracy.
By constructing a multi-level fusion feature map, performing density map prediction and connected component analysis, high-probability candidate regions are selected, and reference detection points are set in the candidate region feature map. Combined with the pest and disease detection model, position offset prediction is performed to achieve accurate positioning.
It significantly improves the efficiency and accuracy of pest and disease detection, and is particularly suitable for real-time monitoring of small-target, high-density pests in agricultural scenarios, reducing computational redundancy and avoiding complex anchor frame designs.
Smart Images

Figure CN122435581A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a method and apparatus for detecting pests and diseases. Background Technology
[0002] With the continuous advancement of agricultural modernization, pests and diseases pose an increasingly serious threat to crop yield and quality, making timely and effective pest monitoring a crucial aspect of agricultural production management. Traditional pest and disease monitoring methods mainly rely on manual field inspections or the deployment of traditional sensors for data collection. These methods are not only time-consuming and labor-intensive, with high labor costs, but their detection accuracy is also greatly affected by subjective factors, making it difficult to meet the real-time monitoring needs of large-scale agricultural production. In recent years, with the rapid development of computer vision and deep learning technologies, image-based automated pest and disease detection has become a research hotspot, providing a new technological path to overcome the limitations of traditional methods.
[0003] However, in actual agricultural scenarios, when detecting pests and diseases, the pests are usually very small and occupy a very small percentage of the pixels in the image. In addition, agricultural images have complex backgrounds, and interfering factors such as branches, leaves, soil, and changes in light occupy most of the image area. As a result, the pest features are easily submerged in complex background noise, which affects the efficiency and accuracy of pest and disease detection. Summary of the Invention
[0004] This application provides a method and apparatus for detecting pests and diseases, which solves the problem that complex background noise in the prior art can affect the efficiency and accuracy of pest and disease detection.
[0005] This application provides a method for detecting pests and diseases, including the following steps: A multi-level fusion feature map corresponding to the image to be detected is determined, wherein the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected; Density map prediction is performed on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map; At least one reference detection point is marked in the candidate region feature map; The feature map of the candidate region marked with reference detection points is input into the pest and disease detection model to obtain the position offset of each reference detection point output by the pest and disease detection model. The location information of the pest is determined based on the detection point coordinates of the reference detection point and the position offset.
[0006] According to the pest and disease detection method provided in this application, the step of performing density map prediction on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map includes: Density map prediction is performed on the multi-level fused feature map to obtain a density map, wherein the pixel value of each pixel in the density map is used to characterize the probability that the corresponding region contains pests; Traverse each pixel in the density map, and if the pixel value of the pixel is greater than or equal to the pixel threshold, determine the pixel as a candidate pixel. The candidate region feature map is determined based on the candidate pixels.
[0007] According to the pest and disease detection method provided in this application, the step of determining the candidate region feature map based on the candidate pixels includes: Perform connected component analysis on the candidate pixels to determine at least one connected component; Based on the connected components, at least one circumscribed rectangular region is determined; The region feature map corresponding to the circumscribed rectangular region is determined as the candidate region feature map.
[0008] According to the pest and disease detection method provided in this application, determining at least one circumscribed rectangular region based on the connected component includes: If at least two of the connected components satisfy a preset merging condition, the at least two connected components are merged into a bounding rectangular region, wherein the preset merging condition includes at least one of the following: At least two of the connected domains have overlapping regions; The distance between at least two of the connected components is less than a preset distance threshold.
[0009] According to the pest and disease detection method provided in this application, the step of determining the multi-level fusion feature map corresponding to the image to be detected includes: The image to be detected is subjected to multi-scale feature sampling processing to obtain multi-level feature maps with different sampling multiples; The multi-level feature maps with different sampling multiples are subjected to feature fusion processing to obtain the multi-level fused feature map.
[0010] According to the pest and disease detection method provided in this application, the method further includes: The labeled candidate region feature map is input into the pest detection model to obtain the pest type information corresponding to each reference detection point output by the pest detection model.
[0011] This application provides a pest and disease detection device, including the following modules: The first determining module is used to determine a multi-level fusion feature map corresponding to the image to be detected, wherein the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected; The second determining module is used to perform density map prediction on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map; The annotation module is used to annotate at least one reference detection point in the feature map of the candidate region; The processing module is used to input the feature map of the candidate region marked with reference detection points into the pest and disease detection model to obtain the position offset of the pest and disease detection model corresponding to each reference detection point. The third determining module is used to determine the location information of the pest based on the detection point coordinates of the reference detection point and the position offset.
[0012] According to the pest and disease detection device provided in this application, the second determining module is specifically used for: Density map prediction is performed on the multi-level fused feature map to obtain a density map, wherein the pixel value of each pixel in the density map is used to characterize the probability that the corresponding region contains pests; Traverse each pixel in the density map, and if the pixel value of the pixel is greater than or equal to the pixel threshold, determine the pixel as a candidate pixel. The candidate region feature map is determined based on the candidate pixels.
[0013] According to the pest and disease detection device provided in this application, the second determining module is specifically used for: Perform connected component analysis on the candidate pixels to determine at least one connected component; Based on the connected components, at least one circumscribed rectangular region is determined; The region feature map corresponding to the circumscribed rectangular region is determined as the candidate region feature map.
[0014] According to the pest and disease detection device provided in this application, the second determining module is specifically used for: If at least two of the connected components satisfy a preset merging condition, the at least two connected components are merged into a bounding rectangular region, wherein the preset merging condition includes at least one of the following: At least two of the connected domains have overlapping regions; The distance between at least two of the connected components is less than a preset distance threshold.
[0015] According to the pest and disease detection device provided in this application, the first determining module is specifically used for: The image to be detected is subjected to multi-scale feature sampling processing to obtain multi-level feature maps with different sampling multiples; The multi-level feature maps with different sampling multiples are subjected to feature fusion processing to obtain the multi-level fused feature map.
[0016] According to the pest and disease detection device provided in this application, the processing module is also used for: The labeled candidate region feature map is input into the pest detection model to obtain the pest type information corresponding to each reference detection point output by the pest detection model.
[0017] This application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement any of the above-described pest and disease detection methods.
[0018] This application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the pest and disease detection method as described above.
[0019] This application also provides a computer program product, including a computer program that, when executed by a processor, implements any of the above-described pest and disease detection methods.
[0020] This application provides a method and apparatus for detecting pests and diseases. By constructing a multi-level fusion feature map, it achieves full extraction and integration of multi-scale features of the original image, providing rich details and semantic information for subsequent detection. Furthermore, through a density map prediction mechanism, it can quickly filter out high-probability candidate regions containing pests from global features, effectively eliminating complex background interference, significantly improving detection efficiency and reducing computational redundancy. By setting reference detection points in the candidate regions and combining them with the position offset predicted by the model for accurate localization, the traditional global search detection method is transformed into local refined regression. This not only greatly improves the localization accuracy of small-sized pests, but also avoids complex anchor frame design and calculation through a lightweight point anchor mechanism, ultimately achieving accurate detection of pests and diseases. It is particularly suitable for the real-time monitoring needs of small-target, high-density pests in agricultural scenarios. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in 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, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is one of the flowcharts of the pest and disease detection method provided in this application.
[0023] Figure 2 This is the second flowchart of the pest and disease detection method provided in this application.
[0024] Figure 3 This is the third flowchart of the pest and disease detection method provided in this application.
[0025] Figure 4 This is a schematic diagram of the pest and disease detection device provided in this application.
[0026] Figure 5 A schematic diagram of the physical structure of an electronic device is provided. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0028] Figure 1 This is one of the flowcharts illustrating the pest and disease detection method provided in this application, such as... Figure 1 As shown, the method includes the following: Step 101: Determine the multi-level fusion feature map corresponding to the image to be detected. The multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected.
[0029] The image to be detected refers to the original input image collected from an agricultural scene that contains potential pest targets.
[0030] Among them, the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected.
[0031] Among them, feature maps of different scales refer to feature representations obtained after downsampling the input image by different factors, such as 2x, 4x, 8x and 16x downsampling feature maps. Feature maps of different scales can be used to capture different levels of features from edge texture to semantic information.
[0032] In some embodiments, determining the multi-level fused feature map corresponding to the image to be detected can be achieved by using MobileNetV3 as a lightweight backbone network, performing multi-scale feature sampling on the image to be detected, and extracting feature layers in the backbone network corresponding to 2x, 4x, 8x, and 16x downsampling of the input image to form a multi-level feature map. To avoid losing features of small target pests, the 32x downsampling layer is discarded. Subsequently, a Bidirectional Feature Pyramid Network (BiFPN) is introduced for multi-scale feature fusion. BiFPN, by introducing cross-scale connections and weighted feature fusion mechanisms, assigns learnable importance weights to features at different levels, achieving bidirectional information flow from 2x to 16x feature maps—both passing deep semantic information from top to bottom to enhance the semantic expressiveness of shallow features, and passing shallow detail information from bottom to top to supplement the spatial resolution of deep features. After multiple iterations of fusion by BiFPN, a multi-level fused feature map that contains rich detail information and has strong semantic expressiveness is finally obtained.
[0033] In other embodiments, determining the multi-level fused feature map corresponding to the image to be detected can also be achieved by using a lightweight ResNet18 as the backbone network, extracting feature maps downsampled by 2x, 4x, 8x, and 16x from the backbone network, and constructing a multi-level feature pyramid. To address the problem of small insect targets being easily lost during feature transfer, an Adaptive Spatial Feature Fusion (ASFF) mechanism is introduced to enhance the multi-level feature maps. The core idea of ASFF is to allow the network to autonomously learn how to perform spatial-level fusion between feature maps of different scales: for each level of target feature map, the feature maps of other levels are adjusted to the same resolution through upsampling or downsampling, and then a fusion weight map is generated through a spatial attention mechanism to weighted summation of multi-source features to obtain the multi-level fused feature map.
[0034] Optionally, in some embodiments, determining the multi-level fusion feature map corresponding to the image to be detected may involve performing multi-scale feature sampling processing on the image to be detected to obtain multi-level feature maps with different sampling multiples; and performing feature fusion processing on the multi-level feature maps with different sampling multiples to obtain the multi-level fusion feature map.
[0035] In this embodiment, a multi-scale feature extraction strategy based on a pest detection model can be used to fuse shallow features with high-dimensional features. Shallow features are mainly used to capture detailed information about pests, such as edges and textures; while high-dimensional features provide richer semantic information and can identify more complex image patterns. The fusion process is implemented through a lightweight backbone network, which not only improves computational efficiency but also ensures that information about pests at different scales is fully extracted. After feature extraction, the network can obtain multi-layer feature maps containing pest details and contextual information. Then, feature maps at different scales can be fused to obtain multi-level fused feature maps. These multi-level feature maps can be, for example, feature maps scaled by 1 / 8, without limitation.
[0036] Step 102: Perform density map prediction on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map.
[0037] Density map prediction refers to the process of calculating a probability value for each position in the input feature map using a density probability prediction model, and finally generating a density map.
[0038] Density maps are probability maps composed of multiple pixels, where the pixel value of each pixel represents the probability that the area contains pests.
[0039] Among them, the candidate region feature map refers to the local feature map corresponding to the high probability region selected from the multi-level fused feature map.
[0040] In some embodiments, density map prediction is performed on the multi-level fused feature map to determine candidate region feature maps. This can be achieved by performing density map prediction on the multi-level fused feature map to obtain an initial density map, and then introducing an adaptive threshold segmentation algorithm to binarize the density map. This algorithm automatically calculates the segmentation threshold that best separates the foreground (high-probability region) from the background (low-probability region) based on the statistical distribution characteristics of pixel values in the density map, thereby generating a binarized density map. Subsequently, morphological opening operations are performed on the binarized density map—first, erosion is used to remove isolated noise points and small false regions, and then dilation is used to restore the original size of the target region and connect adjacent broken regions. After morphological processing, contour extraction is performed on the obtained connected regions, and the region defined by the minimum bounding rectangle of each contour is determined as the candidate region feature map.
[0041] In other embodiments, density map prediction is performed on the multi-level fused feature map to determine candidate region feature maps. Alternatively, density map prediction can be performed on the multi-level fused feature map, and after obtaining the density map, a local peak detection algorithm is used to identify local maxima in the density map. Specifically, the density map is scanned using a sliding window method, and points with the maximum value within each window that are higher than a preset low threshold are marked as candidate peak points. These peak points correspond to the central candidate locations of pest targets. Then, with each candidate peak point as the center, the probability distribution around the peak point is modeled using the Gaussian kernel density estimation method, and the influence area range of each peak point is determined based on the standard deviation parameter of the Gaussian distribution. Peak points with overlapping influence areas are clustered and merged, and each cluster corresponds to a candidate region that may contain one or more pests. Finally, a corresponding bounding rectangle is generated based on the clustering results, and the feature map of the region defined by the bounding rectangle is determined as the candidate region feature map.
[0042] Optionally, in some embodiments, density map prediction is performed on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map. This can be done by performing density map prediction on the multi-level fused feature map to obtain a density map, wherein the pixel value of each pixel in the density map is used to characterize the probability that the corresponding region contains pests; each pixel in the density map is traversed, and if the pixel value of a pixel is greater than or equal to a pixel threshold, the pixel is determined as a candidate pixel; and the candidate region feature map is determined based on the candidate pixels.
[0043] The pixel threshold is a critical value used to determine whether a pixel belongs to a high-probability region. This pixel threshold can be adaptively set in conjunction with the pest and disease detection needs in actual business scenarios, without any restrictions.
[0044] Candidate pixels refer to pixels in the density map whose pixel values are greater than or equal to a preset pixel threshold, indicating that the location is very likely to contain pests.
[0045] In other words, in this embodiment, density map prediction can be performed on the multi-level fused feature map. Based on a set pixel threshold (e.g., 0.5), candidate pixels with probability values higher than the threshold are selected, and then candidate region feature maps are determined based on these candidate pixels. This screening process effectively reduces background noise and irrelevant areas, improving detection efficiency. The screened candidate region feature maps will serve as input for the next step of fine-tuning detection, ensuring that subsequent processing focuses on areas that may contain pests, thereby improving the model's detection accuracy.
[0046] Optionally, in some embodiments, determining the candidate region feature map based on the candidate pixels may involve performing connected component analysis on the candidate pixels to determine at least one connected component; determining at least one circumscribed rectangular region based on the connected component; and determining the region feature map corresponding to the circumscribed rectangular region as the candidate region feature map.
[0047] Connectivity analysis refers to the process of marking and grouping adjacent pixels in a binary image, classifying spatially connected pixels into the same connected component.
[0048] Connected components, obtained through connected component analysis, are spatially adjacent candidate pixels. Each connected component represents a contiguous region that may contain pests. The size and shape of a connected component reflect the projection range of the corresponding pest target onto the feature map.
[0049] Connected regions are irregularly shaped sets of pixels, making them unsuitable as regular inputs for subsequent networks. By generating bounding rectangles, these irregular regions are transformed into regular rectangular regions, facilitating subsequent feature map processing.
[0050] In other words, in the embodiments of this application, after determining the candidate pixels, the candidate pixels can be converted into a binary image, where a pixel with a value of 1 represents a high-probability region and a pixel with a value of 0 represents the background. Then, connected component analysis can be performed on the binary image to determine at least one connected component. Based on the connected component, at least one regularly shaped bounding rectangle region can be determined, and the region feature map corresponding to the bounding rectangle region can be determined as a candidate region feature map, thereby facilitating subsequent feature processing.
[0051] Optionally, in some embodiments, determining at least one bounding rectangular region based on connected components can be achieved by merging at least two connected components into one bounding rectangular region if at least two connected components satisfy a preset merging condition.
[0052] The preset merging condition is a set of rules used to determine whether multiple independent bounding rectangular regions need to be merged into a larger region. The preset merging condition includes at least one of the following: There must be an overlapping region between at least two connected components; The distance between at least two connected components is less than a preset distance threshold.
[0053] Among them, the overlapping region refers to two or more bounding rectangular regions that have spatial intersection, that is, their pixel regions have overlapping parts.
[0054] The preset distance threshold is a critical distance value used to determine whether two circumscribed rectangles are adjacent; it is an adjustable hyperparameter.
[0055] In other words, in the embodiments of this application, if there is an overlapping region between two or more connected regions, or if the distance between two or more connected regions is less than a preset distance threshold, the two or more connected regions can be merged into a larger bounding rectangular region, and the region feature map corresponding to the bounding rectangular region can be determined as a candidate region feature map.
[0056] In this embodiment, merging two or more connected components into a larger bounding rectangle can be achieved by forming a minimum bounding rectangle that covers all connected components based on the overlapping parts of the multiple connected components. This avoids repeated detection and multiple framing of adjacent targets, thereby ensuring the integrity of the target area.
[0057] Step 103: Mark at least one reference detection point in the candidate region feature map.
[0058] Among them, the reference detection point, also known as the reference point or point anchor, refers to the benchmark point strategically set on the feature map to predict the location of pests.
[0059] In this embodiment, at least one reference detection point is marked in the candidate region feature map. This can be achieved by uniformly distributing multiple reference detection points at each pixel location for each candidate region feature map. Considering the potentially dense distribution of pests in agricultural scenarios, this embodiment preferably sets 8 reference detection points at each pixel location. These 8 points are evenly distributed within the spatial range surrounding the pixel, forming a dense "detection grid." This arrangement ensures that regardless of where the pest appears in the feature map, there is at least one reference point adjacent to it, providing sufficient initial observation positions for subsequent offset prediction. The coordinates of the reference detection points are recorded and retained as a reference for calculating the position offset in subsequent steps.
[0060] In this embodiment of the application, by marking at least one reference detection point in the feature map of the candidate region, and then performing subsequent pest detection based on the reference detection point, the originally continuous feature space can be discretized into a series of observation points with clear coordinates, transforming the target detection problem into an offset regression problem from these observation points to the center of the real target.
[0061] Step 104: Input the candidate region feature map labeled with reference detection points into the pest and disease detection model to obtain the position offset of each reference detection point output by the pest and disease detection model.
[0062] Among them, the pest and disease detection model refers to a trained deep neural network model that can receive candidate region feature maps as input and predict the corresponding position offset for each reference detection point.
[0063] In this embodiment, the pest and disease detection model can be a neural network model pre-trained based on a training dataset. Training the pest and disease detection model first requires constructing a high-quality training dataset. This application employs point annotation to label the collected agricultural images to solve the problems of overlapping bounding boxes and information loss that easily occur in densely populated pest areas with traditional bounding box annotation. Specifically, annotation software is used, where annotators precisely label the center position of each pest target in each training image, generating corresponding point label files. Each point label accurately represents the center position of a pest. This annotation method not only improves the annotation accuracy of small and densely populated target areas but also provides a natural supervisory signal for subsequent point anchoring mechanism training. The training dataset consists of a large number of such image-point label pairs, covering agricultural scenes with different pest species, different growth stages, different lighting conditions, and different complex backgrounds, ensuring that the model can learn rich pest feature representations.
[0064] In this embodiment, after the dataset is constructed, the training images are input into the initialized pest detection network for end-to-end training. This network is built on a deep convolutional neural network and includes a lightweight backbone network, a multi-scale feature fusion module, a density map prediction branch, and a point anchor detection head. During training, the images are first processed by the backbone network for multi-scale feature extraction, generating multi-level feature maps with 2x, 4x, 8x, and 16x downsampling. These are then fused using the multi-scale feature fusion module to obtain multi-level fused feature maps. Subsequently, the network performs density map prediction on the 1 / 8x feature map and generates candidate regions through threshold filtering and connected component analysis. On the candidate region feature map, the network uniformly sets eight reference points at each pixel location and predicts the position offset and pest type information for each reference point. To achieve optimal matching between predicted point proposals and ground truth point labels, a Hungarian algorithm is used for one-to-one matching. Successfully matched point proposals are marked as positive samples, and unmatched ones are marked as negative samples. Finally, the network calculates classification loss and localization loss based on the positive and negative samples and updates the network parameters through backpropagation. Through multiple rounds of iterative training, the network gradually learns an end-to-end mapping from the input image to the location and category of pests, ultimately resulting in a well-trained pest detection model. This training process ensures that the model can maintain detection accuracy while possessing high computational performance and excellent small target detection capabilities.
[0065] Among them, the position offset refers to the coordinate change value predicted by the pest detection model from the reference detection point to the actual center point of the corresponding pest.
[0066] In this embodiment, the feature map of the candidate region marked with reference detection points can be input into the pest and disease detection model to obtain the position offset of each reference detection point output by the pest and disease detection model.
[0067] Step 105: Determine the location information of the pests based on the detection point coordinates and position offset of the reference detection point.
[0068] The detection point coordinates refer to the original coordinate positions of the reference detection point on the feature map.
[0069] Location information refers to the final determined position of the pest in the image, usually expressed as the coordinates of the center point.
[0070] In this embodiment of the application, after obtaining the position offset of each reference detection point output by the pest detection model, the original coordinates and the corresponding position offset can be superimposed to calculate the actual center point coordinates of the pest.
[0071] For example, if the coordinates of the reference detection point are (x, y) and the model predicts the position offset as (Δx, Δy), then the actual center point of the pest is (x+Δx, y+Δy).
[0072] The pest and disease detection method in this application constructs a multi-level fusion feature map, which fully extracts and integrates multi-scale features of the original image, providing rich details and semantic information for subsequent detection. Furthermore, through a density map prediction mechanism, it can quickly filter out high-probability candidate regions containing pests from global features, effectively eliminating complex background interference, significantly improving detection efficiency and reducing computational redundancy. By setting reference detection points in the candidate regions and combining them with the position offset predicted by the model for accurate positioning, the traditional global search detection method is transformed into local refined regression. This not only greatly improves the positioning accuracy of small-sized pests, but also avoids complex anchor frame design and calculation through a lightweight point anchor mechanism, ultimately achieving accurate detection of pests and diseases. It is particularly suitable for the real-time monitoring needs of small-target, high-density pests in agricultural scenarios.
[0073] Figure 2 This is the second flowchart of the pest and disease detection method provided in this application, as shown below. Figure 2 As shown, the method includes the following: Step 201: Determine the multi-level fusion feature map corresponding to the image to be detected. The multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected.
[0074] Step 202: Perform density map prediction on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map.
[0075] Step 203: Mark at least one reference detection point in the candidate region feature map.
[0076] For a detailed description of steps 201-203, please refer to the above embodiments, which will not be repeated here.
[0077] Step 204: Input the candidate region feature map labeled with reference detection points into the pest and disease detection model to obtain the position offset of each reference detection point output by the pest and disease detection model.
[0078] Step 205: Input the labeled candidate region feature map into the pest detection model to obtain the pest type information corresponding to each reference detection point output by the pest detection model.
[0079] Among them, pest type information refers to the category label of the pest corresponding to each reference detection point predicted by the model, such as specific pest types such as "aphid", "planthopper", and "red spider".
[0080] Among them, pest type information and location information together constitute a complete pest and disease detection result.
[0081] In other words, in this embodiment, the pest detection model can employ a multi-task learning architecture, including parallel classification and regression branches. For each reference detection point on the input feature map, the model calculates the probability distribution of the pest type corresponding to that point using its classification task head. Specifically, the classification branch processes the local features of each reference detection point, outputting a vector of dimension C. After normalization using the Softmax function, each element of this vector represents the probability of the reference point corresponding to a certain pest category. The model uses the category with the highest probability as the pest type information for that reference detection point.
[0082] Step 206: Determine the location information of the pests based on the detection point coordinates and position offset of the reference detection point.
[0083] For a detailed description of step 206, please refer to the above embodiments, which will not be repeated here.
[0084] The pest and disease detection method of this application constructs a multi-level fusion feature map, which fully integrates the detailed features and semantic information of the image to be detected at different scales, laying a rich feature foundation for subsequent accurate detection. Then, it uses a density map prediction mechanism to efficiently filter out candidate region feature maps that are highly likely to contain pests from global features, effectively eliminating complex background interference and significantly reducing computational redundancy in subsequent processing. On this basis, by marking reference detection points in the candidate region feature maps and combining the pest and disease detection model to output the position offset and pest type information corresponding to each reference point in parallel, it realizes accurate regression localization of pest location and simultaneous identification of category. Finally, the precise location of the pest is determined according to the coordinates and offset of the reference point, thus solving the core problems of where the pest is and what the pest is in an end-to-end manner, significantly improving the accuracy and efficiency of detection, and is particularly suitable for rapid and accurate monitoring of small targets and high-density pests in complex agricultural scenarios.
[0085] In the embodiments of this application, Figure 3 This is the third flowchart of the pest and disease detection method provided in this application, as shown below. Figure 3 As shown, the pest detection model adopts an end-to-end lightweight architecture, using a lightweight network (FasterNet) as the backbone to extract features from the image to be detected at multiple scales, generating multi-level feature maps corresponding to W / 2, W / 4, W / 8, and W / 16 times downsampling of the input image, respectively. To avoid losing features of small targets, the network discards the 32-fold downsampling layer. At each stage of the backbone network, a simplified feature matching (SFM) module is embedded to optimize the features, and the feature map resolution is gradually reduced through feature merging operations. Subsequently, the neck network fuses the multi-level feature maps to generate a multi-level fused feature map. On the W / 8 feature map, the network generates a density map through a high-probability region prediction module, performs probability estimation and threshold screening for the possible locations of pests, and determines candidate regions. Finally, the candidate region feature map is input to the detection head, and the position offset and pest type information of each reference detection point are predicted through a point anchoring mechanism, outputting the final detection result.
[0086] The pest and disease detection device provided in this application is described below. The pest and disease detection device described below can be referred to in correspondence with the pest and disease detection method described above.
[0087] Figure 4 This is a schematic diagram of the pest and disease detection device provided in this application, as shown below. Figure 4 As shown, the device includes the following: The first determining module 401 is used to determine a multi-level fusion feature map corresponding to the image to be detected, wherein the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected; The second determining module 402 is used to perform density map prediction on the multi-level fused feature map in order to determine candidate region feature maps from the multi-level fused feature map; The annotation module 403 is used to annotate at least one reference detection point in the feature map of the candidate region; Processing module 404 is used to input the candidate region feature map labeled with reference detection points into the pest and disease detection model to obtain the position offset of the pest and disease detection model output by each reference detection point. The third determining module 405 is used to determine the location information of the pest based on the detection point coordinates and position offset of the reference detection point.
[0088] According to the pest and disease detection device provided in this application, the second determining module 402 is specifically used for: Density map prediction is performed on the multi-level fused feature map to obtain a density map, where the pixel value of each pixel in the density map is used to represent the probability that the corresponding region contains pests; Traverse each pixel in the density map, and determine the pixel as a candidate pixel if the pixel value is greater than or equal to the pixel threshold. Based on the candidate pixels, determine the feature map of the candidate region.
[0089] According to the pest and disease detection device provided in this application, the second determining module 402 is specifically used for: Perform connected component analysis on candidate pixels to determine at least one connected component; Based on the connected components, at least one bounding rectangular region is determined; The feature map corresponding to the bounding rectangle region is determined as the candidate region feature map.
[0090] According to the pest and disease detection device provided in this application, the second determining module 402 is specifically used for: If at least two connected components satisfy a preset merging condition, merge the at least two connected components into a single bounding rectangular region. The preset merging condition includes at least one of the following: There must be an overlapping region between at least two connected components; The distance between at least two connected components is less than a preset distance threshold.
[0091] According to the pest and disease detection device provided in this application, the first determining module 401 is specifically used for: Multi-scale feature sampling is performed on the image to be detected to obtain multi-level feature maps with different sampling ratios; Feature fusion processing is performed on multi-level feature maps with different sampling multiples to obtain multi-level fused feature maps.
[0092] According to the pest and disease detection device provided in this application, the processing module 404 is also used for: The labeled candidate region feature map is input into the pest detection model to obtain the pest type information corresponding to each reference detection point output by the pest detection model.
[0093] The pest and disease detection device of this application embodiment achieves full extraction and integration of multi-scale features of the original image by constructing a multi-level fusion feature map, providing rich details and semantic information for subsequent detection. Furthermore, through the density map prediction mechanism, it can quickly filter out high-probability candidate regions containing pests from global features, effectively eliminating complex background interference, significantly improving detection efficiency and reducing computational redundancy. By setting reference detection points in the candidate regions and combining them with the position offset predicted by the model for accurate positioning, the traditional global search detection method is transformed into local refined regression. This not only greatly improves the positioning accuracy of small-sized pests, but also avoids complex anchor frame design and calculation through a lightweight point anchor mechanism, ultimately achieving accurate detection of pests and diseases. It is particularly suitable for the real-time monitoring needs of small-target, high-density pests in agricultural scenarios.
[0094] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5 As shown, the electronic device may include: a processor 510, a communications interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communications interface 520, and the memory 530 communicate with each other via the communication bus 540. The processor 510 can call logical instructions in the memory 530 to execute a pest and disease detection method, which includes: Determine the multi-level fusion feature map corresponding to the image to be detected, wherein the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected; Density map prediction is performed on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map; Mark at least one reference detection point in the candidate region feature map; Input the candidate region feature map labeled with reference detection points into the pest and disease detection model to obtain the position offset of each reference detection point output by the pest and disease detection model. The location information of the pests is determined based on the coordinates and offset of the reference detection point.
[0095] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0096] On the other hand, this application also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer is able to perform the pest and disease detection methods provided by the above methods, the method including: Determine the multi-level fusion feature map corresponding to the image to be detected, wherein the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected; Density map prediction is performed on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map; Mark at least one reference detection point in the candidate region feature map; Input the candidate region feature map labeled with reference detection points into the pest and disease detection model to obtain the position offset of each reference detection point output by the pest and disease detection model. The location information of the pests is determined based on the coordinates and position offset of the reference detection point.
[0097] In another aspect, this application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the pest and disease detection methods provided by the above methods, the method comprising: Determine the multi-level fusion feature map corresponding to the image to be detected, wherein the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected; Density map prediction is performed on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map; Mark at least one reference detection point in the candidate region feature map; Input the candidate region feature map labeled with reference detection points into the pest and disease detection model to obtain the position offset of each reference detection point output by the pest and disease detection model. The location information of the pests is determined based on the coordinates and position offset of the reference detection point.
[0098] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0099] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0100] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for detecting pests and diseases, characterized in that, include: A multi-level fusion feature map corresponding to the image to be detected is determined, wherein the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected; Density map prediction is performed on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map; At least one reference detection point is marked in the candidate region feature map; The feature map of the candidate region marked with reference detection points is input into the pest and disease detection model to obtain the position offset of each reference detection point output by the pest and disease detection model. The location information of the pest is determined based on the detection point coordinates of the reference detection point and the position offset.
2. The method according to claim 1, characterized in that, The step of performing density map prediction on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map includes: Density map prediction is performed on the multi-level fused feature map to obtain a density map, wherein the pixel value of each pixel in the density map is used to characterize the probability that the corresponding region contains pests; Traverse each pixel in the density map, and if the pixel value of the pixel is greater than or equal to the pixel threshold, determine the pixel as a candidate pixel. The candidate region feature map is determined based on the candidate pixels.
3. The method according to claim 2, characterized in that, The step of determining the candidate region feature map based on the candidate pixels includes: Perform connected component analysis on the candidate pixels to determine at least one connected component; Based on the connected components, at least one circumscribed rectangular region is determined; The region feature map corresponding to the circumscribed rectangular region is determined as the candidate region feature map.
4. The method according to claim 3, characterized in that, The step of determining at least one circumscribed rectangular region based on the connected components includes: If at least two of the connected components satisfy a preset merging condition, the at least two connected components are merged into a bounding rectangular region, wherein the preset merging condition includes at least one of the following: At least two of the connected domains have overlapping regions; The distance between at least two of the connected components is less than a preset distance threshold.
5. The method according to claim 1, characterized in that, The determination of the multi-level fusion feature map corresponding to the image to be detected includes: The image to be detected is subjected to multi-scale feature sampling processing to obtain multi-level feature maps with different sampling multiples; The multi-level feature maps with different sampling multiples are subjected to feature fusion processing to obtain the multi-level fused feature map.
6. The method according to claim 1, characterized in that, The method further includes: The labeled candidate region feature map is input into the pest detection model to obtain the pest type information corresponding to each reference detection point output by the pest detection model.
7. A pest and disease detection device, characterized in that, include: The first determining module is used to determine a multi-level fusion feature map corresponding to the image to be detected, wherein the multi-level fusion feature map is obtained by fusing feature maps of different scales of the image to be detected; The second determining module is used to perform density map prediction on the multi-level fused feature map to determine candidate region feature maps from the multi-level fused feature map; The annotation module is used to annotate at least one reference detection point in the feature map of the candidate region; The processing module is used to input the feature map of the candidate region marked with reference detection points into the pest and disease detection model to obtain the position offset of the pest and disease detection model corresponding to each reference detection point. The third determining module is used to determine the location information of the pest based on the detection point coordinates of the reference detection point and the position offset.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the pest and disease detection method as described in any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the pest and disease detection method as described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the pest and disease detection method as described in any one of claims 1 to 6.