Automatic counting method for crop seeds

By constructing an automatic seed counting model, using the technology of feature extraction, local and global information fusion, the problems of inefficient crop seed counting and insufficient accuracy in the existing technology are solved, and efficient and accurate automatic crop seed counting is achieved.

CN119559144APending Publication Date: 2025-03-04INST OF GENETICS & DEVELOPMENTAL BIOLOGY CHINESE ACAD OF SCI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411674615.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-21
Publication Date
2025-03-04

AI Technical Summary

Technical Problem

In the prior art, the counting of crop seeds mainly depends on artificial methods, is inefficient and prone to errors, making it difficult to meet the needs of modern agriculture for efficient and accurate data acquisition.

Method used

An automatic crop seed counting method is adopted to pre-process and data enhancement of seed acquisition images, and an automatic seed counting model is constructed, including feature extraction layer, local layer, global layer, fusion layer and density map generation layer. The loss function is used for training to achieve automatic counting of crop seeds.

Benefits of technology

This method can effectively improve the accuracy and robustness of crop seed counting, especially in images with large seed counts and large density variations, which can accurately identify the details and edges of each seed to reduce the situation of repeated counting or missed counting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119559144A_ABST
    Figure CN119559144A_ABST
Patent Text Reader

Abstract

The invention provides a crop seed automatic counting method, and relates to the technical field of machine learning, and the method comprises the steps: carrying out the preprocessing and data enhancement of a seed collection image, and obtaining a seed image training set; constructing an automatic seed counting model by using the feature extraction layer, the local layer, the global layer, the fusion layer and the density map generation layer; inputting a seed image data set into a seed automatic counting model, and training by using a loss function to obtain a trained seed automatic counting model; wherein the trained seed automatic counting model is used for analyzing the crop seed image to obtain a seed counting result, and automatic counting of the crop seeds is completed. The problem that crop seeds are difficult to count accurately is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of machine learning technology, and in particular to a method for automatically counting crop seeds. Background Art

[0002] The number of seeds harvested from crops is an important indicator in agricultural production, and has a direct impact on sowing density, yield prediction, and seed quality assessment. Accurately obtaining the number of crop seeds has important theoretical significance and application value for optimizing sowing strategies, increasing agricultural yields, and ensuring seed quality. At present, the counting of crop seeds mainly relies on manual methods, which usually requires manual counting of seeds. This method is not only inefficient, especially time-consuming and labor-intensive when dealing with large quantities of seeds, but also easily affected by human factors, resulting in errors in counting results. In addition, traditional manual counting methods are difficult to meet the needs of modern agriculture for efficient and accurate data acquisition. Summary of the invention

[0003] In view of the above-mentioned deficiencies in the prior art, the present invention provides an automatic crop seed counting method which solves the problem that it is difficult to accurately count crop seeds.

[0004] In order to achieve the above-mentioned invention object, the technical solution adopted by the present invention is: a method for automatically counting crop seeds, comprising:

[0005] S1: The seed image training set is obtained by preprocessing and data enhancement of the seed collection images;

[0006] S2: Build a seed automatic counting model using feature extraction layer, local layer, global layer, fusion layer and density map generation layer;

[0007] S3: By inputting the seed image data set into the seed automatic counting model, training is performed using a loss function to obtain a trained seed automatic counting model; wherein the trained seed automatic counting model is used to analyze crop seed images, obtain seed counting results, and complete automatic counting of crop seeds.

[0008] The beneficial effects of the present invention are as follows: the processor obtains the seed counting result in the image by integrating the density map. (1) The features extracted by the seed counting model combine the rich local and global information. The local features can help identify the details and edges of each seed and accurately locate the position of a single seed; the global features can capture the overall pattern and long-distance dependence of the seed distribution, especially in the seed-dense area, which can better identify the seeds close to each other and reduce the situation of repeated counting or missing counting; (2) The seed counting model can obtain contextual information while maintaining the ability to recognize details, thereby improving the accuracy and robustness of counting in complex backgrounds or scenes with overlapping seeds; (3) This fusion method can effectively improve the accuracy of seed counting tasks, especially in images with a large number of seeds and large density changes.

[0009] Further, the S1 includes:

