Tomato leaf disease detection method based on YOLO V8

By replacing the Backbone module with ShuffleNetV2 in the YOLO V8 model and adding the multi-head self-attention mechanism and AdamW optimization algorithm, the problem of low accuracy and slow speed in tomato leaf disease detection is solved, achieving higher detection accuracy and speed, and is suitable for Real-time detection of mobile devices.

CN118735858AInactive Publication Date: 2024-10-01HANGZHOU DIANZI UNIV

Patent Information

Application Number
CN202410711949.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-04
Publication Date
2024-10-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

When existing technology detects occluded targets or tiny targets, the detection accuracy of tomato leaf diseases is low, the reasoning speed is slow, and the adaptability and accuracy to complex scenes are poor.

Method used

A lightweight recognition model based on YOLO V8 is used, by replacing the Backbone module with ShuffleNetV2, adding a multi-head self-attention mechanism and AdamW optimization algorithm, and performing preprocessing to enhance the robustness and adaptability of the model.

Benefits of technology

It improves the accuracy and speed of tomato leaf disease detection, reduces false detection and missed detection, is suitable for real-time detection on Android, reduces resource consumption, and is suitable for mobile devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118735858A_ABST
    Figure CN118735858A_ABST
Patent Text Reader

Abstract

The invention relates to a method for identifying tomato leaf diseases based on YOLO V8, and the method comprises the steps: obtaining a tomato leaf disease picture, carrying out the disease marking of the tomato leaf disease picture, and constructing a tomato leaf disease data set; preprocessing the tomato leaf disease data set; a neural network structure of a Backbone module in the YOLO V8 is replaced by a ShuffleNetV2, and the ShuffleNetV2 is used as the neural network structure of the Backbone module in the YOLO V8; replacing an optimization algorithm in the YOLO V8 model with AdamW, and adding a multi-head self-attention mechanism into a Backbone module in the YOLO V8 model to obtain a disease detection model; and training a disease detection model by using the preprocessed tomato leaf disease data set. According to the invention, more types of tomato leaf diseases can be detected, and the phenomena of false detection and missing detection are reduced; in addition, when the method is deployed to the Android end for real-time detection, the detection speed is higher, and the overall detection performance is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of target detection, and in particular relates to a method for identifying tomato leaf diseases based on YOLO V8. Background Art

[0002] Tomato is the world's largest vegetable crop, and my country is currently the country with the highest tomato production in the world. During the growth process of tomatoes, due to the influence of external environment, climate and soil conditions, it is easy to develop a variety of diseases, such as early blight, scab, mosaic virus disease, yellow leaf curl disease, etc.

[0003] In recent years, domestic and foreign scholars have also done a lot of research on the classification of tomato leaf diseases. Xu Kaihong et al. used the divide-and-conquer method to calculate the median, and then used the watershed algorithm to extract the characteristics of tomato leaf diseases. Finally, 13 features including shape, color and texture were selected, and then input into the BP neural network optimized by the genetic algorithm for classification. Finally, the recognition accuracy of the three diseases was 92.5%, 91.25% and 95.5%, and the iteration speed was accelerated. Fuentes et al. used Faster R-CNN, R-FCN, SSD and other models as the basic architecture, combined with VGG network, etc. to construct a fusion system. Experiments have proved that the system can effectively identify different types of diseases and pests. Niu Xuede et al. took 10 types of tomato leaves as the research object and proposed a model of Dense Net network combined with transfer learning. The study first modified the size and quantity of the image samples, then used the Dense Net network to pre-train on the ImageNet dataset, and then applied the training content to the classification of tomato leaf diseases. After retraining, the tomato leaf disease classification model was obtained, and the test accuracy reached 97.76%. Zhao Yanqin et al. used the Ghost module and CoordAttention coordinate attention mechanism as the backbone network to replace the backbone network in YOLO V5, and performed secondary convolution on the feature extraction layer to enhance its recognition of diseases. Finally, they tested on 10 different types of tomato diseased leaves, with an average accuracy of 96.8%, and the model size was 17.1MB smaller than the YOLO V5 model, which performed very well.

[0004] Although the YOLO series of models have greatly improved the detection speed and ensured a certain degree of model accuracy, they still cannot maintain considerable detection accuracy when detecting occluded targets or small targets. Adding an attention mechanism to the original model is one of the methods to specifically improve detection accuracy. Summary of the invention

[0005] In order to solve the shortcomings and deficiencies of the existing technology, a lightweight tomato leaf disease identification model based on yolov8 is provided, which can solve the problems of low detection accuracy of tomato diseases, slow reasoning speed, poor adaptability to complex scenes and poor accuracy of existing detection methods.

