A rice leaf disease identification method and system based on improved ResNet18

By embedding a convolutional block attention module and an L2 norm-constrained loss function into ResNet18, the problems of spatial location information loss and feature channel redundancy in rice disease detection are solved, improving the model's recognition accuracy and training stability, and achieving efficient identification of rice leaf diseases.

CN122416211APending Publication Date: 2026-07-17GUILIN UNIVERSITY OF TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610401665.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-03-30
Publication Date
2026-07-17

Smart Images

  • Figure CN122416211A_ABST
    Figure CN122416211A_ABST
Patent Text Reader

Abstract

This invention discloses a method and system for identifying rice leaf diseases based on an improved ResNet18 model, belonging to the fields of agricultural artificial intelligence and computer vision technology. The method uses ResNet18 as the backbone network and innovatively embeds convolutional block attention modules (CBAM) serially at the feature output of each residual basic unit. It utilizes a dual channel and spatial attention mechanism to recalibrate the feature map, effectively suppressing background noise and focusing on minute lesion features. Simultaneously, it constructs a cross-entropy loss function (L2-CE Loss) with L2 norm regularization constraints, improving training stability and generalization ability by constraining the magnitude of the output layer Logits vector. Experiments show that the method of this invention achieves an average identification accuracy of 99.67% for rice bacterial blight, rice blast, brown spot disease, and healthy leaves under complex backgrounds, significantly outperforming the traditional ResNet18 model. It exhibits higher generalization ability and robustness, making it suitable for real-time disease monitoring in the field.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of agricultural artificial intelligence and computer vision technology, specifically to a method for identifying rice leaf diseases based on deep learning, and particularly to a detection method that enhances feature representation by embedding a dual attention module in the residual block at all stages. Background Technology

[0002] Rice is an important food crop in my country, and it is susceptible to various diseases during its growth, such as bacterial blight, brown spot, and rice blast. Timely and accurate identification of disease types is of great significance for guiding precise pesticide application and ensuring food security.

[0003] In recent years, significant progress has been made in disease detection technology based on convolutional neural networks (CNNs). Among them, ResNet18, as a classic deep residual network, effectively alleviates the gradient vanishing problem of deep networks due to its residual connection structure, and performs excellently in image classification tasks. However, directly applying the standard ResNet18 to rice disease detection still has the following limitations: Loss of spatial location information: After multiple layers of convolution and downsampling, the spatial resolution of the high-level feature maps of ResNet18 is reduced, which makes it easy for small lesion features (such as brown spots of early rice blast) to be submerged by background noise during transmission, making it difficult for the model to accurately locate the disease area.

[0004] Feature channel redundancy: The standard ResNet18 treats all feature channels equally and lacks an adaptive weighting mechanism for key disease feature channels, resulting in a large amount of computational resources being occupied by irrelevant background features, which reduces the model's discriminative ability.

[0005] Training convergence difficulties: When disease samples are imbalanced or the background is complex, the traditional cross-entropy loss function is prone to causing the model to oscillate in the later stages of training, making it difficult to converge to the optimal solution, and it is also prone to overfitting to some high-frequency categories.

[0006] Existing improvement methods typically only add attention modules at the end of the network or use only a single-channel attention mechanism, failing to achieve fine-grained calibration of ResNet18 features throughout the entire process. Therefore, a disease detection method is needed that can simultaneously enhance ResNet18 across both channel and spatial dimensions throughout the entire process, and optimize the loss function to improve convergence stability. Summary of the Invention

[0007] This invention provides a method and system for identifying rice leaf diseases based on an improved ResNet18, comprising the following steps: Step S1: Collecting rice leaf images to construct a dataset, preprocessing and augmenting the images, including at least one of rotation, flipping, color temperature adjustment, background blurring, Gaussian noise addition, and Mosaic data augmentation, and dividing the dataset into training set, validation set, and test set; Step S2: Referring to... Figure 2 A dual-attention-enhanced ResNet18 recognition model is constructed. The model uses ResNet18 as its backbone network, and a Convolutional Block Attention (CBAM) module is serially embedded at the output of each residual basic unit of the backbone network. The channel attention submodule and spatial attention submodule of the CBAM are used to sequentially weight and calibrate the feature maps. Step S3: [The text abruptly ends here, likely due to an incomplete sentence or a formatting error.] Figure 1 The model is trained using an improved loss function with L2 norm constraints, where N is the batch size of the samples, K is the total number of categories, y_ik is the true label, y_hat_ik is the predicted probability, z_i is the Logits output vector, ||z_i||2 is the L2 norm, and λ is the regularization balance coefficient. The loss function introduces an L2 norm penalty term for the network output Logits vector on the basis of the traditional cross-entropy loss, which is used to constrain the amplitude of the activation values ​​of the output layer and smooth the loss surface. Step S4: Input the image to be identified into the trained model and output the disease category identification result.

