Grain semantic segmentation method based on multi-feature fusion and related equipment
The grain semantic segmentation method through multi-feature fusion, using the improved U-Net network and attention mechanism, solves the problem of difficulty in segmenting adherent grain particles with traditional methods, achieves accurate identification and classification of grain particles, and improves detection efficiency. and precision.
Patent Information
- Application Number
- CN202410942818.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-15
AI Technical Summary
During the grain detection process, traditional image processing methods are difficult to effectively segment adhering grain particles, resulting in incomplete extraction of target grain particle information and affecting grain processing efficiency and quality.
Using a grain semantic segmentation method based on multi-feature fusion, by constructing a multi-feature extraction module and an improved U-Net network model, combined with the CBAM-SimAM attention mechanism, RGB features, edge features and grayscale features are extracted, and Gaussian distribution weights are used The loss function achieves accurate segmentation of adherent grain particles.
In the state of grain adhesion, the target grain particles can be effectively extracted and the excess parts are detected as background, which improves the accuracy of identification and classification of grain particles and improves detection efficiency and accuracy.
Smart Images

Figure CN118470334B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of crop image recognition, and in particular to a grain semantic segmentation method based on multi-feature fusion, a grain semantic segmentation system based on multi-feature fusion, an electronic device and a computer-readable storage medium. Background Art
[0002] With the development of modern agriculture and the improvement of people's living standards, agriculture has become increasingly prominent as the foundation of the national economy. However, in my country's agricultural production, the problem of over-processing of grains is still relatively common, which not only causes a large amount of food waste, but also restricts agricultural efficiency and farmers' income. The loss of grain due to over-processing every year has become one of the important factors affecting national food security.
[0003] In order to reduce food losses and improve the quality and efficiency of grain processing, it is crucial to accurately detect and control the quality of grains. In the grain processing process, grain segmentation is the basis for evaluating grain quality, which directly affects the accuracy of subsequent processing steps and product quality. However, in the current grain detection stage, there are generally challenges of dense adhesion and small size of grain particles. The target grain particles are often tightly adhered to other particles, which makes it difficult for traditional image processing methods to effectively perform grain semantic segmentation, and thus it is difficult to extract complete grain particle information. Summary of the invention
[0004] The present invention aims to solve one of the technical problems in the related art to at least a certain extent. To this end, the first purpose of the present invention is to propose a grain semantic segmentation method based on multi-feature fusion, which segments grain images with adhered grain grains through an improved grain semantic segmentation model, and the segmented grain images only include target grain grains, which solves the problem that in the state of grain adhesion, the target grain grains can be effectively extracted, and the excess grains can be accurately detected as background, thereby achieving accurate recognition and classification of grain grains.
[0005] To achieve the above object, a first embodiment of the present invention proposes a grain semantic segmentation method based on multi-feature fusion, comprising:
[0006] Acquire a target grain image, and pre-process the target grain image to obtain a first grain image; wherein the first grain image includes target grain particles and adhered grain particles;
[0007] The first grain image is input into a pre-built grain semantic segmentation model to segment target grain particles and adhered grain particles, thereby obtaining a second grain image output by the grain semantic segmentation model; wherein the second grain image includes target grain particles.
[0008] In addition, the grain semantic segmentation method based on multi-feature fusion according to the above embodiment of the present invention may also have the following additional technical features:
[0009] As an optional embodiment, the grain semantic segmentation model includes a multi-feature extraction module, and the multi-feature extraction module is constructed in the following manner:
[0010] constructing a first feature extraction channel, wherein the first feature extraction channel is used to extract RGB features from the first grain image;
[0011] constructing a second feature extraction channel, wherein the second feature extraction channel is used to perform edge detection on the first grain image to extract edge features of the first grain image;
[0012] constructing a third feature extraction channel, wherein the third feature extraction channel is used to perform histogram equalization processing on the first grain image to extract grayscale features of the first grain image;
[0013] A multi-feature extraction module is constructed according to the first feature extraction channel, the second feature extraction channel and the third feature extraction channel.
[0014] As an optional embodiment, the grain semantic segmentation model also includes a U-Net network, and the U-Net network includes a CBAM-SimAM sequence structure obtained by combining a CBAM attention mechanism module and a SimAM parameter-free attention module.
[0015] As an optional embodiment, the method further includes:
[0016] Collect multiple grain semantic images to be segmented, perform semantic segmentation and annotation on the edge areas of single grains in a portion of the grain semantic images, and obtain a labeled training data set; do not perform semantic segmentation and annotation on the remaining grain semantic images, and obtain an unlabeled verification data set; wherein the training data set includes a label map after the grain semantic images are annotated;
[0017] The grain semantic segmentation model is trained using the training data set and the verification data set.
[0018] As an optional embodiment, the binary cross entropy loss function of the output segmentation map and label map of the model during the training process is as follows:
[0019]
[0020] in, is the total number of pixels, is the true label, the value of the true label is 0 or 1, is the probability of the model output, It is The weight of each pixel is designed to be the largest at the center of the image and then decreases as the distance from the center increases. The two-dimensional Gaussian function formula is:
[0021]
[0022] in is the center point of the two-dimensional Gaussian function, is a parameter that controls the range of weight distribution. and is the pixel position.
[0023] As an optional embodiment, the method further includes:
[0024] The output of the multi-feature extraction module is used as the input of the CBAM-SimAM sequence structure.
[0025] As an optional embodiment, the step of inputting the first grain image into a pre-built grain semantic segmentation model to segment the target grain particles and the adhering grain particles to obtain a second grain image output by the grain semantic segmentation model further includes:
[0026] Extract features of the input image in the spatial dimension and channel dimension to obtain an input feature map;
[0027] Mining the importance of each neuron in the input feature map through an energy function to obtain a three-dimensional attention weight of the input feature map;
[0028] The second grain image is obtained according to the three-dimensional attention weight and the input feature map.
[0029] According to the grain semantic segmentation method based on multi-feature fusion according to the embodiment of the present invention, the ability to extract the edge features of grain particles is significantly improved by constructing and optimizing features such as target edge details, so that even when the grains are in a state of adhesion, the target grain particles can be accurately distinguished and extracted. The use of multi-feature enhancement technology effectively expands the network's learning ability for target features and edge features, further improving the accuracy and efficiency of grain particle detection. Using a loss function with Gaussian distribution weights can specifically reduce the loss value of the edge part of the image, thereby better highlighting and extracting the target grain particles in the center part, reducing false detections and missed detections caused by blurred edges or adhesions. In the state of grain adhesion, not only can the target grain particles be effectively extracted, but the excess particles can also be accurately detected as background, achieving accurate recognition and classification of grain particles.
[0030] The second object of the present invention is to propose a grain semantic segmentation system based on multi-feature fusion, comprising:
[0031] A preprocessing module is configured to obtain a target grain image, preprocess the target grain image, and obtain a first grain image; wherein the first grain image includes target grain particles and adhered grain particles;
[0032] The segmentation module is configured to input the first grain image into a pre-built grain semantic segmentation model to segment the target grain particles and the adhered grain particles to obtain a second grain image output by the grain semantic segmentation model; wherein the second grain image includes the target grain particles.
[0033] According to the grain semantic segmentation system based on multi-feature fusion of the embodiment of the present invention, the target grain image is obtained through the preprocessing module, and the target grain image is preprocessed to obtain a first grain image; wherein the first grain image includes target grain particles and adhered grain particles; the first grain image is input into a pre-built grain semantic segmentation model through the segmentation module to segment the target grain particles and adhered grain particles, and obtain a second grain image output by the grain semantic segmentation model; wherein the second grain image includes the target grain particles. In the grain adhesion state, not only the target grain particles can be effectively extracted, but also the excess particles can be accurately detected as the background, thereby realizing the accurate recognition and classification of grain particles.
[0034] To achieve the above objectives, the third aspect of the present invention proposes an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the above-mentioned grain semantic segmentation method based on multi-feature fusion is implemented.
[0035] According to the electronic device of the embodiment of the present invention, by executing the above-mentioned grain semantic segmentation method based on multi-feature fusion, when the grains are in a sticky state, it is not only possible to effectively extract the target grain particles, but also to accurately detect the excess particles as the background, thereby realizing the accurate recognition and classification of the grain particles.
[0036] To achieve the above objectives, the fourth aspect of the present invention proposes a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a computer to execute the above-mentioned grain semantic segmentation method based on multi-feature fusion.
[0037] The computer-readable storage medium of an embodiment of the present invention, by executing the above-mentioned grain semantic segmentation method based on multi-feature fusion, can not only effectively extract target grain particles when the grains are in a sticky state, but also accurately detect the excess particles as the background, thereby realizing accurate recognition and classification of grain particles.
[0038] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only for the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 A schematic flow chart of a method for grain semantic segmentation based on multi-feature fusion provided in an embodiment of the present invention.
[0041] Figure 2 Schematic diagram of a grain semantic segmentation model provided in an embodiment of the present invention.
[0042] Figure 3 A schematic diagram of a multi-feature extraction module provided in an embodiment of the present invention.
[0043] Figure 4 A schematic diagram of a CBAM attention module provided in an embodiment of the present invention.
[0044] Figure 5 A schematic diagram of the CBAM-SimAM sequence structure provided in an embodiment of the present invention.
[0045] Figure 6 A schematic diagram of a single particle semantic segmentation result provided by an embodiment of the present invention.
[0046] Figure 7 Schematic diagram of a grain semantic segmentation system based on multi-feature fusion according to an embodiment of the present invention.
[0047] Figure 8 A more specific schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings.
[0049] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the present invention should be understood by people with ordinary skills in the field to which the present invention belongs. The "first", "second" and similar words used in the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0050] As described in the background technology section, in the semantic segmentation detection of single grains of cereals, because the cereals are generally in a state of dense adhesion, mutual occlusion, and small particle size, the traditional segmentation method tends to segment out the cereals that are adhered to the target particles. The segmentation result will show that the target particles are adhered to other particles, and it is impossible to achieve semantic segmentation of cereals only for the target particles.
[0051] In the process of implementing the present invention, the applicant found that traditional semantic segmentation techniques, such as threshold-based segmentation methods and edge-based segmentation methods, although widely used in the field of image processing, show low accuracy in grain segmentation. These traditional methods often have difficulty in accurately distinguishing target grains from adhering grains, resulting in inaccurate segmentation results, which affects the accuracy of subsequent analysis.
[0052] With the rise of deep learning technology, semantic segmentation methods based on deep learning, such as FCN and DeepLab, have provided new solutions for grain segmentation. These methods can accurately identify the foreground and background of grains by automatically learning features in images, and significantly improve segmentation accuracy. However, these methods still have problems when dealing with adhered grains, because they tend to segment the adhered parts as foregrounds and cannot segment the target grains separately and completely.
[0053] In addition, instance segmentation technology can segment each grain particle, but in the process of single grain detection, this method will also segment other grains that are attached to it or on the edge, affecting the single grain segmentation effect.
[0054] Therefore, although the existing technical methods have improved the accuracy of grain particle segmentation to a certain extent, there are still many challenges and limitations. In order to solve these problems, this application provides a grain semantic segmentation method based on multi-feature fusion, which can accurately distinguish and segment individual grains while maintaining high segmentation accuracy, providing a more effective solution for the field of grain image processing and analysis.
[0055] The technical solution of the present invention is further described in detail below through specific embodiments.
[0056] refer to Figure 1 , which is a flow chart of a grain semantic segmentation method based on multi-feature fusion provided in an embodiment of the present invention.
[0057] Step S101, acquiring a target grain image, and preprocessing the target grain image to obtain a first grain image; wherein the first grain image includes target grain particles and adhered grain particles;
[0058] Step S102, inputting the first grain image into a pre-constructed grain semantic segmentation model to segment the target grain particles and the adhering grain particles, and obtaining a second grain image output by the grain semantic segmentation model; wherein the second grain image includes the target grain particles.
[0059] In a specific implementation, the target grain image may be a grain sample photographed or scanned by a camera, a scanner, etc. The image format may be RGB, grayscale, or other formats, depending on the needs of subsequent processing.
[0060] Preprocessing the target grain image may be to convert a color image into a grayscale image to reduce the amount of calculation. It may also be to use a filter (such as a Gaussian filter, a median filter, etc.) to remove noise in the image. It may also be to enhance the contrast of the image by methods such as histogram equalization to make the grain particles easier to identify. It may also be to convert the image into a black and white binary image to facilitate subsequent segmentation processing. It may also be to perform morphological operations on the image to smooth the image edges. The first grain image obtained after preprocessing may be an image including target grain particles and adhered grain particles, wherein the target grain particles are single grain particles to be segmented, and the adhered grain particles are grain particles adhered to the single grain particles. Further, the first grain image is input into a pre-constructed grain semantic segmentation model to segment the target grain particles and the adhered grain particles, and obtain a second grain image output by the grain semantic segmentation model; wherein the second grain image includes the target grain particles. After the first grain image is semantically segmented by the grain semantic segmentation model, the target grain particles are effectively extracted, and the redundant particles are detected as background, so as to obtain a second grain image including only the target grain particles.
[0061] refer to Figure 2 , which is a schematic diagram of a grain semantic segmentation model provided in an embodiment of the present invention.
[0062] As an optional embodiment, the grain semantic segmentation model in the present invention is an improved U-Net network model. The improved U-Net network model may include two parts, one part is a multi-feature extraction module, and the other part is a U-Net network. The U-Net network includes a CBAM-SimAM sequence structure obtained by combining a CBAM attention mechanism module and a SimAM parameter-free attention module.
[0063] As an optional embodiment, it is also necessary to obtain training data for training the grain semantic segmentation model. By collecting multiple grain semantic images to be segmented, semantic segmentation and annotation are performed on the edge areas of single grains in a part of the grain semantic images to obtain a labeled training data set; the remaining grain semantic images are not semantically segmented and annotated to obtain an unlabeled verification data set; wherein, the training data set includes a label map for the grain semantic images; and the grain semantic segmentation model is trained using the training data set and the verification data set.
[0064] Specifically, the collected grain images are subjected to image preprocessing, including image rotation, flipping, geometric transformation and other operations, to obtain multiple grain semantic images to be segmented, and the target single grain areas in the multiple grain semantic images to be segmented are segmented, labeled and saved. The saved files are used as training data sets, and the improved U-Net segmentation model is trained using the training data sets.
[0065] refer to Figure 3 , is a schematic diagram of a multi-feature extraction module provided in an embodiment of the present invention.
[0066] As an optional embodiment, a multi-feature extraction module may be constructed in the following manner:
[0067] Firstly, a first feature extraction channel is constructed, and the first feature extraction channel is used to extract RGB features from a first grain image; further, a second feature extraction channel is constructed, and the second feature extraction channel is used to perform edge detection on the first grain image to extract edge features of the first grain image; then, a third feature extraction channel is constructed, and the third feature extraction channel is used to perform histogram equalization processing on the first grain image to extract grayscale features of the first grain image; finally, a multi-feature extraction module is constructed according to the first feature extraction channel, the second feature extraction channel and the third feature extraction channel.
[0068] As an optional embodiment, the multi-feature extraction module performs three branch processes on the input image (i.e., the first grain image). The first is to directly use the RGB of the original image as the first input. The second process is to perform Canny edge detection on the three RGB channels of the input image respectively. The third process is to perform histogram equalization on the three RGB channels of the input image respectively.
[0069] As an optional embodiment, in actual application, the first grain image is input into a pre-built grain semantic segmentation model to segment the target grain particles and the adhered grain particles to obtain a second grain image output by the grain semantic segmentation model, including: extracting RGB features from the first grain image; performing edge detection on the first grain image to extract edge features of the first grain image; performing histogram equalization processing on the first grain image to extract grayscale features of the first grain image; and obtaining an output feature map based on RGB features, edge features and grayscale features.
[0070] Canny edge detection is an efficient edge detection algorithm that combines Gaussian filtering, gradient calculation, non-maximum suppression and double threshold processing.
[0071] First, use Gaussian filtering, that is, use the Gaussian kernel to smooth the input single channel to reduce the impact of noise. The calculation process is as follows:
[0072]
[0073] in, is the value of the Gaussian kernel, and is the offset relative to the center, is a parameter that controls the width of the Gaussian distribution.
[0074] The convolution operation can be expressed as:
[0075]
[0076] in, is the pixel value in the original image, is the image after Gaussian filtering, Represents the size of the Gaussian kernel.
[0077] Furthermore, the Sobel operator is used to calculate the gradients in the horizontal and vertical directions of the smoothed channel, which can be calculated by the following formula:
[0078] Sobel operator in the horizontal direction:
[0079]
[0080] Sobel operator in the vertical direction:
[0081]
[0082] By performing horizontal and vertical Sobel calculations on the image, two gradient maps can be obtained, representing the gradients in the horizontal and vertical directions respectively:
[0083]
[0084]
[0085] in, Represents a convolution operation.
[0086] The gradient magnitude and direction can be calculated using the following formula:
[0087]
[0088]
[0089] Furthermore, the gradient map is scanned using non-maximum suppression, the pixels with the largest local gradient in the gradient map are retained, and other pixels are suppressed to zero, so that refined edges can be obtained. This step can extract the detailed features of the grain edge and solve the problem of mutual adhesion during grain segmentation.
[0090] Furthermore, two thresholds are used, a higher threshold (strong edge) and a lower threshold (weak edge). Pixels in the gradient map that are higher than the higher threshold are marked as strong edges, and pixels that are lower than the lower threshold are marked as background. Then, if the pixels between the two thresholds are adjacent to the strong edge, they are marked as strong edges, and if they are not adjacent, they are marked as weak edges and also marked as background.
[0091] Finally, the input image is histogram equalized on the three RGB channels.
[0092] First, the number of pixels at each gray level in a single-channel image is counted to generate a histogram. The histogram shows the distribution of each gray level in the image. Further, the cumulative distribution function (CDF) is calculated, which shows the cumulative number of each gray level in the image.
[0093] The calculation formula of CDF is as follows:
[0094]
[0095] in, Indicates Gray levels, Represents the gray level in the histogram The number of pixels.
[0096] Furthermore, the new pixel value is calculated as follows:
[0097]
[0098] in, Represents the original pixel value, Indicates the total number of gray levels, usually 256. and They are The minimum and maximum values of is the new pixel value, Is a mathematical function that rounds a floating point number to the nearest integer.
[0099] Finally, the first three processed Classify, that is, three The channels are grouped into one category , three The channels are grouped into one category , three The channels are grouped into one category For each category Operation, respectively , and finally Merge channels to get output feature maps .
[0100] The present invention applies a multi-feature extraction module to the U-Net network, classifies the channels of the original image, the Canny edge detection result and the RGB of the histogram equalization result, extracts features from each category respectively, and obtains the extracted feature map after merging the features. , which integrates multiple contour information and detail feature information, is beneficial to the boundaries of grain adhesion particles.
[0101] It should be noted that when performing edge detection, the parameters of the Gaussian filter need to be carefully selected (such as ) and the threshold of the Canny detector to ensure the best edge detection effect. Histogram equalization can enhance the contrast of the image, but it may also cause some details to be lost. Therefore, in practical applications, it needs to be adjusted according to specific circumstances. The method of feature fusion can be selected according to the specific task, such as simple splicing, weighted fusion, or more complex fusion methods.
[0102] The U-Net network includes a CBAM-SimAM sequence structure obtained by combining the CBAM attention mechanism module and the SimAM parameter-free attention module.
[0103] As an optional embodiment, the output feature map The input image as the CBAM-SimAM sequence structure.
[0104] Specifically, we build an improved U-Net network model. First, we use a multi-feature extraction module, followed by two Conv, CBAM-SimAM, BN, and SiLU to obtain the features. . Then the first maximum pooling layer downsampling, followed by two Conv, CBAM-SimAM, BN, SiLU to obtain features . Then the second maximum pooling downsampling, followed by two Conv, CBAM-SimAM, BN, SiLU to get the features . Then the third maximum pooling downsampling, followed by two Conv, CBAM-SimAM, BN, SiLU to get the features . After upsampling Perform channel dimension splicing, followed by two Conv, CBAM-SimAM, BN, SiLU to obtain features . After upsampling Perform channel dimension splicing, followed by two Conv, CBAM-SimAM, BN, SiLU to obtain features . After upsampling Perform channel dimension splicing, followed by two Conv, CBAM-SimAM, BN, SiLU to obtain features .at last The output result is obtained after the convolution layer.
[0105] In computer vision and deep learning, Conv usually refers to the convolution operation, which is the core component of the convolutional neural network (CNN). The convolution operation is mainly used for feature extraction. It extracts the local features of the image by sliding the convolution kernel (filter) on the input image (or feature map) and performing local weighted summation. The convolution layer can retain the spatial features of the image, but the amount of data will be reduced. The data through the convolution layer will still obtain a three-dimensional tensor, but the depth (dimension), height and width will change.
[0106] BN is a regularization method for deep learning. It normalizes the input data before each neural network layer so that the distribution of the input data remains within a stable range. BN can accelerate training, reduce overfitting, and improve the generalization ability of the model. BN contains a set of learnable parameters (mean and variance), which keep the mean and variance of the input data within a stable range through normalization operations.
[0107] SiLU (Sigmoid-weighted Linear Unit) is an activation function in deep learning that combines the characteristics of Sigmoid function and linear function. SiLU has the properties of lower bound, no upper bound, smoothness, non-monotonicity, etc. It can improve the regularization effect, prevent network saturation, make it easier to optimize, and retain some negative inputs to improve the network's expressiveness.
[0108] In the embodiment of the present application, the calculation formula of the SiLU activation function is as follows:
[0109]
[0110] refer to Figure 4 , is a schematic diagram of a CBAM attention module provided in an embodiment of the present invention.
[0111] As an optional embodiment, CBAM (Convolutional Block Attention Module) is an attention mechanism that combines channel attention and spatial attention, which aims to improve the representation and generalization capabilities of the convolutional neural network (CNN) model. CBAM uses two sub-modules, namely the channel attention module (CAM) and the spatial attention module (SAM), to weight the input feature map in the channel dimension and the spatial dimension respectively, and finally multiply the two attention mechanisms to obtain the final attention feature map. CBAM can adaptively learn the correlation between different features, thereby improving the feature extraction and generalization capabilities of the network. The SimAM module mines the importance of each neuron in the feature map through the energy function, and the three-dimensional attention weight of the feature map can be obtained without additional parameters. Therefore, the present application combines the CBAM module with the SimAM module to construct a CBAM-SimAM sequence structure to improve the feature extraction capability of the CBAM module without increasing the number of additional parameters of the model.
[0112] As an optional embodiment, the first grain image is input into a pre-built grain semantic segmentation model to segment the target grain particles and the adhered grain particles to obtain a second grain image output by the grain semantic segmentation model, and also includes: extracting features of the input image in spatial dimensions and channel dimensions to obtain an input feature map; mining the importance of each neuron in the input feature map through an energy function to obtain a three-dimensional attention weight of the input feature map; and obtaining a second grain image based on the three-dimensional attention weight and the input feature map.
[0113] refer to Figure 5 , which is a schematic diagram of the CBAM-SimAM sequence structure provided in an embodiment of the present invention.
[0114] The structure is obtained by CBAM from the input image Get feature map Specifically, the input is feature extracted in the spatial dimension and channel dimension, and then the feature map is mined through a set of energy functions. The importance of each neuron in , thus obtaining the feature map A set of three-dimensional attention weights, and finally, the obtained weights are combined with the feature map Multiply to get the final output feature map .
[0115] The energy function equation is as follows:
[0116]
[0117] in, and Representation feature map The target neurons and other neurons, Representation feature map The index of the neuron in , Representation feature map The total number of neurons in and express The weights and biases of the neurons, express The energy of neurons, is the coefficient.
[0118] As an optional embodiment, multiple semantic images of grains to be segmented are collected, and semantic segmentation and annotation are performed on the edge areas of single grains in a part of the grain semantic images to obtain a labeled training data set; semantic segmentation and annotation are not performed on the remaining grain semantic images to obtain an unlabeled verification data set; wherein the training data set includes a label map after the grain semantic images are annotated; and the grain semantic segmentation model is trained using the training data set and the verification data set.
[0119] Specifically, the improved U-Net segmentation model can be trained through the training data set. First, select a suitable image annotation tool, such as Labelme, VIA (VGG Image Annotator), etc., to segment and annotate the grain image.
[0120] Specifically, use the annotation tool to manually draw the boundary of the target single grain area in multiple grain semantic images to be segmented to form the annotation of the edge of the single grain grain. Further, save the annotation results in the format required for model training, such as JSON, XML, etc. The preprocessed grain semantic images and the corresponding annotation files (i.e., label maps) are combined into a training data set, and the remaining grain semantic images are not semantically segmented and annotated to obtain a validation data set without labels. It should be noted that the entire process needs to ensure that the data set contains a sufficient number of grain semantic images in different situations to cover various possible segmentation scenarios. Further, write data loading and preprocessing code to load the training data set into the model. Further data enhancement techniques, such as color perturbation and noise addition, are applied during the data loading process to increase the robustness of the model. Among them, the annotation file (label map) should contain information such as image path and annotation area coordinates. Further, configure the training parameters of the model, such as learning rate, batch size, number of iterations, etc. Use the training data to train the model, and record the loss function value and evaluation indicators (such as IoU, precision, recall, etc.) during the training process.
[0121] Finally, the performance of the model is evaluated on the training validation set, and the model is optimized based on the evaluation results. The trained model is deployed in practical applications to segment new grain images.
[0122] It should be noted that you can try to adjust parameters such as model structure, loss function, optimization algorithm, etc. to improve the segmentation effect of the model.
[0123] Among them, the binary cross entropy loss function of the output segmentation map and label map of the model during training is as follows:
[0124]
[0125] in, is the total number of pixels, is the true label, the value of the true label is 0 or 1, is the probability of the model output, It is The weight of each pixel is adjusted according to its position by means of a Gaussian function. That is, the weight is designed to be the largest at the center of the image and then decreases as the distance from the center increases. The two-dimensional Gaussian function formula is:
[0126]
[0127] in is the center point of the two-dimensional Gaussian function, is a parameter that controls the range of weight distribution. and is the pixel position.
[0128] The present invention adds a two-dimensional Gaussian distribution weight to the binary cross entropy loss function, so that the grain semantic segmentation model pays more attention to the segmentation effect of the central area, and further improves the segmentation accuracy of the single grain part of the grain adhesion.
[0129] The CBAM-SimAM module proposed in this paper combines the CBAM attention mechanism with the SimAM attention. CBAM extracts correlations from features at the channel and spatial levels respectively, and then connects to the SimAM module to extract correlations at the overall feature level. The CBAM-SimAM module is used after each convolution operation in the U-Net network, thereby enhancing the feature extraction capability of the U-Net network and improving the model image segmentation accuracy.
[0130] refer to Figure 6 , is a schematic diagram of a single particle semantic segmentation result provided by an embodiment of the present invention.
[0131] Figure 6 (a) is the first grain image, Figure 6 (b) in the figure is the grain image segmentation map. Figure 6 (c) in the figure is the second grain image.
[0132] As can be seen from the figure, the improved UNet model used in the present invention has a high segmentation accuracy for the adhesion part of the grain and the whole grain, the outline of the target single grain is relatively complete, and the segmentation of the grain coverage part is relatively clear. Among them, the multi-feature extraction module can improve the outline clarity and details of the grain, the CBAM-SimAM module adopts the attention mechanism, increases the feature extraction capability, and the loss function part adopts the binary cross entropy loss function with two-dimensional Gaussian distribution weights, which further improves the segmentation accuracy of the target particles.
[0133] As can be seen from the above, the grain semantic segmentation method based on multi-feature fusion and the related device provided by the present invention first obtain the target grain image, pre-process the target grain image, and obtain the first grain image; wherein the first grain image includes the target grain grains and the adhesion grain grains; further, the first grain image is input into the pre-constructed grain semantic segmentation model to segment the target grain grains and the adhesion grain grains, and obtain the second grain image output by the grain semantic segmentation model; wherein the second grain image includes the target grain grains. The present invention adopts an improved U-Net model, which shows excellent performance in processing the grain adhesion grain image segmentation task. Compared with the traditional model, the improved U-Net shows higher accuracy in segmenting the adhesion part and the overall structure of the grain grains. It is particularly noteworthy that for the target single grain, the model can present a more complete outline, effectively capture the grain edge details, and improve the accuracy of segmentation. At the same time, for the grain covering part, the improved U-Net model presents a clear and accurate segmentation result, making the boundary between the grains more clear and discernible, which is helpful for further analysis and processing. This invention provides a new idea for the field of grain adhesion grain image processing and provides a reliable tool for refined grain grain analysis.
[0134] It should be noted that the method of the embodiment of the present invention can be executed by a single device, such as a computer or a server. The method of this embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only execute one or more steps in the method of the embodiment of the present invention, and the multiple devices will interact with each other to complete the grain semantic segmentation method based on multi-feature fusion.
[0135] It should be noted that some embodiments of the present invention are described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0136] Based on the same inventive concept, corresponding to the method provided in any of the above embodiments, the present invention also provides a grain semantic segmentation system based on multi-feature fusion.
[0137] refer to Figure 7, which is a schematic diagram of a cereal semantic segmentation system based on multi-feature fusion according to an embodiment of the present invention. The cereal semantic segmentation system based on multi-feature fusion according to an embodiment of the present invention may include: a preprocessing module 701 and a segmentation module 702 .
[0138] The preprocessing module 701 is configured to obtain a target grain image, preprocess the target grain image, and obtain a first grain image; wherein the first grain image includes target grain particles and adhering grain particles. The segmentation module 702 is configured to input the first grain image into a pre-constructed grain semantic segmentation model to segment the target grain particles and adhering grain particles, and obtain a second grain image output by the grain semantic segmentation model; wherein the second grain image includes target grain particles.
[0139] In some embodiments of the present invention, the grain semantic segmentation model includes a multi-feature extraction module, and the multi-feature extraction module is constructed in the following manner: constructing a first feature extraction channel, the first feature extraction channel is used to extract RGB features from the first grain image; constructing a second feature extraction channel, the second feature extraction channel is used to perform edge detection on the first grain image to extract edge features of the first grain image; constructing a third feature extraction channel, the third feature extraction channel is used to perform histogram equalization processing on the first grain image to extract grayscale features of the first grain image; and constructing a multi-feature extraction module based on the first feature extraction channel, the second feature extraction channel and the third feature extraction channel.
[0140] In some embodiments of the present invention, the grain semantic segmentation model also includes a U-Net network, and the U-Net network includes a CBAM-SimAM sequence structure obtained by combining a CBAM attention mechanism module and a SimAM parameter-free attention module.
[0141] In some embodiments of the present invention, the preprocessing module 701 is also used to collect multiple grain semantic images to be segmented, perform semantic segmentation and annotation on the edge areas of single grains in a part of the grain semantic images, and obtain a labeled training data set; the remaining grain semantic images are not semantically segmented and labeled to obtain an unlabeled verification data set; wherein the training data set includes a label map for the grain semantic images; and the grain semantic segmentation model is trained using the training data set and the verification data set.
[0142] In some embodiments of the present invention, the segmentation module 702 inputs the first grain image into a pre-built grain semantic segmentation model to segment the target grain particles and the adhered grain particles to obtain a second grain image output by the grain semantic segmentation model, which is specifically used to: extract RGB features from the first grain image; perform edge detection on the first grain image to extract edge features of the first grain image; perform histogram equalization on the first grain image to extract grayscale features of the first grain image; and obtain an output feature map based on RGB features, edge features, and grayscale features.
[0143] In some embodiments of the present invention, the segmentation module 702 is further configured to use the output feature map as an input image of the CBAM-SimAM sequence structure.
[0144] In some embodiments of the present invention, a first grain image is input into a pre-built grain semantic segmentation model to segment the target grain particles and the adhered grain particles to obtain a second grain image output by the grain semantic segmentation model. The segmentation module 702 is also used to extract features of the input image in spatial dimensions and channel dimensions to obtain an input feature map; to mine the importance of each neuron in the input feature map through an energy function to obtain a three-dimensional attention weight of the input feature map; and to obtain a second grain image based on the three-dimensional attention weight and the input feature map.
[0145] According to the grain semantic segmentation system based on multi-feature fusion of the embodiment of the present invention, the target grain image is obtained through the preprocessing module, and the target grain image is preprocessed to obtain a first grain image; wherein the first grain image includes target grain particles and adhered grain particles; the first grain image is input into the pre-built grain semantic segmentation model through the segmentation module to segment the target grain particles and adhered grain particles, and obtain the second grain image output by the grain semantic segmentation model; wherein the second grain image includes the target grain particles. In the grain adhesion state, not only the target grain particles can be effectively extracted, but also the excess particles can be accurately detected as the background, thereby realizing the accurate recognition and classification of grain particles.
[0146] For the convenience of description, the above system is described as being divided into various modules according to their functions. Of course, when implementing the present invention, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0147] The system of the above embodiment is used to implement the corresponding grain semantic segmentation method based on multi-feature fusion in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0148] Based on the same inventive concept, corresponding to the method of any of the above embodiments, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for grain semantic segmentation based on multi-feature fusion of any of the above embodiments is implemented.
[0149] Figure 8 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 810, a memory 820, an input / output interface 830, a communication interface 840, and a bus 850. The processor 810, the memory 820, the input / output interface 830, and the communication interface 840 are connected to each other in communication within the device through the bus 850.
[0150] The processor 810 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0151] The memory 820 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 820 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 820 and are called and executed by the processor 810.
[0152] The input / output interface 830 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.
[0153] The communication interface 840 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0154] The bus 850 includes a path that transmits information between the various components of the device (eg, the processor 810 , the memory 820 , the input / output interface 830 , and the communication interface 840 ).
[0155] It should be noted that, although the above device only shows the processor 810, the memory 820, the input / output interface 830, the communication interface 840 and the bus 850, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.
[0156] The electronic device of the above embodiment is used to implement the corresponding grain semantic segmentation method based on multi-feature fusion in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0157] Based on the same inventive concept, corresponding to the grain semantic segmentation method based on multi-feature fusion of any of the above embodiments, the present invention also provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a computer to execute the grain semantic segmentation method based on multi-feature fusion of any of the above embodiments.
[0158] The above-mentioned non-transitory computer-readable storage medium can be any available medium or data storage device that can be accessed by a computer, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)), etc.
[0159] The computer instructions stored in the storage medium of the above embodiment are used to enable a computer to execute the grain semantic segmentation method based on multi-feature fusion of any embodiment in the above exemplary method part, and have the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0160] In addition, although the operations of the method of the present invention are described in a specific order in the accompanying drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. On the contrary, the steps depicted in the flow chart can be performed in a different order. Additionally or alternatively, some steps can be omitted, multiple steps can be combined into one step, and / or one step can be decomposed into multiple steps.
[0161] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0162] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present invention should be understood by people with ordinary skills in the field to which the present invention belongs. The "first", "second" and similar words used in the embodiments of the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. "Include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0163] Although the spirit and principle of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the disclosed specific embodiments, and the division of various aspects does not mean that the features in these aspects cannot be combined to benefit, and this division is only for the convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements included in the spirit and scope of the attached claims. The scope of the attached claims conforms to the broadest interpretation, thereby including all such modifications and equivalent structures and functions.
Claims
1. A grain semantic segmentation method based on multi-feature fusion, characterized in that: include: Acquire a target grain image, and preprocess the target grain image to obtain a first grain image; wherein the first grain image includes target grain particles and adhered grain particles; Inputting the first grain image into a pre-built grain semantic segmentation model to segment the target grain particles and the adhering grain particles, and obtaining a second grain image output by the grain semantic segmentation model; wherein the second grain image includes the target grain particles; The grain semantic segmentation model includes a multi-feature extraction module, which is constructed in the following way: constructing a first feature extraction channel, wherein the first feature extraction channel is used to extract RGB features from the first grain image; constructing a second feature extraction channel, wherein the second feature extraction channel is used to perform edge detection on the first grain image to extract edge features of the first grain image; constructing a third feature extraction channel, wherein the third feature extraction channel is used to perform histogram equalization processing on the first grain image to extract grayscale features of the first grain image; A multi-feature extraction module is constructed according to the first feature extraction channel, the second feature extraction channel and the third feature extraction channel; The grain semantic segmentation model also includes a U-Net network, and the U-Net network includes a CBAM-SimAM sequence structure obtained by combining a CBAM attention mechanism module and a SimAM parameter-free attention module; The method further comprises: Using the output of the multi-feature extraction module as the input of the CBAM-SimAM sequence structure; The step of inputting the first grain image into a pre-built grain semantic segmentation model to segment the target grain particles and the adhering grain particles to obtain a second grain image output by the grain semantic segmentation model further includes: Extract features of the input image in the spatial dimension and channel dimension to obtain an input feature map; Mining the importance of each neuron in the input feature map through an energy function to obtain a three-dimensional attention weight of the input feature map; Obtaining the second grain image according to the three-dimensional attention weight and the input feature map; The energy function equation is as follows: in, and Representation feature map The target neurons and other neurons, Representation feature map The index of the neuron in , Representation feature map The total number of neurons in and express The weights and biases of the neurons, express The energy of neurons, is the coefficient.
2. The method according to claim 1, characterized in that The method further comprises: Collect multiple grain semantic images to be segmented, perform semantic segmentation and annotation on the edge areas of single grains in a portion of the grain semantic images, and obtain a labeled training data set; do not perform semantic segmentation and annotation on the remaining grain semantic images, and obtain an unlabeled verification data set; wherein the training data set includes a label map after the grain semantic images are annotated; The grain semantic segmentation model is trained using the training data set and the verification data set.
3. The method according to claim 2, characterized in that The binary cross entropy loss function of the output segmentation map and label map of the model during the training process is as follows: in, is the total number of pixels, is the true label, the value of the true label is 0 or 1, is the probability of the model output, It is The weight of each pixel is designed to be the largest at the center of the image and then decreases as the distance from the center increases. The two-dimensional Gaussian function formula is: in is the center point of the two-dimensional Gaussian function, is a parameter that controls the range of weight distribution. and is the pixel position.
4. A grain semantic segmentation system based on multi-feature fusion, wherein the grain semantic segmentation system based on multi-feature fusion is used to execute the method according to any one of claims 1 to 3, characterized in that: include: A preprocessing module is configured to obtain a target grain image, preprocess the target grain image, and obtain a first grain image; wherein the first grain image includes target grain particles and adhered grain particles; The segmentation module is configured to input the first grain image into a pre-built grain semantic segmentation model to segment the target grain particles and the adhered grain particles to obtain a second grain image output by the grain semantic segmentation model; wherein the second grain image includes the target grain particles.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 3 is implemented.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method according to any one of claims 1 to 3.
