Insect counting method based on self-adaption from weak supervision point to rotating frame and density area

By using a unified density-aware network based on the Transformer architecture, and by adaptively generating rotated bounding boxes and density distribution maps using weakly supervised point annotations, the problem of accurate calculation in pest detection in mixed density scenarios is solved, and low-cost, high-precision pest counting is achieved.

CN122048904APending Publication Date: 2026-05-15HEFEI INST OF TECH INNOVATION ENG CHINESE ACAD OF SCI
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HEFEI INST OF TECH INNOVATION ENG CHINESE ACAD OF SCI
Filing Date
2026-02-05
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing pest detection technologies struggle to achieve accurate calculations in mixed-density scenarios, especially for slender pests, which fail to be detected in dense environments. Furthermore, existing methods require costly manual annotation of rotated bounding boxes, hindering large-scale deployment.

Method used

A unified density-aware network based on the Transformer architecture is adopted. The rotating bounding boxes and region densities are automatically learned through weakly supervised point annotation. A multi-density region adaptive algorithm is used to switch between regions to generate high-precision rotating bounding boxes and density distribution maps.

Benefits of technology

It achieves optimal detection performance for pest counting in mixed scenarios, reduces annotation costs, improves detection accuracy and recall, significantly reduces false alarm rate, and adapts to the detection needs of areas with different densities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122048904A_ABST
    Figure CN122048904A_ABST
Patent Text Reader

Abstract

The invention relates to a pest counting method based on self-adaption from a weak supervision point to a rotating frame and a density area. Compared with the prior art, the defect that precise calculation of pests is difficult to achieve is overcome. The method comprises the following steps: collecting and preprocessing pest images in a multi-density area; constructing a unified density sensing network; unifying the training of the density sensing network; inputting a pest image; and pests are automatically counted. Under a unified network framework, a pixel-level mask is generated by using a region-level density sensing module, a high-precision rotating frame is generated in a sparse region by using a dynamic guide network, and a high-confidence density map is generated in a dense region, so that the optimal detection performance of pest counting in a mixed scene is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of pest identification technology, specifically a pest counting method based on weak supervision point to rotating frame and density region adaptation. Background Technology

[0002] Pest infestation is a major cause of post-harvest grain loss, and timely and accurate pest monitoring is a crucial prerequisite for ensuring food security. With the rapid development of artificial intelligence technology, target detection methods based on deep learning technology have been widely applied in the agricultural field.

[0003] Existing pest detection technologies still face the following serious challenges in practical applications:

[0004] 1. The contradiction between morphology and annotation: Many pests have slender forms (such as the sawtooth flour beetle and the red flour beetle), with large aspect ratios and arbitrary orientations. Traditional horizontal bounding boxes (HBBs) contain a lot of background noise, which can lead to severe box overlap (excessive IoU) in dense scenes, resulting in incorrect rejection by non-maximum suppression (NMS). While rotated bounding boxes (OBBs) can closely fit the insect body, manual annotation is extremely costly (requiring annotation of angles and four-corner coordinates), making large-scale implementation difficult.

[0005] 2. Limitations of a Single Density Perspective: Existing solutions (such as partial density map methods or simple classification switching methods) typically divide the entire image into a single "sparse" or "dense" mode. However, real-world trap images often exhibit "mixed density" characteristics (e.g., extremely dense in the center of the trap, while sparse at the edges). Existing "one-size-fits-all" strategies can lead to model failures in the center region (excessive box overlap) or inaccurate counting in the edge region (blurred density map), failing to balance individual location accuracy and group counting accuracy within the same image.

[0006] Therefore, there is an urgent need for a detection method that can automatically learn the rotation features of pests using only low-cost point annotations and can adaptively switch algorithms based on density differences in local areas of an image. Summary of the Invention

[0007] The purpose of this invention is to address the shortcomings of existing technologies in achieving accurate pest counting by providing a pest counting method based on weak supervision point to rotating frame and density region adaptation.

[0008] To achieve the above objectives, the technical solution of the present invention is as follows:

[0009] A pest counting method based on weakly supervised point-to-rotation frame and density region adaptation includes the following steps:

[0010] 11) Collection and preprocessing of pest images in multi-density areas: Collect pest images and perform standardized preprocessing. Use annotation tools to annotate only the pests in the images at the point level, record the coordinates of the center point and the category of the pests, and construct a training dataset.

[0011] 12) Construct a unified density-aware network: Construct a unified density-aware network based on the Transformer architecture;

[0012] 13) Training of the unified density-aware network: Using the training dataset, the network is trained end-to-end through a hybrid loss function, enabling the unified density-aware network to automatically learn the rotation box and region density division from point annotations; 14) Pest image input: Acquire the pest images to be detected and perform size unification preprocessing; 15) Automatic pest counting: Input the preprocessed pest images to be detected into the trained unified density-aware network. Based on the density region perception module, it adaptively selects to enter the weakly supervised point-to-rotation box generation module or the multi-class density counting module, and finally outputs the fused pest rotation box position, density distribution map and classification counting results.