[0008] The present invention also provides a rice leaf disease identification system based on a dual attention mechanism to enhance ResNet18, including an image acquisition module, an image preprocessing module, a model loading module, a disease identification module, and a result display module. Attached image description: Figure 1 This is the complete expanded formula diagram of the L2-CE Loss function of this invention. Figure 2 This is a structural diagram of the Basic Block embedded CBAM module of the present invention. Figure 3 This is a comparison chart of the accuracy convergence curves of ResNet18-C in this invention. Figure 4 This is a comparison chart of the accuracy convergence curves of ResNet18-SC in this invention. Detailed Implementation

[0009] The technical solution of the present invention will be described in detail below.

[0010] Example 1 This embodiment provides a method for identifying rice leaf diseases based on an improved ResNet18. This method is implemented on a computer equipped with an ADM processor and an NVIDIA RTX 4060 GPU, using the PyTorch deep learning framework. The specific steps are as follows: Step 1: Data Acquisition and Preprocessing This embodiment uses a dataset of common rice leaf diseases sourced from the open-source platforms Mendeley and Kaggle, containing four categories of samples: bacterial blight, rice blast, brown spot, and healthy leaves. The original dataset contains 662 images, with an imbalance in the number of samples across categories. To improve data quality and expand the sample size, this embodiment performs data augmentation on the original dataset using the following 11 methods: 90° rotation, 180° rotation, 270° rotation, horizontal flip, vertical flip, 90° rotation combined with horizontal flip, 90° rotation combined with vertical flip, random color temperature adjustment, background blur, Gaussian noise addition, and Mosaic data augmentation. After augmentation, the dataset contains 7820 images. The dataset is then divided into training, validation, and test sets at a ratio of 70%, 15%, and 15%, respectively, maintaining a balance among the categories.

[0011] Step 2: Constructing an improved ResNet18 rice leaf disease identification model. This embodiment improves upon the original ResNet18 network: (1) Full-stage CBAM embedding: In this embodiment, a CBAM module is serially embedded at the output of each of the eight residual basic blocks in the four stages of ResNet18, from Layer 1 to Layer 4. After the input features are processed by residual operations, channel weights are first generated through the channel attention submodule of CBAM (including global average pooling, max pooling, and shared MLP), and then spatial weights are generated through the spatial attention submodule (including channel-dimensional pooling and 7×7 convolution) to achieve dual feature calibration. (2) Using the L2-CE Loss function: This embodiment designs a loss function with L2 norm constraints (denoted as L2-CE Loss), the expression of which is referenced. Figure 1 Where N is 32 (Batch Size), K=4, and z_i is the Logits vector output by the fully connected layer. In this embodiment, the regularization balance coefficient λ is set to 0.01. This setting aims to address the gradient oscillation problem that is prone to occur in deep ResNet18 structures by constraining the Logits norm to smooth the loss surface.

[0012] Step 3: Model Training. This example uses the Adam optimizer with an initial learning rate of 0.001, adjusted using a cosine annealing strategy. The training set images are input into the model, and the error is calculated using L2-CE Loss and backpropagated to update the weights. The training process lasts for 50 epochs.

[0013] Step 4: Rice leaf disease identification. After the image to be tested has undergone the same preprocessing, it is input into the trained model. The model outputs a probability distribution of four categories, and the category corresponding to the maximum value is taken as the final identification result.

[0014] Example 2 This example provides a recognition system based on the above method, including: an image acquisition module (industrial camera), an image preprocessing module (embedded GPU board), a model loading module (memory storing the training weights of Example 1), a disease recognition module (processor running inference code), and a result display module (LED display screen or mobile APP interface).

