A Maize Ear Classification Method Based on a Custom Lightweight Convolutional Neural Network

By customizing a lightweight convolutional neural network and optimizing the training strategy, the problems of adaptability and computational cost of traditional models on small-scale maize ear datasets were solved, achieving efficient and interpretable maize ear classification and improving sorting efficiency and accuracy.

CN116258899BActive Publication Date: 2025-12-02CHINA AGRI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310072702.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-07
Publication Date
2025-12-02
Estimated Expiration
2043-02-07

AI Technical Summary

Technical Problem

In existing technologies, traditional convolutional neural network models are too deep to adapt to small-scale corn ear datasets, and have high computational costs, making them difficult to deploy on corn seed production lines. They also lack interpretability, affecting sorting efficiency and quality.

Method used

A method for classifying maize ears based on a custom lightweight convolutional neural network was designed. It employs five convolutional layers, a global average pooling layer, and an attention mechanism. The training strategy is optimized by combining data augmentation and dynamic learning rate, and the classification results are visualized using the Grad-CAM algorithm.

Benefits of technology

A balance was struck between performance and computational cost, improving the efficiency and quality of maize ear sorting, enhancing model interpretability, and increasing classification accuracy and training efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116258899B_ABST
    Figure CN116258899B_ABST
Patent Text Reader

Abstract

This invention proposes a corn ear classification method based on a custom lightweight convolutional neural network, which solves the problems of high computational cost and poor interpretability of traditional deep learning models. The main steps include: S1, collecting corn ear images and constructing a corresponding dataset; S2, constructing a classification model based on a convolutional neural network, including: an input layer for scaling and normalizing the image and inputting it into the model; a feature extraction layer for extracting features from the input image; a classification layer for performing classification prediction using the extracted features; and an output layer for outputting the image prediction results; S3, iteratively training and validating the classification model according to an optimized training strategy until its performance indicators stabilize and then saving the model; S4, testing the classification model saved in step S3; if the performance does not meet the requirements, repeating step S3; and S5, visualizing the classification results of the classification model using the Grad-CAM algorithm.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of deep learning and image processing technology, specifically to a corn ear classification method based on a custom lightweight convolutional neural network suitable for corn ear sorting production lines. Background Technology

[0002] Hybrid maize seed production is the main method of producing maize seeds, and hybrid seeds have a significant yield-increasing effect. During field production, incomplete detasseling and lax impurity removal can easily lead to the production of impure or substandard maize seeds, seriously affecting the purity and quality of the seeds. To improve the purity and quality of maize seeds, manual methods are typically used in the field or seed processing plants to remove abnormal maize ears containing impurities and substandard kernels based on color and appearance differences. Sorting abnormal maize ears is the first step in the maize seed production line and the final step in effectively separating abnormal ears.

[0003] The current method of sorting corn ears by hand, relying on visual observation and experience, suffers from several drawbacks. The sorting quality is heavily influenced by human subjective judgment and attention, and sorting costs and efficiency are constrained by labor costs and manual sorting efficiency. Therefore, there is an urgent need for a new method that can quickly and accurately replace manual labor to improve the efficiency and quality of corn seed production.

[0004] In recent years, deep learning and image processing technologies have achieved significant progress in image classification, providing a new approach to solving the problem of corn seed sorting. However, traditional convolutional neural networks have a large number of parameters and high network depth, making them unsuitable for solving problems with small sample datasets and for deployment in resource-constrained embedded devices. Most research on deep learning models focuses on performance metrics while neglecting computational cost, which hinders the deployment and widespread application of deep learning in corn seed production lines. Furthermore, deep learning models have poor interpretability, making it difficult for researchers to verify the accuracy of the learned classification features. Therefore, this technology is difficult to further promote in practical applications. Summary of the Invention

[0005] The technical problem to be solved by this invention is to overcome the defects of the existing technology. This invention proposes a corn ear classification method based on a custom lightweight convolutional neural network. This method can achieve a good balance between performance and computational cost, overcome the shortcomings of traditional convolutional neural network models such as deep model and insufficient generalization ability for small datasets, and provide a visual model classification result to improve the interpretability of the model, which is conducive to improving the efficiency and quality of corn ear sorting.

