Tomato leaf disease identification method based on improved DenseNet model
By improving the DenseNet model to LGDNet and utilizing the Ghost bottleneck and CMIFA attention mechanism modules, the problems of low accuracy and model complexity in tomato leaf disease identification were solved, achieving efficient and accurate disease identification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NINGBO UNIV
- Filing Date
- 2023-04-10
- Publication Date
- 2026-06-09
AI Technical Summary
Existing methods for identifying tomato leaf diseases suffer from low accuracy, complex model structures, and large amounts of parameters and computation, making them difficult to promote and use in real-world applications.
An improved DenseNet model (LGDNet) is adopted. By replacing the Bottleneck layer with the Ghost bottleneck module, adding the CMIFA attention mechanism module, and optimizing the convolution kernel and pooling layer, the model structure is simplified, the number of parameters and computation are reduced, and the recognition accuracy is improved.
It achieves high-precision identification of tomato leaf diseases, with a simple model structure, small number of parameters and computational load, and can be widely used in real life.
Smart Images

Figure CN116563845B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for identifying tomato leaf diseases, and more particularly to a method for identifying tomato leaf diseases based on an improved DenseNet model. Background Technology
[0002] Tomatoes are rich in nutrients and are widely cultivated around the world. However, tomatoes are susceptible to various diseases during their growth and development. These diseases can reduce their quality and yield, affect their taste, and even lead to total crop failure, causing severe economic losses. Most of these diseases manifest on the tomato leaves. Therefore, rapid and accurate detection of tomato leaf diseases contributes to sustainable agricultural development and prevents unnecessary waste of financial and other resources.
[0003] Traditional methods for identifying tomato leaf diseases require manual inspection or chemical analysis of the affected area, typically necessitating identification and diagnosis by trained experts. However, experts are susceptible to personal factors such as fatigue and emotional fluctuations during diagnosis, leading to misdiagnosis or delayed diagnosis, resulting in significant economic losses for farmers. The rapid development of machine learning and deep learning in recent years has brought about breakthroughs in tomato leaf disease identification. Machine learning-based methods for identifying tomato leaf diseases manually extract features such as texture and shape from disease images and then input them into a machine learning classifier for identification. However, this method has low accuracy and requires manual annotation of tomato disease features, which vary from disease to disease, making it time-consuming and labor-intensive. Furthermore, even for the same disease, symptoms can differ significantly at different stages of the disease and are easily affected by noise such as light and complex backgrounds, making the extraction of disease symptom features extremely difficult. Convolutional neural networks (CNNs) have made significant progress in crop disease identification due to their ability to automatically extract features from diseased leaves. However, while traditional CNNs use multiple columns with different receptive fields or multiple branches from different stages of the network to capture multi-scale changes in tomato leaf diseases within and between classes, the scale diversity they capture is limited by the number of columns or branches. Therefore, when the scale changes are too drastic, the network's recognition accuracy will be low. Furthermore, traditional CNNs do not extract features comprehensively enough, failing to focus on learning important features in the image. Therefore, in complex backgrounds, the network model learns more background features, leading to low recognition accuracy. In addition, such methods have complex model structures, resulting in a large number of parameters and computational costs, making them difficult to promote and use in practical applications. Summary of the Invention
[0004] The technical problem to be solved by this invention is to provide a tomato leaf disease identification method based on an improved DenseNet model that has high recognition accuracy, simple model structure, small number of model parameters and computational load, and can be widely used in real life.
[0005] The technical solution adopted by this invention to solve the above-mentioned technical problems is as follows: a method for identifying tomato leaf diseases based on an improved DenseNet model, comprising the following steps:
[0006] S1. The DenseNet model is improved in the following four ways to obtain the LGDNet (Lightweight Ghost DenseNetwork) model:
[0007] First, replace the multiple sequentially connected Bottleneck layers in each Dense Block of the DensenNet model with three sequentially connected Ghost bottleneck modules. Name these three sequentially connected Ghost bottlenecks as the first Ghost bottleneck, the second Ghost bottleneck, and the third Ghost bottleneck, respectively. At this time, the third Ghost bottleneck in the DensenNet model, except for the last Dense Block, is connected to its global average pooling layer. The third Ghost bottleneck in each Dense Block is connected to a Transition Layer.
[0008] Second, in every three consecutively connected Ghost bottleneck modules, the ordinary convolution with a kernel size of 3×3 in the second Ghost module of the second Ghost bottleneck is replaced with a dilated convolution with a kernel size of 3, padding of 2, stride of 1, and dilation of 1. Similarly, the ordinary convolution with a kernel size of 3×3 in the second Ghost module of the third Ghost bottleneck is replaced with a dilated convolution with a kernel size of 3, padding of 3, stride of 1, and dilation of 2, thereby further expanding the receptive field of the model.
[0009] 3. In every three sequentially connected Ghost bottleneck modules, a CMIFA attention mechanism module is added between the first Ghost bottleneck and the second Ghost bottleneck, between the second Ghost bottleneck and the third Ghost bottleneck, and between the third Ghost bottleneck and the Transition Layer or the global average pooling layer. In this case, the first Ghost bottleneck and the second Ghost bottleneck are no longer directly connected, but are connected through a CMIFA attention mechanism module; the second Ghost bottleneck and the third Ghost bottleneck are no longer directly connected, but are connected through a CMIFA attention mechanism module; and the third Ghost bottleneck is no longer directly connected to the Transition Layer or the global average pooling layer, but is connected through a CMIFA attention mechanism module.
[0010] Fourth, the average pooling layer of each Transition Layer in the Dense Block was replaced with a max pooling layer;
[0011] The LGDNet model obtained after making the above four improvements to the DenseNet model includes one Feature Block, four Dense Blocks, three Transition Layers, one Global Average Pooling Layer, and one Fully Connected Layer. The four Dense Blocks are arranged in the following order: the Feature Block precedes the first Dense Block; there is a Transition Layer between the first and second Dense Blocks, another between the second and third Dense Blocks, and yet another between the third and fourth Dense Blocks; the Global Average Pooling Layer follows the fourth Dense Block; and the Fully Connected Layer follows the Global Average Pooling Layer. Each Feature Block consists of a 7×7 convolutional layer with 3 padding and a stride of 2, and a 3×3 max-pooling layer with a stride of 2. The Block is used to downsample the input feature map. Each TransitionLayer consists of a convolutional layer with a kernel size of 1×1, padding of 0, and stride of 1, and a max pooling layer with a kernel size of 3×3, padding of 1, and stride of 2. The size of the feature map output by the Dense Block connected to it is reduced by 1 / 2 before output, improving computational efficiency. The global average pooling layer is used to reduce the dimensionality of the feature map output by the Dense Block connected to it, resulting in a dimensionality-reduced feature map output. This greatly reduces the parameters of the LGDNet model and performs structural regularization on the LGDNet model to prevent overfitting. The fully connected layer is used to non-linearly map the dimensionality-reduced feature map output by the global average pooling layer into a one-dimensional feature vector containing all feature information. Then, the softmax function is used to convert it into the probability of classification into each category to obtain the final category output.
[0012] S2. Prepare the dataset, the specific process is as follows:
[0013] S2.1. Take N images of tomato leaves with diseases at a tomato farm, where N is an integer greater than 2000. Then, have tomato leaf disease experts manually determine the disease type corresponding to the N tomato leaf images to obtain the disease type of each tomato leaf image, i.e., the label of each tomato leaf image. Label each tomato leaf image according to its disease type, and use the N labeled tomato leaf disease images obtained at this time to form the original image dataset of tomato leaf diseases.
[0014] S2.2 Preprocessing of the original image dataset of tomato leaf diseases, the specific processing procedure is as follows:
[0015] S2.2.1. The tomato leaf images in the original tomato leaf disease image dataset are processed using methods such as flipping, random rotation, brightness transformation, Gaussian blur, adding agitation, random cropping, and random translation to obtain the tomato leaf disease extended image dataset.
[0016] S2.2.2 First, scale the resolution of each tomato leaf image in the expanded image dataset of tomato leaf diseases to 224×224, and then normalize it to obtain the normalized image dataset of tomato leaf diseases.
[0017] S2.2.3 First, divide the tomato leaf images for each disease type in the normalized image dataset of tomato leaf diseases into training set, test set and validation set in a ratio of 6:2:2. If the total number of tomato leaf images for a certain disease type is not divisible by 10, then put the excess tomato leaf images into the training set for that disease type. Then, combine the training sets of all disease types together to obtain the overall training set, combine the test sets of all disease types together to obtain the overall test set, and combine the validation sets of all disease types together to obtain the overall validation set.
[0018] S3. Input the overall training set obtained in step S2 into the LGDNet model to train the LGDNet model. The initial learning rate of the LGDNet model is set to 0.1, the optimizer momentum is set to 0.9, the weight decay is set to 0.0001, and the batch size is set to 16. During the training process, the SGDM optimization algorithm is used to optimize the network weights of the LGDNet model, and the cosine annealing method is used to dynamically adjust the learning rate to 0.00001. The training ends after 60 epochs. After each epoch is completed, a trained LGDNet model is obtained. At this time, 60 trained LGDNet models are obtained.
[0019] S4. Using the LGDNet model obtained after each epoch in S3, predict and recognize each tomato leaf image in the overall test set obtained in step S2, and calculate its recognition accuracy. Save the three trained LGDNet models with the highest recognition accuracy according to the size of the recognition accuracy. If there are more than three trained LGDNet models with the highest recognition accuracy, save them all.
[0020] S5. Using all the LGDNet models saved in S4, predict and recognize each tomato leaf image in the overall validation set obtained in step S2, and calculate the recognition accuracy. Select the LGDNet model with the highest recognition accuracy as the best LGDNet model. If multiple LGDNet models with the highest recognition accuracy exist at this time, select the LGDNet model with the highest recognition accuracy in the overall test set under the same epoch as the best LGDNet model. If multiple LGDNet models with the highest recognition accuracy in the overall test set under the same epoch exist at this time, select the LGDNet model with the highest recognition accuracy in the overall training dataset under the same epoch as the best LGDNet model. If multiple LGDNet models with the highest recognition accuracy in the overall training dataset under the same epoch still exist, randomly select one LGDNet model as the best LGDNet model and save the network weights of the best LGDNet model.
[0021] S6. Take an image of the tomato leaf disease to be identified, process the tomato leaf disease image in the same way as in step S2.2.2, and then input it into the best LGDNet model for disease identification. The best LGDNet model outputs its identification results and accuracy.
[0022] Furthermore, the CMIFA attention mechanism module includes a first average pooling layer, a second average pooling layer, a first max pooling layer, a second max pooling layer, a first feature fusion layer, a first convolutional layer, a second convolutional layer, and a second feature fusion layer. The CMIFA attention mechanism module is connected to the preceding Ghost bottleneck module through the first average pooling layer, the second average pooling layer, the first max pooling layer, the second max pooling layer, and the second feature fusion layer, respectively. The first average pooling layer has a convolutional kernel size of 1×w, used to input the feature map output by the connected Ghost bottleneck module, performing average pooling on the width dimension to obtain a feature map with c channels, h height, and 1 width. Figure 1 The output is fed to the first feature fusion layer; where w is the width of the feature map output by the Ghost bottleneck module connected to it, c is the number of channels of the feature map output by the Ghost bottleneck module connected to it, and h is the height of the feature map output by the Ghost bottleneck module connected to it; the second average pooling layer has a convolution kernel size of h×1, which is used to input the feature map output by the Ghost bottleneck module connected to it, and perform average pooling operation in the height dimension to obtain a feature map with c channels, 1 height, and w width. Figure 2The output is fed to the first feature fusion layer; the kernel size of the first max-pooling layer is 1×w, used to input the feature map output by the Ghost bottleneck module connected to it, and perform max-pooling operation in the width dimension to obtain a feature map with c channels, h height, and 1 width. Figure 3 The output is fed to the first feature fusion layer; the second max pooling layer has a convolution kernel size of h×1, which is used to input the feature map output by the Ghost bottleneck module connected to it, and perform average pooling in the height dimension to obtain a feature map 4 with c channels, 1 height, and w width, which is then output to the first feature fusion layer; the first feature fusion layer includes a first reshaping unit and a first feature concatenation unit; the first reshaping unit is used to input the feature map output by the first average pooling layer. Figure 1 The features output by the second average pooling layer Figure 2 The features output by the first max pooling layer Figure 3 And the feature map 4 output by the second max pooling layer, and the features Figure 1 The reshaping operation is performed to obtain feature map 5 with 1 channel, height c, and width h. The output is then sent to the first feature concatenation unit to process the features. Figure 2 The reshaping operation is performed to obtain a feature map 6 with 1 channel, height c, and width w. This feature map is then output to the first feature concatenation unit. Figure 3 The reshaping operation is performed to obtain feature map 7 with 1 channel, c height, and h width, which is output to the first feature splicing unit. The reshaping operation is performed on feature map 4 to obtain feature map 8 with 1 channel, c height, and w width, which is output to the first feature splicing unit. The first feature splicing unit is used to access feature map 5, feature map 6, feature map 7, and feature map 8, and splice these four feature maps in the width dimension to obtain spliced feature map 9 with 1 channel, c height, and 2×h+2×w width, which is output to the first convolutional layer and the second convolutional layer respectively. The convolutional kernel size of the first convolutional layer is 1×k1, the padding is k1 / 2, and the stride is 1. It is used to access feature map 9 output by the first feature fusion layer and perform convolution processing to obtain feature map 10 with 1 channel, c height, and 2×h+2×w width, which is output to the second feature fusion layer. K1 is calculated using formula (1):
[0023] k1=odd (︱log2h︳) (1)
[0024] In equation (1), k1 is the width of the convolution kernel of the first convolutional layer, odd() is the rounding down operation to the nearest odd number, and || is the absolute value sign;
[0025] The second convolutional layer has a kernel size of k2×1, padding of k2 / 2, and a stride of 1. It is used to input the feature map 9 output from the first feature fusion layer and perform convolution processing to obtain a feature map 11 with 1 channel, height c, and width 2×h+2×w, which is then output to the second feature fusion layer. k2 is calculated using equation (2).
[0026] k2=odd (︱log2c︳) (2)
[0027] In equation (2), k2 is the height of the convolution kernel of the second convolutional layer;
[0028] The second feature fusion layer includes a first element-wise addition function, a first feature separation unit, a second reshaping unit, a first Hard-sigmoid activation function, a second Hard-sigmoid activation function, a third Hard-sigmoid activation function, a fourth Hard-sigmoid activation function, a first element-wise multiplication function, a second element-wise multiplication function, an attention fusion unit, and a third element-wise multiplication function. The second feature fusion layer is connected to the corresponding Ghost bottleneck module through its third element-wise multiplication function. The first element-wise addition function is used to input the feature map 10 output from the first convolutional layer and the feature map 11 output from the second convolutional layer, and performs element-wise addition on these two feature maps to obtain a feature map 12 with 1 channel, height c, and width 2×h+2×w, which is then output to the first feature separation unit. The first feature separation unit is used to input the feature map 12 output by the first element-wise addition function, and first divides the feature map 12 in the width dimension according to the sizes h,w,h,w to obtain a feature map 12 with 1 channel and height c. Feature map 13 (width h, channel c), feature map 14 (height c, width w), feature map 15 (height c, width h, channel c), and feature map 16 (width w, channel c, height c, and height w) are all output to the second reshaping unit. The second reshaping unit receives feature maps 13, 14, 15, and 16, and reshapes feature map 13 to obtain feature map 17 (width h, channel c, height h, and width 1), which is then output to the first Hard-Si... The first Hard-sigmoid activation function reshapes feature map 14 to obtain feature map 18 with channel c, height 1, and width w, which is then output to the second Hard-sigmoid activation function. Feature map 15 is reshaped to obtain feature map 19 with channel c, height h, and width 1, which is then output to the third Hard-sigmoid activation function. Feature map 16 is reshaped to obtain feature map 20 with channel c, height 1, and width w, which is then output to the fourth Hard-sigmoid activation function. The Hard-sigmoid activation function is used to input the feature map 17 output by the second reshaping unit, and processes it through the Hard-sigmoid function to obtain a feature map with c channels, h height, and 1 width. Attention 1 is then output to the first element-wise multiplication function. The second Hard-sigmoid activation function is used to input the feature map 18 output by the second reshaping unit, and processes it through the Hard-sigmoid function to obtain a feature map with c channels, 1 height, and w width. Attention 2 is then output to the first element-wise multiplication function.The third Hard-sigmoid activation function is used to input the feature map 19 output by the second reshaping unit, and processes it through the Hard-sigmoid function to obtain feature map attention 3 with channel c, height h, and width 1, which is then output to the second element-wise multiplication function. The fourth Hard-sigmoid activation function is used to input the feature map 20 output by the second reshaping unit, and processes it through the Hard-sigmoid function to obtain feature map attention 4 with channel c, height 1, and width w, which is then output to the second element-wise multiplication function. The first element-wise multiplication function is used to input the feature map attention 1 output by the first Hard-sigmoid activation function and the feature map attention 2 output by the second Hard-sigmoid activation function, and performs element-wise multiplication on these two feature map attentions to obtain feature map attention 5 with channel c, height h, and width w, which is then output to the attention fusion unit. The second element-wise multiplication function is used to input the third Hard-sigmoid function. The feature map attention 3 output by the activation function is multiplied by the feature map attention 4 output by the fourth Hard-sigmoid activation function, and these two feature map attentions are multiplied element-wise to obtain the feature map attention 6 with channel c, height h, and width w, which is then output to the attention fusion unit. The attention fusion unit is used to receive the feature map attention 5 output by the first element-wise multiplication function and the feature map attention 6 output by the second element-wise multiplication function, and multiplies the feature map attention 5 element-wise with the adaptability parameter α to obtain the first result, and multiplies the feature map attention 6 element-wise with 1-α to obtain the second result. Then, these two results are added element-wise to obtain the feature map attention 7 with channel c, height h, and width w, which is then output to the third element-wise multiplication function. The adaptability parameter α is initially set to 0.5 and is continuously updated as the model is trained until the training ends. The value of the adaptability parameter α is the latest value at each calculation. The third element-wise multiplication function is used to receive the feature map attention 7 and the Ghost connected to it. The feature map output by the bottleneck module is then multiplied element-wise by the feature map attention 7 and the feature map output by the Ghost bottleneck module to obtain feature map 21 with channel c, height h, and width w. Feature map 21 output by the third element-wise multiplication function is the output of the CMIFA attention mechanism module. Feature map 21 is then output to the Ghost bottleneck module, Transition Layer, or Global Average Pooling Layer, which are located after and connected to the CMIFA attention mechanism module.
[0029] Compared with existing technologies, the advantages of this invention lie in replacing the Bottleneck layer of the original DenseNet model with a Ghost bottleneck module and reducing the number of network layers. This significantly reduces the computational load and parameter count while maintaining recognition performance, simplifying the model structure and accelerating inference speed. Furthermore, this invention replaces the ordinary 3×3 convolutional kernel in the second Ghost module of the second Ghost bottleneck in the three sequentially connected Ghost bottlenecks with a dilated convolutional kernel of size 3, padding of 2, stride of 1, and dilation rate of 1. And the second Ghost module in the third Ghost bottleneck... The module replaces the ordinary convolution with a kernel size of 3×3 with a dilated convolution with a kernel size of 3, padding of 3, stride of 1, and dilation rate of 2. This allows the model to expand its receptive field while avoiding the complete loss of local information in the original feature map due to the increase in the dilation coefficient, thus improving the recognition accuracy of tomato diseases with multi-scale variations. In addition, this invention introduces a CMIFA attention mechanism module, which improves the recognition accuracy of tomato diseases in complex backgrounds by fusing feature map channel information, spatial information, and dual pooling information with only a small increase in parameters and computational cost. Therefore, this invention has high recognition accuracy, a simple model structure, and a small number of parameters and computational cost, making it suitable for widespread use in real life. Attached Figure Description
[0030] Figure 1 This is a structural diagram of the LGDNet model in the tomato leaf disease identification method based on the improved DenseNet model of the present invention.
[0031] Figure 2 This is a structural diagram of the CMIFA attention mechanism module in the tomato leaf disease identification method based on the improved DenseNet model of the present invention.
[0032] Figure 3 This is a visualization of the tomato leaf disease feature recognition results of the tomato leaf disease recognition method based on the improved DenseNet model of the present invention. Detailed Implementation
[0033] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments.
[0034] Example 1: A method for identifying tomato leaf diseases based on an improved DenseNet model, comprising the following steps:
[0035] S1. The DenseNet model is improved in the following four ways to obtain the LGDNet (Lightweight Ghost DenseNetwork) model:
[0036] First, replace the multiple sequentially connected Bottleneck layers in each Dense Block of the DensenNet model with three sequentially connected Ghost bottleneck modules. Name these three sequentially connected Ghost bottlenecks as the first Ghost bottleneck, the second Ghost bottleneck, and the third Ghost bottleneck, respectively. At this time, the third Ghost bottleneck in the DensenNet model, except for the last Dense Block, is connected to its global average pooling layer. The third Ghost bottleneck in each Dense Block is connected to a Transition Layer.
[0037] Second, in every three consecutively connected Ghost bottleneck modules, the ordinary convolution with a kernel size of 3×3 in the second Ghost module of the second Ghost bottleneck is replaced with a dilated convolution with a kernel size of 3, padding of 2, stride of 1, and dilation of 1. Similarly, the ordinary convolution with a kernel size of 3×3 in the second Ghost module of the third Ghost bottleneck is replaced with a dilated convolution with a kernel size of 3, padding of 3, stride of 1, and dilation of 2, thereby further expanding the receptive field of the model.
[0038] 3. In every three sequentially connected Ghost bottleneck modules, a CMIFA attention mechanism module is added between the first Ghost bottleneck and the second Ghost bottleneck, between the second Ghost bottleneck and the third Ghost bottleneck, and between the third Ghost bottleneck and the Transition Layer or the global average pooling layer. At this time, the first Ghost bottleneck and the second Ghost bottleneck are no longer directly connected, but are connected through a CMIFA attention mechanism module; the second Ghost bottleneck and the third Ghost bottleneck are no longer directly connected, but are connected through a CMIFA attention mechanism module; and the third Ghost bottleneck and the Transition Layer or the global average pooling layer are no longer directly connected, but are connected through a CMIFA attention mechanism module.
[0039] Fourth, the average pooling layer of each Transition Layer in the Dense Block was replaced with a max pooling layer;
[0040] like Figure 1As shown, the LGDNet model obtained after making the above four improvements to the DenseNet model includes 1 Feature Block, 4 Dense Blocks, 3 Transition Layers, 1 Global Average Pooling Layer, and 1 Fully Connected Layer. The 4 Dense Blocks are arranged in the following order: the Feature Block precedes the first Dense Block; there is a Transition Layer between the first and second Dense Blocks, a Transition Layer between the second and third Dense Blocks, and a Transition Layer between the third and fourth Dense Blocks; the Global Average Pooling Layer follows the fourth Dense Block; and the Fully Connected Layer follows the Global Average Pooling Layer. Each Feature Block consists of a 7×7 convolutional layer with 3 padding and a stride of 2, and a 3×3 max-pooling layer with 1 padding and a stride of 2. The Feature Block is used to downsample the feature maps input to it. Each Transition Layer... Each layer consists of a convolutional layer with a kernel size of 1×1, padding of 0, and stride of 1, and a max pooling layer with a kernel size of 3×3, padding of 1, and stride of 2. This max pooling layer reduces the size of the feature map output from the connected Dense Block by half before outputting it, improving computational efficiency. The global average pooling layer reduces the dimensionality of the feature map output from the connected Dense Block to obtain a dimensionality-reduced feature map output, significantly reducing the parameters of the LGDNet model and performing structural regularization to prevent overfitting. The fully connected layer non-linearly maps the dimensionality-reduced feature map output from the global average pooling layer into a one-dimensional feature vector containing all feature information. This vector is then transformed into probabilities of classification into various categories using the softmax function to obtain the final category output.
[0041] S2. Prepare the dataset, the specific process is as follows:
[0042] S2.1. Take N images of tomato leaves with diseases at a tomato farm, where N is an integer greater than 2000. Then, have tomato leaf disease experts manually determine the disease type corresponding to the N tomato leaf images to obtain the disease type of each tomato leaf image, i.e., the label of each tomato leaf image. Label each tomato leaf image according to its disease type, and use the N labeled tomato leaf disease images obtained at this time to form the original image dataset of tomato leaf diseases.
[0043] S2.2 Preprocessing of the original image dataset of tomato leaf diseases, the specific processing procedure is as follows:
[0044] S2.2.1. The tomato leaf images in the original tomato leaf disease image dataset are processed using methods such as flipping, random rotation, brightness transformation, Gaussian blur, adding agitation, random cropping, and random translation to obtain the tomato leaf disease extended image dataset.
[0045] S2.2.2 First, scale the resolution of each tomato leaf image in the expanded image dataset of tomato leaf diseases to 224×224, and then normalize it to obtain the normalized image dataset of tomato leaf diseases.
[0046] S2.2.3 First, divide the tomato leaf images for each disease type in the normalized image dataset of tomato leaf diseases into training set, test set and validation set in a ratio of 6:2:2. If the total number of tomato leaf images for a certain disease type is not divisible by 10, then put the excess tomato leaf images into the training set for that disease type. Then, combine the training sets of all disease types together to obtain the overall training set, combine the test sets of all disease types together to obtain the overall test set, and combine the validation sets of all disease types together to obtain the overall validation set.
[0047] S3. Input the overall training set obtained in step S2 into the LGDNet model to train the LGDNet model. The initial learning rate of the LGDNet model is set to 0.1, the optimizer momentum is set to 0.9, the weight decay is set to 0.0001, and the batch size is set to 16. During the training process, the SGDM optimization algorithm is used to optimize the network weights of the LGDNet model, and the cosine annealing method is used to dynamically adjust the learning rate to 0.00001. The training ends after 60 epochs. After each epoch is completed, a trained LGDNet model is obtained. At this time, 60 trained LGDNet models are obtained.
[0048] S4. Using the LGDNet model obtained after each epoch in S3, predict and recognize each tomato leaf image in the overall test set obtained in step S2, and calculate its recognition accuracy. Save the three trained LGDNet models with the highest recognition accuracy according to the size of the recognition accuracy. If there are more than three trained LGDNet models with the highest recognition accuracy, save them all.
[0049] S5. Using all the LGDNet models saved in S4, predict and recognize each tomato leaf image in the overall validation set obtained in step S2, and calculate the recognition accuracy. Select the LGDNet model with the highest recognition accuracy as the best LGDNet model. If multiple LGDNet models with the highest recognition accuracy exist at this time, select the LGDNet model with the highest recognition accuracy in the overall test set under the same epoch as the best LGDNet model. If multiple LGDNet models with the highest recognition accuracy in the overall test set under the same epoch exist at this time, select the LGDNet model with the highest recognition accuracy in the overall training dataset under the same epoch as the best LGDNet model. If multiple LGDNet models with the highest recognition accuracy in the overall training dataset under the same epoch still exist, randomly select one LGDNet model as the best LGDNet model and save the network weights of the best LGDNet model.
[0050] S6. Take an image of the tomato leaf disease to be identified, process the tomato leaf disease image in the same way as in step S2.2.2, and then input it into the best LGDNet model for disease identification. The best LGDNet model outputs its identification results and accuracy.
[0051] Example 2: This example is basically the same as Example 1, except that: Figure 2 As shown, in this embodiment, the CMIFA attention mechanism module includes a first average pooling layer, a second average pooling layer, a first max pooling layer, a second max pooling layer, a first feature fusion layer, a first convolutional layer, a second convolutional layer, and a second feature fusion layer. The CMIFA attention mechanism module is connected to the Ghost bottleneck module located before it through the first average pooling layer, the second average pooling layer, the first max pooling layer, the second max pooling layer, and the second feature fusion layer, respectively. The convolutional kernel size of the first average pooling layer is 1×w, which is used to input the feature map output by the Ghost bottleneck module connected to it, and perform average pooling operation on the width dimension to obtain a feature map with c channels, h height, and 1 width. Figure 1 The output is fed to the first feature fusion layer; where w is the width of the feature map output by the Ghost bottleneck module connected to it, c is the number of channels of the feature map output by the Ghost bottleneck module connected to it, and h is the height of the feature map output by the Ghost bottleneck module connected to it; the second average pooling layer has a convolution kernel size of h×1, which is used to input the feature map output by the Ghost bottleneck module connected to it, and performs average pooling operation on the height dimension to obtain a feature map with c channels, 1 height, and w width. Figure 2The output is fed into the first feature fusion layer; the kernel size of the first max pooling layer is 1×w, which is used to input the feature map output by the Ghost bottleneck module connected to it, and max pooling is performed in the width dimension to obtain a feature map with c channels, h height, and 1 width. Figure 3 The output is fed to the first feature fusion layer; the second max pooling layer has a convolution kernel size of h×1, which is used to input the feature map output by the Ghostbottleneck module connected to it, and performs average pooling in the height dimension to obtain a feature map 4 with c channels, 1 height, and w width, which is then output to the first feature fusion layer; the first feature fusion layer includes a first reshaping unit and a first feature concatenation unit; the first reshaping unit is used to input the feature map output by the first average pooling layer. Figure 1 Features of the output of the second average pooling layer Figure 2 Features output by the first max pooling layer Figure 3 The feature map output by the second max pooling layer is shown in Figure 4, and the features are analyzed. Figure 1 The reshaping operation is performed to obtain feature map 5 with 1 channel, height c, and width h. The output is then sent to the first feature concatenation unit to process the features. Figure 2 The reshaping operation is performed to obtain a feature map 6 with 1 channel, height c, and width w. This feature map is then output to the first feature concatenation unit. Figure 3 The reshaping operation is performed to obtain feature map 7 with 1 channel, c height, and h width, which is output to the first feature splicing unit. The reshaping operation is performed on feature map 4 to obtain feature map 8 with 1 channel, c height, and w width, which is output to the first feature splicing unit. The first feature splicing unit is used to access feature map 5, feature map 6, feature map 7 and feature map 8, and splice these four feature maps in the width dimension to obtain spliced feature map 9 with 1 channel, c height, and 2×h+2×w width, which is output to the first convolutional layer and the second convolutional layer respectively. The convolutional kernel size of the first convolutional layer is 1×k1, the padding is k1 / 2, and the stride is 1. It is used to access feature map 9 output by the first feature fusion layer and perform convolution processing to obtain feature map 10 with 1 channel, c height, and 2×h+2×w width, which is output to the second feature fusion layer. K1 is calculated using formula (1):
[0052] k1=odd (︱log2h︳) (1)
[0053] In equation (1), k1 is the width of the convolution kernel of the first convolutional layer, odd() is the rounding down operation to the nearest odd number, and || is the absolute value sign;
[0054] The kernel size of the second convolutional layer is k2×1, the padding is k2 / 2, and the stride is 1. It is used to input the feature map 9 output from the first feature fusion layer, perform convolution processing to obtain a feature map 11 with 1 channel, height c, and width 2×h+2×w, which is then output to the second feature fusion layer; where k2 is calculated using equation (2):
[0055] k1=odd (︱log2c︳) (2)
[0056] In equation (2), k2 is the height of the convolution kernel of the second convolutional layer;
[0057] The second feature fusion layer includes a first element-wise addition function, a first feature separation unit, a second reshaping unit, a first Hard-sigmoid activation function, a second Hard-sigmoid activation function, a third Hard-sigmoid activation function, a fourth Hard-sigmoid activation function, a first element-wise multiplication function, a second element-wise multiplication function, an attention fusion unit, and a third element-wise multiplication function. The second feature fusion layer connects to the corresponding Ghostbottleneck module through its third element-wise multiplication function. The first element-wise addition function is used to input the feature map 10 output from the first convolutional layer and the feature map 11 output from the second convolutional layer, and performs element-wise addition on these two feature maps to obtain... Feature map 12, with channel 1, height c, and width 2×h+2×w, is output to the first feature separation unit. The first feature separation unit receives feature map 12 from the first element-wise addition function and first segments feature map 12 along the width dimension according to the sizes h,w,h,w, resulting in feature map 13 (channel 1, height c, width h), feature map 14 (channel 1, height c, width w), feature map 15 (channel 1, height c, width h), and feature map 16 (channel 1, height c, width w). Feature maps 13, 14, 15, and 16 are then output to the second reshaping unit. The second reshaping unit receives feature maps 13, 14, 15, and 16 and reshapes them. 13. A reshaping operation is performed to obtain feature map 17 with channel c, height h, and width 1, which is output to the first Hard-sigmoid activation function. Feature map 14 is reshaped to obtain feature map 18 with channel c, height 1, and width w, which is output to the second Hard-sigmoid activation function. Feature map 15 is reshaped to obtain feature map 19 with channel c, height h, and width 1, which is output to the third Hard-sigmoid activation function. Feature map 16 is reshaped to obtain feature map 20 with channel c, height 1, and width w, which is output to the fourth Hard-sigmoid activation function. The first Hard-sigmoid activation function is used to input feature map 17 output from the second reshaping unit, and... The feature map 18 is processed by the Hard-sigmoid function to obtain a feature map with c channels, h height, and 1 width. Attention 1 is output to the first element-wise multiplication function. The second Hard-sigmoid activation function is used to input the feature map 18 output by the second reshaping unit, and it is processed by the Hard-sigmoid function to obtain a feature map with c channels, 1 height, and w width. Attention 2 is output to the first element-wise multiplication function. The third Hard-sigmoid activation function is used to input the feature map 19 output by the second reshaping unit, and it is processed by the Hard-sigmoid function to obtain a feature map with c channels, h height, and 1 width. Attention 3 is output to the second element-wise multiplication function.The fourth Hard-sigmoid activation function is used to input the feature map 20 output by the second reshaping unit, and processes it through the Hard-sigmoid function to obtain feature map attention 4 with c channels, 1 height, and w width, which is then output to the second element-wise multiplication function. The first element-wise multiplication function is used to input the feature map attention 1 output by the first Hard-sigmoid activation function and the feature map attention 2 output by the second Hard-sigmoid activation function, and performs element-wise multiplication on these two feature map attentions to obtain feature map attention 5 with c channels, h height, and w width, which is then output to the attention fusion unit. The second element-wise multiplication function is used to input the feature map attention 3 output by the third Hard-sigmoid activation function and the feature map attention 4 output by the fourth Hard-sigmoid activation function, and processes these two feature map attentions... Element-wise multiplication yields a feature map attention 6 with channel c, height h, and width w, which is output to the attention fusion unit. The attention fusion unit receives the feature map attention 5 output from the first element-wise multiplication function and the feature map attention 6 output from the second element-wise multiplication function. It then multiplies feature map attention 5 element-wise with the adaptability parameter α to obtain the first result, and multiplies feature map attention 6 element-wise with 1-α to obtain the second result. These two results are then summed element-wise to obtain a feature map attention 7 with channel c, height h, and width w, which is output to the third element-wise multiplication function. The adaptability parameter α is initially set to 0.5 and is continuously updated during model training until the training ends. Each calculation uses the latest value of the adaptability parameter α. The third element-wise multiplication function receives feature map attention 7 and its connected Ghost. The feature map output by the bottleneck module is then multiplied element-wise by the feature map attention function 7 and the feature map output by the Ghost bottleneck module to obtain feature map 21 with channel c, height h, and width w. Feature map 21 output by the third element-wise multiplication function is the output of the CMIFA attention mechanism module. Feature map 21 is then output to the Ghost bottleneck module, Transition Layer, or Global Average Pooling Layer, which are located after and connected to the CMIFA attention mechanism module.
[0058] To verify the performance of the tomato leaf disease identification method based on the improved DenseNet model of this invention, the LGDNet (Lightweight Ghost Dense Network) model of this invention and three existing models were used to identify tomato leaf disease images, and the results were compared. The three existing models are ResNet50 disclosed in the paper "Deep Residual Learning for Image Recognition", DenseNet121 disclosed in the paper "Densely Connected Convolutional Networks", and Res2Net50 disclosed in the paper "Res2Net: A New Multi-scale Backbone Architecture". The experimental results are shown in Table 1.
[0059] Table 1: Performance evaluation of tomato leaf disease identification based on four models
[0060]
[0061] As shown in Table 1, the LGDNet model of this invention has the highest accuracy compared to the ResNet50, DenseNet121, and Res2Net50 models. The accuracy of the LGDNet model of this invention is improved by 15.6%, 6.7%, and 7.57% respectively compared to the ResNet50, DenseNet121, and Res2Net50 models, reaching 99%. Furthermore, the number of parameters in the LGDNet model of this invention is only about 1 / 23 of that of the ResNet50 model, about 1 / 6 of that of the DenseNet121 model, and about 1 / 23 of that of the Res2Net50 model. The computational cost is also only about 1 / 17 of that of the ResNet50 model, about 1 / 12 of that of the DenseNet121 model, and about 1 / 18 of that of the Res2Net50 model, significantly reducing the number of parameters and computational cost.
[0062] To observe the feature information of the LGDNet model of this invention in relation to tomato leaf disease images, the feature heatmap of the LGDNet model of this invention is visualized, such as... Figure 3 As shown. By Figure 3It can be observed that the LGDNet model of this invention mainly focuses on the diseased parts of the tomato leaves in the tomato leaf disease images for feature extraction, and is less affected by complex background interference. This indicates that the LGDNet model proposed in this invention has strong feature extraction capabilities, can remove the influence of complex background interference information to a certain extent, and enhances the robustness of the model.
[0063] In summary, the LGDNet model proposed in this invention, based on the improved DenseNet model for identifying tomato leaf diseases, has high accuracy and low computational cost, and can be widely used in practical applications.
Claims
1. A method for identifying tomato leaf diseases based on an improved DenseNet model, characterized in that, Includes the following steps: S1. The DenseNet model is improved in the following four ways to obtain the LGDNet model: First, replace the multiple sequentially connected bottleneck layers in each Dense Block of the DensenNet model with three sequentially connected Ghost bottleneck modules. Name these three sequentially connected Ghost bottlenecks as the first Ghost bottleneck, the second Ghost bottleneck, and the third Ghost bottleneck in chronological order.
2. In every three consecutively connected Ghost bottleneck modules, replace the ordinary convolution with a kernel size of 3×3 in the second Ghost module of the second Ghost bottleneck with a dilated convolution with a kernel size of 3, padding of 2, stride of 1, and dilation of 1; and replace the ordinary convolution with a kernel size of 3×3 in the second Ghost module of the third Ghost bottleneck with a dilated convolution with a kernel size of 3, padding of 3, stride of 1, and dilation of 2. Third, in every three sequentially connected Ghost bottleneck modules, a CMIFA attention mechanism module is added between the first Ghost bottleneck and the second Ghost bottleneck, between the second Ghost bottleneck and the third Ghost bottleneck, and between the third Ghost bottleneck and the Transition Layer or the global average pooling layer; the CMIFA attention mechanism module includes a first average pooling layer, a second average pooling layer, a first max pooling layer, a second max pooling layer, a first feature fusion layer, a first convolutional layer, a second convolutional layer, and a second feature fusion layer; Fourth, the average pooling layer of each Transition Layer in the Dense block was replaced with a max pooling layer; S2. Take images of tomato leaf diseases to be identified, identify them based on the LGDNet model, and obtain the identification results and accuracy.
2. The tomato leaf disease identification method based on the improved DenseNet model according to claim 1, characterized in that, The CMIFA attention mechanism module is connected to the preceding Ghost layer through the first average pooling layer, the second average pooling layer, the first max pooling layer, the second max pooling layer, and the second feature fusion layer, respectively. The bottleneck module; the first feature fusion layer includes a first reshaping unit and a first feature concatenation unit; the first reshaping unit is connected to a first average pooling layer, a second average pooling layer, a first max pooling layer, and a second max pooling layer, respectively; the first feature concatenation unit is connected to the first reshaping unit; the first convolutional layer and the second convolutional layer are connected to the first feature concatenation unit, respectively; the second feature fusion layer includes a first element-wise addition function, a first feature separation unit, a second reshaping unit, a first Hard-sigmoid activation function, a second Hard-sigmoid activation function, a third Hard-sigmoid activation function, a fourth Hard-sigmoid activation function, a first element-wise multiplication function, a second element-wise multiplication function, an attention fusion unit, and a third element-wise multiplication function; the second feature fusion layer is connected to the corresponding Ghostbottleneck module through its third element-wise multiplication function; the first element-wise addition function... The element-wise addition function is connected to the first convolutional layer and the second convolutional layer, respectively. The first element-wise addition function, the first feature separation unit, and the second reshaping unit are connected sequentially. The first hard-sigmoid activation function, the second hard-sigmoid activation function, the third hard-sigmoid activation function, and the fourth hard-sigmoid activation function are connected to the second reshaping unit, respectively. The first element-wise multiplication function is connected to the first hard-sigmoid activation function and the second hard-sigmoid activation function, respectively. The second element-wise multiplication function is connected to the third hard-sigmoid activation function and the fourth hard-sigmoid activation function, respectively. The attention fusion unit is connected to the first element-wise multiplication function and the second element-wise multiplication function, respectively. The third element-wise multiplication function is connected to the attention fusion unit, respectively.