[0013] The construction of the unified density-aware network includes the following steps:

[0014] 21) The unified density-aware network is defined as including a feature extraction backbone network, a density distribution awareness module, a multi-class density counting module, a weakly supervised point-to-rotation box generation module, and an inference fusion logic module;

[0015] 22) The feature extraction backbone network adopts the Transformer module with a Gaussian pyramid structure to extract multi-scale features of the image; the input image is processed by block embedding and multi-layer self-attention mechanism, and the output is a feature pyramid set containing rich semantic and spatial details. ;

[0016] 23) The density distribution sensing module is set to generate pixel-level density masks and receive feature pyramid sets. The highest level of semantics By expanding the receptive field through dilated convolutional layers, a density mask with the same resolution as the feature map is generated for prediction. ,in The value in the value indicates the probability that the pixel location belongs to a densely overlapping region;

[0017] 24) Set up a multi-category density counting module to receive the feature pyramid set. With density mask The weighted features are used to fuse multi-scale information using a feature pyramid network, combined with a spatial-channel attention mechanism, and a multi-channel density map is generated by Gaussian kernel density estimation, with each channel corresponding to the distribution of a type of pest.

[0018] 25) Set up a weak supervision point to rotate box generation module to handle sparse regions and receive the feature pyramid set. and using density mask The generated sparse region mask is filtered; in the case of only point labels, the feature anisotropy analysis mechanism is used to predict the major and minor axis ratios and rotation angles of feature points through a regression subnetwork to generate a rotating bounding box that fits the insect body; the weakly supervised point-to-rotation box generation module introduces rotation consistency constraints to self-supervisedly learn the orientation of the pest in the absence of angle labels.

[0019] 26) Set up an inference fusion logic module to integrate prediction results based on scene density: This module receives a multi-channel density map generated by a multi-category density counting module and a rotated bounding box generated by a weak supervision point to rotated box generation module; during the inference stage, a density mask is used as a spatial gating signal; for regions where the density mask value is lower than a set threshold, a rotated bounding box is output as the detection result for that region; for regions where the density mask value is higher than a set threshold, the multi-channel density map is integrated, and the integration result is output as the counting result for that region; the final output is a full-map pest monitoring result that integrates the rotated boxes in sparse areas and the density counts in dense areas.

[0020] The training of the unified density-aware network includes the following steps:

[0021] 31) Constructing a composite loss function It is caused by rotational consistency loss Region segmentation loss and density counting loss composition:

[0022] = + + ;

[0023] 32) Set rotational consistency loss For supervised generation of rotated bounding boxes without angle annotations: input image Rotation angle get The predicted bounding boxes are obtained by inputting them into the network. and Mandatory requirements After rotation Later and To maintain consistency, geometric constraints are used to force the network to learn stable rotational features;

[0024] 33) Set the region segmentation loss To optimize the region-level density sensing module: a pseudo-label mask is generated based on local density calculations of point annotations, and the density mask is trained using a binary cross-entropy loss function. This enables it to accurately distinguish between sparse and dense areas;

[0025] 34) Setting density counting loss To optimize the multi-category density counting module: mean squared error and spatial contrast loss are used to make the predicted density map numerically approximate the ground truth map generated by Gaussian, while suppressing feature confusion between different pest categories.

[0026] 35) Overall model training process: Input the preprocessed image into the network, perform forward propagation to calculate the output of each module, and combine the point annotation information to calculate the above composite loss function. The network parameters are updated using the backpropagation algorithm until the loss function converges, thus completing model training.

[0027] The process of setting the feature extraction backbone network includes the following steps:

[0028] 41) Image segmentation and embedding: The pest image after the input size is unified is divided into non-overlapping fixed-size image blocks, and each image block is mapped to a high-dimensional linear embedding vector as the sequence input;

[0029] 42) Multi-stage feature encoding: High-dimensional linear embedding vectors are input into stacked Transformer encoder blocks. Feature interaction is performed using a multi-head self-attention mechanism based on moving windows to extract local and global contextual information and output the first-stage feature map.

[0030] 43) Feature downsampling and layer extraction: The feature map output from the previous stage is downsampled through a patch merging layer, which halves the resolution of the feature map while doubling the number of channels. Then it is input into the Transformer encoder block of the next stage. Repeat steps 41-43) to output feature maps of different scales at different network layers of different depths.

[0031] 44) Feature Pyramid Construction: Collect feature maps output from each stage to construct a feature pyramid set containing information ranging from shallow texture information to deep semantic information. This feature pyramid set is then used as the shared feature input for subsequent modules.

[0032] The set density distribution sensing module includes the following steps:

[0033] 51) High-level semantic feature reception and extended perception: Receiving the feature pyramid set output by the backbone network for feature extraction. The highest level semantic feature map The feature map is then fed into a series of dilated convolutional layers to expand the receptive field without reducing resolution, thereby capturing the global crowding context of pest distribution; 52) Feature channel compression: The feature map after dilated perception is compressed through... The convolutional layer performs dimensionality reduction, compressing multi-channel high-dimensional features into a single-channel feature map. Each pixel value in this single-channel feature map represents the density response intensity of the corresponding region. 53) Pixel-level probabilistic activation: The single-channel feature map is non-linearly mapped using the Sigmoid activation function, normalizing the response intensity to... Range, generate pixel-level density mask 54) Mask binarization and complementary mask generation: setting a density threshold Based on density mask Generate sparse region attention mask and dense area focus mask The two complementary masks are then fed to the weakly supervised point and the rotating box generation module and the multi-class density counting module, respectively.

[0034] The setting of the multi-category density counting module includes the following steps:

[0035] 61) Dense region feature weighting: Receiving feature pyramid set and dense area focus mask 62) Multi-scale feature fusion: The densely enhanced feature pyramid is input into the feature pyramid network. High-level semantic features are upsampled and fused with low-level detail features via a top-down path to generate a fused multi-scale feature map. 63) Spatial-channel attention enhancement: The fused multi-scale feature map is input into the spatial-channel attention module. Attention weights are calculated in both the channel and spatial dimensions to further enhance the feature differentiation of different pests within densely overlapping areas, generating an enhanced feature map. 64) Multi-channel density regression: The enhanced feature map is input into a regression head composed of multiple convolutions, outputting a channel number of... Multi-channel density map, in which To determine the number of pest categories, pixel integration is performed on the density maps of each channel to obtain the number of each pest category in dense areas.

[0036] The module for setting weak supervision points to generate a rotating frame includes the following steps:

[0037] 71) Sparse region feature selection and resampling: Receiver feature pyramid set Focus on sparse region masks Sparse enhancement features are obtained through element-wise multiplication; the center point coordinates of the point labels are used.

[0038] Feature point sampling is performed on the sparse enhanced feature map to extract the local feature vector corresponding to the center point of each pest; 72) Feature anisotropy analysis: The extracted local feature vectors are input into the affine transformation prediction sub-network. The network implicitly infers the main axis direction and length-to-width ratio of the pest's body by analyzing the spatial distribution dispersion of the features; 73) Rotation box parameter regression: The affine transformation prediction sub-network outputs the geometric deformation parameters corresponding to each center point, including the rotation angle. Major axis length and minor axis length 74) Coordinate transformation and rotation box generation: based on center point coordinates and the geometric deformation parameters obtained by regression The coordinates of the four vertices are generated by the geometric transformation formula, and a rotating bounding box that tightly surrounds the insect's body is constructed; 75) Non-maximum suppression: Non-maximum suppression based on IoU is performed on all generated rotating bounding boxes to remove redundant boxes with excessive overlap, and the final rotating bounding box of the sparse region insect body is output.

[0039] A computer-readable storage medium storing a computer program that, when executed by a processor, enables a pest counting method based on weak supervision point to rotating frame and density region adaptation.

[0040] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, which, when executed by the processor, enables a pest counting method based on weak supervision point to rotating frame and density region adaptation.

[0041] Beneficial effects

[0042] The pest counting method of the present invention, based on weak supervision point to rotating box and density region adaptation, compared with the prior art, utilizes a region-level density perception module to generate a pixel-level mask under a unified network framework, dynamically guides the network to generate a high-precision rotating box in sparse areas and a high-confidence density map in dense areas, and achieves the optimal detection performance of pest counting in mixed scenes.

[0043] The present invention also has the following advantages:

[0044] 1. Capable of fine-grained scene adaptation: Breaking through the limitations of "one sheet of paper" Figure 1 By overcoming the limitations of a single algorithm, a "one region, one strategy" approach was implemented. In the same image, density map counting was used for dense central areas, while rotational bounding boxes were used for sparse edge areas, significantly improving the detection accuracy in mixed scenes.

[0045] 2. Low cost and high precision: It pioneered a weakly supervised rotating box generation technology in the field of pest counting. No manual angle annotation is required; high-precision rotating boxes (RBoxes) can be generated solely from point annotations, effectively solving the problem of missed detection of slender pests such as sawtooth millet beetles when they are densely packed.

[0046] 3. Strong anti-interference ability: The rotating frame can tightly wrap around the insect body, eliminating interference from irrelevant background targets to the greatest extent and significantly reducing the false alarm rate. Attached Figure Description

[0047] Figure 1 This is a sequence diagram of the method of the present invention;

[0048] Figure 2 This is a schematic diagram of the unified density sensing network structure involved in this invention;

[0049] Figure 3 This is a test result diagram of the present invention. Detailed Implementation

[0050] To provide a better understanding of the structural features and effects achieved by the present invention, a detailed description is provided below, accompanied by preferred embodiments and accompanying drawings:

[0051] like Figure 1 As shown, the pest counting method based on weak supervision point to rotating frame and density region adaptation of the present invention includes the following steps:

[0052] The first step is the collection and preprocessing of pest images in multi-density areas: collect pest images and perform standardized preprocessing, use annotation tools to annotate only the pests in the images at the point level, record the coordinates of the center point of the pests and their categories, and construct a training dataset.

[0053] The second step is to build a unified density-aware network: a unified density-aware network is built based on the Transformer architecture.

[0054] like Figure 2 As shown, the unified density-aware network is configured to include a feature extraction backbone network, a density distribution awareness module, a multi-class density counting module, a weakly supervised point-to-rotation box generation module, and an inference fusion logic module.

[0055] (1) The feature extraction backbone network adopts the Transformer module with a Gaussian pyramid structure to extract multi-scale features of the image; the input image is processed by block embedding and multi-layer self-attention mechanism, and the output is a feature pyramid set containing rich semantic and spatial details. .

[0056] Setting up a feature extraction backbone network includes the following steps:

[0057] A1) Image segmentation and embedding: The pest image after the input size is unified is divided into non-overlapping fixed-size image blocks, and each image block is mapped to a high-dimensional linear embedding vector as the sequence input;

[0058] A2) Multi-stage feature encoding: High-dimensional linear embedding vectors are input into stacked Transformer encoder blocks. Feature interaction is performed using a multi-head self-attention mechanism based on moving windows to extract local and global contextual information and output the first-stage feature map.

[0059] A3) Feature downsampling and layer extraction: The feature map output from the previous stage is downsampled through a patch merging layer, which halves the feature map resolution and doubles the number of channels. Then it is input into the Transformer encoder block of the next stage. Repeat steps A1-A3) to output feature maps of different scales at different network layers at different depths.

[0060] A4) Feature Pyramid Construction: Collect the feature maps output from each stage to construct a feature pyramid set containing information ranging from shallow texture information to deep semantic information. This feature pyramid set is then used as the shared feature input for subsequent modules.

[0061] (2) The density distribution sensing module is set to generate a pixel-level density mask and receive the feature pyramid set. The highest level of semantics By expanding the receptive field through dilated convolutional layers, a density mask with the same resolution as the feature map is generated for prediction. ,in The value in the value represents the probability that the pixel location belongs to a densely overlapping region.

[0062] The main technical challenge of this step lies in solving the problem of region-level density semantic alignment and non-convex optimization under unsupervised conditions. Since the training data only contains weakly supervised annotations at the point level and lacks pixel-level "sparse / dense" ground truth for segmentation, the network struggles to spontaneously learn clear density boundaries. At the same time, the background of images of stored grain pests is complex, with a large amount of debris and impurities interfering. Designing a feature extraction mechanism that can ignore background noise, adaptively perceive the degree of crowding based on the intensity of local feature responses, and ensure that the backpropagation gradient can correctly guide the mask generation is extremely challenging.

[0063] This step represents a crucial leap from "image-level classification" to "region-level adaptive strategy switching." Its core technological significance lies in decoupling complex mixed scenes into two relatively simple sub-problems, avoiding the forced fitting of vastly different data distributions with the same set of parameters, and significantly reducing the learning difficulty of the model. Simultaneously, the soft mask generated based on full-image features not only preserves complete contextual information and eliminates the boundary truncation effect caused by traditional tile clipping, but also instructs the network to call computationally intensive algorithms only in necessary dense areas, maintaining efficient detection in sparse areas, thus achieving the optimal balance between inference speed and detection accuracy.

[0064] B1) High-level semantic feature reception and extended perception: Receiving the feature pyramid set output by the feature extraction backbone network. The highest level semantic feature map The input is then fed into a series of dilated convolutional layers to expand the receptive field without reducing resolution, thereby capturing the global crowding context of pest distribution; B2) Feature channel compression: The feature map after dilated perception is compressed through... The convolutional layer performs dimensionality reduction, compressing multi-channel high-dimensional features into a single-channel feature map. Each pixel value in this single-channel feature map represents the density response intensity of the corresponding region. B3) Pixel-level probabilistic activation: The single-channel feature map is non-linearly mapped using the Sigmoid activation function, normalizing the response intensity to... Range, generate pixel-level density mask B4) Mask binarization and complementary mask generation: setting a density threshold Based on density mask Generate sparse region attention mask and dense area focus mask The two complementary masks are then fed to the weakly supervised point and the rotating box generation module and the multi-class density counting module, respectively.

[0065] (4) Set up a multi-category density counting module to receive the feature pyramid set. With density mask The weighted features are used to fuse multi-scale information using a feature pyramid network and combined with a spatial-channel attention mechanism. A multi-channel density map is generated by Gaussian kernel density estimation, with each channel corresponding to the distribution of a type of pest.

[0066] The technical challenge of this step lies in overcoming the difficulties of fine-grained feature decoupling and multi-scale adaptation in high-density overlapping scenarios. Stored grain pests (such as rice weevils and grain borers) have highly similar appearances, and the grain pile background contains a large number of pest-like textured grain husk impurities. When densely stacked, feature space confusion easily occurs, leading to density thermal point drift or misattribution. Furthermore, the effective pixel area changes drastically due to occlusion and different pitch angles of the pests, making it difficult for Gaussian density estimation with a fixed kernel bandwidth to adapt to such dynamic scale changes, easily causing counting bias.