[0006] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is: a corn ear classification method based on a custom lightweight convolutional neural network, comprising the following steps:

[0007] S1. Collect images of corn ears and construct a corresponding dataset, the dataset including images of normal corn ears and images of abnormal corn ears;

[0008] S2. Construct a classification model based on a convolutional neural network, wherein the classification model includes,

[0009] The input layer is used to scale and normalize the maize ear image from step S1 and input it into the model.

[0010] The feature extraction layer is used to extract features from the maize ear image input to the input layer. This layer consists of five convolutional blocks of increasing depth. Each convolutional block comprises a convolutional layer, a pooling layer, a batch normalization layer, an activation function, and an attention mechanism. The convolutional layer first performs convolution on the input maize ear image to extract initial features. Subsequently, the initial features are downsampled, data distribution adjusted, and non-linearly augmented through the pooling layer, batch normalization layer, and activation function to obtain classification features. The attention mechanism is used to extract the importance of each channel in the classification features.

[0011] The classification layer, consisting of a global average pooling layer, a fully connected layer, and a classifier, is used to predict the classification based on the features extracted by the feature extraction layer.

[0012] The output layer is used to output the prediction results of maize ear images. The prediction results include normal maize ears and abnormal maize ears.

[0013] S3. Based on the optimized training strategy, repeatedly train and verify the classification model until its performance indicators tend to stabilize and save the model.

[0014] S4. Test the classification model obtained in step S3. If the performance does not meet the requirements, repeat the training and verification process in step S3.

[0015] S5. Visualize the classification results of the classification model using the Grad-CAM algorithm.

[0016] Furthermore, in step S2,

[0017] The scaling function in the input layer is Resize, and the normalization function is Normalize.

[0018] In the feature extraction layer, the convolutional function corresponding to the convolutional layer is Conv2d, the pooling function corresponding to the pooling layer is MaxPool2d, the batch normalization function corresponding to the batch normalization layer is BatchNorm2d, the activation function is ReLU, and the attention mechanism is Squeeze-and-Excitation Networks.

[0019] In the classification layer, the global average pooling layer corresponds to the function AdaptiveAvgPool2d, the fully connected layer corresponds to the function Linear, and the classifier is the Softmax classifier.

[0020] Furthermore, the steps for the attention mechanism to extract the importance of each channel in the classification features are as follows:

[0021] The classification features X derived from convolutional layers, pooling layers, batch normalization layers, and activation functions c Squeeze.

[0022] The classification feature X is processed by a global average pooling layer. c Planar dimensionality is used to obtain the channel attention vector Z. c ,

[0023] For Z c The incentive is applied by capturing the weight relationship S between feature channels through a global average pooling layer, a fully connected layer, and a ReLU function. c Using the Sigmoid function to convert S c Mapped to the [0,1] interval,

[0024] S c With X c The corresponding weights are applied, and the output feature X′ is calculated. c The calculation formula is:

[0025] X′ c =X c σ(W2δ(W1Z c ))

[0026] Where σ represents the Sigmoid function, δ represents the ReLU function, and W1 and W2 represent two fully connected layers, respectively.

[0027] Furthermore, the optimized training strategy in step S3 involves data augmentation and dynamic learning rate setting. The specific steps of data augmentation are as follows:

[0028] Offline data augmentation is performed on the original dataset to obtain an augmented dataset, and the augmented dataset is combined with the original dataset to obtain a new dataset.

[0029] The new dataset is randomly divided into training, validation, and test sets. Images from the training and validation sets are input into the classification model for training and validation, while online data augmentation is performed on the input images.

[0030] The specific steps for setting the dynamic learning rate are as follows: based on the model's performance at different fixed learning rates and the changes in the training process, set the initial learning rate and decay period of the dynamic learning rate.

