A rice seed classification method based on attention residual network
By using the combination of attention residual network and ResNet in rice seed classification, the problem of identifying small varieties with different appearance and morphology in rice seed classification is solved, the classification accuracy and information extraction ability are improved, and the calculation cost is reduced.
Patent Information
- Application Number
- CN202310998489.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-08
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2043-08-08
AI Technical Summary
The prior art is difficult to accurately identify varieties with small differences in appearance and morphology in rice seed classification. The shallow feature extraction capability of traditional machine vision methods is limited, and the high price of hyperspectral image acquisition equipment is limited, which limits the application.
Using an attention residual network method, a rice seed classification model is constructed through the ResNet backbone network combined with the attention mechanism, using the ECA attention module and multi-convolution kernel feature fusion, a cross-entropy loss function is introduced, and image preprocessing and data expansion are performed. Increase and enhance the multi-scale feature extraction capability.
It effectively avoids image background interference, improves feature extraction ability, improves the accuracy of rice seed classification, reduces calculation costs, and solves the problem of identifying similar varieties.
Smart Images

Figure CN117011607B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of deep learning and machine vision, and in particular, relates to a rice seed classification method based on an attention residual network. Background Art
[0002] Rice is one of the important food crops in my country, and its annual output accounts for more than 40% of the total output of food crops in China. There are many varieties of rice in my country, and with the development of hybrid rice technology, the number of rice varieties has increased year by year. Many rice varieties have small differences in appearance morphological characteristics such as shape, color, and texture. It is difficult to distinguish the differences between varieties with similar appearance characteristics by the naked eyes of breeding experts or inspectors, resulting in low accuracy in rice variety identification. In order to improve the accuracy of rice variety identification with small differences in appearance morphological characteristics, rice seeds are manually identified by using chemical reagents, but the seeds after identification cannot be reused due to damage caused by chemical reagents, and there are still disadvantages such as large workload and more consumables. Therefore, it is necessary to develop a method that can quickly and accurately identify and classify rice seeds among the growing number of rice varieties.
[0003] With the continuous development of agricultural automation and intelligent technology, machine vision technology is gradually used in the identification of crop seeds. Traditional seed classification methods based on machine vision mostly identify seed varieties by extracting shallow features such as geometric shape, color, and texture in seed images, but shallow features usually lack the ability to express high-level semantics, and have limitations in rice seeds with small differences in appearance morphological features, resulting in a decrease in the accuracy of rice seed classification. Compared with traditional methods, deep learning technology achieves better results in image target classification with its excellent feature learning ability. For example, patent number: 202111287410.5, invention name: Invention patent for a method for identifying wheat seed varieties based on a lightweight convolutional neural network, the collected hyperspectral data is input into a lightweight convolutional network for wheat seed classification, but the lightweight convolutional network based on 2D convolution kernel has limited feature extraction capabilities and cannot automatically focus on the important features of each category of seeds, resulting in difficulty in ensuring the accuracy of classification. The literature Research on Rice Seed Image Classification Algorithm Based on Deep Learning (Cui Yan, Jilin University) combines hyperspectral imaging technology with image classification algorithm based on deep learning to construct a rice seed classification method that integrates SENet residual network, so that the network can automatically learn important features with large differences between rice varieties. However, compared with visible light image acquisition equipment, hyperspectral acquisition equipment is more expensive, which limits its application. Therefore, finding a method that can automatically obtain important feature information with large differences between rice varieties in visible light images, thereby realizing accurate classification of rice seeds, plays an important role in reducing the manual input in the seed classification process. Summary of the invention
[0004] The present invention provides a rice seed classification method based on an attention residual network to solve the problems existing in the above-mentioned background technology.
[0005] In order to achieve the above object, the technical solution adopted by the present invention is: a rice seed classification method based on attention residual network, which specifically includes the following steps:
[0006] Step S1: collecting rice seed images;
[0007] Step S2: preprocessing the collected rice seed images;
[0008] Step S3: creating a rice seed image dataset based on the preprocessed rice seed images;
[0009] Step S4: construct a classification model of rice seeds with ResNet as the backbone network and attention mechanism;
[0010] Step S5: training the classification model of rice seeds;
[0011] Step S6: classifying the rice seed images;
[0012] In step S4, the specific steps include:
[0013] Step S40: defining the input part of the model based on the data set;
[0014] Step S41: construct the ResNet neural network model part and define it to include the ECA attention module;
[0015] Step S42: constructing a feature fusion part based on multiple convolution kernels;
[0016] Step S43: Select the loss function to define the output part of the model.
[0017] Preferably, in step S2, preprocessing the collected rice seed image specifically includes: adjusting the size of the target rice seed image photographed in step S1, and center-cropping the image into a square of a certain size.
[0018] Preferably, in step S2, preprocessing the collected rice seed image specifically includes: adjusting the size of the target rice seed image photographed in step S1, and center-cropping the image into a square of a certain size.
[0019] Preferably, in step S3, the specific steps of preparing the rice seed image dataset include:
[0020] Step S30: Processing the acquired rice seed image by a data amplification method of rotation and brightness enhancement adjustment to amplify the number of samples to several times the original number;
[0021] Step S31: Processing the amplified data set by resizing and center cropping to obtain square images of the same size filled with rice seeds;
[0022] Step S32: Divide the data into a training set and a test set.
[0023] Preferably, in step S40, defining the input part of the model based on the data set includes: using normalization processing to achieve better convergence effect of training.
[0024] Preferably, in step S41, specifically: construct a ResNet neural network model and define it to include an Input part and a Bottleneck part.
[0025] Preferably, in step S42, the ECA attention module is an improved network based on SENet, which uses one-dimensional convolution to replace the bottleneck structure consisting of two fully connected layers in SENet, and proposes a local cross-channel interaction strategy without dimensionality reduction and adaptive selection of convolution kernel size.
[0026] Preferably, in step S43, Cross Entropy Loss is selected as the loss function; the Cross Entropy Loss uses the size of the cross entropy to represent the difference between two probability distributions, and obtains the approximate distribution of the target probability distribution by minimizing the cross entropy.
[0027] Preferably, in step S6, the rice seed images to be predicted are preprocessed and put into the above-mentioned trained model to classify the rice seeds, specifically: first, edge detection is performed on the input image and it is geometrically cropped into n parts, and the proportion of white pixels in the n parts of the image in the binary image is calculated. After comparison, the image size of the image with the largest proportion is adjusted to the same size as the image in the training set, and finally input into the model for prediction.
[0028] The beneficial effects of adopting the above technical solution are:
[0029] 1. The rice seed classification method based on the attention residual network of the present invention effectively avoids the interference of image background on model prediction through image preprocessing method, and reduces the influence of objective factors on practical application.
[0030] 2. The rice seed classification method based on the attention residual network of the present invention obtains sufficient effective information in the sampling process, and the feature extraction is more sufficient; it draws on the improved model of the Res2Net network and introduces the attention mechanism, which increases the depth of the network without changing the number of network layers, enhances the multi-scale feature extraction capability, effectively solves the problem of identifying similar varieties, and increases the information extraction capability without causing a significant increase in computational costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A schematic diagram of a rice seed classification method based on an attention residual network of the present invention;
[0032] Figure 2 This is an example diagram of a rice seed image in Example 1 of the present invention;
[0033] Figure 3 This is an example of an image in the rice seed dataset in Example 1 of the present invention;
[0034] Figure 4 This is a structural diagram of the ResNet network model in Example 1 of the present invention;
[0035] Figure 5 This is a unit structure diagram of the ResNet50 network model in Example 1 of the present invention;
[0036] Figure 6 This is a diagram of the improved Bottleneck structure in Example 1 of the present invention;
[0037] Figure 7 This is a structural diagram of the ECA attention module in Example 1 of the present invention;
[0038] Figure 8 The rice seed image after edge detection and the proportion of white dots in each part in Example 1 of the present invention; DETAILED DESCRIPTION
[0039] The specific implementation methods of the present invention are further explained in detail below by describing the embodiments with reference to the accompanying drawings, with the aim of helping those skilled in the art to have a more complete, accurate and in-depth understanding of the concept and technical solution of the present invention and facilitating its implementation.
[0040] like Figures 1 to 8 As shown, the present invention is a rice seed classification method based on the attention residual network. The specific working method is described below with a specific embodiment:
[0041] Embodiment 1:
[0042] The present invention provides a rice seed classification method based on an attention residual network, which specifically comprises the following steps:
[0043] Step S1: collecting rice seed images;
[0044] The rice seeds in this Example 1 were taken from a rice experimental base. Four kinds of rice seeds were randomly sampled and stacked on a white background. The camera was fixed at a distance of 11 cm to take pictures. The nine-square grid was used as the dividing line to ensure that the central square could be completely filled. The image size was 3024×3024. Figure 2 This is an example diagram of a rice seed image in Example 1 of the present invention.
[0045] Step S2: preprocessing the collected rice seed images;
[0046] The acquired image is resized to 768×768, and then a 256×256 image is obtained after a one-ninth-size center crop. Figure 3 This is an example of an image in the rice seed dataset in Example 1 of the present invention.
[0047] Step S3: creating a rice seed image dataset;
[0048] The images after center cropping were flipped and brightness enhanced, and the data was expanded to three times the original size, totaling 2112 images. After shuffling, the data was divided into a training set and a test set at a ratio of 9:1. Table 1 is a statistical chart of the number of images of each category in the rice seed dataset in Example 1 of the present invention.
[0049] Table 1
[0050] Nineteen Incense Jade Needle Incense 93-11 Dangjing No.8 total Original image 176 176 176 176 704 After enhancement 528 528 528 528 2112 Training set 476 476 476 476 1904 Test Set 52 52 52 52 208
[0051] Step S4: Build a classification model of rice seeds with ResNet as the backbone network and combine it with the attention mechanism;
[0052] The ResNet plant seed classification detection model with integrated attention mechanism built according to the dataset consists of three parts: Input, Backbone, and Output. Figure 4 The figure shows the structure diagram of the ResNet network model in Example 1 of the present invention.
[0053] The input part uses transforms in PyTorch to normalize the input image pixels, and determines the size of the three channels based on the average values calculated by sampling in the imagenet training set: [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]. Using normalization in the input stage can achieve better convergence of model training. In the input stage, compared with the preprocessing based on the image algorithm to make the image pattern the same and not interfered by the background, the use of the above-mentioned center-cropped image can specify the format of the input image and also help users to better prepare data sets.
[0054] like Figure 5 The figure shows the unit structure diagram of the ResNet50 network model in Example 1 of the present invention. Backbone consists of five stages, where stage 1 is the preprocessing of the Input part, including Conv convolution layer, BN layer, ReLU activation function, and Maxpool maximum pooling layer. The last four stages contain 3, 4, 6, and 3 Bottlenecks respectively.
[0055] After the Bottleneck improvement, an ECA attention module is added before the 1×1 convolution, and the input feature group after the 1×1 convolution is divided into two groups. After performing 3×3 convolution on the two groups respectively, the outputs of the two groups are spliced in the channel dimension, and finally a 1×1 convolution operation is performed. Figure 6 This is a diagram of the improved Bottleneck structure in Example 1 of the present invention.
[0056] like Figure 5 In the figure, the Conv layer is the abbreviation of convolution, 7×7 is the convolution kernel size, and 64 is the number of convolution kernels; the BN layer is the abbreviation of Batch Normalization, which refers to the normalization of the input part; the ReLU activation function refers to retaining and mapping the features of the activated neurons through the function; the Maxpool layer refers to extracting the feature data of the specified window to significantly reduce the size of the feature tensor.
[0057] like Figure 6 The ECA attention module shown in the figure refers to the Efficient Channel Attention Networks (ECANet), which is an improved network based on SENet. It uses one-dimensional convolution to replace the bottleneck structure composed of two fully connected layers in SENet, proposes a local cross-channel interaction strategy without dimensionality reduction and a method for adaptively selecting the convolution kernel size, which significantly reduces the complexity of the model while maintaining performance. Figure 7 Shown is the structure diagram of the ECA attention module.
[0058] The Output part predicts the model output results and selects Cross Entropy Loss as the loss function to measure the difference between the two probability distributions. It can well reflect the prediction accuracy of the model and is less sensitive to outliers. The formula is as follows:
[0059]
[0060] Among them, y i Represents the true label, a represents the probability predicted by the model, N represents the number of training samples, and C is the loss value.
[0061] Step S5: training the rice seed classification model; adjusting parameters to obtain the best effect, as shown in Table 2, which is a comparison of experimental results of different models under the same parameters.
[0062] Table 2
[0063] Model Params Accuracy ResNet50 25557032 94.8 ResNet50-SE 25557544 97.6 ResNet50-ECA 9272171 98.4
[0064] Step S6: pre-processing the rice seed images and inputting them into the model for classification;
[0065] The image is edge detected based on the Canny operator, and then the image is divided into nine equal parts. The proportion of white pixels in each part is calculated by comparison. The area with the largest proportion of white pixels is the largest filling area, and this area is input for prediction. Figure 8 Shown is the rice seed image after edge detection and the proportion of white points in each part.
[0066] The rice seed classification method based on the attention residual network of the present invention effectively avoids the interference of image background on model prediction through the image preprocessing method, and reduces the influence of objective factors on practical application.
[0067] The rice seed classification method based on the attention residual network of the present invention obtains sufficient effective information in the sampling process, and the feature extraction is more sufficient; it draws on the improved mode of the Res2Net network, introduces the attention mechanism, increases the depth of the network without changing the number of network layers, enhances the multi-scale feature extraction capability, effectively solves the identification problem of similar varieties, and increases the information extraction capability without causing a large increase in computing costs.
[0068] The present invention is described above by way of example in conjunction with the accompanying drawings. Obviously, the specific implementation of the present invention is not limited to the above-mentioned method. As long as various non-substantial improvements are made using the method concept and technical solution of the present invention; or the above-mentioned concept and technical solution of the present invention are directly applied to other occasions without improvement, they are all within the protection scope of the present invention.
Claims
1. A rice seed classification method based on attention residual network, characterized in that: The specific steps include: Step S1: collecting rice seed images; Step S2: preprocessing the collected rice seed images; Step S3: creating a rice seed image dataset based on the preprocessed rice seed images; Step S4: construct a classification model of rice seeds with ResNet as the backbone network and attention mechanism; Step S5: training the classification model of rice seeds; Step S6: classifying the rice seed images; In step S4, the specific steps include: Step S40: defining the input part of the model based on the data set; Step S41: construct the ResNet neural network model part and define it to include the ECA attention module; Step S42: constructing a feature fusion part based on multiple convolution kernels; Step S43: Select the output part of the loss function definition model; In the step S1, collecting the rice seed image specifically includes: photographing the target rice seed image by an image acquisition device, wherein the image includes a stack of rice seeds of a certain type, wherein the rice seeds in the center of the photographed image should fill a square of a certain size and do not include the photographing background; In the step S2, preprocessing the collected rice seed image specifically includes: adjusting the size of the target rice seed image photographed in the step S1, and cutting the center of the image into a square of a certain size; In step S3, the specific steps of preparing the rice seed image dataset include: Step S30: Processing the acquired rice seed image by a data amplification method of rotation and brightness enhancement adjustment to amplify the number of samples to several times the original number; Step S31: Processing the amplified data set by resizing and center cropping to obtain square images of the same size filled with rice seeds; Step S32: Divide the data into a training set and a test set; In the step S40, the input part of the model defined based on the data set includes: using normalization processing to achieve better convergence effect of training; In the step S41, specifically: construct a ResNet neural network model and define it to include an Input part and a Bottleneck part; the Bottleneck part is to add an ECA attention module before the 1×1 convolution, and divide the input feature group after the 1×1 convolution into two groups, and after performing 3×3 convolution on the two groups respectively, splice the outputs of the two groups in the channel dimension, and finally perform a 1×1 convolution operation; In step S42, the ECA attention module is an improved network based on SENet, which uses one-dimensional convolution to replace the bottleneck structure composed of two fully connected layers in SENet, proposes a local cross-channel interaction strategy without dimensionality reduction and adaptively selects the convolution kernel size; In step S43, Cross Entropy Loss is selected as the loss function; Cross Entropy Loss uses the size of cross entropy to represent the difference between two probability distributions, and obtains an approximate distribution of the target probability distribution by minimizing the cross entropy; In the step S6, the rice seed images to be predicted are preprocessed and put into the above-mentioned trained model to classify the rice seeds. Specifically, the input image is first edge detected and cut into n parts in a geometric manner. The proportion of white pixels in the n images in the binary image is calculated. After comparison, the image with the largest proportion is adjusted to the same size as the image in the training set, and finally input into the model for prediction.