[0067] The technical significance of this step lies in proposing a spatial-channel attention-enhanced feature fusion mechanism, which effectively solves the problem of failure due to dense occlusion. By forcing the network to focus on the discriminative parts (such as antennae and texture) unique to different pests through the attention mechanism, the inter-class distance is increased in the feature space, thereby achieving accurate separation of multiple pest categories on the same density map. Compared with the detection box method, which is prone to erroneous rejection due to nonmaximum suppression in dense areas, the density map integral method can accurately estimate the population size even when individuals cannot be completely separated. Combined with the feature pyramid's ability to capture small targets, it significantly improves the reliability of pest monitoring during outbreaks.

[0068] C1) Dense Region Feature Weighting: Receiving Feature Pyramid Set and dense area focus mask C1) **Dense Enhanced Feature Pyramid:** The feature pyramid is spatially weighted through element-wise multiplication to suppress feature responses in sparse regions and retain features in dense regions, resulting in a densely enhanced feature pyramid. C2) **Multi-scale Feature Fusion:** The densely enhanced feature pyramid is input into the feature pyramid network. High-level semantic features are upsampled and fused laterally with low-level detail features via a top-down path, generating a fused multi-scale feature map. C3) **Spatial-Channel Attention Enhancement:** The fused multi-scale feature map is input into the spatial-channel attention module. Attention weights are calculated in both the channel and spatial dimensions to further enhance the feature discrimination of different pest individuals within densely overlapping regions, generating an enhanced feature map. C4) **Multi-channel Density Regression:** The enhanced feature map is input into a regression head composed of multiple convolutional layers, outputting a multi-channel number of... Multi-channel density map, in which To determine the number of pest categories, pixel integration is performed on the density maps of each channel to obtain the number of each pest category in dense areas.

[0069] (5) Set up a weak supervision point to rotate box generation module to handle sparse regions and receive the feature pyramid set. and using density mask The generated sparse region mask is filtered; in the case of only point labels, the feature anisotropy analysis mechanism is used to predict the major and minor axis ratios and rotation angles of feature points through a regression subnetwork to generate a rotating bounding box that fits the insect body; the weakly supervised point-to-rotation box generation module introduces rotation consistency constraints to self-supervisedly learn the orientation of the pest in the absence of angle labels.

[0070] This step is the core challenge of the invention, mainly in solving the underdetermined inverse problem of "from single-point annotation to full-dimensional geometric parameters". When only the coordinates of the center point are known but the true values ​​of angles and dimensions are lacking, the regression network is prone to collapse into an output circle or horizontal box, making it difficult to capture the true posture of the pest. How to extract the implicit anisotropic direction information from the convolutional features and map it to the rotation angle in the physical world, while overcoming the periodic oscillations and divergence problems that easily occur in weakly supervised training due to the lack of strong constraints, places extremely high demands on the network structure design and geometric consistency constraint mechanism.

[0071] This step implements a low-cost, high-precision weakly supervised detection paradigm, which is of great technical significance. It completely eliminates the expensive rotating bounding box annotation, generating a high-precision rotating bounding box during the inference stage simply by clicking the center point, reducing annotation costs by more than 65% and greatly promoting the deployment of the algorithm. Especially for slender pests such as sawtooth millet beetles, the generated rotating boxes can closely fit the insect body, effectively removing background noise redundancy caused by horizontal boxes, significantly reducing the cross-union ratio in densely arranged cases, avoiding false deletions caused by non-maximum suppression, and greatly improving recall and detection accuracy in complex scenarios.

[0072] C1) Sparse region feature selection and resampling: Receiving feature pyramid set Focus on sparse region masks Sparse enhancement features are obtained through element-wise multiplication; the center point coordinates of the point labels are used. Feature point sampling is performed on the sparse enhanced feature map to extract the local feature vector corresponding to the center point of each pest; C2) Feature anisotropy analysis: The extracted local feature vectors are input into the affine transformation prediction sub-network. The network implicitly infers the main axis direction and length-to-width ratio of the pest's body by analyzing the spatial distribution dispersion of the features; C3) Rotation box parameter regression: The affine transformation prediction sub-network outputs the geometric deformation parameters corresponding to each center point, including the rotation angle. Major axis length and minor axis length C4) Coordinate Transformation and Rotation Box Generation: Based on Center Point Coordinates and the geometric deformation parameters obtained by regression The coordinates of the four vertices are generated through geometric transformation formulas to construct a rotating bounding box that tightly surrounds the insect's body; C5) Non-maximum suppression: Non-maximum suppression based on IoU is performed on all generated rotating bounding boxes to remove redundant boxes with excessive overlap, and the final rotating bounding box of the sparse region insect body is output.