[0031] Furthermore, the specific steps for training, validating, and saving the classification model in step S3 are as follows:

[0032] The DataLoader function is used to input images from the training set into the classification model. The classification model calculates the predicted values ​​and uses the CrossEntropyLoss function to calculate the loss between the predicted values ​​and the true values. The loss value is used to call the Backward function to backpropagate and update the classification model parameters. After training on all images in the training set, the performance of the network parameters in this training cycle is verified through the validation set.

[0033] The DataLoader function is used to input images from the validation set into the classification model. The classification model calculates the predicted values, and the CrossEntropyLoss function is used to calculate the loss between the predicted values ​​and the true values. Based on the predicted values, various performance indicators of the classification model are calculated.

[0034] The classification model is repeatedly trained and validated until the performance indicators tend to stabilize, and the classification model is obtained and saved.

[0035] Furthermore, the performance metrics include model accuracy, precision, recall, and F1 score, and the formulas for calculating each performance metric are as follows:

[0036]

[0037]

[0038]

[0039]

[0040] Where TP represents a correctly identified positive sample, FP represents a incorrectly identified negative sample, FN represents a incorrectly identified positive sample, and TN represents a correctly identified negative sample.

[0041] Furthermore, the specific steps for visualizing the classification results using the Grad-CAM algorithm in step S4 are as follows:

[0042] Backpropagation is performed on the prediction results of a certain category to obtain the gradient information of a certain feature layer backpropagated.

[0043] The average gradient information in both width and height dimensions is calculated to determine the importance of each channel.

[0044] The data from each channel of this feature layer is weighted and summed, and a Grad-CAM heatmap is obtained by applying the ReLU activation function. The heatmap and the original image are then overlaid to obtain the final visualization result. The Grad-CAM calculation formula is as follows:

[0045]

[0046] Where A represents a feature layer; k represents the k-th channel in feature layer A; c represents the category c; A k This represents the data of channel k in feature layer A; α c k A represents k The weights of y c This represents the predicted value for category c; A k ij Z represents the data of feature layer A at position (i, j) in channel k; Z represents the width × height of the feature layer.

[0047] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps of the corn ear classification method based on a custom lightweight convolutional neural network described above.

[0048] A non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is used to implement the steps of the corn ear classification method based on a custom lightweight convolutional neural network described above.

[0049] Compared with the prior art, the beneficial effects of the present invention include:

[0050] (1) This method achieves a good balance between model performance and computational cost, meeting the deployment requirements of maize seed ear sorting production line;

[0051] (2) Compared with traditional deep network models, this method can achieve better generalization ability on small datasets;

[0052] (3) The image acquisition device can acquire corn ear images with the same characteristics as the images generated in actual applications, which helps to reduce the amount of data required for model training and thus improve the efficiency of deep learning deployment in actual applications.

[0053] (4) The two training strategies, data augmentation and dynamic learning rate, were optimized to improve model performance and training efficiency.

[0054] (5) The model’s classification results were explained using visualization algorithms, which improved the interpretability of the model. Attached Figure Description

[0055] The disclosure of this invention is illustrated with reference to the accompanying drawings. It should be understood that the drawings are for illustrative purposes only and are not intended to limit the scope of protection of this invention. In the drawings, the same reference numerals are used to refer to the same parts. Wherein:

[0056] Figure 1 A schematic diagram illustrating the overall method flowchart according to one embodiment of the present invention is shown.

[0057] Figure 2 The illustration shows a schematic diagram of a normal maize ear according to an embodiment of the present invention;

[0058] Figure 3 The illustration shows a schematic diagram of an abnormal maize ear image according to an embodiment of the present invention;

[0059] Figure 4 The diagram schematically illustrates the network structure of a classification model proposed according to an embodiment of the present invention.

[0060] Figure 5 The diagram schematically shows the model classification visualization results proposed according to an embodiment of the present invention, wherein (a) is the visualization result of maize ears with only one category in an image, and (b) is the visualization result of maize ears with two categories in an image. Detailed Implementation