[0010] The target area image is collected using an RGB camera to obtain a seed collection image;

[0011] Adjusting parameters, cropping images and adding labels to the seed collection images to obtain a seed image dataset; wherein the seed image dataset includes a training set, a validation set and a test set;

[0012] The training set is randomly cropped, randomly flipped in horizontal and vertical directions, rotated at random angles, scaled at random ratios, and randomly changed in brightness, contrast, saturation and hue, and spliced ​​using mosaic data enhancement to obtain the seed image training set.

[0013] Through data preprocessing and enhancement, the diversity of the seed image dataset and the generalization ability of the model are significantly improved. (1) Parameter adjustment, cropping and label addition ensure that the quality of the seed image dataset is suitable for subsequent modeling. (2) Data enhancement operations such as random cropping, flipping, rotation and scaling can simulate various observation conditions in real scenes and make the model more robust. (3) Mosaic data enhancement allows the model to learn the feature distribution of multiple targets in the same image by randomly splicing multiple images of different crop seeds together, which helps to more efficiently capture the differences between the features of different seeds (such as rice, wheat, corn, etc.), thereby improving the model's adaptability and detection accuracy to complex and diverse seed scenes.

[0014] Furthermore, the automatic seed counting model in S2 includes:

[0015] A feature extraction layer, comprising a feature extraction module, a splicing module and a compression module, for performing multi-scale feature extraction on the seed image training set, and obtaining a first separation feature map and a second separation feature map based on a separation ratio;

[0016] A local layer, including a convolution module and a channel attention module, is used to perform convolution and attention enhancement processing on the first separation feature map to obtain a local output feature map;

[0017] A global layer, including a fast Fourier transform module, a spatial attention module, and a connection module, for obtaining a global output feature map by performing convolution, fast Fourier transform, adding spatial positions, and fusing local and global information on the second separation feature map;

[0018] A fusion layer, used for performing additive fusion on the local output feature map and the global output feature map to obtain a fused feature map;

[0019] The density map generation layer is used to perform deconvolution processing on the fused feature map to obtain a seed counting result.

[0020] Furthermore, the feature extraction layer includes:

[0021] A feature extraction module, used for performing convolution and pooling processing on the seed image training set to obtain a multi-scale feature map; wherein the multi-scale feature map includes feature maps of sizes H / 4×W / 4, H / 8×W / 8, and H / 16×W / 16;

[0022] The splicing module is used to perform maximum pooling on the feature map of size H / 4×W / 4 and downsample it to size H / 8×W / 8; use nearest neighbor interpolation to upsample the feature map of size H / 16×W / 16 to size H / 8×W / 8; and splice the scaled feature map to obtain a spliced ​​feature map;

[0023] A compression module is used to convolve the concatenated feature map to reduce the dimension of the feature map and keep the size of the feature map unchanged to obtain a compressed feature map; based on the separation ratio, the compressed feature map is divided to obtain the first separated feature map and the second separated feature map.

[0024] Through multi-level feature extraction and fusion, the model's ability to represent multi-scale targets is improved. (1) The feature extraction module generates a multi-scale feature map through convolution and pooling, enabling the model to capture features of different sizes and shapes in the seed image. (2) The splicing module aligns features between different scales, balances the fusion of resolution and context information, and splices multi-scale features into a unified spliced ​​feature map. (3) The compression module reduces the feature dimension and extracts more refined semantic information. (4) The separation operation divides the features according to the separation ratio, and divides the extracted feature map into a first separation feature map and a second separation feature map, which helps to optimize the feature expression of different scales respectively.

[0025] Furthermore, the global layer includes:

[0026] A fast Fourier transform module, used for performing convolution and fast Fourier transform on the second separation feature map to obtain long-distance dependency information;

[0027] A spatial attention module, configured to process the second separation feature map using a spatial attention mechanism based on the long-distance dependency information to obtain a second separation feature map with enhanced important spatial position information;

[0028] The connection module is used to obtain a global output feature map through inverse Fourier transform and residual connection based on the second separated feature map of the enhanced important spatial position information.