[0073] (6) Set up an inference fusion logic module to integrate prediction results according to the density of the scene: This module receives the multi-channel density map generated by the multi-category density counting module and the rotating bounding box generated by the weak supervision point to rotating box generation module; In the inference stage, the density mask is used as a spatial gating signal; For areas where the density mask value is lower than the set threshold, the rotating bounding box is output as the detection result of the area; For areas where the density mask value is higher than the set threshold, the multi-channel density map is integrated and the integration result is output as the counting result of the area; The final output is the whole map pest monitoring result that integrates the rotating box of the sparse area and the density count of the dense area.

[0074] The third step is training the unified density-aware network: using the training dataset, the network is trained end-to-end through a hybrid loss function, enabling the unified density-aware network to automatically learn rotated boxes and region density division from point annotations.

[0075] (1) Constructing a composite loss function It is caused by rotational consistency loss Region segmentation loss and density counting loss composition:

[0076] = + + .

[0077] (2) Set rotational consistency loss For supervised generation of rotated bounding boxes without angle annotations: input image Rotation angle get The predicted bounding boxes are obtained by inputting them into the network. and Mandatory requirements After rotation Later and To maintain consistency, geometric constraints are used to force the network to learn stable rotational features.

[0078] (3) Set the region segmentation loss To optimize the region-level density sensing module: a pseudo-label mask is generated based on local density calculations of point annotations, and the density mask is trained using a binary cross-entropy loss function. This enables it to accurately distinguish between sparse and dense areas.

[0079] (4) Set density counting loss To optimize the multi-category density counting module: mean squared error and spatial contrast loss are used to make the predicted density map numerically approximate the ground truth map generated by Gaussian, while suppressing feature confusion between different pest categories.

[0080] (5) Overall model training process: The preprocessed image is input into the network, the output of each module is calculated through forward propagation, and the composite loss function is calculated by combining the point annotation information. The network parameters are updated using the backpropagation algorithm until the loss function converges, thus completing model training.

[0081] Step 4, Pest Image Input: Acquire pest images and perform size standardization preprocessing. Step 5, Automatic Pest Counting: Input the preprocessed pest images to be detected into the trained unified density perception network. Based on the density region perception module, the network adaptively selects whether to enter the weakly supervised point to the rotating box generation module or the multi-class density counting module. Finally, it outputs the fused pest rotating box positions, density distribution map, and classification counting results.

[0082] like Figure 3 As shown, it is a schematic diagram of the test effect of the pest detection model based on density distribution area involved in the present invention under different density scenarios. Figure 3 This demonstrates how the model adaptively outputs rotated bounding boxes or density maps within the same frame based on the mask generated by the Region Density Awareness Module (P-DCM). Specifically, Figure 3(a) shows the detection performance of this model on sparsely distributed images of the sawtooth millet beetle (O. surinamensis). Due to the slender body shape of this pest, the weakly supervised generation module of this invention successfully reconstructed a rotated bounding box (RBox) that fits the insect body from the point annotations, effectively avoiding background redundancy in the horizontal bounding box. The actual number of pests in the image is 53, and the model outputs 53, demonstrating high localization accuracy. Figure 3 (b) shows the counting effect of this model on densely distributed booklice (L. bostrychophila) images. For high-density overlapping areas, the model automatically switches to the density counting branch. The generated density map clearly reflects the pest aggregation center. The actual number of pests in the image is 1207, and the model outputs 1198, with minimal error. Figure 3 (c) shows the effect of this model applied in a mixed-density scene. The center of the image is a high-density trapping area, and the edges are sparse areas. The model successfully generated a rotated detection box at the edges and a density integral map at the center, achieving the optimal strategy combination at the region level. Figure 3As can be seen, the method proposed in this invention breaks through the limitations of a single detection mode, and solves the problem of overlapping counting in high-density areas while ensuring the accuracy of capturing the posture of slender pests in low-density areas.

[0083] Table 1

[0084] Pest categories Sawmiller Rice Elephant grain beetle Indian meal moth Spotted dermatitis Japanese spider Booklice average value Mean Absolute Error (MAE) 0.97 3.87 6.24 5.28 2.97 2.18 3.15 3.74 Mean Squared Error (RMSE) 3.87 16.31 20.03 22.76 10.43 6.12 9.89 12.77 Weighted mean squared error (WMSE) - - - - - - - 13.65

[0085] Table 1 shows the performance indicators of the method involved in this invention. The experiment used mean absolute error (MAE) and the weighted mean square error (WMSE) proposed in this invention as core evaluation indicators. WMSE incorporates a pest risk coefficient, which better reflects the actual risk of pest occurrence. This invention achieved a WMSE score of 13.65, demonstrating its robustness in handling complex scenarios with multiple species and densities, and its ability to more accurately provide early warnings of high-risk pests.