[0061] It is readily understood that, based on the technical solution of this invention, those skilled in the art can propose various interchangeable structural methods and implementations without altering the essential spirit of the invention. Therefore, the following detailed embodiments and accompanying drawings are merely illustrative examples of the technical solution of this invention and should not be considered as the entirety of the invention or as limitations or restrictions on the technical solution of this invention.

[0062] According to one embodiment of the present invention, Figures 1-5 As shown.

[0063] like Figure 1 As shown, the present invention provides a method for classifying maize ears based on a custom lightweight convolutional neural network, comprising the following steps:

[0064] S1. Set up an image acquisition device to collect images of corn ears and construct a corn ear dataset;

[0065] In the actual sorting process of corn ears, workers only care whether the ear is an abnormal ear that needs to be removed, and do not care about the specific type of abnormal ear. Therefore, the corn ear categories, i.e., the dataset, are divided into two categories: normal corn ears and abnormal corn ears. Figure 2As shown, the phenotypic characteristics of normal corn ears are relatively consistent, such as plump and glossy kernels, neat rows, and uniform overall color. Figure 3 As shown, the phenotypes of abnormal corn ears differ significantly from those of normal corn ears, exhibiting characteristics such as discoloration, uneven ear color, color difference, shriveled kernels, disordered ear rows, and mold. To ensure that the acquired images have consistent characteristics with those in actual production, the image acquisition device was constructed based on an actual corn ear sorting production line. The industrial camera was positioned 20–40 cm directly above the conveyor belt, which had a black background and a speed of 0.4–1 m / s. The specific workflow of the image acquisition device was as follows: the corn ears moved along the conveyor belt, and after passing a specific position, a power-off sensor was triggered, which in turn triggered the industrial camera to acquire an image. When developing deep learning models for specific application scenarios, this method helps reduce the amount of data required for model training, improves the model's generalization ability, and increases the efficiency of model deployment in practical applications. Finally, 520 corn ear images were acquired using the image acquisition device as the dataset for model training, including 170 normal corn ear images and 350 abnormal corn ear images.

[0066] S2. Design a classification model based on convolutional neural networks for corn ear image classification;

[0067] To meet the requirements of high performance and low computational cost in a corn ear sorting production line, this invention defines a novel lightweight convolutional neural network for corn ear classification, named CornNet. The network structure of CornNet is as follows: Figure 4 As shown, CornNet consists of an input layer, a feature extraction layer, a classification layer, and an output layer.

[0068] (1) The input layer inputs the scaled and normalized image into the model. The scaling function is Resize, and the scaled image size is 224×224×3; the normalization function is Normalize, and the channel mean and standard deviation used for normalization are [0.485, 0.456, 0.406] and [0.229, 0.224, 0.225].

[0069] (2) The feature extraction layer consists of five convolutional blocks, each of which comprises a convolutional layer, a pooling layer, a batch normalization layer, an activation function, and an attention mechanism module. The convolutional function of the convolutional layer is Conv2d, with a kernel size of 3×3 and padding of 1; the pooling function of the pooling layer is MaxPool2d, with a kernel size of 2×2 and a stride of 2; the function of the batch normalization layer is BatchNorm2d; the activation function is ReLU; and the attention mechanism is "Squeeze-and-Excitation Networks" (SE).

[0070] (3) The classification layer consists of a global average pooling layer, a fully connected layer, and a classifier. The global average pooling layer uses the function AdaptiveAvgPool2d; the fully connected layer uses the function Linear, with 128 input neurons and 2 output neurons; and the classifier is a Softmax classifier. The output layer outputs the prediction results of the maize ear image, with the prediction results categorized as normal maize ears or abnormal maize ears.

[0071] Models with deeper network structures can learn more complex feature relationships, at the cost of increased parameter count and computational cost. However, they are prone to local optimization and overfitting when faced with insufficient data. CornNet reduces the number of convolutional layers, fully connected layers, and channels in convolutional layers to reduce parameter count and model depth, thereby improving the model's adaptability and generalization ability on small datasets.