[0006] A method for detecting tomato leaf diseases based on YOLO V8, comprising the following steps:

[0007] Step S1, obtaining tomato leaf disease pictures, wherein the tomato leaf diseases specifically include: tomato late blight, tomato mosaic disease, tomato scab, and tomato leaf spot;

[0008] Step S2, annotating the tomato leaf disease pictures to obtain a tomato leaf disease dataset;

[0009] Step S3, preprocessing the tomato leaf disease data set;

[0010] Step S4, replace the neural network structure of the Backbone module in YOLO V8 with ShuffleNetV2;

[0011] Step S5: Replace the optimization algorithm in the YOLO V8 model with AdamW.

[0012] Step S6, adding a multi-head self-attention mechanism to the Backbone module in the YOLO V8 model to obtain a disease detection model;

[0013] Step S7: Using the tomato leaf disease dataset obtained after preprocessing in step S3, the disease detection model obtained in step S6 is trained.

[0014] Preferably, the tomato leaf disease images obtained in step S1 are derived from the Plant-Village plant disease public dataset.

[0015] Preferably, in step S3, the preprocessing specifically includes: using the image processing library function in OpenCV to rotate the image by 90°, perform blur processing, perform color conversion, and add noise.

[0016] Preferably, in step S4, the neural network structure of the Backbone module in YOLO V8 is replaced with ShuffleNetV2, specifically including: using two cascaded ShuffleNetV2 modules as the Backbone module in YOLO V8.

[0017] Preferably, in step S6, the Backbone module in the YOLO V8 model adds a multi-head self-attention mechanism, specifically including: adding a multi-head self-attention mechanism module after two cascaded ShuffleNetV2 modules, then adding four cascaded ShuffleNetV2 modules after the multi-head self-attention mechanism module, and then adding an SPPF module;

[0018] The tomato leaf disease data preprocessed in step S3 first enters the pooling layer for pooling; then enters two cascaded ShuffleNetV2 modules; then is further processed by the MHSA multi-head self-attention module; then enters four cascaded ShuffleNetV2 modules; then enters the SPPF module to convert the image into a vector output; and finally is classified.

[0019] Beneficial effects of the present invention

[0020] When performing actual tomato leaf disease detection, the present invention can detect more types of tomato leaf diseases while producing fewer false detections and missed detections; in addition, when deployed on an Android terminal for real-time detection, the detection speed is faster, effectively improving the overall detection performance.

[0021] Furthermore, the step 1 comprises the following steps:

[0022] S101. Collect pictures of tomato leaf diseases;

[0023] S102, using the image processing library function in OpenCV, rotating the image by 90°, blurring it, changing its color, and adding noise to it.

[0024] The beneficial effects of the above further scheme are: the disease features of tomato leaves in the preprocessed images are more obvious than before, which solves the problem of unbalanced samples with a small proportion of small targets in the data set, facilitates the learning process of the detection target features in the subsequent training process, and improves the detection performance of the entire network model; in addition, it has better robustness in actual detection.

[0025] Furthermore, step 2 comprises the following steps:

[0026] S201, adding a category to the marked rectangular frame, and saving the tomato leaf disease image in XML format;

[0027] S202: Use the road damage image in XML format to train a detection model.

[0028] The beneficial effect of the above further solution is that reasonable labeling of the rectangular box makes it easier to perform subsequent network regression, which is equivalent to better prediction results.

[0029] Furthermore, step 3 comprises the following steps:

[0030] S301, an optimization method for replacing the original network structure in the Backbone module in YOLO V8 with a lightweight neural network model ShuffleNet;

[0031] S302. Add the MSHA multi-head self-attention mechanism and AdamW optimization algorithm to the YOLO V8 model.

[0032] The beneficial effect of the above further scheme is that after the improved lightweighting, the converted model can be well deployed on the smartphone device carried by the user, and then the detection process is completed using its camera, which facilitates real-time detection and reduces detection costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the specific implementation of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for the specific implementation or the prior art description. Some specific embodiments of the present invention will be described in detail in an exemplary but not restrictive manner with reference to the drawings. The same reference numerals in the drawings indicate the same or similar components or parts. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings:

[0034] Figure 1 It is a flow chart of a tomato leaf disease identification method based on improved YOLO V8 provided by the present invention;

[0035] Figure 2 This is a picture of four common diseases of tomato leaves: a. scab, c. leaf spot, b. late blight, d. mosaic disease;

[0036] Figure 3 This is a schematic diagram of the YOLO V8 algorithm network structure before optimization;

