Multi-density pest counting method combining point positioning and density map
By combining point positioning and density maps, the multi-density pest counting method uses backbone networks and generators to build models, which solves the problem of inaccurate multi-density pest counting in the existing technology and achieves accurate counting in low-density and high-density areas. and distributed feedback.
Patent Information
- Application Number
- CN202410962374.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-18
- Publication Date
- 2024-09-24
AI Technical Summary
Existing pest counting methods are significantly less effective when dealing with multi-density pests, especially in high-density areas where counting is inaccurate, lacks portability, and cannot effectively distinguish pest boundaries and feedback information.
A multi-density pest counting method that combines point positioning and density maps is used to build a counting model through a backbone network, point position generator and density map generator. The labelme tool is used to annotate images and train the model to achieve accurate counting of multi-density pests.
Achieve more accurate pest counting in different density areas. Low-density areas ensure accurate location output, and high-density areas feedback more accurate distribution, improving counting accuracy and portability.
Smart Images

Figure CN118692111A
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of agricultural pest identification, in particular to a multi-density pest counting method combining point positioning and density map. Background Art
[0002] In grain storage, monitoring the infestation level of pests is crucial for preventing pests and ensuring agricultural yields. At the same time, the task of pest counting is also a key component of integrated pest management. Existing pest counting methods are relatively accurate in counting under specific circumstances. However, the spatial distribution of pests in grain storage is quite complex, so the existing methods are significantly less effective when dealing with various distribution patterns and become impractical.
[0003] In the field of pest counting, the use of machine learning for detection and counting dates back to the early days.
[0004] Machine learning methods mainly use some specific operators to extract features from images, or use binarization, grayscale and other methods to transform images to find patterns. These methods rely on manual feature extraction, and the factors considered are naturally limited by human thinking. In addition, machine learning methods can only handle significant pests in simple backgrounds, and are very sensitive to factors such as light, image angle and pest morphology. Therefore, they are not transferable and can only deal with scenarios specifically designed.
[0005] Research using deep learning methods has gradually become the mainstream, and frame-based target detection algorithms, such as MPest-RCNN and S-RPN, have also played a role in the field of pest counting. However, the effect is greatly reduced when facing high-density pests. First, the pests themselves are very small, and frame selection annotation consumes a lot of effort and is difficult to accurately label. Second, pests are prone to stacking, and frame-based target detection algorithms cannot distinguish the boundaries of pests, resulting in inaccurate counting.
[0006] Subsequently, point positioning-based counting algorithms emerged, such as P2PNet and PET. These algorithms use point annotation methods to achieve counting. Since the annotation information they use is smaller than the annotation information based on box selection, they perform better for pest counting in sparse scenes. However, they also encounter the problem of inaccurate counting in high-density pest areas. Their highly stacked nature means that the point counting method can only work on edges and surfaces, and the information feedback for high-density areas is not accurate enough, and their existence is easily ignored.
[0007] Another counting method is to use a density map counting algorithm, which pays more attention to the overall situation. The generated density map is transformed using Gaussian inverse transformation to obtain the counting result, which can better reflect the distribution of pests. Representative algorithms include Mb-CNN, CSRNet, etc. These algorithms can well reflect the distribution trend in dense areas, but are not sensitive to sparse areas. Due to the inherent characteristics of the feature map, the positioning of pests is very vague, so the pest counting is not accurate enough. Summary of the invention
[0008] The purpose of the present invention is to solve the defect that it is difficult to count multi-density pests in the prior art, and to provide a multi-density pest counting method combining point positioning and density map to solve the above problem.
[0009] In order to achieve the above object, the technical solution of the present invention is as follows:
[0010] A multi-density pest counting method combining point location and density map, comprising the following steps:
[0011] Collection and preprocessing of multi-density pest images: Collect multi-density pest images, remove the images with focus failure, blur, and obvious halos, and use the point mode in the labelme tool to annotate the pests in the images;
[0012] Construction of multi-density pest counting model: A multi-density pest counting model is constructed based on the backbone network combined with the point location generator and the density map generator;
[0013] Training of multi-density pest counting model: Use the preprocessed multi-density pest images to train the multi-density pest counting model;
[0014] Acquisition of images of multi-density pests to be detected: acquiring images of multi-density pests to be detected and performing preprocessing;
[0015] Counting of multi-density pests to be detected: The preprocessed multi-density pest images to be detected are input into the trained multi-density pest counting model to obtain the multi-density pest counting results.
[0016] The construction of the multi-density pest counting model comprises the following steps:
[0017] The multi-density pest counting model is set to include a backbone network, a point location generator, and a density map generator; the input image first passes through the backbone network to obtain a feature map , feature map Input point position generator and density map generator; point position generator for feature map At the same time, double upsampling and 1x1 convolution are performed, and the two are added element by element to obtain the feature map ;
[0018] The point position generator outputs the coordinates (x, y) of the predicted point, and the density map generator outputs a density map of the same size as the input image;
[0019] The backbone network is set to consist of 10 convolutional layers and 4 pooling layers. The convolution kernel size is 3x3, the step size is 1, the number of output channels increases from 64 to 128, then to 256, and finally to 512. The pooling layer kernel size is 2x2, the step size is 2, and the input image is gradually condensed to one sixteenth of the original size, with a feature map with 512 channels. ;
[0020] The set point position generator consists of two branches, namely the regressor branch and the classifier branch. The feature map output by the backbone network In the point position generator, two times upsampling and 1x1 convolution are performed simultaneously, and the two are added element by element to obtain the feature map. , feature map Input into the two branches of the point position generator respectively;
[0021] The structure of the regressor branch is the same as that of the classifier branch. They are composed of three convolutional layers with a convolution kernel of 3x3. The number of channels is changed from 256 to 8, and then converted to The final output of the matrix with two columns and two rows is the predicted position coordinates in the regression branch. ; The final output in the classifier branch is the confidence of positive and negative samples ; Count the output results of the classifier branch in the point location generator, and the number of output results that are greater than the set confidence level is the predicted number;
[0022] The density map generator is set to consist of 7 convolutional layers and an upsampling operation. The first six convolution kernels are 3x3 in size, the last convolution kernel is 1x1, the dimension is changed from 512 to 64, and the final output is 1D.
[0023] Feature map output by the backbone network The image is sent to the density map generator for processing through each convolution layer. After the final eight-fold upsampling operation of the density map generator, it becomes a density map with the same size as the input image and a dimension of 1. The density map is subjected to an inverse Gaussian transform to obtain the number of density map predictions.
[0024] Map the coordinates output by the point position generator to the input image to generate an image with coordinates. Use a sliding window of size 90x90 to slide on the image with coordinates. When the number of recognitions in the window is greater than 5, the area is considered to be a high-density area. Map the area position to the density map generated by the density map generator. Use Gaussian inverse transformation on the mapped density map to get the number of , count the number of point coordinates in the remaining non-low-density area , and the final total number is: .
[0025] The training of the multi-density pest counting model includes the following steps:
[0026] Setpoint Position Generator Output points, the actual number of points in the input data is , in order for the training to run properly, set , the coordinates of the predicted points are To express, , the coordinates of the real target point are To express, , Represents the confidence score of the target point, and the loss function is as follows:
[0027] , ,
[0028] ,
[0029] in, and are the loss functions of the classification branch and regression branch in the point position generator, respectively. is the loss function of the density map generator, where represents the Euclidean distance, is the negative sample weighting factor, is the training batch size, is the output of the density map generator, and its parameters are expressed as , represents the input image, Represents the input image The true value of
[0030] The total loss function As shown below:
[0031] ,
[0032] in, is the parameter factor for balancing loss;
[0033] The overall training process of the model is as follows:
[0034] The input image first enters the backbone network, and the feature map is obtained after being processed by the backbone network. , feature map Input to the point location generator and density map generator respectively;
[0035] Point location generator gets feature map Then, two times upsampling and 1x1 convolution are used at the same time, and the results of the two are added element by element to obtain the feature map , feature map They are input into the regressor branch and the classifier branch respectively, and the coordinate values and confidence are obtained after three layers of convolution and one layer of shape transformation; the coordinate values predicted by the regressor branch are and the real coordinates Using loss function Calculate the confidence of the positive and negative samples predicted by the classifier Through the loss function Calculate to ensure that the target position predicted by the regressor is close to the true value and the confidence of the positive sample predicted by the classifier Close to 1, negative sample confidence Close to 0;
[0036] Density map generator gets feature map After 8 convolutional layers and an eight-fold upsampling operation, the density map is obtained. The predicted density map output by the density map generator and the real density map are compared using the loss function Calculate to ensure that the density map predicted by the density map generator is close to the distribution of the real density map;
[0037] Finally, the overall loss will be calculated through the above loss function , back-propagate the network to update the network parameters, thereby completing the overall training of the model.
[0038] Beneficial Effects
[0039] The multi-density pest counting method of the present invention, which combines point positioning and density map, is more accurate in counting pest images of different densities than the prior art. The point positioning counting method used in low-density areas can ensure accurate counting while outputting the pest positions. The density map counting method used in high-density areas can feedback the distribution and output a more accurate estimated number. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 is a method sequence diagram of the present invention;
[0041] Figure 2 It is a schematic diagram of the structure of the multi-density pest counting model involved in the present invention;
[0042] Figure 3 This is a picture of the test effect of the multi-density pest counting model involved in the present invention in the pest image;
[0043] Figure 4This is an index comparison chart of the multi-density pest counting model involved in the present invention and other counting algorithms. DETAILED DESCRIPTION
[0044] In order to have a further understanding and recognition of the structural features and the effects achieved by the present invention, a preferred embodiment and accompanying drawings are used for detailed description as follows:
[0045] like Figure 1 As shown, the multi-density pest counting method combining point positioning and density map of the present invention comprises the following steps:
[0046] The first step is to collect and preprocess multi-density pest images: collect multi-density pest images, remove images with focus failure, blur, and obvious halos, and use the point mode in the labelme tool to mark the pests in the images.
[0047] The second step is the construction of a multi-density pest counting model: a multi-density pest counting model is constructed based on the backbone network combined with the point location generator and the density map generator.
[0048] like Figure 2 As shown in the figure, the multi-density pest counting model consists of three main parts, namely the backbone network, the point location generator and the density map generator. In order to make the three modules play their respective roles, each module is designed to ensure that the output results meet expectations. At the same time, in order to make the three modules work together, it is necessary to adjust the input and output parameters of each module to ensure that the modules are connected correctly. At the same time, in order to simplify the network structure, the backbone network is designed so that both the point location generator and the density map generator can be used directly. At the same time, the multi-density pest counting model adopts an end-to-end overall network structure. Although it contains three main modules and two different forms of output, it is included in one network. The different loss functions designed ensure that each module updates the parameters according to the settings.
[0049] Here, the multi-density pest counting model integrates three modules into one network, streamlines the processing process, realizes the network integrated structure, and makes the model calling and training easier to use.
[0050] (1) The multi-density pest counting model is set up to include a backbone network, a point location generator, and a density map generator; the input image first passes through the backbone network to obtain a feature map , feature map Input point position generator and density map generator; point position generator for feature map At the same time, double upsampling and 1x1 convolution are performed, and the two are added element by element to obtain the feature map ;
[0051] The point location generator outputs the coordinates (x, y) of the predicted point, and the density map generator outputs a density map of the same size as the input image.
[0052] (2) The backbone network is set to consist of 10 convolutional layers and 4 pooling layers. The convolution kernel size is 3x3, the step size is 1, the number of output channels increases from 64 to 128, then to 256, and finally to 512. The pooling layer kernel size is 2x2, the step size is 2, and the input image is gradually condensed to one sixteenth of the original size, with a feature map with 512 channels. .
[0053] (3) The set point position generator consists of two branches, namely the regressor branch and the classifier branch. The feature map output by the backbone network In the point position generator, two times upsampling and 1x1 convolution are performed simultaneously, and the two are added element by element to obtain the feature map. , feature map Input into the two branches of the point position generator respectively;
[0054] The structure of the regressor branch is the same as that of the classifier branch. They are composed of three convolutional layers with a convolution kernel of 3x3. The number of channels is changed from 256 to 8, and then converted to The final output of the matrix with two columns and two rows is the predicted position coordinates in the regression branch. ; The final output in the classifier branch is the confidence of positive and negative samples ; The output results of the classifier branch in the point location generator are counted, and the number of output results that are greater than the set confidence level is the number of predictions that meet the requirements.
[0055] (4) The density map generator is set to consist of 7 convolutional layers and an upsampling operation. The size of the first six convolution kernels is 3x3, the last convolution kernel is 1x1, the dimension is changed from 512 to 64, and the final output is 1D;
[0056] Feature map output by the backbone network The image is sent to the density map generator for processing through each convolutional layer. After the final eight-fold upsampling operation of the density map generator, it becomes a density map with the same size as the input image and a dimension of 1. The density map is subjected to an inverse Gaussian transform to obtain the number of density map predictions.
[0057] (5) Map the coordinates output by the point position generator to the input image to generate an image with coordinates. Use a sliding window of size 90x90 to slide on the image with coordinates. When the number of recognitions in the window is greater than 5, the area is considered to be a high-density area. Map the area position to the density map generated by the density map generator. Use the Gaussian inverse transform on the mapped density map to obtain the number of , count the number of point coordinates in the remaining low-density area , and the final total number is: .
[0058] The third step is training of the multi-density pest counting model: using the preprocessed multi-density pest images to train the multi-density pest counting model.
[0059] The multi-density pest counting model consists of three main parts, namely the backbone network, the point location generator and the density map generator. In order to enable the three modules to update parameters smoothly during the training process, three different loss functions are designed, namely , and At the same time, in order to balance the loss of the entire network, different balance parameters are used for each loss function to balance the final loss. The multi-density pest counting model integrates three modules into one network, simplifies the processing process, realizes the network integration structure, and makes the model calling and training easier to use.
[0060] (1) Setpoint position generator output points, the actual number of points in the input data is , in order for the training to run properly, set , the coordinates of the predicted points are To express, , the coordinates of the real target point are To express, , Represents the confidence score of the target point, and the loss function is as follows:
[0061]
[0062]
[0063] in, and are the loss functions of the classification branch and regression branch in the point position generator, respectively. is the loss function of the density map generator, where represents the Euclidean distance, is the negative sample weighting factor, is the training batch size, is the output of the density map generator, and its parameters are expressed as , represents the input image, Represents the input image The true value of
[0064] The total loss function As shown below:
[0065] ,
[0066] in, is the parameter factor for balancing loss.
[0067] (2) The overall training process of the model is as follows:
[0068] The input image first enters the backbone network, and the feature map is obtained after being processed by the backbone network. , feature map Input to the point location generator and density map generator respectively;
[0069] Point location generator gets feature map Then, two times upsampling and 1x1 convolution are used at the same time, and the results of the two are added element by element to obtain the feature map , feature map They are input into the regressor branch and the classifier branch respectively, and the coordinate values and confidence are obtained after three layers of convolution and one layer of shape transformation; the coordinate values predicted by the regressor branch are and the real coordinates Using loss function Calculate the confidence of the positive and negative samples predicted by the classifier Through the loss function Calculate to ensure that the target position predicted by the regressor is close to the true value and the confidence of the positive sample predicted by the classifier Close to 1, negative sample confidence Close to 0;
[0070] Density map generator gets feature map After 8 convolutional layers and an eight-fold upsampling operation, the density map is obtained. The predicted density map output by the density map generator and the real density map are compared using the loss function Calculate to ensure that the density map predicted by the density map generator is close to the distribution of the real density map;
[0071] Finally, the overall loss will be calculated through the above loss function , back-propagate the network to update the network parameters, thereby completing the overall training of the model.
[0072] Step 4: Acquisition of multi-density pest images to be detected: Acquisition of multi-density pest images to be detected and preprocessing.
[0073] Step 5: Counting the multi-density pests to be detected: input the preprocessed multi-density pest image to be detected into the trained multi-density pest counting model to obtain the multi-density pest counting result.
[0074] like Figure 3 As shown, it is a test effect picture of the multi-density pest counting model involved in the present invention in the pest image. Figure 3 (a) is the picture of the counting effect of the model applied to grain borers. The actual number of pests in the picture is 98, and the model output number is 101; (b) is the picture of the counting effect of the model applied to book lice. The actual number of pests in the picture is 53, and the model output number is 55; (c) is the picture of the counting effect of the model applied to saw-saw grain beetles. The actual number of pests in the picture is 73, and the model output number is 73; (d) is the picture of the counting effect of the model applied to rusty red flat grain beetles. The actual number of pests in the picture is 76, and the model output number is 78. Figure 3 It can be seen that the multi-density pest counting model proposed in the present invention has good counting accuracy in both high-density areas and low-density areas. At the same time, the pest positions in low-density areas can be obtained through the point position generator in the model, and the pest distribution in high-density areas can be obtained through the density map generator in the model.
[0075] like Figure 4 As shown in the figure, it is an index comparison chart of the multi-density pest counting model involved in the present invention and other counting algorithms, using the mean absolute error (MAE) and mean square error (MSE) as test indicators. The smaller the values of the two, the better the effect of the model and the more accurate the counting. Among them, P2PNet and PET are counting algorithms based on point positioning, YOLOv10 and Co-Detr are counting algorithms based on box selection, CCTrans and CSRNet are counting algorithms based on density maps, and Ours represents the counting algorithm proposed in the present invention. From Figure 4 It can be seen that compared with other algorithms, the multi-density pest counting model proposed in the present invention has the lowest number of indicators and the best counting effect.
[0076] The indicators of different pests counted using the multi-density pest counting model are shown in Table 1, and the mean absolute error (MAE) and mean square error (MSE) are used as test indicators. The smaller the values of the two, the better the effect of the model and the more accurate the counting. It can be seen from Table 1 that the multi-density pest counting model involved in the present invention has a good effect on different species of pests, and the indicators are maintained at a very low level. After mixing some species of pests together, the indicators of the mixed pests are also very low, showing a good counting accuracy.
[0077] Table 1 Index table of different pests counted using multi-density pest counting model
[0078] Pest Types Grain borer Sawtooth beetle Booklice Rhizoctonia rubrum Mixed worms Mean Absolute Error (MAE) 1.23 1.88 8.32 1.63 3.13 Mean Square Error (MSE) 3.34 4.36 12.56 4.11 5.63
[0079] The above shows and describes 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 above embodiments and descriptions only describe the principles of the present invention. The present invention may be subject to various changes and improvements without departing from the spirit and scope of the present invention. These changes and improvements fall within the scope of the present invention. The scope of protection claimed by the present invention is defined by the attached claims and their equivalents.
Claims
1. A multi-density pest counting method combining point location and density map, characterized in that: The following steps are involved: 11) Collection and preprocessing of multi-density pest images: Collect multi-density pest images, remove images with focus failure, blur, and obvious halos, and use the point mode in the labelme tool to annotate the pests in the images; 12) Construction of multi-density pest counting model: A multi-density pest counting model is constructed based on the backbone network combined with the point location generator and the density map generator; 13) Training of multi-density pest counting model: Use the preprocessed multi-density pest images to train the multi-density pest counting model; 14) Acquisition of images of multi-density pests to be detected: Acquisition of images of multi-density pests to be detected and pre-processing; 15) Counting of multi-density pests to be detected: The preprocessed multi-density pest images to be detected are input into the trained multi-density pest counting model to obtain the multi-density pest counting results.
2. A method for counting multi-density pests combining point location and density map according to claim 1, characterized in that: The construction of the multi-density pest counting model comprises the following steps: 21) Set the multi-density pest counting model to include a backbone network, a point location generator, and a density map generator; the input image first passes through the backbone network to obtain a feature map , feature map Input point position generator and density map generator; point position generator for feature map At the same time, double upsampling and 1x1 convolution are performed, and the two are added element by element to obtain the feature map ; The point position generator outputs the coordinates (x, y) of the predicted point, and the density map generator outputs a density map of the same size as the input image; 22) The backbone network is set to consist of 10 convolutional layers and 4 pooling layers. The convolution kernel size is 3x3, the step size is 1, the number of output channels increases from 64 to 128, then to 256, and finally to 512. The pooling layer kernel size is 2x2, the step size is 2, and the input image is gradually condensed to one sixteenth of the original size, with a feature map with 512 channels. ; 23) The set point position generator consists of two branches, namely the regressor branch and the classifier branch. The feature map output by the backbone network In the point position generator, two times upsampling and 1x1 convolution are performed simultaneously, and the two are added element by element to obtain the feature map. , feature map Input into the two branches of the point position generator respectively; The structure of the regressor branch is the same as that of the classifier branch. They are composed of three convolutional layers with a convolution kernel of 3x3. The number of channels is changed from 256 to 8, and then converted to The final output of the matrix with two columns and two rows is the predicted position coordinates in the regression branch. ; The final output in the classifier branch is the confidence of positive and negative samples ; Count the output results of the classifier branch in the point location generator, and the number of output results that are greater than the set confidence level is the predicted number; 24) Set the density map generator to consist of 7 convolutional layers and an upsampling operation. The first six convolution kernels are 3x3 in size, the last convolution kernel is 1x1, the dimension is changed from 512 to 64, and the final output is 1D. Feature map output by the backbone network The image is sent to the density map generator for processing through each convolution layer. After the final eight-fold upsampling operation of the density map generator, it becomes a density map with the same size as the input image and a dimension of 1. The density map is subjected to an inverse Gaussian transform to obtain the number of density map predictions. 25) Map the coordinates output by the point position generator to the input image to generate an image with coordinates. Use a sliding window of size 90x90 to slide on the image with coordinates. When the number of recognitions in the window is greater than 5, the area is considered to be a high-density area. Map the area position to the density map generated by the density map generator. Use Gaussian inverse transform on the mapped density map to get the number of , count the number of point coordinates in the remaining non-low-density area , and the final total number is: .
3. A method for counting multi-density pests combining point location and density map according to claim 1, characterized in that: The training of the multi-density pest counting model includes the following steps: 31) Set point position generator output points, the actual number of points in the input data is , in order for the training to run properly, set , the coordinates of the predicted points are To express, , the coordinates of the real target point are To express, , Represents the confidence score of the target point, and the loss function is as follows: , , , in, and are the loss functions of the classification branch and regression branch in the point position generator, respectively. is the loss function of the density map generator, where represents the Euclidean distance, is the negative sample weighting factor, is the batch size for training, is the output of the density map generator, and its parameters are expressed as , represents the input image, Represents the input image The true value of The total loss function As shown below: , in, is the parameter factor for balancing loss; 32) The overall training process of the model is as follows: The input image first enters the backbone network, and the feature map is obtained after being processed by the backbone network. , feature map Input to the point location generator and density map generator respectively; Point location generator gets feature map Then, two times upsampling and 1x1 convolution are used at the same time, and the results of the two are added element by element to obtain the feature map , feature map They are input into the regressor branch and the classifier branch respectively, and the coordinate values and confidence are obtained after three layers of convolution and one layer of shape transformation; the coordinate values predicted by the regressor branch are and the real coordinates Using loss function Calculate the confidence of the positive and negative samples predicted by the classifier Through the loss function Calculate to ensure that the target position predicted by the regressor is close to the true value and the confidence of the positive sample predicted by the classifier Close to 1, negative sample confidence Close to 0; Density map generator gets feature map After 8 convolutional layers and an eight-fold upsampling operation, the density map is obtained. The predicted density map output by the density map generator and the real density map are compared using the loss function Calculate to ensure that the density map predicted by the density map generator is close to the distribution of the real density map; Finally, the overall loss will be calculated through the above loss function , back-propagate the network to update the network parameters, thereby completing the overall training of the model.