[0072] The number of convolutional layers and channels in the five convolutional blocks are 1, 1, 1, 1, and 3-8, 8-16, 16-32, 32-64, and 64-128, respectively. CornNet uses a global average pooling layer instead of the first fully connected layer in a traditional classification layer. One advantage is that it enforces the correspondence between feature maps and classes, which better aligns with the characteristics of a convolutional structure. Another advantage is that no parameters need to be optimized, which not only reduces the number of model parameters but also effectively avoids overfitting.

[0073] SE attention mechanism allows the model to automatically learn the importance of each feature channel, focusing it on specific feature channels and thus improving the model's feature extraction ability. Batch normalization layers use the mean and standard deviation of each mini-batch input to continuously adjust the intermediate output of each neural network layer, accelerating the forward propagation of the network model and effectively avoiding gradient vanishing.

[0074] Based on the above, the steps of the attention mechanism to extract the importance of each channel in classification features are as follows:

[0075] The classification features X derived from convolutional layers, pooling layers, batch normalization layers, and activation functions c Squeeze.

[0076] The channel attention vector Z is obtained through a global average pooling layer. c This means that the categorical features are planarized using an average pooling layer.

[0077] For Z c The incentive is applied by capturing the weight relationship S between feature channels through a global average pooling layer, a fully connected layer, and a ReLU function. c Using the Sigmoid function to convert S cMapped to the [0,1] interval,

[0078] S c With X c The corresponding weights are applied, and the output feature X′ is calculated. c The calculation formula is:

[0079] X′ c =X c σ(W2δ(W1Z c ))

[0080] Where σ represents the Sigmoid function, δ represents the ReLU function, and W1 and W2 represent two fully connected layers, respectively.

[0081] S3. Train and validate the model designed in step S2 based on the improved training strategy, and save the model;

[0082] In this embodiment of the invention, to further improve model performance and training efficiency, two traditional training strategies—data augmentation and dynamic learning rate—are optimized. The specific operation process is as follows:

[0083] Data augmentation is a method to generate more effective data from limited data, increasing the quantity and diversity of training samples, preventing overfitting, and improving generalization ability. It can be divided into online and offline data augmentation. Offline data augmentation directly expands the sample size of the original dataset, but significantly increases the computational and time costs of model training. Online data augmentation can increase the diversity of training images without increasing the number of images in the dataset, but its effectiveness depends on the sample size of the original dataset. Addressing the advantages and disadvantages of both offline and online data augmentation, this invention proposes a comprehensive data augmentation strategy.

[0084] First, the original dataset was expanded using offline data augmentation, preprocessing images in three different ways (horizontal flip, vertical flip, and random rotation). The augmented images were then combined with the original images to construct a new dataset of 2080 images (640 normal maize ears and 1400 abnormal maize ears). The new dataset was then randomly divided into three groups: a training set (60%), a validation set (20%), and a test set (20%), with a 17:35 ratio of normal to abnormal maize ear images in each group. Finally, when the training and validation sets were used to train and validate the model, online data augmentation was employed to further enhance the diversity of data features. Brightness adjustment, Gaussian blur, and random cropping were preprocessed on each batch of images input to the model.

[0085] The learning rate is a crucial hyperparameter in convolutional neural networks, determining the update rate of the model's weight parameters. Both excessively high and low learning rates negatively impact model training, and it's difficult to determine the optimal learning rate based solely on experience. To address this issue, this invention proposes analyzing the performance and training process variations under different fixed learning rates through preliminary experiments to rationally set the initial learning rate and decay period for dynamic learning. Analysis of model performance and training process fluctuations at fixed learning rates of 0.1, 0.01, 0.001, 0.0001, and 0.00001 reveals that at learning rates of 0.01, 0.001, and 0.0001, the model converges quickly, exhibiting high accuracy and low loss, but with significant fluctuations in weight parameter updates during training. At a learning rate of 0.00001, the model training process is stable with no significant fluctuations, but the convergence time is longer. Ultimately, an initial learning rate of 0.01 was determined, decaying tenfold in the 2nd, 3rd, and 10th cycles.