[0029] The global layer significantly enhances the model's ability to capture global features by combining frequency domain information and spatial attention mechanisms. (1) The fast Fourier transform module maps features from the spatial domain to the frequency domain by performing convolution and fast Fourier transform on the second separated feature map, effectively extracting long-distance dependency information and supplementing global context features that are difficult to capture with traditional convolution operations. (2) The spatial attention module uses the extracted long-distance dependency information to focus on key spatial positions in the feature map. By enhancing the information of important spatial positions, the model's attention ability is further improved, enabling it to focus on salient target areas in the image. (3) The connection module restores frequency domain features to the spatial domain through inverse Fourier transform, and combines residual connections to integrate the global information processed in the frequency domain with the original feature map, avoiding information loss and enhancing the robustness of feature expression.

[0030] Furthermore, the loss function is expressed as:

[0031]

[0032] Among them, L Bayes represents the loss function result, F represents the l1 distance function, E[c n ] means c n The expected value of n Represents y n The total number of correlations, n represents y n The index of N represents the target point y n The total number of represents the contribution count of xm to yn, m represents the index of xm, M represents the total number of xm, p(y n |x m ) represents xm to y n The probability estimate of est Represents the position x m The density estimate of y n Indicates the actual position of the target point, x m Indicates the location of the input data.

[0033] Bayesian loss optimizes the prediction accuracy of target points in point-level supervision tasks by introducing the matching degree between the probability distribution of target points and the position estimate. This loss function represents the association between the target point and the input position with probability, and weights the contribution of each input position in combination with the density estimate to generate a total expected value. By accumulating the expected loss of all target points, this function effectively solves the overlap problem in dense target scenes, enabling the model to adapt more robustly to changes in the distance between target points while improving the overall positioning accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] This specification will be further described in the form of exemplary embodiments, which will be described in detail by the accompanying drawings. These embodiments are not restrictive, and in these embodiments, the same number represents the same structure, wherein:

[0035] Figure 1 It is an exemplary flow chart of a method for automatically counting crop seeds according to some embodiments of this specification. DETAILED DESCRIPTION

[0036] The specific implementation modes of the present invention are described below so that those skilled in the art can understand the present invention. However, it should be clear that the present invention is not limited to the scope of the specific implementation modes. For those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the attached claims, these changes are obvious, and all inventions and creations utilizing the concept of the present invention are protected.

[0037] Example

[0038] Figure 1 is an exemplary flow chart of a method for automatically counting crop seeds according to some embodiments of this specification. Figure 1 As shown, the process includes the following steps. In some embodiments, the process can be executed by a processor.

[0039] S1: The seed image training set is obtained by preprocessing and data enhancement of the seed collection images.

[0040] Seed collection images are original photographed images of crop seeds.

[0041] In some embodiments, the processor may use an RGB camera to take a bird's-eye view of a target area with uniform illumination and less reflection, or use a scanning device to scan the target area to obtain a seed collection image.

[0042] The seed image training set is a crop seed image dataset used to train the automatic seed counting model.

[0043] In some embodiments, the processor can randomly crop the training set, randomly flip it horizontally and vertically, rotate it at random angles, scale it at random ratios, randomly change its brightness, contrast, saturation and hue, and splice it using mosaic data enhancement to obtain a seed image training set.

[0044] In some embodiments, the processor can implement S1 based on the following steps: using an RGB camera to collect images of the target area to obtain a seed collection image; adjusting parameters, cropping and adding labels to the seed collection image to obtain a seed image data set; randomly cropping, randomly flipping in the horizontal and vertical directions, rotating at random angles, scaling at random proportions, randomly changing brightness, contrast, saturation and hue of the training set, and splicing it using mosaic data enhancement to obtain the seed image training set.

[0045] The seed image dataset is the seed collection images after adding labels and adjusting parameters. For example, the seed image dataset may include a training set, a validation set, and a test set.

[0046] The training set is the dataset used to train the automatic seed counting model.

[0047] The validation set is a dataset used to verify the effect of the trained seed automatic counting model.

[0048] The test set is a dataset used to test the performance of the trained seed automatic counting model.

[0049] In some embodiments, the processor can adjust parameters such as brightness and contrast of the seed collection image and crop it, add a label of each seed position to the cropped image, and divide the data set into a training set, a validation set, and a test set in a ratio of 8:1:1 to obtain a seed image data set.

