Apple leaf disease detection method based on YOLOv7 and parameter-free attention mechanism
Through the apple leaf disease detection method based on YOLOv7 and the parameter-free attention mechanism, the problems of false detection and missed detection caused by background clutter and small lesion area are solved, and high-precision and lightweight detection effects are achieved.
Patent Information
- Application Number
- CN202311101180.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-29
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2043-08-29
AI Technical Summary
In the existing technology, when the image background is cluttered and the diseased area is small, the apple leaf disease detection model is prone to false detection and missed detection.
An apple leaf disease detection method based on YOLOv7 and a parameter-free attention mechanism is adopted. Through data enhancement, labeling, model construction and loss function optimization, combined with the parameter-free attention mechanism SimAM and Neck network module, the detection accuracy is improved and the number of model parameters is reduced.
The accuracy and recall rate of apple leaf disease detection are improved, the number of model parameters is reduced, and the problems of false detection and missed detection are solved.
Smart Images

Figure CN117274666B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of image recognition technology and deep learning technology, and specifically relates to an apple leaf disease detection method based on YOLOv7 and a parameter-free attention mechanism. Background Art
[0002] China's agricultural industry plays an indispensable role in the development of the national economy. Crop foliar diseases are a typical problem in agricultural production and a major constraint on its development. Apples, one of the most consumed fruits, are experiencing increasing market demand. Apples are cultivated extensively in the Los Plateau and the Bohai Bay region of northwestern my country, becoming a major source of income for local fruit farmers. However, in practice, apple production and quality are often affected by diseases. Research has found that apple diseases primarily manifest on leaves, with diseased leaves exhibiting certain abnormalities in color, texture, and shape, with different types of diseased leaves exhibiting distinct appearance characteristics. Therefore, accurately analyzing the characteristics of apple leaf diseases and promptly detecting and diagnosing their types can minimize the economic losses caused by these diseases, which is of great theoretical and practical significance.
[0003] Deep learning technology improves detection accuracy while alleviating the high image processing costs of traditional machine learning. Consequently, plant leaf disease detection has gradually evolved from traditional machine learning methods to deep learning. Improving existing convolutional neural networks or employing custom convolutional neural networks to perform plant leaf disease detection has become the mainstream approach in the apple leaf disease detection field. Deep learning-based apple leaf disease detection methods can be broadly categorized into two types: those based on image classification models and those based on object detection models. Image classification methods directly classify images using convolutional neural networks as a backbone. While simple and efficient, these methods can only determine the type of leaf disease, not the location of the diseased area, and are only applicable to scenarios with a single background. Object detection methods use convolutional neural networks as feature extractors to learn features of leaf disease areas and output both their location and category. These methods are more suitable for detecting apple leaf diseases in low-resolution and complex imagery. Developing an effective apple leaf disease detection method based on this approach is crucial for protecting fruit quality, increasing yield, and achieving smart agriculture.
[0004] However, in the actual farmland context, the background of the collected images is cluttered and the diseased area is small, and general detection models are prone to false detection and missed detection problems. Summary of the Invention
[0005] The purpose of the present invention is to provide an apple leaf disease detection method based on YOLOv7 and a parameter-free attention mechanism, which solves the problem that the existing technology is prone to false detection and missed detection when the image background is cluttered and the diseased area is small.
[0006] The technical solution adopted by the present invention is an apple leaf disease detection method based on YOLOv7 and a parameter-free attention mechanism, which is specifically implemented according to the following steps:
[0007] Step 1: Preprocess the apple leaf disease images to obtain a data set;
[0008] Step 2: Label the dataset from step 1 and divide it into a training set and a validation set;
[0009] Step 3: Based on the training set in step 2, build an apple leaf disease detection model based on YOLOv7 and the parameter-free attention mechanism;
[0010] Step 4: Set the loss function, input the training set and validation set from step 2 into the detection model from step 3, adjust the model parameters and perform training, and save the trained apple leaf disease detection model;
[0011] Step 5: Verify whether the apple leaf disease detection model trained in step 4 is fit by observing various evaluation indicators during the model training process. If it is fit, use the trained apple leaf disease detection model to detect and output the category and location of apple leaf diseases, otherwise return to step 4.
[0012] The present invention is also characterized in that:
[0013] In step 1, preprocessing is to unify the pixels of the apple leaf disease images and perform data augmentation to expand the dataset.
[0014] Data enhancement specifically involves rotating the apple leaf disease image, changing the brightness, sharpness, contrast, and chromaticity.
[0015] The expansion is to increase the data volume to 12 times the original amount.
[0016] Step 2 is as follows:
[0017] Step 2.1: Use LabelImg software to label the apple leaf diseases in the dataset from step 1. Use rectangular boxes to outline the location of the apple leaf diseases and indicate their categories. Create an "images" file to store the apple leaf disease images and a "labels" folder to store the labeled information in a txt file containing the location and category of the leaf diseases, according to the YOLO dataset format.
[0018] Step 2.2: Divide the labeled apple leaf disease images into a training set and a validation set in a ratio of 8:2.
[0019] Step 3 is as follows:
[0020] Step 3.1: Introduce the YOLOv7 model and introduce the parameter-free attention mechanism SimAM into the original YOLOv7 Backbone network. Input the training set data from step 2 into the Backbone network for feature extraction to obtain three feature layers of different scales.
[0021] In step 3.2, the GSConv and VOVGSCSP modules are used in the Neck network to input the feature maps output by the three different scale feature layers in step 3.1 into the Neck network for further feature extraction and feature fusion. The Neck network outputs the model prediction results, namely the category and location of the leaf disease in the apple leaf disease image.
[0022] Step 3.1 is specifically as follows: introduce the YOLOv7 model and introduce the parameter-free attention mechanism SimAM into the Backbone network. Input the training set data of step 2 into the Backbone network with the parameter-free attention mechanism SimAM. The training set data passes through four CBS modules, one E-ELAN module, one MP module and one E-ELAN module in turn, and then enters the SimAM attention module to obtain the first scale feature layer; then passes through an E-ELAN module and an MP module, and then enters the SimAM attention module to obtain the second scale feature layer; finally, passes through an E-ELAN module and an MP module, and then enters the SimAM attention module to obtain the third scale feature layer.
[0023] Step 3.2 is as follows:
[0024] Step 3.2.1. Use the output of the third scale feature layer as the input of the SPPCSPC module in the Neck network. After feature fusion, input it into the VOVGSCSP module, and then input it into the RepConv module. Use YoloHead for regression and classification, and output the large-scale prediction result.
[0025] Step 3.3.2: The output of the second scale feature layer is first input into GSConv, and feature fused with the output of the SPPCSPC module. Then, it is input into the L-ELAN module, and after feature fusion, it is input into the VOVGSCSP module. Finally, it is input into the RepConv module and uses YoloHead for regression and classification, and outputs the mesoscale prediction result.
[0026] Step 3.3.3: Input the output of the first scale feature layer into GSConv first, fuse it with the output of the L-ELAN module, then input it into the VOVGSCSP module, and then input it into the RepConv module and use YoloHead for regression and classification, and output the small-scale prediction result.
[0027] In step 4, the loss function is EIOU Loss; the model parameters include the batch size, initial learning rate, optimization function, and momentum parameter during model training;
[0028] In step 5, the evaluation indicators include: precision, recall, average accuracy and mean average accuracy.
[0029] The batch size is 16, the initial learning rate is 0.0001, the optimization function is Adam, and the momentum parameter is 0.9.
[0030] The beneficial effects of the present invention are as follows: the apple leaf disease detection method based on YOLOv7 and the parameter-free attention mechanism of the present invention replaces the original YOLOv7 model loss function with EIOU Loss, introduces the parameter-free attention mechanism SimAM into the backbone network of the YOLOv7 model to improve the model detection accuracy; and reduces the number of model parameters by using GSConv and VOVGSCSP modules in the neck network of the YOLOv7 model, thereby achieving model lightweighting. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 This is a flowchart of the apple leaf disease detection method based on YOLOv7 and the non-parameter attention mechanism of the present invention;
[0032] Figure 2 This is a network architecture diagram of the model in the apple leaf disease detection method of the present invention;
[0033] Figure 3 is a structural diagram of the MP module in the apple leaf disease detection method of the present invention;
[0034] Figure 4 is a structural diagram of the E-ELAN module in the apple leaf disease detection method of the present invention;
[0035] Figure 5 It is a structural diagram of the SPPCSPC module in the apple leaf disease detection method of the present invention;
[0036] Figure 6 is a structural diagram of the L-ELAN module in the apple leaf disease detection method of the present invention;
[0037] Figure 7 4 is a structural diagram of the VOVGSCSP module in the apple leaf disease detection method of the present invention;
[0038] Figure 8 This is a diagram showing the detection effect of the YOLOv7 algorithm in the prior art of the present invention on four common leaf diseases of apple;
[0039] Figure 9 This is a diagram showing the detection effects of the apple leaf disease detection method of the present invention on four common leaf diseases of apple. DETAILED DESCRIPTION
[0040] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0041] The present invention is based on the apple leaf disease detection method of YOLOv7 and the non-attention mechanism. The process is as follows: Figure 1 As shown, please follow the steps below:
[0042] Step 1: The pixel size of apple leaf disease images is unified to 512×512, and data augmentation is performed to expand the dataset. The data volume is expanded to 12 times the original through data augmentation to avoid overfitting.
[0043] Data enhancement involves rotating the apple leaf disease image, changing the brightness, sharpness, contrast, and color.
[0044] Step 2: Based on the expanded dataset in step 1, use LabelImg software to label the apple leaf diseases in the apple leaf disease images and divide them into a training set and a validation set in a ratio of 8:2.
[0045] Step 2.1: Use LabelImg, a commonly used object detection annotation tool, to label the apple leaf disease. Use a rectangular box to outline the location of the apple leaf disease and indicate its category. Following the YOLO dataset format, create an "images" folder to store the apple leaf disease images and a "labels" folder to store the annotation information in a txt file. This txt file contains the category and location of the target leaf disease.
[0046] Step 2.2: Divide the labeled apple leaf disease images into a training set and a validation set in a ratio of 8:2.
[0047] Step 3: Based on the apple leaf disease image features in the training set constructed in step 2, an apple leaf disease detection model based on YOLOv7 and the non-parameter attention mechanism is constructed.
[0048] like Figure 2As shown in the figure, the YOLOv7 model is introduced. The network structure includes a Backbone network for feature extraction and a Neck network for enhanced feature extraction and prediction output. The Backbone network incorporates the parameter-free attention mechanism SimAM, which allows the model to focus more on apple leaf diseases in apple leaf disease images without increasing the number of model parameters. The Neck network uses the GSConv and VOVGSCSP modules to reduce the number of model parameters and achieve model lightweighting. The feature maps extracted from the Backbone network are input into the Neck network for further feature extraction and feature fusion. The Neck network finally outputs the model's prediction result, namely the category and location of the leaf disease present in the input apple leaf disease image.
[0049] Specifically: Step 3.1, if Figure 2 As shown in the figure, the training set constructed in step 2 is input into the Backbone network that introduces the parameter-free attention mechanism SimAM. The image data input into the Backbone network passes through four CBS modules, one E-ELAN module, and then one MP module and one E-ELAN module in sequence, which is called the first MP+E-ELAN module, and then enters the SimAM attention module to obtain the first scale feature layer; after the first MP+E-ELAN module, it passes through another MP module and an E-ELAN module, which is called the second MP+E-ELAN module, and then enters the SimAM attention module to obtain the second scale feature layer; finally, after the second MP+E-ELAN module, it passes through another MP module and an E-ELAN module, which is called the third MP+E-ELAN module, and then enters the SimAM attention module to obtain the third scale feature layer.
[0050] Specifically, the first and third CBS modules are composed of convolution with kernel size of 3×3, stride of 1, Batachnorm normalization and SiLU activation function; the second and fourth CBS modules are composed of convolution with kernel size of 3×3, stride of 2, Batachnorm normalization and SiLU activation function; Figure 4As shown in the figure, the E-ELAN module consists of four branches and seven CBS modules. Specifically, the first branch is a CBS module (consisting of convolution with a kernel size of 1×1, a step size of 1, Batachnorm normalization, and a SiLU activation function) connected in series with four CBS modules (consisting of convolution with a kernel size of 3×3, a step size of 1, Batachnorm normalization, and a SiLU activation function); the second branch is the output of the first CBS module; the third branch is the output of the third CBS module; the fourth branch is only passed through one CBS module (consisting of convolution with a kernel size of 1×1, a step size of 1, Batachnorm normalization, and a SiLU activation function); the features output by the four branches are spliced in the channel dimension, and then passed through a CBS module (consisting of convolution with a kernel size of 1×1, a step size of 1, Batachnorm normalization, and a SiLU activation function) to obtain the output of the E-ELAN module. As shown in the figure, the E-ELAN module is composed of four branches (consisting of convolution with a kernel size of 1×1, a step size of 1, Batachnorm normalization, and a SiLU activation function). Figure 3 As shown in the figure, the MP module consists of two branches, three CBS modules and a maximum pooling layer. Specifically, the first branch passes through a maximum pooling layer and a CBS module (consisting of convolution with a kernel size of 1×1 and a stride of 1, Batachnorm normalization and SiLU activation function) in sequence; the second branch is a CBS module (consisting of convolution with a kernel size of 1×1 and a stride of 1, Batachnorm normalization and SiLU activation function) connected in series with a CBS module (consisting of convolution with a kernel size of 3×3 and a stride of 2, Batachnorm normalization and SiLU activation function); the features output by the two branches are spliced in the channel dimension to obtain the output of the MP module.
[0051] The present invention introduces the SimAM module into the original YOLOv7 Backbone network to improve the model's attention to apple leaf diseases and further enhance the model's detection accuracy. In neuroscience, information-rich neurons typically exhibit different discharge patterns from surrounding neurons. Moreover, activated neurons typically inhibit surrounding neurons, i.e., spatial inhibition. Neurons with spatial inhibition effects should be given higher importance. The simplest way to find important neurons is to measure the linear separability between neurons. Specifically, the following energy function is defined:
[0052]
[0053] in, M=H×W,e t represents the energy function, ω t represents the weighted value, b t represents bias exchange, t represents the target neuron, x iRepresents other neurons, H represents the height of the input feature, W represents the width of the input feature, y represents the binary label, y o =-1,y t =1, the final energy function is defined as follows:
[0054]
[0055] Each channel has M = H × W energy functions, and the above formula has the following analytical solution:
[0056]
[0057] in, λ=0.0001,u t represents the mean of other neurons excluding the target neuron t, σ t represents the variance of other neurons excluding the target neuron t. Therefore, the minimum energy It can be obtained by the following formula:
[0058]
[0059] From the above formula, we can see that the lower the energy, the greater the difference between the target neuron t and the surrounding neurons, and the higher the importance. Therefore, the importance of a neuron can be expressed by The weight matrix of the feature map is obtained by multiplying the features of the input SimAM module by the weight matrix to obtain the output of the SimAM module.
[0060] Step 3.2: Input the feature maps output by the three different scale feature layers into the Neck network for further feature extraction and feature fusion. Finally, the Neck network outputs the model prediction results, that is, the category and location of the leaf disease in the input apple leaf disease image.
[0061] Step 3.2 is as follows:
[0062] Step 3.2.1. Use the output of the third scale feature layer as the input of the SPPCSPC module in the Neck network. After feature fusion, input it into the VOVGSCSP module, and then input it into the RepConv module and use YoloHead for regression and classification to output the large-scale prediction results.
[0063] Step 3.2.2: The output of the second scale feature layer is first input into GSConv, and feature fused with the output of the SPPCSPC module, then input into the L-ELAN module, and after feature fusion, input into the VOVGSCSP module, and then input into the RepConv module and use YoloHead for regression and classification, and output the mesoscale prediction result.
[0064] Step 3.2.3: Input the output of the first scale feature layer into GSConv first, fuse it with the output of the L-ELAN module, then input it into the VOVGSCSP module, and then input it into the RepConv module and use YoloHead for regression and classification, and output the small-scale prediction result.
[0065] like Figure 5 As shown in the figure, the SPPCSPC module consists of two branches, three maximum pooling layers, and seven CBS modules. The first branch first passes through three CBS modules (consisting of convolution with a kernel size of 1×1 and a step size of 1, Batachnorm normalization, and SiLU activation function), and then passes through three maximum pooling layers respectively. The outputs of the three CBS modules and the outputs of the three maximum pooling layers are feature fused, and then pass through two CBS modules in sequence; the second branch passes through only one CBS module (consisting of convolution with a kernel size of 1×1 and a step size of 1, Batachnorm normalization, and SiLU activation function); after the output of the first branch is feature fused with the output of the second branch, it passes through another CBS module (consisting of convolution with a kernel size of 1×1 and a step size of 1, Batachnorm normalization, and SiLU activation function) to obtain the output of the SPPCSPC module. As shown in the figure, the first branch first passes through three CBS modules (consisting of convolution with a kernel size of 1×1 and a step size of 1, Batachnorm normalization, and SiLU activation function), and then passes through three maximum pooling layers respectively. The outputs of the three CBS modules and the outputs of the three maximum pooling layers are feature fused, and then pass through two CBS modules in sequence; the second branch passes through only one CBS module (consisting of convolution with a kernel size of 1×1 and a step size of 1, Batachnorm normalization, and SiLU activation function). Figure 6 As shown in Figure 1, the L-ELAN module consists of six branches and seven CBS modules. Specifically, the first branch is a CBS module (consisting of a convolution kernel size of 1×1, a stride of 1, a Batachnorm normalization, and a SiLU activation function) connected in series with four CBS modules (consisting of a convolution kernel size of 3×3, a stride of 1, a Batachnorm normalization, and a SiLU activation function); the second branch is the output of the first CBS module; the third branch is the output of the second CBS module; the fourth branch is the output of the first CBS module. is the output of the third CBS module; the fifth branch is the output of the fourth CBS module; the sixth branch is only passed through a CBS module (consisting of convolution with a kernel size of 1×1, a stride of 1, Batachnorm normalization, and a SiLU activation function); the features output by the six branches are spliced in the channel dimension, and then passed through a CBS module (consisting of convolution with a kernel size of 1×1, a stride of 1, Batachnorm normalization, and a SiLU activation function) to obtain the output of the L-ELAN module. Figure 7As shown in Figure 1, the VOVGSCSP module consists of two branches. Specifically, the first branch first passes through a CBS module (consisting of a convolution with a kernel size of 1×1 and a stride of 1, Batachnorm normalization, and a SiLU activation function), and then passes through a GS structure; the second branch only passes through a CBS module (consisting of a convolution with a kernel size of 1×1 and a stride of 1, Batachnorm normalization, and a SiLU activation function); the features output by the first and second branches are fused, and then pass through a CBS module (consisting of a convolution with a kernel size of 1×1 and a stride of 1, Batachnorm normalization, and a SiLU activation function) to obtain the output of the VOVGSCSP module. Among them, the GS structure consists of two branches. Specifically, the first branch passes through two GSConvs continuously; the second branch passes through a CBS module (consisting of a convolution with a kernel size of 3×3, a step size of 1, Batachnorm normalization, and a SiLU activation function); the features output by the first and second branches are fused to obtain the output of the GS structure.
[0066] Step 4: Based on the apple leaf disease image features in the training set constructed in step 2, set the model loss function, input the training set and validation set in step 2 into the detection model in step 3, adjust the model parameters and perform training, and save the trained apple leaf disease detection model;
[0067] Specifically, the original CIOU Loss is replaced with EIOU Loss. Although CIOU Loss takes into account the overlapping area, center point distance, and aspect ratio of bounding box regression, it cannot reflect the real difference between width and height and their confidence, and therefore may hinder model optimization. EIOU Loss, on the other hand, separates the influencing factors of the aspect ratio based on the penalty term of CIOU Loss, and calculates the length and width of the target box and anchor box respectively. EIOU Loss consists of three parts: overlap loss, center distance loss, and width and height loss. The first two parts continue the methods in CIOU, but the width and height loss directly minimizes the difference between the width and height of the target box and the anchor box, making the convergence faster. At the same time, Focal Loss is introduced in EIOU Loss to optimize the sample imbalance problem in the bounding box regression task, that is, to reduce the optimization contribution of a large number of anchor boxes that have less overlap with the target box to BBox regression, so that the regression process focuses on high-quality anchor boxes.
[0068] Adjust the model parameters to set the batch size, initial learning rate, optimization function, and momentum parameter during model training.
[0069] Optimal solution: batch size is set to 16, initial learning rate is 0.0001, optimization function is Adam, and momentum parameter is 0.9.
[0070] Step 5: Verify whether the apple leaf disease detection model trained in step 4 is fit by observing various evaluation indicators during the model training process. If it is fit, use the trained apple leaf disease detection model to detect and output the category and location of apple leaf diseases, otherwise return to step 4.
[0071] Evaluation indicators include: Precision, Recall, Average Precision (AP), and Mean Average Precision (mAP). The calculation method of these four indicators is as follows:
[0072]
[0073]
[0074]
[0075]
[0076] Where TP, TN, FP, and FN represent the number of correctly predicted positive samples, the number of correctly predicted negative samples, the number of incorrectly predicted positive samples, and the number of incorrectly predicted negative samples, respectively. P(R) represents the curve composed of precision and recall, and n represents the number of categories.
[0077] Example 1
[0078] The apple leaf disease detection method based on YOLOv7 and the non-attention mechanism of the present invention is specifically implemented according to the following steps:
[0079] Step 1: The pixel size of the apple leaf disease images is unified to 512×512, and data augmentation is performed to expand the dataset to obtain the expanded dataset;
[0080] Data augmentation involves rotating the apple leaf disease image, changing its brightness, sharpness, contrast, and chromaticity. Data augmentation techniques are used to increase the data volume by 12 times.
[0081] Step 2: Label the dataset from step 1 and divide it into a training set and a validation set;
[0082] Step 2.1: Use LabelImg software to label the apple leaf diseases in the dataset from step 1. Use rectangular boxes to outline the location of the apple leaf diseases and indicate their categories. Create an "images" file to store the apple leaf disease images and a "labels" folder to store the labeled information in a txt file containing the location and category of the leaf diseases, according to the YOLO dataset format.
[0083] Step 2.2: Divide the labeled apple leaf disease images into a training set and a validation set in a ratio of 8:2.
[0084] Step 3: Based on the training set in step 2, build an apple leaf disease detection model based on YOLOv7 and the parameter-free attention mechanism;
[0085] Step 3.1: Introduce the parameter-free attention mechanism SimAM into the original YOLOv7 Backbone network, input the training set data from step 2 into the Backbone network for feature extraction, and obtain three feature layers of different scales;
[0086] Specifically, the training set data of step 2 is input into the Backbone network that introduces the parameter-free attention mechanism SimAM. The training set data passes through four CBS modules, an E-ELAN module, an MP module and an E-ELAN module in sequence, and then enters the SimAM attention module to obtain the first scale feature layer; then passes through an E-ELAN module and an MP module, and then enters the SimAM attention module to obtain the second scale feature layer; finally, passes through an E-ELAN module and an MP module, and then enters the SimAM attention module to obtain the third scale feature layer.
[0087] In step 3.2, the GSConv and VOVGSCSP modules are used in the Neck network to input the feature maps output by the three different scale feature layers in step 3.1 into the Neck network for further feature extraction and feature fusion. The Neck network outputs the model prediction results, namely the category and location of the leaf disease in the apple leaf disease image.
[0088] Step 3.2.1. Use the output of the third scale feature layer as the input of the SPPCSPC module in the Neck network. After feature fusion, input it into the VOVGSCSP module, and then input it into the RepConv module. Use YoloHead for regression and classification, and output the large-scale prediction result.
[0089] Step 3.3.2: The output of the second scale feature layer is first input into GSConv, and feature fused with the output of the SPPCSPC module. Then, it is input into the L-ELAN module, and after feature fusion, it is input into the VOVGSCSP module. Finally, it is input into the RepConv module and uses YoloHead for regression and classification, and outputs the mesoscale prediction result.
[0090] Step 3.3.3: Input the output of the first scale feature layer into GSConv first, fuse it with the output of the L-ELAN module, then input it into the VOVGSCSP module, and then input it into the RepConv module and use YoloHead for regression and classification, and output the small-scale prediction result.
[0091] Step 4: Set the loss function to EIOU Loss, and input the training set and validation set from step 2 into the detection model from step 3. Adjust the batch size, initial learning rate, optimization function, and momentum parameters during model training, and then train the model. Save the trained apple leaf disease detection model.
[0092] The specific parameters for model training in this example are shown in Table 1 below:
[0093] Table 1
[0094] parameter value Batch size 16 Initial learning rate 0.0001 Optimization function Adam Momentum parameter 0.9
[0095] Step 5: Verify whether the apple leaf disease detection model trained in step 4 is suitable by using four objective evaluation indicators: precision, recall, average accuracy (AP), and mean average precision (mAP). If it is suitable, use the trained apple leaf disease detection model to detect and output the category and location of apple leaf diseases. Otherwise, return to step 4.
[0096] In order to verify the effect of introducing EIOU Loss, SimAM module, GSConv and VOVGSCSP modules into the model, this example conducted four groups of ablation experiments. Group A used the Yolov7 model, Group B used the Yolov7+EIOU model, Group C used the Yolov7+EIOU+SimAM model, and Group D, i.e. Example 1, used the Yolov7+EIOU+SimAM+GSConv+VOVGSCSP model. The training sets and validation sets of all models used the same set of data. The specific values are shown in Table 2 below.
[0097] Table 2
[0098] Precision Recall mAP@0.5 mAP@0.5:0.95 Parameter quantity A 81.6% 72.7% 82.8% 45.2% 37.2MB B 80.7% 78.5% 83.9% 47.3% 37.2MB C 85.5% 75.3% 84.8 47.3% 37.2MB D 85.8% 76.1% 86.0% 48.3% 32MB
[0099] As can be seen from Table 2, in the Yolov7 model algorithm of Group A, the Precision value of apple leaf disease is 81.6%, the Recall value is 72.7%, the mAP value is 82.8%, and the parameter amount is 37.2MB. Group C first introduced EIOU and SimAM into the Yolov7 algorithm. As can be seen from Table 2, the model of Group C after introducing EIOU and SimAM has improved the Precision by 3.9%, the Recall by 2.6%, and the mAP by 2.0% compared with the Yolov7 model algorithm in Group A, but the number of model parameters has not been increased. Secondly, on the basis of introducing EIOU and SimAM, the GSConv and VOVGSCSP modules are further introduced, which is Example 1 of Group D. As can be seen from Table 2, the Precision value of Group D Example 1, which continues to introduce GSConv and VOVGSCSP, continues to improve by 0.3%, and the Recall continues to improve by 0.8% compared with the Group C model that only introduces EIOU and SimAM, but the number of parameters is reduced by 14%. As shown in Table 2, in Example 1 of the present invention, the Precision value of apple leaf disease is 85.8%, the Recall value is 76.1%, the mAP value is 86.0%, and the parameter amount is 32MB. The Precision value and mAP value are the highest, while the parameter amount is the lowest.
[0100] As shown in Table 2, compared with the YOLOv7 algorithm, the precision value of the proposed method is improved by 4.2%, the recall value is improved by 3.4%, and the mAP value is improved by 3.2%, while the number of parameters is reduced by 14%. Figure 8 The figure shows the detection effect of Yolov7 algorithm on four common leaf diseases of apple: leaf spot disease, brown spot disease, gray spot disease, and mosaic disease. Figure 9 The graph shows the detection effect of the method provided by the present invention on four common leaf diseases of apple, namely, leaf spot, brown spot, gray spot and mosaic disease. Figure 8 and Figure 9 It can be seen that the method provided by the present invention can solve the problem of false detection and missed detection of the Yolov7 algorithm, while improving the detection accuracy of the model.
[0101] In order to verify the effect of the model of the present invention, four currently commonly used models were selected as comparative examples for comparison:
[0102] Comparative Example 1: Apple leaf disease detection method using the SSD model;
[0103] Comparative Example 2: Apple leaf disease detection method using Yolov3 with spp model;
[0104] Comparative Example 3: Apple leaf disease detection method using Yolov5s model;
[0105] Comparative Example 4: Apple leaf disease detection method using Yolov7 model;
[0106] The training and validation sets of all models use the same set of data. The specific values are shown in Table 3 below.
[0107] Table 3
[0108]
[0109] As can be seen from Table 3, in the present invention, among the four common leaf diseases of apple, the AP value of leaf spot is 86.4%, the AP value of brown spot is 90.7%, the AP value of gray spot is 87.4%, the AP value of mosaic is 79.3%, and the mAP value is 86.0%. Compared with Comparative Examples 1, 2, 3, and 4, Example 1 of the present invention using the apple leaf disease detection method based on YOLOv7 and the no-attention mechanism has the highest AP value and mAP value for detecting the four common leaf diseases of apple (leaf spot, brown spot, gray spot, and mosaic), indicating that the apple leaf disease detection method based on YOLOv7 and the no-attention mechanism of the present invention has a good detection effect.
[0110] The present invention proposes an apple leaf disease detection method based on YOLOv7 and a parameter-free attention mechanism. The YOLOv7 model loss function is replaced by EIOU Loss, and the parameter-free attention mechanism SimAM is introduced into the backbone network of the YOLOv7 model to improve the model detection accuracy. The GSConv and VOVGSCSP modules are used in the neck network of the YOLOv7 model to reduce the number of model parameters and achieve model lightweighting.
Claims
1. An apple leaf disease detection method based on YOLOv7 and non-attention mechanism, characterized by: Please follow the steps below to implement it: Step 1: Preprocess the apple leaf disease images to obtain a data set; Step 2: Label the dataset from step 1 and divide it into a training set and a validation set; Step 3: Based on the training set in step 2, build an apple leaf disease detection model based on YOLOv7 and the parameter-free attention mechanism; Step 4: Set the loss function, input the training set and validation set from step 2 into the detection model from step 3, adjust the model parameters and perform training, and save the trained apple leaf disease detection model; Step 5: Verify whether the apple leaf disease detection model trained in step 4 is fit by observing various evaluation indicators during the model training process. If it is fit, use the trained apple leaf disease detection model to detect and output the category and location of apple leaf diseases. Otherwise, return to step 4. The step 3 is specifically as follows: Step 3.1: Introduce the YOLOv7 model and introduce the parameter-free attention mechanism SimAM into the original YOLOv7 Backbone network. Input the training set data from step 2 into the Backbone network for feature extraction to obtain three feature layers of different scales. In step 3.2, the GSConv and VOVGSCSP modules are used in the Neck network to input the feature maps output by the three different scale feature layers in step 3.1 into the Neck network for further feature extraction and feature fusion. The Neck network then outputs the model prediction results, i.e., the category and location of the leaf disease in the apple leaf disease image. The step 3.1 is specifically as follows: introducing the YOLOv7 model and introducing the parameter-free attention mechanism SimAM into the Backbone network, inputting the training set data of step 2 into the Backbone network with the parameter-free attention mechanism SimAM, and inputting the training set data into the SimAM attention module after passing through four CBS modules, one E-ELAN module, one MP module, and one E-ELAN module in sequence to obtain a first scale feature layer; then, after passing through an E-ELAN module and an MP module, inputting the SimAM attention module to obtain a second scale feature layer; and finally, after passing through an E-ELAN module and an MP module, inputting the SimAM attention module to obtain a third scale feature layer; The step 3.2 is specifically as follows: Step 3.2.
1. Use the output of the third scale feature layer as the input of the SPPCSPC module in the Neck network. After feature fusion, input it into the VOVGSCSP module, and then input it into the RepConv module. Use YoloHead for regression and classification, and output the large-scale prediction result. Step 3.3.2: The output of the second scale feature layer is first input into GSConv, and feature fused with the output of the SPPCSPC module. Then, it is input into the L-ELAN module, and after feature fusion, it is input into the VOVGSCSP module. Finally, it is input into the RepConv module and uses YoloHead for regression and classification, and outputs the mesoscale prediction result. Step 3.3.3: Input the output of the first scale feature layer into GSConv first, fuse it with the output of the L-ELAN module, then input it into the VOVGSCSP module, and then input it into the RepConv module and use YoloHead for regression and classification, and output the small-scale prediction result.
2. The apple leaf disease detection method based on YOLOv7 and no-attention mechanism according to claim 1 is characterized in that: In step 1, the preprocessing is to unify the pixels of the apple leaf disease image and perform data enhancement to expand the data set.
3. The apple leaf disease detection method based on YOLOv7 and no-attention mechanism according to claim 2, characterized in that: The data enhancement specifically includes rotating the apple leaf disease image, changing the brightness, changing the sharpness, changing the contrast, and changing the chromaticity.
4. The apple leaf disease detection method based on YOLOv7 and no-attention mechanism according to claim 2, characterized in that: The expansion is to expand the data volume to 12 times the original amount.
5. The apple leaf disease detection method based on YOLOv7 and no-attention mechanism according to claim 2, characterized in that: The step 2 is specifically as follows: Step 2.1: Use LabelImg software to label the apple leaf diseases in the dataset from step 1. Use rectangular boxes to outline the location of the apple leaf diseases and indicate their categories. Create an "images" file to store the apple leaf disease images and a "labels" folder to store the labeled information in a txt file containing the location and category of the leaf diseases, according to the YOLO dataset format. Step 2.2: Divide the labeled apple leaf disease images into a training set and a validation set in a ratio of 8:
2.
6. The apple leaf disease detection method based on YOLOv7 and no-attention mechanism according to claim 1, characterized in that: In step 4, the loss function is EIOU Loss; the model parameters include batch size, initial learning rate, optimization function and momentum parameter during model training; In step 5, the evaluation indicators include: precision, recall rate, average accuracy and mean of average accuracy.
7. The apple leaf disease detection method based on YOLOv7 and no-attention mechanism according to claim 6, characterized in that: The batch size is 16, the initial learning rate is 0.0001, the optimization function is Adam, and the momentum parameter is 0.9.
Citation Information
Patent Citations
Apple detection positioning method and system based on deep convolutional neural network
CN115880477A
High-precision textile defect intelligent detection method considering large and small targets
CN116402769A