[0086] Specifically, the process of training, validating, and saving the classification model is as follows:

[0087] (1) The input layer uses the DataLoader function to input maize ear images from the training set into the feature extraction layer. The image size is scaled to 224×224×3 and normalized. The number of images input in each batch is 8.

[0088] (2) The feature extraction layer consists of five convolutional blocks from shallow to deep to extract features from the corn ear image. The processing of each convolutional block is as follows: first, the input image is convolved by the convolutional layer to extract classification features; then, the classification features are downsampled by the pooling layer to reduce the spatial dimension and positional sensitivity of the features; then, the data distribution of the classification features is adjusted by the batch normalization layer to ensure the stability of parameter updates and prevent gradient vanishing; then, the nonlinearity of the classification features is increased by the activation function; and finally, the importance of each channel of the classification features is extracted by the SE attention mechanism.

[0089] (3) After extracting the classification features, the classification layer performs classification prediction. First, the classification features are input into the global average pooling layer to calculate the average value of each channel to obtain the global receptive field. Then, all features are integrated into two features with category information through the fully connected layer. Finally, the features are input into the classifier Softmax to obtain the predicted value. The loss value between the predicted value and the true value is calculated by the loss function CrossEntropyLoss. The loss value calls the Backward function to backpropagate and update the network model parameters. After training all images in the training set once, the performance of the network parameters in this training cycle is verified using the validation set. The validation image is input to the model using the DataLoader function. The model calculates the predicted value. The loss value between the predicted value and the true value is calculated by the loss function CrossEntropyLoss. Based on the predicted value, performance indicators such as model accuracy, precision, recall, and F1 score are calculated.

[0090] The calculation formulas for each performance index are as follows:

[0091]

[0092]

[0093]

[0094]

[0095] Where TP represents a correctly identified positive sample, FP represents a incorrectly identified negative sample, FN represents a incorrectly identified positive sample, and TN represents a correctly identified negative sample.

[0096] (4) Repeatedly iterate the training and verification process until each performance index tends to stabilize, obtain the classification model of maize ears and save it.

[0097] S4, use the test set to test the saved classification model;

[0098] In this embodiment of the invention, the classification model obtained in step S3 is tested using maize ear images from the test set. If the model performance does not meet the requirements, the model is retrained until the performance meets the requirements. Ultimately, CornNet performs well in terms of accuracy, F1 score, model size, and FLOPs, at 98.56%, 98.93%, 0.42MB, and 0.07G, respectively, indicating that it achieves a good balance between model performance and computational cost.

[0099] S5. Visualize the classification results of the classification model using the Grad-CAM algorithm;

[0100] In this embodiment of the invention, the Grad-CAM algorithm is used to visualize the classification results of the model to verify whether the classification features learned by the model are correct. An image of a corn ear is input into the model to obtain a predicted value. The predicted value of this image category is backpropagated to obtain the gradient information of a certain feature layer. Then, the mean of the gradient information in both width and height dimensions is calculated to obtain the importance of each channel. The data of each channel in this feature layer are then weighted and summed. Finally, a Grad-CAM heatmap is obtained through the ReLU activation function. The heatmap and the original image are then overlaid to obtain the final visualization result.

[0101] The Grad-CAM calculation formula is as follows:

[0102]

[0103] Where A represents a feature layer; k represents the k-th channel in feature layer A; c represents the category c; A k This represents the data of channel k in feature layer A; α c k A represents k The weights of y c This represents the predicted value for category c; A k ij Z represents the data of feature layer A at position (i, j) in channel k; Z represents the width × height of the feature layer.

[0104] Visualization results as follows Figure 5 As shown, Figure 5 (a) To visualize images of maize ears with only one category, the model focuses on the relatively consistent regions of interest for normal maize ears, which corresponds to the relatively consistent phenotypic features of normal maize ears; the model focuses on different regions of interest for each abnormal maize ear, extracts the unique features of each abnormal ear, and focuses on the kernels, ignoring other factors such as the background and maize ears. Figure 5 (b) To visualize images of maize ears with two categories, the model can completely avoid the other category of maize ears when extracting features from one category. These results demonstrate that the model can learn the correct classification features.