[0050] S2: Build an automatic seed counting model using feature extraction layer, local layer, global layer and fusion layer.

[0051] The automatic seed counting model is used to analyze the number of seeds in the crop seed image to obtain the seed counting result. There are many types of automatic seed counting models. For example, the type of automatic seed counting model may include a convolutional neural network model.

[0052] In some embodiments, the input of the automatic seed counting model may be a seed image training set, and the output of the automatic seed counting model may be a seed counting result.

[0053] In some embodiments, the structure of the seed automatic counting model is as follows: the seed automatic counting model includes a feature extraction layer, a local layer, a global layer, a fusion layer, and a density map generation layer. The output of the feature extraction layer is used as the input of the local layer and the global layer, the output of the local layer and the global layer is used as the input of the fusion layer, the output of the fusion layer is used as the input of the density map generation layer, and the output of the density map generation layer is used as the final output of the seed automatic counting model.

[0054] The feature extraction layer is used to perform multi-scale feature extraction on the seed image training set, and obtain a first separation feature map and a second separation feature map based on the separation ratio. The input of the feature extraction layer may include the seed image training set, and the output may include the first separation feature map and the second separation feature map. The feature extraction layer may use VGG16 as the backbone network.

[0055] The first separation feature map is a seed image training set for performing local analysis within the separation ratio. For example, the first separation feature map may include a seed image training set with a channel number of 256×α, where α represents the separation ratio.

[0056] The second separation feature map is a seed image training set for global analysis outside the separation ratio. The second separation feature map may include a seed image training set with a channel number of 256×(1-α).

[0057] In some embodiments, the feature extraction layer may include a feature extraction module, a splicing module, and a compression module.

[0058] The feature extraction module is used to perform convolution and pooling processing on the seed image training set to obtain a multi-scale feature map. The input of the feature extraction module may include the seed image training set, and the output may include the multi-scale feature map.

[0059] The multi-scale feature map is an image of different scales reflecting the seed features of the seed image training set. For example, the multi-scale feature map may include feature maps of sizes H / 4×W / 4, H / 8×W / 8, and H / 16×W / 16.

[0060] In some embodiments, the expression of the multi-scale feature map may be:

[0061]

[0062] Among them, F1 represents H / 4×W / 4 feature map, F2 represents H / 8×W / 8 feature map, F3 represents H / 16×W / 16 feature map, R represents that the tensor dimension of the feature map is in the real number domain, H represents the height of the input image, W represents the width of the input image, and C represents the number of channels of the feature map.

[0063] The splicing module is used to perform maximum pooling on the feature map of size H / 4×W / 4 and downsample it to size H / 8×W / 8; use nearest neighbor interpolation to upsample the feature map of size H / 16×W / 16 to size H / 8×W / 8; and splice the scaled feature map to obtain a spliced ​​feature map. The input of the splicing module may include multi-scale feature maps, and the output may include a spliced ​​feature map.

[0064] In some embodiments, the expression of the concatenated feature map may be:

[0065]

[0066] Among them, F concat represents the concatenated feature map, Concat represents the concatenation function, F1' represents the H / 4×W / 4 feature map after downsampling, and F3' represents the H / 16×W / 16 feature map after upsampling.

[0067] The concatenated feature map is an image with a uniform size that reflects the seed features of the seed image training set. For example, the concatenated feature map may include a feature map of H / 8×W / 8×896.

[0068] A compression module is used to convolve the concatenated feature map to reduce the dimension of the feature map and keep the size of the feature map unchanged to obtain a compressed feature map; based on the separation ratio, the compressed feature map is divided to obtain the first separation feature map and the second separation feature map. The input of the compression module may include the concatenated feature map, and the output may include the first separation feature map and the second separation feature map.

[0069] In some embodiments, the expressions of the first separation characteristic graph and the second separation characteristic graph may be:

[0070]

[0071] F l =F compressed [:,:,:256α];

[0072] F g =F compressed [:,:,256α:];

[0073] Among them, F compressed Represents the concatenated feature map after convolution, Conv 1×1 represents 1×1 convolution, F l represents the first separation feature map, α represents the separation ratio, F g Represents the second separation feature map.