[0086] The table details the test results for seven major pests. Lower values ​​for both indicate better model performance. This invention demonstrates excellent performance for pests with significant morphological differences: For the sawtooth grain beetle, thanks to the weakly supervised rotating box generation technique, the MAE is only 0.97, solving the false detection problem of slender targets in horizontal box detection; For small, dense pests such as booklice, thanks to the introduction of region density branches, the MAE is controlled at an extremely low level of 3.15; For high-risk pests such as rice weevils and grain borers, the model maintains extremely high counting accuracy in mixed scenarios (MAEs of 3.87 and 6.24, respectively). Overall, the model's average MAE on the entire dataset is 3.74, validating the effectiveness of the "point-to-rotated box" and "dynamic region switching" mechanisms.

[0087] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the claimed invention. The scope of protection claimed by the appended claims and their equivalents is defined.

Claims

1. A pest counting method based on weak supervision point to rotating frame and density region adaptation, characterized in that, Includes the following steps: 11) Collection and preprocessing of pest images in multi-density areas: Collect pest images and perform standardized preprocessing. Use annotation tools to annotate only the pests in the images at the point level, record the coordinates of the center point and the category of the pests, and construct a training dataset. 12) Construct a unified density-aware network: Construct a unified density-aware network based on the Transformer architecture; 13) Training of the unified density-aware network: Using the training dataset, the network is trained end-to-end through a hybrid loss function, enabling the unified density-aware network to automatically learn the rotation box and region density division from point annotations; 14) Pest image input: Acquire the pest images to be detected and perform size unification preprocessing; 15) Automatic pest counting: Input the preprocessed pest images to be detected into the trained unified density-aware network. Based on the density region perception module, it adaptively selects to enter the weakly supervised point-to-rotation box generation module or the multi-class density counting module, and finally outputs the fused pest rotation box position, density distribution map and classification counting results.

2. The pest counting method based on weak supervision point to rotating frame and density region adaptation according to claim 1, characterized in that, The construction of the unified density-aware network includes the following steps: 21) The unified density-aware network is defined as including a feature extraction backbone network, a density distribution awareness module, a multi-class density counting module, a weakly supervised point-to-rotation box generation module, and an inference fusion logic module; 22) The feature extraction backbone network adopts the Transformer module with a Gaussian pyramid structure to extract multi-scale features of the image; the input image is processed by block embedding and multi-layer self-attention mechanism, and the output is a feature pyramid set containing rich semantic and spatial details. ; 23) The density distribution sensing module is set to generate pixel-level density masks and receive feature pyramid sets. The highest level of semantics By expanding the receptive field through dilated convolutional layers, a density mask with the same resolution as the feature map is generated for prediction. ,in The value in the value indicates the probability that the pixel location belongs to a densely overlapping region; 24) Set up a multi-category density counting module to receive the feature pyramid set. With density mask The weighted features are used to fuse multi-scale information using a feature pyramid network, combined with a spatial-channel attention mechanism, and a multi-channel density map is generated by Gaussian kernel density estimation, with each channel corresponding to the distribution of a type of pest. 25) Set up a weak supervision point to rotate box generation module to handle sparse regions and receive the feature pyramid set. and using density mask The generated sparse region mask is filtered; in the case of only point labels, the feature anisotropy analysis mechanism is used to predict the major and minor axis ratios and rotation angles of feature points through a regression subnetwork to generate a rotating bounding box that fits the insect body; the weakly supervised point-to-rotation box generation module introduces rotation consistency constraints to self-supervisedly learn the orientation of the pest in the absence of angle labels. 26) Set up an inference fusion logic module to integrate prediction results based on scene density: This module receives a multi-channel density map generated by a multi-category density counting module and a rotated bounding box generated by a weak supervision point to rotated box generation module; during the inference stage, a density mask is used as a spatial gating signal; for regions where the density mask value is lower than a set threshold, a rotated bounding box is output as the detection result for that region; for regions where the density mask value is higher than a set threshold, the multi-channel density map is integrated, and the integration result is output as the counting result for that region; the final output is a full-map pest monitoring result that integrates the rotated boxes in sparse areas and the density counts in dense areas.

3. The pest counting method based on weak supervision point to rotating frame and density region adaptation according to claim 1, characterized in that, The training of the unified density-aware network includes the following steps: 31) Constructing a composite loss function It is caused by rotational consistency loss Region segmentation loss and density counting loss composition: = + + ; 32) Set rotational consistency loss For supervised generation of rotated bounding boxes without angle annotations: input image Rotation angle get The predicted bounding boxes are obtained by inputting them into the network. and Mandatory requirements After rotation Later and To maintain consistency, geometric constraints are used to force the network to learn stable rotational features; 33) Set the region segmentation loss To optimize the region-level density sensing module: a pseudo-label mask is generated based on local density calculations of point annotations, and the density mask is trained using a binary cross-entropy loss function. This enables it to accurately distinguish between sparse and dense areas; 34) Setting density counting loss To optimize the multi-category density counting module: mean squared error and spatial contrast loss are used to make the predicted density map numerically approximate the ground truth map generated by Gaussian, while suppressing feature confusion between different pest categories. 35) Overall model training process: Input the preprocessed image into the network, perform forward propagation to calculate the output of each module, and combine the point annotation information to calculate the above composite loss function. The network parameters are updated using the backpropagation algorithm until the loss function converges, thus completing model training.