[0105] Similarly, this embodiment also provides an electronic device, which includes: a memory, a processor, and a computer program stored in the memory and capable of running on the processor. The processor can execute the steps of the above-mentioned corn ear classification method based on a custom lightweight convolutional neural network by calling program instructions, and can achieve the same technical effect as the above method.

[0106] Similarly, this embodiment also provides a storage medium storing a computer program. When the computer program is executed by at least one processor, it implements the steps of the corn ear classification method based on a custom lightweight convolutional neural network, and achieves the same technical effect as the above method.

[0107] This invention provides a corn ear classification method based on a custom lightweight convolutional neural network. A novel lightweight convolutional neural network model is defined, optimizing traditional training strategies. The Grad-CAM algorithm is used to visualize the model's classification results. Experiments in corn ear classification show that, for small-scale corn ear datasets, this method achieves a good balance between model performance and computational cost compared to deep learning models with deeper networks, resulting in superior generalization ability and facilitating deployment in corn ear sorting pipelines. The two optimized training strategies proposed in this invention effectively improve model performance and training efficiency, increasing classification accuracy by 3.07–16.08% and 0.26–30.91%, respectively, compared to traditional training strategies. This invention utilizes the Grad-CAM algorithm to visualize the model's classification results, providing interpretability and verifying the correctness of the learned classification features.

[0108] The technical scope of this invention is not limited to the content described above. Those skilled in the art can make various modifications and variations to the above embodiments without departing from the technical concept of this invention, and all such modifications and variations should fall within the protection scope of this invention.

Claims

1. A method for classifying maize ears based on a custom lightweight convolutional neural network, characterized in that, Includes the following steps: S1. Collect images of corn ears and construct a corresponding dataset, the dataset including images of normal corn ears and images of abnormal corn ears; S2. Construct a classification model based on a convolutional neural network, wherein the classification model includes, The input layer is used to scale and normalize the corn ear image from step S1 and input it into the model; The feature extraction layer is used to extract features from the maize ear image input to the input layer. The feature extraction layer consists of five convolutional blocks from shallow to deep. Each convolutional block consists of a convolutional layer, a pooling layer, a batch normalization layer, an activation function, and an attention mechanism. The convolutional layer first performs convolution on the input maize ear image to extract initial features. Then, the initial features are downsampled, data distribution adjusted, and nonlinearly increased through the pooling layer, batch normalization layer, and activation function to obtain classification features. The attention mechanism is used to extract the importance of each channel in the classification features. The attention mechanism is a Squeeze-and-Excitation Network. The classification layer, consisting of a global average pooling layer, a fully connected layer, and a classifier, is used to predict the classification based on the features extracted by the feature extraction layer. The output layer is used to output the prediction results of maize ear images. The prediction results include normal maize ears and abnormal maize ears. S3. Based on the optimized training strategy, repeatedly train and verify the classification model until its performance indicators tend to stabilize and save the model. S4. Test the classification model obtained in step S3. If the performance does not meet the requirements, repeat the training and verification process in step S3. S5. Visualize the classification results of the classification model using the Grad-CAM algorithm.

2. The method for classifying maize ears based on a custom lightweight convolutional neural network according to claim 1, characterized in that: In step S2 The scaling function in the input layer is Resize, and the normalization function is Normalize. In the feature extraction layer, the convolution function corresponding to the convolution layer is Conv2d, the pooling function corresponding to the pooling layer is MaxPool2d, the batch normalization function corresponding to the batch normalization layer is BatchNorm2d, and the activation function is ReLU; In the classification layer, the global average pooling layer corresponds to the function AdaptiveAvgPool2d, the fully connected layer corresponds to the function Linear, and the classifier is the Softmax classifier.