[0074] The compressed feature map is a concatenated feature map after convolution compression of the number of channels. For example, the compressed feature map may include a feature map of H / 8×W / 8×256.

[0075] The local layer is used to perform convolution and weighting processing on the first separation feature map to obtain a local output feature map. The input of the local layer may include the first separation feature map, and the output may include the local output feature map.

[0076] The local output feature map is an image that reflects the local feature information of the seed image training set.

[0077] In some embodiments, the local layer may include a convolution module and a channel attention module, wherein the convolution module may perform a 3x3 convolution operation on the first separation feature map to extract detail features, and the channel attention module may utilize the channel attention mechanism to enhance the weights of important channels in the feature map, and apply batch normalization and ReLU activation function to obtain a local output feature map.

[0078] In some embodiments, the expression of the local output feature map may be:

[0079]

[0080] Among them, F l ' represents the local output feature map, ReLU represents the ReLU activation function, BatchNorm represents batch normalization, Conv 3×3 represents 3×3 convolution, represents the element-by-element multiplication operation, A c represents the channel attention weight.

[0081] The global layer is used to obtain a global output feature map by performing convolution, fast Fourier transform, adding spatial position, and fusing local and global information on the second separation feature map. The input of the global layer may include the second separation feature map, and the output may include the global output feature map.

[0082] In some embodiments, the expression of the global output feature map may be:

[0083] F g,FFT =FFT(F g );

[0084] Fg'=IFFT(Attention(Fg, FFT ))+Fg;

[0085] Among them, F g,FFT represents long-distance dependent information, FFT represents fast Fourier transform, F g' represents the global output feature map, IFFT represents the inverse Fourier transform, and Attention represents the spatial attention mechanism.

[0086] The global output feature map is an image that reflects the global feature information of the seed image training set.

[0087] In some embodiments, the global layer may include a fast Fourier transform module, a spatial attention module, and a connection module.

[0088] The fast Fourier transform module is used to perform convolution and fast Fourier transform on the second separation feature map to obtain long-distance dependency information. The input of the fast Fourier transform module may include the second separation feature map, and the output may include the long-distance dependency information.

[0089] The long-distance dependency information is information reflecting the long-distance dependency of the seed position in the second separation feature map.

[0090] In some embodiments, the processor may allow the second separated feature map to undergo 3x3 convolution, batch normalization, and ReLU activation, and convert it to the frequency domain through a fast Fourier transform module to obtain long-distance dependency information.

[0091] A spatial attention module is used to process the second separation feature map using a spatial attention mechanism based on the long-distance dependency information to obtain a second separation feature map with enhanced important spatial position information. The input of the spatial attention module may include the long-distance dependency information and the second separation feature map, and the output may include the second separation feature map with enhanced important spatial position information.

[0092] The second separated feature map that enhances the important spatial position information is a second separated feature map that focuses on reflecting the important spatial position.

[0093] In some embodiments, the processor may perform convolution and activation processing on the second separation feature map using a spatial attention mechanism based on long-distance dependency information to obtain a second separation feature map that enhances important spatial position information.

[0094] A connection module is used to obtain a global output feature map based on the second separated feature map that enhances the important spatial position information through inverse Fourier transform and residual connection. The input of the spatial attention module may include the second separated feature map that enhances the important spatial position information, and the output may include the global output feature map.

[0095] In some embodiments, the processor can use an inverse Fourier transform to bring the second separated feature map that enhances important spatial position information back to the real space, add the inverse transformed features to the original second separated feature map through a residual connection to form a fusion of local and global information, and finally adjust the number of channels or fuse features through a 1x1 convolution to obtain an enhanced feature map with multi-scale and global context information as a global output feature map.

[0096] The fusion layer is used to perform additive fusion on the local output feature map and the global output feature map to obtain a fused feature map. The input of the fusion layer may include the local output feature map and the global output feature map, and the output may include the fused feature map.

[0097] The fused feature map is a feature map that fuses the local output feature map and the global output feature map.

[0098] In some embodiments, the processor may perform additive fusion on the partial output feature map and the global output feature map to obtain a fused feature map.

[0099] In some embodiments, the expression of the fused feature map may be:

[0100]