[0037] Figure 4 Schematic diagram of dual-channel branch feature information exchange based on ShuffleNet channel separation used in the present invention, wherein (a) is to add a channel splitting (Channel Split) operation, and (b) is not to perform a channel splitting operation;

[0038] Figure 5 This is a schematic diagram of the YOLOv8-ShuffleNetV2 network structure. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0040] In step 1, in order to solve the problem of small target proportion and unbalanced samples in the data set, the above disease images are scaled and spliced ​​(such as scaling and splicing four random images in the data set into one image) to make large targets become medium targets, medium targets become small targets, and the proportion and number of samples of small targets are increased. Noise, brightness, rotation and cropping are also performed to expand the scale of small target samples and enhance the robustness and generalization ability of the model.

[0041] In step 2, the open source software LabelImg is used for labeling, and local labeling is performed according to the type of tomato disease during the labeling process.

[0042] In step 3, a small target disaster recognition model with an improved YOLOv8-ShuffleNetV2 network structure is constructed.

[0043] The ShuffleNetV2 network structure is shown in the following table:

[0044]

[0045] The starting module of each stage uses a 3x3 convolution kernel with a stride of 2, and there is only one such module. The following modules use a 3x3 convolution kernel with a stride of 1, and this operation is repeated many times.

[0046] In step 4, in the MSHA multi-head self-attention mechanism, it can capture complex dependencies within the sequence. Specifically, in MHSA, the input sequence is projected into multiple spaces simultaneously, which correspond to different heads. Each head learns attention weights for different parts of the sequence, which indicate which parts of the input sequence the model should focus on when generating each output element. Its self-attention formula is:

[0047]

[0048] Q, K, and V represent query, key, and value respectively. They are the results of transforming the input matrix under different weight matrices. K is the dimension of the key vector, which is used to scale the dot product to prevent the dot product from being too large, which in turn leads to gradient loss.

[0049] Due to multi-head self-attention, there will be multiple such attention functions operating in parallel, and each head can learn different representations in different subspaces. The formula can be expressed as:

[0050] MultiHead(Q,K,V)=Concat(head1,...,headh)W o

[0051] head i =Attention(QW i Q ,KW i K ,VW i V )

[0052] Where QW i Q , KW i K , VW i V , W o is the parameter matrix learned in the model.

[0053] Due to its excellence, Adam has been widely used by researchers in recent years, but it still has some shortcomings during use, which can be listed as follows:

[0054] ① Confusion weight decay and L2 regularization

[0055] ② Since the weights in the BN layer may decrease in performance if they are decayed, Adam may not be so effective when processing networks with BN layers

[0056] ③ Although Adam can adaptively adjust the learning rate for each parameter, this process may ignore the effect of regularization in the early stages of training, causing the model to be more adaptable to certain specific noises.

[0057] ④ At the beginning of training, the estimated first-order and second-order moments are often not very accurate, which will cause the optimizer parameter update to become very large, which may lead to unstable training

[0058] Based on the above shortcomings, Loshchilov et al. proposed the AdamW model, whose update rules are as follows:

[0059]

[0060] m t =β1·m t-1 +(1-β1)·g t

[0061]

[0062]

[0063] Where θ represents the model parameters, g t represents the gradient at time step t, m t ,v t are the first-order moment estimate and the second-order moment estimate of the gradient, Represents the bias-corrected first-order and second-order moment estimates, β1, β2 are hyperparameters used to control the moving average of the two moments, 1r is the learning rate, ξ is a small constant whose purpose is to avoid division by 0, and wd is the weight decay coefficient.

[0064] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0065] like Figure 1 As shown, the present invention provides a method for detecting tomato leaf diseases based on YOLO V8, comprising the following steps:

[0066] Step S1: Use tomato leaf disease images in the Plant-Village plant disease public dataset to form a tomato leaf disease dataset, specifically including: tomato late blight, tomato mosaic, tomato scab, tomato leaf spot, such as Figure 2 shown.

[0067] Step S2: Label different types of diseases using the LabelImg labeling tool.

[0068] Step S3: preprocessing the tomato leaf disease image.

[0069] In step S3, the specific method for preprocessing the tomato leaf disease image is as follows:

[0070] S31. Use the image processing library functions in OpenCV to rotate the image by 90°, blur it, change its color, and add noise. This increases the diversity and richness of the dataset. This not only expands the scope of the dataset, allowing the model to be exposed to a wider variety of images, but also helps to improve the model's sensitivity to various image features.