4. The pest counting method based on weak supervision point to rotating frame and density region adaptation according to claim 2, characterized in that, The process of setting the feature extraction backbone network includes the following steps: 41) Image segmentation and embedding: The pest image after the input size is unified is divided into non-overlapping fixed-size image blocks, and each image block is mapped to a high-dimensional linear embedding vector as the sequence input; 42) Multi-stage feature encoding: High-dimensional linear embedding vectors are input into stacked Transformer encoder blocks. Feature interaction is performed using a multi-head self-attention mechanism based on moving windows to extract local and global contextual information and output the first-stage feature map. 43) Feature downsampling and layer extraction: The feature map output from the previous stage is downsampled through a patch merging layer, which halves the resolution of the feature map while doubling the number of channels. Then it is input into the Transformer encoder block of the next stage. Repeat steps 41-43) to output feature maps of different scales at different network layers of different depths. 44) Feature Pyramid Construction: Collect feature maps output from each stage to construct a feature pyramid set containing information ranging from shallow texture information to deep semantic information. This feature pyramid set is then used as the shared feature input for subsequent modules.

5. The pest counting method based on weak supervision point to rotating frame and density region adaptation according to claim 2, characterized in that, The set density distribution sensing module includes the following steps: 51) High-level semantic feature reception and extended perception: Receiving the feature pyramid set output by the backbone network for feature extraction. The highest level semantic feature map The feature map is then fed into a series of dilated convolutional layers to expand the receptive field without reducing resolution, thereby capturing the global crowding context of pest distribution; 52) Feature channel compression: The feature map after dilated perception is compressed through... The convolutional layer performs dimensionality reduction, compressing multi-channel high-dimensional features into a single-channel feature map. Each pixel value in this single-channel feature map represents the density response intensity of the corresponding region. 53) Pixel-level probabilistic activation: The single-channel feature map is non-linearly mapped using the Sigmoid activation function, normalizing the response intensity to... Range, generate pixel-level density mask 54) Mask binarization and complementary mask generation: setting a density threshold Based on density mask Generate sparse region attention mask and dense area focus mask The two complementary masks are then fed to the weakly supervised point and the rotating box generation module and the multi-class density counting module, respectively.

6. The pest counting method based on weak supervision point to rotating frame and density region adaptation according to claim 2, characterized in that, The setting of the multi-category density counting module includes the following steps: 61) Dense region feature weighting: Receiving feature pyramid set and dense area focus mask 62) Multi-scale feature fusion: The densely enhanced feature pyramid is input into the feature pyramid network. High-level semantic features are upsampled and fused with low-level detail features via a top-down path to generate a fused multi-scale feature map. 63) Spatial-channel attention enhancement: The fused multi-scale feature map is input into the spatial-channel attention module. Attention weights are calculated in both the channel and spatial dimensions to further enhance the feature differentiation of different pests within densely overlapping areas, generating an enhanced feature map. 64) Multi-channel density regression: The enhanced feature map is input into a regression head composed of multiple convolutions, outputting a channel number of... Multi-channel density map, in which To determine the number of pest categories, pixel integration is performed on the density maps of each channel to obtain the number of each pest category in dense areas.

7. The pest counting method based on weak supervision point to rotating frame and density region adaptation according to claim 2, characterized in that, The module for setting weak supervision points to generate a rotating frame includes the following steps: 71) Sparse region feature selection and resampling: Receiver feature pyramid set Focus on sparse region masks Sparse enhancement features are obtained through element-wise multiplication; the center point coordinates of the point labels are used. Feature point sampling is performed on the sparse enhanced feature map to extract the local feature vector corresponding to the center point of each pest. 72) Feature anisotropy analysis: The extracted local feature vectors are input into the affine transformation prediction sub-network. The network implicitly infers the main axis direction and length-to-width ratio of the pest's trunk by analyzing the spatial distribution dispersion of the features. 73) Rotation Box Parameter Regression: The affine transformation prediction subnetwork outputs the geometric deformation parameters corresponding to each center point, including the rotation angle. Major axis length and minor axis length ; 74) Coordinate Transformation and Rotation Box Generation: Based on Center Point Coordinates and the geometric deformation parameters obtained by regression The coordinates of the four vertices are generated by the geometric transformation formula, and a rotating bounding box that tightly surrounds the insect's body is constructed. 75) Non-maximum suppression: Perform non-maximum suppression based on IoU on all generated rotated bounding boxes, remove redundant boxes with excessive overlap, and output the final rotated bounding boxes of the sparse region pest trunk.

8. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, enables the pest counting method based on weak supervision point to rotating frame and density region adaptation as described in any one of claims 1-7.

9. A computer device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it can implement the pest counting method based on weak supervision point to rotating frame and density region adaptation as described in any one of claims 1-7.