[0101] Among them, F output represents the fusion feature map, C out Indicates the number of channels of the output feature map.

[0102] The density map generation layer is used to perform deconvolution processing on the fused feature map to obtain a seed counting result. The input of the fusion layer may include the fused feature map, and the output may include a seed counting result. The seed counting result is a result representing the number and position information of seeds in the crop seed image.

[0103] In some embodiments, the processor can restore the feature map to the same resolution as the original image through deconvolution of the density map generation to obtain a seed counting result; wherein each pixel value of the seed counting result represents the seed density at that position and its neighborhood.

[0104] In some embodiments, the expression of the seed count result may be:

[0105]

[0106] D=Deconv(F output )∈R H×W ;

[0107] Among them, N seedsrepresents the seed counting result, D represents the density map after deconvolution, i and j represent the pixel coordinates in the density map, and Deconv represents the deconvolution operation.

[0108] S3: By inputting the seed image data set into the seed automatic counting model, training is performed using a loss function to obtain a trained seed automatic counting model; wherein the trained seed automatic counting model is used to analyze crop seed images, obtain seed counting results, and complete automatic counting of crop seeds.

[0109] The crop seed image is a data image containing crop seeds.

[0110] In some embodiments, the seed automatic counting model can be obtained by training multiple labeled training samples. For example, multiple labeled training samples can be input into the initial seed automatic counting model, and the loss function can be constructed by the labels and the results of the initial seed automatic counting model. The labeled points are used as the probability distribution center and the learning rate is dynamically adjusted using the Adam optimizer. The parameters of the initial seed automatic counting model are iteratively updated based on the loss function by gradient descent or other methods. When the preset conditions are met, the model training is completed and a trained seed automatic counting model is obtained. Among them, the preset conditions can be that the loss function converges, the number of iterations reaches a threshold, etc.

[0111] By treating the marked points as the center of the probability distribution, all seeds in dense areas can be effectively detected, improving the counting accuracy of seeds in occluded and dense scenes.

[0112] In some embodiments, the training sample may include a seed image training set. The label may be a corresponding seed counting result. The label may be manually annotated.

[0113] In some embodiments, the loss function may be expressed as:

[0114]

[0115] Among them, L Bayes represents the loss function result, F represents the l1 distance function, E[c n ] means c n The expected value of n Represents y n The total number of correlations, n represents y n The index of N represents the target point y n The total number of represents the contribution count of xm to yn, m represents the index of xm, M represents the total number of xm, p(y n |x m ) represents xm to y n The probability estimate ofest Represents the position x m The density estimate of y n Indicates the actual position of the target point, x m Indicates the location of the input data.

[0116] In some embodiments, the processor can use the mean square error as an indicator to perform a preliminary evaluation on the validation set to adjust the seed automatic counting model hyperparameters and training strategies, and perform a final evaluation on the test set to determine the performance of the seed automatic counting model on unseen data; by comparing the MAE of multiple seed automatic counting models on the test set, the seed automatic counting model with the smallest error is selected as the final seed automatic counting model.

[0117] In some embodiments, the expression of mean square error may be:

[0118]

[0119] Among them, MAE represents the mean square error value, n represents the total number of samples, and y i represents the true value of sample i, Represents the predicted value of sample i.

[0120] In some embodiments, the processor can use a trained automatic seed counting model to analyze crop seed images, use a feature extraction layer to perform multi-scale feature extraction on a seed image training set, and obtain a first separation feature map and a second separation feature map based on the separation ratio; use a local layer to convolve and weight the first separation feature map to obtain a local output feature map; use a global layer to convolve, fast Fourier transform, add spatial position, and fuse local and global information on the second separation feature map to obtain a global output feature map; use a fusion layer to perform additive fusion on the local output feature map and the global output feature map, and obtain a seed counting result through density map generation to complete the automatic counting of crop seeds.