[0071] Step S4, optimizing the neural network structure of the Backbone module in the YOLO V8 algorithm model, considering using lightweight neural network models ShuffleNet and MobileNet to replace the original network structure in the Backbone module in YOLO V8, and proposing a model fusion algorithm based on YOLO V8, including YOLO V8+ShuffleNet V2 and YOLO V8+MobileNet V3 and other algorithm model combinations.

[0072] The YOLOv8-ShuffleNetV2 network structure is as follows Figure 5 As shown;

[0073] In step S4, the specific method for optimizing the neural network structure of the Backbone module in the YOLO V8 algorithm model is:

[0074] S41. Considering the comprehensive factors such as algorithm model accuracy, speed and ease of model deployment required by actual agricultural detection tasks, the network structure of the Back bone module in the YOLO V8 algorithm is replaced with the lightweight neural network model ShuffleNet, and the original YOLO V8 network uses a dual-channel feature information exchange strategy with channel splitting, and proposes the YOLOV8+ShuffleNet V2 algorithm model combination. Figure 4 For block type a, first for each block unit, the channel c of the input feature matrix is ​​split into two branches cc' and c', which corresponds to channel split. After convolution, the two branches are spliced ​​through Concat, which makes the number of channels before and after the block remain unchanged, and then channel shuffle is performed in the block. For block type b, that is, the case of downsampling, there is no channelsplit operation, and finally the channel of the output feature matrix is ​​doubled after Concat. And the 3×3 average pooling of one branch in a is changed to 3×3 DW conv. Originally, average pooling is done by channel, and it can be regarded as DW Conv with all weights of 1 / 9. The change to DW Conv here adds more possibilities. Then a 1×1 convolution is added.

[0075] The YOLO V8+ShuffleNet V2 algorithm model combination has a model size of 0.94MB, which is 1.9MB smaller than YOLO V8; in terms of accuracy, the accuracy is 97.36%, which is 2.18% higher than the YOLO V8 model; on the basis of maintaining or improving the training speed and accuracy of the model, it significantly reduces resource consumption so that it can be effectively applied in resource-constrained environments. The lightweight model with high accuracy and adaptability to mobile devices can be deployed on a mobile phone app to facilitate farmers to use it in identifying tomato leaf diseases.

[0076] Step S5: Improve the optimization algorithm in the YOLO V8 model, and consider using SGD, Adam, AdamW, etc.

[0077] In step S5, the specific method for improving the optimization algorithm in the YOLO V8 model is:

[0078] S51. In the training process of deep learning models, choosing a suitable optimization algorithm has a crucial impact on improving model performance. Consider replacing the optimization algorithm in the YOLO V8 model with the AdamW optimization algorithm. Since in non-convex optimization problems, directly introducing weights in parameter updates is not equivalent to adding L2 regularization terms to the objective function, this problem is corrected in the AdamW algorithm, which decouples weight decay and gradient updates to ensure that weight decay only affects the size of the parameters rather than the direction. At the same time, this correction also makes the algorithm have better generalization ability than Adam in most cases and reduces overfitting. And because weight decay is independent of learning rate scheduling, this makes the learning rate adjustment in the optimization process more effective, which helps to improve the performance of the model on the validation set. The AdamW optimization algorithm introduces the concepts of first-order moment estimation and second-order moment estimation when calculating parameters, and its rules for updating parameters are as follows:

[0079]

[0080] m t =β1·m t-1 +(1-β1)·g t

[0081]

[0082] Where θ represents the model parameters, g t represents the gradient at time step t, m t , v t are the first-order moment estimate and the second-order moment estimate of the gradient, represents the first-order and second-order moment estimates after bias correction, β1 and β2 are hyperparameters used to control the moving average of the two moments, 1r is the learning rate, ξ is a small constant whose purpose is to avoid division by 0, and wd is the weight decay coefficient. It improves the performance of the model on the validation set and improves the efficiency and accuracy of the model for image recognition.

[0083] Step S6: Adjust the backbone network in the YOLO V8 model and consider adding the MSHA multi-head self-attention mechanism.

[0084] In step S6, the specific method for adjusting the backbone network in the YOLO V8 model is:

[0085] S61. In the MSHA multi-head self-attention mechanism, it can capture complex dependencies within a sequence. Specifically, in MHSA, the input sequence is projected into multiple spaces simultaneously, which correspond to different heads. Each head learns attention weights for different parts of the sequence, which indicate which parts of the input sequence the model should focus on when generating each output element. Its self-attention formula is:

[0086]

[0087] Q, K, and V represent query, key, and value respectively, and are the results of transforming the input matrix under different weight matrices. K is the dimension of the key vector, which is used to scale the dot product to prevent the dot product from being too large, which in turn leads to gradient loss.