3. The method for classifying maize ears based on a custom lightweight convolutional neural network according to claim 1, characterized in that: The steps for the attention mechanism to extract the importance of each channel in the classification features are as follows: Classification features derived from convolutional layers, pooling layers, batch normalization layers, and activation functions. Squeeze. Classification features are processed through a global average pooling layer. Planar dimensionality to obtain channel attention vectors , right The activation is achieved by capturing the weight relationships between feature channels through a global average pooling layer, a fully connected layer, and a ReLU function. Using the Sigmoid function to Mapped to the [0,1] interval, Will and The corresponding weights are applied to output the features. The calculation formula is: ; in, This represents the Sigmoid function. Represents the ReLU function. and These represent two fully connected layers.

4. The method for classifying maize ears based on a custom lightweight convolutional neural network according to claim 1, characterized in that: The optimized training strategy in step S3 involves data augmentation and dynamic learning rate setting. The specific steps for data augmentation are as follows. Offline data augmentation is performed on the original dataset to obtain an augmented dataset, and the augmented dataset is combined with the original dataset to obtain a new dataset. The new dataset is randomly divided into training, validation, and test sets. Images from the training and validation sets are input into the classification model for training and validation, while online data augmentation is performed on the input images. The specific steps for setting the dynamic learning rate are as follows: based on the model's performance at different fixed learning rates and the changes in the training process, set the initial learning rate and decay period of the dynamic learning rate.

5. The method for classifying maize ears based on a custom lightweight convolutional neural network according to claim 4, characterized in that: The specific steps for training, validating, and saving the classification model in step S3 are as follows: The DataLoader function is used to input training set images into the classification model. The classification model calculates the predicted values. The CrossEntropyLoss function is used to calculate the loss between the predicted values ​​and the true values. The loss value is used to call the Backward function to backpropagate and update the classification model parameters. After training on all images in the training set, the performance of the network parameters during the training cycle is verified through the validation set. The DataLoader function is used to input validation set images into the classification model. The classification model calculates the predicted values, and the CrossEntropyLoss function is used to calculate the loss between the predicted values ​​and the true values. Based on the predicted values, various performance indicators of the classification model are calculated. The classification model is repeatedly trained and validated until the performance indicators tend to stabilize, and the classification model is obtained and saved.

6. The method for classifying maize ears based on a custom lightweight convolutional neural network according to claim 1, characterized in that: The performance metrics include model accuracy. Accuracy Accuracy precision Recall rate recall and F1 score F1 score The calculation formulas for each performance index are as follows: ; ; ; ; in, TP This indicates a correctly identified positive sample. FP Indicates a misidentified negative sample. FN This represents a positive sample that was incorrectly identified. TN This represents a correctly identified negative sample.

7. The method for classifying maize ears based on a custom lightweight convolutional neural network according to claim 1, characterized in that: The specific steps for visualizing the classification results using the Grad-CAM algorithm in step S4 are as follows: Backpropagation is performed on the prediction results of a certain category to obtain the gradient information of a certain feature layer backpropagated. The average gradient information in both width and height dimensions is calculated to determine the importance of each channel. The data from each channel of this feature layer is weighted and summed, and a Grad-CAM heatmap is obtained by applying the ReLU activation function. The heatmap and the original image are then overlaid to obtain the final visualization result. The Grad-CAM calculation formula is as follows: ; in, A Represents a certain feature layer; k Representation of feature layer A The first in k One channel; c Indicate category c ; A k Representation of feature layer A Central Channel k Data; α c k express A k The weights; y c Indicates category c The predicted value; A k ij Representation of feature layer A In the passage k middle( i , j Data at ) Z This represents the width × height of the feature layer.

8. 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, it implements the steps of the corn ear classification method based on a custom lightweight convolutional neural network as described in any one of claims 1 to 7.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, it is used to implement the steps of the corn ear classification method based on a custom lightweight convolutional neural network as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Highway congestion identification model construction method and device and identification method

    CN112101117A

  • Lightweight small target detection method coupling attention and context

    CN113673616A