[0121] In some embodiments of the present specification, the processor obtains the seed counting result in the image by integrating the density map. (1) The features extracted by the seed counting model combine the rich local and global information. The local features can help identify the details and edges of each seed and accurately locate the position of a single seed; the global features can capture the overall pattern and long-distance dependence of the seed distribution, especially in areas with dense seeds, which can better identify seeds close to each other and reduce repeated counting or omissions; (2) The seed counting model can obtain contextual information while maintaining the ability to recognize details, thereby improving the accuracy and robustness of counting in complex backgrounds or scenes with overlapping seeds; (3) This fusion method can effectively improve the accuracy of seed counting tasks, especially in images with a large number of seeds and large density changes.

Claims

1. A method for automatically counting crop seeds, characterized in that: include: S1: The seed image training set is obtained by preprocessing and data enhancement of the seed collection images; S2: Build a seed automatic counting model using feature extraction layer, local layer, global layer, fusion layer and density map generation layer; S3: By inputting the seed image data set into the seed automatic counting model, training is performed using a loss function to obtain a trained seed automatic counting model; wherein the trained seed automatic counting model is used to analyze crop seed images, obtain seed counting results, and complete automatic counting of crop seeds.

2. The automatic crop seed counting method according to claim 1, characterized in that: The S1 includes: The target area image is collected using an RGB camera to obtain a seed collection image; Adjusting parameters, cropping images and adding labels to the seed collection images to obtain a seed image dataset; wherein the seed image dataset includes a training set, a validation set and a test set; The training set is randomly cropped, randomly flipped in horizontal and vertical directions, rotated at random angles, scaled at random ratios, and randomly changed in brightness, contrast, saturation and hue, and spliced ​​using mosaic data enhancement to obtain the seed image training set.

3. The automatic crop seed counting method according to claim 1, characterized in that: The automatic seed counting model in S2 includes: A feature extraction layer, comprising a feature extraction module, a splicing module and a compression module, for performing multi-scale feature extraction on the seed image training set, and obtaining a first separation feature map and a second separation feature map based on a separation ratio; A local layer, including a convolution module and a channel attention module, is used to perform convolution and attention enhancement processing on the first separation feature map to obtain a local output feature map; A global layer, including a fast Fourier transform module, a spatial attention module, and a connection module, for obtaining a global output feature map by performing convolution, fast Fourier transform, adding spatial positions, and fusing local and global information on the second separation feature map; A fusion layer, used for performing additive fusion on the local output feature map and the global output feature map to obtain a fused feature map; The density map generation layer is used to perform deconvolution processing on the fused feature map to obtain a seed counting result.

4. The automatic crop seed counting method according to claim 3, characterized in that: The feature extraction layer comprises: A feature extraction module, used for performing convolution and pooling processing on the seed image training set to obtain a multi-scale feature map; wherein the multi-scale feature map includes feature maps of sizes H / 4×W / 4, H / 8×W / 8, and H / 16×W / 16; The splicing module is used to perform maximum pooling on the feature map of size H / 4×W / 4 and downsample it to size H / 8×W / 8; use nearest neighbor interpolation to upsample the feature map of size H / 16×W / 16 to size H / 8×W / 8; and splice the scaled feature map to obtain a spliced ​​feature map; A compression module is used to convolve the concatenated feature map to reduce the dimension of the feature map and keep the size of the feature map unchanged to obtain a compressed feature map; based on the separation ratio, the compressed feature map is divided to obtain the first separated feature map and the second separated feature map.

5. The automatic crop seed counting method according to claim 3, characterized in that: The global layer includes: A fast Fourier transform module, used for performing convolution and fast Fourier transform on the second separation feature map to obtain long-distance dependency information; A spatial attention module, configured to process the second separation feature map using a spatial attention mechanism based on the long-distance dependency information to obtain a second separation feature map with enhanced important spatial position information; The connection module is used to obtain a global output feature map through inverse Fourier transform and residual connection based on the second separated feature map of the enhanced important spatial position information.

6. The automatic crop seed counting method according to claim 1, characterized in that: The expression of the loss function is: Among them, L Bayes represents the loss function result, F represents the l1 distance function, E[c n ] means c n The expected value of n Represents y n The total number of correlations, n represents y n The index of N represents the target point y n The total number of represents the contribution count of xm to yn, m represents the index of xm, M represents the total number of xm, p(y n |x m ) represents xm to y n The probability estimate of est Represents the position x m The density estimate of y n Indicates the actual position of the target point, x m Indicates the location of the input data.