Improved ResNet18 corn leaf disease classification method
By improving the ResNet18 neural network model, using higher-order residual structure, SK attention mechanism, asymmetric convolutional layer and alternating activation function, the problems of low recognition rate and many model parameters in corn leaf disease recognition are solved, and higher recognition accuracy and lower model volume are achieved.
Patent Information
- Application Number
- CN202411925335.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-06-27
AI Technical Summary
The existing convolutional neural network method has a low recognition rate in corn leaf disease recognition, and its feature difference recognition is not obvious. There are many model parameters and large model volume, resulting in low efficiency and low accuracy.
The ResNet18 neural network model is improved, the higher-order residual structure is used instead of the ordinary residual structure, the SK attention mechanism is introduced, the asymmetric convolution layer is used, and the ReLU and SELU activation functions are used alternately to improve feature extraction capabilities and recognition accuracy.
It improves the accuracy of corn leaf disease classification, reduces network parameters, reduces model volume, and improves calculation speed and identification efficiency.
Smart Images

Figure CN120219786A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of image processing technology, relates to computer vision and pattern recognition technology, and specifically relates to a corn leaf disease classification method based on an improved ResNet18. Background Art
[0002] In recent years, my country's corn planting area has continued to expand, and corn diseases have always been a problem that plagues corn planting. These diseases have a great impact on corn quality and yield, and also affect people's lives and economy. Disease identification and prevention are important means to ensure crop quality and yield. With the development of artificial intelligence technology, it is particularly important to be able to identify and detect corn leaf diseases in a timely and effective manner.
[0003] The traditional identification method uses naked eye observation and relies more on the personal experience of agricultural technicians. This method is greatly influenced by subjective judgment, has some limitations in identification, is not efficient, and has low accuracy. With the development of computer image recognition technology, it has become a common practice in this field to apply image recognition technology to crop prevention and control diagnosis. However, the general convolutional neural network method often has a low recognition rate for diseases, especially corn leaf diseases, and the feature difference recognition is not obvious. There are also problems such as many model parameters and large model size. Summary of the invention
[0004] To solve the above problems, the present invention discloses a corn leaf disease classification method based on an improved ResNet18, which saves computing resources, improves recognition accuracy, and obtains accurate and stable crop leaf disease recognition effect.
[0005] To achieve the above object, the technical solution of the present invention is as follows:
[0006] A corn leaf disease classification method based on improved ResNet18 includes the following steps:
[0007] Step 1, obtaining a corn leaf image, and preprocessing the image to obtain an image data set;
[0008] Step 2: Send the image data to the improved ResNet18 neural network model for training, and classify the output results using the softmax function;
[0009] The improved ResNet18 neural network model includes the following sequentially connected components:
[0010] 1 convolution layer with 64 convolution kernels of size 7×7 connected to a maximum pooling layer;
[0011] The first residual block is a high-order residual module composed of three 3×3 convolutional layers with 64 channels each and two skip connections; the calculation formula of the high-order residual module is:
[0012] H(x) = F(x) + x + F(F(F(x))),
[0013] where x is the input, F is the convolution operation, F(x) is the output after the first convolutional layer, F(F(x)) is the output after two convolutional layers, and F(F(F(x))) is the output after three convolutional layers;
[0014] The second residual block is a high-order residual module composed of three 3×3 convolutional layers with 64 channels each and two skip connections;
[0015] The third residual block is a common residual block composed of two 3×3 convolutional layers with 128 channels each and one skip connection;
[0016] The fourth residual block is a residual block with an embedded attention mechanism composed of two 3×3 convolutional layers with 128 channels each, one layer of SK attention mechanism, and one skip connection;
[0017] The fifth residual block is a common residual block composed of two 3×3 convolutional layers with 256 channels each and one skip connection;
[0018] The sixth residual block is a residual block in which an asymmetric convolutional layer composed of three parallel convolutional layers of 256 3×3, 1×3, and 3×1 replaces the ordinary convolution;
[0019] One global average pooling layer;
[0020] One fully connected layer;
[0021] Step 3: Input the disease image to be recognized into the improved ResNet18 neural network model trained in Step 2 for recognition and classification to obtain the maize leaf disease information under the corresponding category.
[0022] Furthermore, in the improved ResNet18 neural network model, the ReLU activation function is used in the first, third, and fifth residual blocks, and the SELU activation function is used in the second, fourth, and sixth residual blocks.
[0023] Furthermore, the process of preprocessing the image includes: screening, labeling, and enhancing the image.
[0024] Furthermore, screening the image includes: selecting the images that conform to maize leaf diseases from the images and discarding the images that do not conform to maize leaf diseases.
[0025] Furthermore, labeling the image includes: classifying and labeling each type of different disease leaves.
[0026] Further, enhancing the image includes any one or a combination of several of the following methods: blurring, horizontal flipping, adding noise, and magnifying the image.
[0027] Further, the image dataset includes a training set and a test set, and the images are enhanced for the training set.
[0028] The beneficial effects of the present invention are as follows:
[0029] 1. The present invention uses an improved ResNet18, replacing the ordinary residual structure with a high-order residual structure. The sum operation is performed on multiple inputs. First, low-level features are extracted through the first convolutional layer, and then connected to ordinary residual blocks to further extract richer features, forming a high-order residual structure. The information of the shallow network is directly transmitted to the following network structure for continued extraction, providing rich and detailed feature expressions for the disease manifestations of corn leaves, and improving the network's ability to extract features of tiny lesions.
[0030] 2. To ensure the feature extraction ability of the entire network, rich features obtained from the shallow network are extracted, and the SK attention mechanism is inserted. The network itself learns to select and fuse the feature map information of different receptive fields, capturing multi-scale features in the complex image space, enabling the model to pay more attention to the lesion area.
[0031] 3. In the last residual block of the backbone network, an asymmetric convolutional layer composed of three parallel convolutional layers of 3×3, 1×3, and 3×1 is used to replace the ordinary convolutional layer, enhancing the weight of the convolutional kernel skeleton, improving the diversity of feature extraction, better extracting the rich features obtained from the previous several layers of the network, reducing the calculation parameters of the convolutional layer, reducing the training time of the model, and improving the calculation speed.
[0032] 4. Alternating the ReLU activation function and the SELU activation function compensates for the phenomenon of neuron "death" during the model training process.
[0033] 5. The method of the present invention improves the accuracy of corn leaf disease classification, thereby improving the recognition accuracy of corn diseases, reducing network parameters, and thus reducing the model size. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 It is a structural diagram of the improved ResNet18 model provided by the present invention.
[0035] Figure 2 It is a schematic diagram of the high-order residual module structure.
[0036] Figure 3 It is a schematic diagram of the attention mechanism model.
[0037] Figure 4It is a schematic diagram of the structure of the asymmetric convolution layer.
[0038] Figure 5 It is a comparison chart of the images of two activation functions, ReLU and SELU.
[0039] Figure 6 It is a schematic diagram of the training accuracy of the model.
[0040] Figure 7 It is a schematic diagram of the training loss of the model. Specific implementation manners
[0041] The technical solution provided by the present invention will be described in detail below in combination with specific embodiments. It should be understood that the following specific implementation manners are only used to illustrate the present invention and not to limit the scope of the present invention.
[0042] An improved method for classifying maize leaf diseases based on ResNet18 provided in this embodiment includes the following steps:
[0043] Step 1, acquisition and preprocessing of maize leaf images
[0044] In this example, the processed images are of maize diseased leaves obtained from the public dataset PlantVillage. First, the images need to be screened, and the images that meet the maize leaf diseases are selected from the images, and the images that do not meet are discarded.
[0045] The images are labeled, and each different type of diseased leaf is classified and labeled. In this example, a total of 3 types of diseased images of maize are obtained, including northern leaf blight of maize, gray leaf spot of maize, and rust of maize. These 3 diseases are used as positive samples for the experiment. In addition, images of healthy maize leaves need to be obtained as negative samples for the experiment. A total of 4 types of maize sample images are obtained, totaling 4354.
[0046] 60% of all the images are used as the training set, and 40% are used as the test set. Data augmentation is performed on the images. The principle of data augmentation is to only augment the training set. The data augmentation of the images includes image blurring, horizontal flipping, noise, and zooming operations. The purpose is to improve the generalization of the data. The blurring transformation simulates the unclear images taken. Horizontal flipping can simulate different shooting angles, and the relative positions of the maize leaf diseases in the image will not change. Salt-and-pepper noise simulates the influence of weather or dust on the shooting of maize leaf diseases, and the zooming operation increases the diversity of the images.
[0047] Step 2, sending the image data into the improved ResNet18 neural network model for training, and using the softmax function for classification of the output results.
[0048] The original ResNet18 contains 18 convolutional layers, and its input layer accepts RGB images with a size of 224x224; the convolutional layer consists of 4 convolutional layers using 3x3 convolutional kernels and ReLU activation functions, which are used to extract local features of the image; the residual block is composed of two convolutional layers and a skip connection, and there are 8 residual blocks in total, which are used to solve the problems of gradient disappearance and gradient explosion in deep neural networks; the global average pooling layer performs global average pooling on the feature map and converts it into a one-dimensional vector; it contains a fully connected layer for classification output; the output layer uses the softmax activation function.
[0049] The original ResNet18 has more parameters, so it is larger in size and has a lower recognition accuracy. The present invention optimizes the ResNet18 network structure. The improved ResNet18 model in this embodiment is obtained on the basis of the original one, and mainly includes the following improvement points:
[0050] Since the pixel of the corn leaf lesion occupies a relatively small proportion of the leaf pixels, the feature information is likely to be lost in the deep network. Therefore, the present invention uses a high-order residual module to replace the ordinary residual module in ResNet18, so that the network can retain the original features of the leaf disease, and extract the underlying features after convolution and the high-level detailed features obtained after multiple convolutions together.
[0051] The present invention introduces the SK attention mechanism in the middle layer of the network, adds the SK attention mechanism module to the residual module, and can help the network focus more on the leaf lesion area extracted by the high-order residual structure by adaptively adjusting the weights of convolutional kernels of different scales, thereby improving the accuracy and efficiency of lesion extraction.
[0052] At the same time, the present invention introduces an asymmetric convolutional kernel to replace the standard convolutional kernel in the last residual block of the backbone network, which can better adapt to the local characteristics of the image, especially the edges or corners of the lesions, and reduces the number of parameters and the amount of calculation while maintaining the accuracy of the extracted features. Because the asymmetric convolution can extract features by using convolutional kernels of different sizes, it can more flexibly adapt to the distribution of data. Therefore, it is placed in the last stage of the network, which helps the model to capture the key features in the image more accurately.
[0053] The improved ResNet model structure is as follows: a convolutional layer with 64 convolutional kernels of size 7×7 in the first layer is connected to a max pooling layer. The first residual block is a high-order residual module, which consists of 3 convolutional layers with 64 3×3 convolutional kernels and two skip connections. The second residual block is a high-order residual module, which consists of 3 convolutional layers with 64 3×3 convolutional kernels and 2 skip connections. The third residual block is a normal residual block, which consists of 2 convolutional layers with 128 3×3 convolutional kernels and 1 skip connection. The fourth residual block is a residual block embedded with an attention mechanism, which consists of 2 convolutional layers with 128 3×3 convolutional kernels, 1 layer of SK attention mechanism and 1 skip connection. The fifth residual block is a normal residual block, which consists of 2 convolutional layers with 256 3×3 convolutional kernels and 1 skip connection. The sixth residual block is composed of an asymmetric convolutional layer instead of a normal convolution, which is composed of three parallel convolutional layers of 256 3×3, 1×3 and 3×1. There is 1 global average pooling layer and 1 fully connected layer. The entire model has 16 convolutional layer models, and the structure diagram is as Figure 1 shown.
[0054] Among them, the structure of the high-order residual module is as Figure 2 shown. There are 3 convolutional layers inside the residual block and it contains 1 residual structure, so as to be able to capture richer feature information. When the depth of the neural network changes, the problem of gradient disappearance or gradient explosion often occurs, resulting in the network being difficult to train. The high-order residual effectively alleviates this problem by introducing two skip connections, allowing the gradient to directly flow back to the shallower layers. This enables us to train networks with different depths. During the training process, the network is easier to converge, which can accelerate the training process and reduce the risk of overfitting, while maintaining stable performance. There are certain similarities between different types of corn leaf diseases, and more are the differences in the underlying small lesions. Both the gray leaf spot and rust leaves of corn have many nearly yellow small spots. Insufficient extraction of underlying features is likely to cause the model to make misjudgments. Therefore, when identifying corn leaf diseases, more similar underlying features need to be considered to increase the accuracy of disease identification. The calculation formula of the high-order residual module is:
[0055] H(x) = F(x) + x + F(F(x)).
[0056] Where x is the input, F is the convolutional operation, F(x) is the output after the first convolutional layer, F(F(x)) is the output after two convolutional layers, and F(F(F(x))) is the output after three convolutional layers.
[0057] In the middle layer of the network of the present invention, the SK attention mechanism is introduced, and the SK attention mechanism module is added to the residual module. As Figure 3As shown in the figure, the SK attention mechanism has a building block of a selective kernel unit. By adaptively adjusting the convolutional kernel weights of different scales, the network can better adapt to the lesion features of different sizes and shapes extracted by the high-order residual structure, improving the robustness of recognition. Introducing the attention mechanism can make the model pay more attention to the lesion area of corn leaves.
[0058] To reduce the model parameters and the training time of the model, in the present invention, an asymmetric convolutional layer composed of three parallel convolutional layers of 3×3, 1×3, and 3×1 is used to replace the ordinary convolutional layer. The original 3×3 convolution is decomposed into three branches of 3×3, 1×3, and 3×1, and then the outputs of these three branches are summed, reducing the calculation parameters of the convolutional layer and improving the calculation speed. The structure of the asymmetric convolutional layer is as Figure 4 shown. This kind of convolution divides the single-branch convolution into multiple-branch convolutions, strengthens the skeleton weights of the convolutional kernels, increases the diversity of feature extraction and the ability of spatial feature extraction, and the three-branch convolutional kernels contain the previous 3×3 convolutional kernel, so the accuracy of the extracted features can be maintained not lower than the previously extracted feature information. Since there are a large number of irregular features in the corn leaf lesion images, the asymmetric convolution has the effect of improving the robustness of flipped and rotated images, and can better capture and emphasize these features, thereby improving the recognition ability of the model. At the last stage of the network, this optimization can more directly affect the output of the model, thus realizing the improvement of the recognition accuracy of corn leaf diseases.
[0059] During the neural network training process, when applying the ReLU activation function, there may be a problem of neuron "death", that is, they stop outputting anything other than 0, which will reduce the generalization ability of the model. ReLU sets all negative values to zero, while SELU will have an exponential function calculation when the parameter is less than 0, which can, to a certain extent, alleviate the situation of neuron "death". The SELU formula is as follows:
[0060]
[0061] where λ and α are fixed parameters, λ = 1.050700987, α = 1.673263242 (the following decimal places are omitted). As Figure 5 shown is the image comparison diagram of ReLU and SELU. During the neural network training process, the ReLu activation function and the SELU activation function are alternately used. Specifically, during the neural network training process, the ReLU activation function and the SELU activation function are alternately used in 6 residual blocks, that is, the ReLU activation function is used in the 1st, 3rd, and 5th residual blocks, and the SELU activation function is used in the 2nd, 4th, and 6th residual blocks.
[0062] Step 3: Input the disease image to be recognized into the trained improved ResNet18 neural network model for recognition and classification to obtain the corn leaf disease information under the corresponding category.
[0063] Train the neural network model based on the obtained corn leaf disease image dataset: Use the Python language to train in the pytorch1.13.1+cpu framework. The size of the input image is 256*256, and the number of channels is 3. The softmax function is used for classification in the final output result. Use the trained improved ResNet18 neural network model to analyze and predict the disease image to be recognized to obtain the corn leaf disease information under the corresponding category.
[0064] As Figure 6 and Figure 7 shown, they are respectively the training result diagrams of the disease dataset, Figure 6 is the model accuracy, Figure 7 is the model loss value. In this embodiment, 50 epochs are trained. At the same time, in order to verify the effect of this improved model, the original ResNet18 model is used as a control group for the same experiment, and the test set is used as the validation set for verification and comparison. The parameter settings are all consistent with the improved ResNet18 model. The comparison table of the two models is shown in Table 1 below:
[0065]
[0066] Table 1
[0067] It can be seen from Table 1 that on the basis of improving the recognition accuracy, the number of parameters of the improved ResNet18 model is much smaller than that of ResNet18. This is because the improved ResNet18 model reduces the number of channels and the number of convolutional layers of the ResNet18 model, and at the same time replaces the continuous ordinary convolutional structure with a separable convolutional structure, and changes the 3*3 convolutional kernel to a combination of 3*3, 1*3, and 3*1 convolutional kernels. It can be seen from the training results that the improved method is better than the original method both in terms of accuracy and loss value.
[0068] It should be noted that the above content only illustrates the technical idea of the present invention and cannot limit the protection scope of the present invention. For those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and retouches can be made, and these improvements and retouches all fall within the protection scope of the claims of the present invention.
Claims
1. A corn leaf disease classification method based on improved ResNet18, characterized in that: The steps include: Step 1, obtaining a corn leaf image, and preprocessing the image to obtain an image data set; Step 2: Send the image data to the improved ResNet18 neural network model for training, and classify the output results using the softmax function; The improved ResNet18 neural network model includes the following sequentially connected components: 1 convolution layer with 64 convolution kernels of size 7×7 connected to a maximum pooling layer; The first residual block is a high-order residual module consisting of three layers of 64 3×3 convolutional layers and two skip connections; the calculation formula of the high-order residual module is: H(x)=F(x)+x+F(F(F(x))), Where x is the input, F is the convolution operation, F(x) is the output after the first convolution layer, F(F(x)) is the output after two convolution layers, and F(F(F(x))) is the output after three convolution layers; The second residual block is a high-order residual module consisting of three layers of 64 3×3 convolutional layers and two skip connections; The third residual block is a common residual block consisting of 2 layers of 128 3×3 convolutional layers and 1 skip connection; The fourth residual block is a residual block with an embedded attention mechanism consisting of 2 layers of 128 3×3 convolutional layers, 1 layer of SK attention mechanism, and 1 skip connection; The fifth residual block is a common residual block consisting of 2 layers of 256 3×3 convolutional layers and 1 skip connection; The sixth residual block is a residual block consisting of an asymmetric convolution layer consisting of 256 parallel 3×3, 1×3 and 3×1 convolution layers instead of ordinary convolutions; 1 global average pooling layer; 1 fully connected layer; Step 3: Input the disease image to be identified into the improved ResNet18 neural network model trained in step 2 for identification and classification, and obtain the corn leaf disease information under the corresponding category.
2. The improved ResNet18 corn leaf disease classification method according to claim 1, characterized in that: In the improved ResNet18 neural network model, the ReLU activation function is used in the 1st, 3rd and 5th residual blocks, and the SELU activation function is used in the 2nd, 4th and 6th residual blocks.
3. The improved ResNet18 corn leaf disease classification method according to claim 1, characterized in that: The process of image preprocessing includes: screening, marking and enhancing images.
4. The improved ResNet18 corn leaf disease classification method according to claim 3 is characterized in that: Screening the images includes: selecting images that match corn leaf diseases from the images, and discarding images that do not match corn leaf diseases.
5. The improved ResNet18 corn leaf disease classification method according to claim 3 is characterized in that: Labeling the images includes classifying and labeling each type of diseased leaves.
6. The improved ResNet18 corn leaf disease classification method according to claim 3, characterized in that: Image enhancement includes any one or a combination of the following methods: image blurring, horizontal flipping, noise, and magnification operations.
7. The improved ResNet18 corn leaf disease classification method according to claim 3, characterized in that: The image data set includes a training set and a test set, and the images in the training set are enhanced.
Citation Information
Cited By
Method and system for evaluating damage level of spodoptera frugiperda based on machine vision
GB2702866A