[0088] Due to multi-head self-attention, there will be multiple such attention functions operating in parallel, and each head can learn different representations in different subspaces. The formula can be expressed as:

[0089] MultiHead(Q,K,V)=Concat(head1,...,headh)W o

[0090] head i =Attention(QW i Q ,KW i K ,VW i V )

[0091] Where QW i Q , KW i K , VW i V , Wo is the parameter matrix learned in the model. In order to minimize the complexity of the lightweight backbone network, an MHSA module is introduced immediately after the ShuffleNetV2 module with two repetitions to enhance the model's ability to capture spatial features. After this module, feature fusion and dimensionality reduction operations are continued.

[0092] Step S7: train and verify the optimized YOLO V8 model fusion algorithm.

[0093] In step S7, the specific method for training and verifying the optimized YOLO V8 model fusion algorithm is as follows:

[0094] S71. Download the configuration file of the pre-trained model and network structure from the YOLO V8 official website. The configuration file contains the default hyperparameters and related weight values ​​for YOLO V8 model training, and loads it into the improved YOLO V8 model fusion neural network.

[0095] S72. According to the optimization methods of S4, S5, and S6, the description of the neural network structure in the YOLO V8 network configuration file is adjusted, and the image processing library function in OpenCV is used to rotate the image 90°, blur it, change the color, and add noise to expand the data set.

[0096] S73. As shown in the following table, the detection accuracy and results of the YOLO V8 algorithm for tomato leaf diseases before and after optimization are tested respectively.

[0097]

[0098] The above descriptions are only some specific implementation methods of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by any person familiar with the art within the technical scope disclosed in the present invention should be covered within the protection scope of the present invention.

Claims

1. A method for detecting tomato leaf diseases based on YOLO V8, characterized in that: The following steps are involved: Step S1, obtaining tomato leaf disease pictures, wherein the tomato leaf diseases specifically include: tomato late blight, tomato mosaic disease, tomato scab, and tomato leaf spot; Step S2, annotating the tomato leaf disease pictures to obtain a tomato leaf disease dataset; Step S3, preprocessing the tomato leaf disease data set; Step S4, replace the neural network structure of the Backbone module in YOLO V8 with ShuffleNetV2; Step S5: Replace the optimization algorithm in the YOLO V8 model with AdamW. Step S6, adding a multi-head self-attention mechanism to the Backbone module in the YOLO V8 model to obtain a disease detection model; Step S7: Using the tomato leaf disease dataset obtained after preprocessing in step S3, the disease detection model obtained in step S6 is trained.

2. The method for detecting tomato leaf diseases based on YOLO V8 as claimed in claim 1, characterized in that: The tomato leaf disease images obtained in step S1 are from the Plant-Village plant disease public dataset.

3. The method for detecting tomato leaf diseases based on YOLO V8 as claimed in claim 1, characterized in that: In step S3, the preprocessing specifically includes: using the image processing library function in OpenCV to rotate the image by 90 degrees, blur it, change the color, and add noise.

4. The method for detecting tomato leaf diseases based on YOLO V8 as claimed in claim 1, characterized in that: In step S4, the neural network structure of the Backbone module in YOLO V8 is replaced with ShuffleNetV2, specifically including: using two cascaded ShuffleNetV2 modules as the Backbone module in YOLO V8.

5. The method for detecting tomato leaf diseases based on YOLO V8 as claimed in claim 4, characterized in that: In step S6, the Backbone module in the YOLO V8 model adds a multi-head self-attention mechanism, specifically including: adding a multi-head self-attention mechanism module after two cascaded ShuffleNetV2 modules, then adding four cascaded ShuffleNetV2 modules after the multi-head self-attention mechanism module, and then adding an SPPF module; The tomato leaf disease data preprocessed in step S3 first enters the pooling layer for pooling; then enters two cascaded ShuffleNetV2 modules; then is further processed by the MHSA multi-head self-attention module; then enters four cascaded ShuffleNetV2 modules; then enters the SPPF module to convert the image into a vector output; and finally is classified.

Citation Information

Patent Citations

  • Aeroponic tomato feature extraction method based on semantic segmentation

    CN115937533A

  • Deep learning-based tomato disease and insect pest detection and identification method

    CN116630803A

  • Tomato leaf disease detection method, device and equipment and storage medium

    CN117636063A

Cited By

  • Method for detecting plant diseases and insect pests of tomato leaves based on improved YOLOv8

    CN120070960A

  • Tomato leaf disease and pest detection method based on improved YOLOv8

    CN120070960B