[0015] The system in this embodiment can be deployed on a field inspection robot to achieve real-time disease monitoring.

[0016] Experimental results: The ablation experiment results in Table 1 below show that the test set accuracy based on the ResNet18 model is 98.51%. Introducing the improved loss function (LOSS) or the attention mechanism (CBAM) separately improves the accuracy to 99.42% and 99.59%, respectively, validating the effectiveness of each module. The ResNet18+LOSS+CBAM combination model used in this embodiment achieves the best results, with a test set accuracy of 99.67%, and all metrics (precision, recall, and F1 score) reaching their highest levels. Compared to the baseline model, this combination improves the test set accuracy by 1.16% and outperforms the validation set on the test set, fully demonstrating the significant synergistic effect of the improved loss function and attention mechanism, effectively enhancing the model's generalization ability and robustness.

[0017] Table 1 Ablation Experiment Results

[0018] Figure 3 and Figure 4 A comparison of the accuracy convergence curves of adding ResNet18, ResNet18-C, and ResNet18-SC was plotted. It can be seen that after combining the two improvement strategies, the accuracy curve is smoother and the jitter is reduced.

Claims

1. A method for identifying rice leaf diseases based on an improved ResNet18, characterized in that, Includes the following steps: Step S1: Construct a rice leaf disease image dataset, perform image preprocessing and multi-scale data augmentation, and divide the dataset into training and validation sets; Step S2: Construct an attention-enhanced ResNet18 network model, which uses the standard ResNet18 as the backbone network, and serially embeds convolutional block attention modules (CBAMs) at the feature output of each residual basic unit (Basic Block) of the backbone network; Step S3: Construct a cross-entropy loss function L2-CE Loss with L2 norm regularization constraints, and iteratively train the attention-enhanced ResNet18 network model using the training set, suppressing the peak probability distribution of the model's output layer through the regularization term and optimizing the gradient descent path; Step S4: Input the rice leaf image to be detected into the trained attention-enhanced ResNet18 network model, and output the disease category and confidence level.

2. The method according to claim 1, characterized in that, In step S2, the standard ResNet18 backbone network contains four convolutional layer stages, each stage consisting of several residual basic units stacked together. The specific method of the serial embedding is as follows: for any residual basic unit, its internal operation flow is as follows: the input feature map passes through two 3×3 convolutional layers and a batch normalization layer in the main branch in sequence to obtain an intermediate feature map; the intermediate feature map is added to the shortcut connection output of the residual basic unit to obtain a residual output feature map; the residual output feature map is used as input and immediately fed into the convolutional block attention module (CBAM) for recalibration of channel weights and spatial weights to obtain the final output feature map of the residual basic unit.

3. The method according to claim 1, characterized in that, In S3, the calculation logic of the L2-CE Loss function is as follows: the total loss value is equal to the standard cross-entropy loss value plus the product of the regularization coefficient and the L2 norm of the model output layer Logits vector.

4. The rice leaf disease identification method based on dual attention mechanism enhanced ResNet18 according to claim 1, characterized in that, In S1, data augmentation includes at least one of the following methods: 90° rotation, 180° rotation, 270° rotation, horizontal flip, vertical flip, 90° rotation combined with horizontal flip, 90° rotation combined with vertical flip, random color temperature adjustment, background blur, Gaussian noise addition, and Mosaic data augmentation.

5. The rice leaf disease identification method based on dual attention mechanism enhanced ResNet18 according to claim 1, characterized in that, In S1, the disease categories include four types: bacterial blight, rice blast, brown spot, and healthy leaves.

6. A rice leaf disease detection system based on multi-scale attention-enhanced ResNet18, characterized in that, include: The data preprocessing module is used to perform step S1 as described in claim 1; The network construction module is used to perform step S2 of claim 1, constructing a ResNet18 network in which a CBAM module is embedded after each residual basic unit; the model training module is used to perform step S3 of claim 1, updating the network parameters based on the cross-entropy loss function with L2 norm regularization constraints; and the detection and recognition module is used to perform step S4 of claim 1.

7. 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 rice leaf disease identification method based on dual attention mechanism enhanced ResNet18 as described in any one of claims 1-6.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.