Apple tree leaf disease detection method based on improved YOLOv7
By improving the YOLOv7 network, cat_BiFPN, ECA attention mechanism and SIOU loss function were introduced, which solved the problem of poor detection accuracy of apple tree leaf disease, achieving higher detection accuracy and faster model convergence.
Patent Information
- Application Number
- CN202311543247.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-20
- Publication Date
- 2025-05-20
AI Technical Summary
The prior art has poor accuracy in apple tree leaf disease detection, especially due to the diverse disease morphology and dense distribution, the detection effect is not ideal.
Improve the YOLOv7 network, and enhance feature extraction and detection accuracy by introducing new feature fusion modules cat_BiFPN, ECA attention mechanism and SIOU loss function.
The model's detection ability of diseases of different scales in apple leaves is improved, the ability to extract important features is enhanced, and the convergence speed of the model is accelerated, which significantly improves the detection accuracy.
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] The present invention relates to the field of fruit tree leaf disease identification, and particularly to a method for detecting apple tree leaf diseases based on improved YOLOv7. Background Technique
[0002] In recent years, the output of Chinese apples has been increasing year by year and has become one of the main economic sources in some regions of China. However, certain diseases may occur during the growth of apple trees, which will affect the quality and output of apples, thus causing economic losses to fruit farmers.
[0003] With the continuous development and progress of agricultural technology, object detection technology based on deep learning has been widely applied in the agricultural field. Based on the convolutional neural network (CNN) algorithm of deep learning, a large amount of data is required for training to more accurately extract the features of the object. However, the simple CNN algorithm has poor detection effects on apple tree leaf diseases. The one-stage detection algorithm YOLOv7 can be well applied to the detection of apple tree leaf diseases. However, due to the characteristics of diverse morphology and dense distribution of apple tree leaf diseases, the detection accuracy of apple tree leaf diseases is not good. Summary of the Invention
[0004] Aiming at the deficiencies of the prior art, the present invention proposes a method for detecting apple tree leaf diseases based on improved YOLOv7 to solve the problems existing in the above background technique.
[0005] The method for detecting apple tree leaf diseases based on improved YOLOv7 specifically includes the following steps.
[0006] Step 1: Use a mobile phone or camera to collect picture information of apple tree leaf diseases (scab, powdery mildew, rust, and frogeye leaf spot), and label the pictures.
[0007] Step 2: Screen and process the labeled disease pictures in Step 1, and then divide them into a training set, a test set, and a validation set.
[0008] Step 3: The present invention designs a new feature fusion module cat_BiFPN, and adds the BiFPN structure to the YOLOv7 network in a cascaded manner, which is combined with the feature fusion module in the detection network. While enhancing the feature position information, it also takes into account the extraction of deeper feature information and can accurately extract features of different scales.
[0009] Step 4: Add the ECA attention mechanism after the ELAN and ELAN-H modules in the YOLOv7 network structure to enhance the extraction of important features. This attention mechanism can improve the detection accuracy of the model without increasing the model complexity.
[0010] Step 5: Replace the loss function CIOU in the YOLOv7 network with SIOU to improve the regression speed of the prediction box, accelerate the convergence of the model, and thus improve the detection accuracy.
[0011] Step 6: Input the dataset divided in Step 2 into the improved network model in Step 5, and set initial parameters such as the number of iterations, learning rate, momentum factor, batch sample size, etc. Use an optimizer to adjust the network parameters, and save the best weight parameters at this time when the set number of training iterations is completed.
[0012] Step 7: Use the best weight parameters saved in Step 6 as the pre-trained weights, then detect the apple tree leaf disease pictures to be detected, and view the detection effect.
[0013] The present invention has the following beneficial effects.
[0014] Compared with other detection methods, the present invention improves the detection accuracy of the model through the introduced improvement scheme. By using the multi-scale fusion module (cat_BiFPN), the detection ability of the model for diseases of different scales in apple leaves is improved. Adding the efficient channel attention mechanism (ECA) can enhance the ability of the model to extract important features of apple leaves and improve the detection accuracy of the model. Replacing the loss function with the SIOU loss function can accelerate the convergence speed of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a flow chart of a method for detecting apple tree leaf diseases based on improved YOLOv7 proposed by the present invention.
[0016] Figure 2 It is a network structure diagram of the improved YOLOv7 in the present invention.
[0017] Figure 3 It is a structure diagram of the multi-scale feature fusion module in the present invention.
[0018] Figure 4 It is a structure diagram of the efficient channel attention mechanism (ECA) module in the present invention.
[0019] Figure 5 It is a schematic diagram of the SIOU loss function in the present invention. DETAILED DESCRIPTION OF THE INVENTION
[0020] The following further illustrates the method and advantages of the present invention with reference to the accompanying drawings.
[0021] As Figure 1 shown, the present invention proposes a method for detecting apple tree leaf diseases based on improved YOLOv7, including the following steps:
[0022] Step 1: Collect apple tree leaf disease pictures and construct an experimental dataset.
[0023] Step 2: Manually annotate the dataset and divide the dataset into a training set, a validation set, and a test set.
[0024] Step 3: Use the training set to train the improved YOLOv7 model to obtain an apple tree leaf disease detection model.
[0025] Step 4: Use the obtained apple tree leaf disease detection model to detect apple tree leaf diseases.
[0026] Furthermore, the specific content of Step 1 is as follows: The apple leaves planted in the apple orchard in Zhuanglang County, Gansu Province are taken as the research object in this invention. Between July and September 2023 during the apple growth period, a Huawei smartphone nova7 5G is used to collect four common leaf diseases in the orchard, namely scab, frogeye leaf spot, rust, and powdery mildew.
[0027] Furthermore, the specific content of Step 2 is as follows: A total of 5000 pictures of the four diseases are collected. After screening, 4500 pictures are finally retained for the experiment. They are divided into a training set, a validation set, and a test set according to the ratio of 7:2:1. Among them, there are 3272 training set pictures, 818 validation set pictures, and 409 test set pictures. Then the dataset is manually annotated through LabelImg.
[0028] Furthermore, the specific content of Step 3 is as follows: This invention designs a new feature fusion module cat_BiFPN, as shown in the appendix Figure 3 , and adopts a cascading method to add the BiFPN structure to the YOLOv7 network, combines it with the feature fusion module in the detection network, and replaces the feature fusion module in the YOLOv7 network.
[0029] Currently, the feature fusion PANeT used in YOLOv7 is a one-way feature fusion method, which is difficult to extract important disease features in the context of apple leaf disease detection. Moreover, the PANeT structure only enhances the position information. When fusing inputs of different resolutions, it simply adds them together, and the original features are lacking in the extracted information. Therefore, this paper designs a new feature fusion module cat_BiFPN, which adds the BiFPN structure to the YOLOv7 network in a cascaded manner and combines it with the feature fusion module in the detection network. BiFPN is a multi-scale fusion module that learns the importance of input features at different resolutions by introducing weights and applies top-down and bottom-up multi-scale feature fusion to achieve deeper feature fusion. The cat_BiFPN module combines the feature fusion module in the original YOLOv7 and the BiFPN feature fusion module, enhancing the feature position information while also taking into account the extraction of deeper feature information, and can accurately extract features at different scales. The YOLOv7 network with cat_BiFPN increases the fusion of multi-scale features, providing strong semantic information for the network. It helps to detect apple leaf diseases of different sizes and improves the accuracy of the network in detecting overlapping and blurred targets.
[0030] Furthermore, step 3 is specifically as follows: Add the ECA attention mechanism after the ELAN and ELAN-H modules in the YOLOv7 network structure.
[0031] The efficient channel attention (ECA) attention mechanism is a local cross-channel interaction strategy that does not require dimensionality reduction and can be implemented through one-dimensional convolution operations, as shown in the appendix. Figure 4 In addition, the size of the one-dimensional convolution kernel can be adaptively adjusted according to the number of channels. This attention mechanism can improve the accuracy of model detection without increasing the model complexity. In the ECA module, first use the average pooling layer to aggregate the convolutional features, then adaptively determine the convolution kernel size, perform one-dimensional convolution, and then obtain the weight values of each channel through the sigmoid function. Finally, add the result to the original feature map, so that the importance of each channel can be learned without affecting the representation of spatial information.
[0032] Furthermore, step 3 is specifically as follows: Replace the loss function CIOU in the YOLOv7 network with SIOU.
[0033] The SIoU loss function adopted in the present invention takes into account the vector angle between the centers of two bounding boxes when the predicted bounding box regresses to the ground truth bounding box on the basis of CIoU, and redefines the angular penalty metric, which enables the predicted bounding box to move to the nearest coordinate axis at the fastest speed and only needs to regress on one coordinate axis, effectively reducing the number of free variables in the loss function and thus improving the accuracy of the detection model. The SIoU loss function consists of four parts: angular loss, distance loss, shape loss, and IoU loss, as shown in Figure 5 shown. The formula of the SIoU loss function is as follows.
[0034] The expression of the angular loss is , which enables the predicted bounding box to quickly approach the nearest coordinate axis and then approach the ground truth bounding box along the coordinate axis, thus accelerating the calculation speed of the distance between the two bounding boxes. Among them, , , , are the coordinate positions of the predicted bounding box and the ground truth bounding box; the distance loss refers to the distance between the centers of the predicted bounding box and the ground truth bounding box. When calculating the distance loss, SIoU adjusts the minimum rectangle enclosing the predicted bounding box and the ground truth bounding box according to the angular loss, and the calculation formula is. Among them, , , ; the shape loss takes into account the aspect ratio between the predicted bounding box and the ground truth bounding box, making the shapes of the two bounding boxes more similar, and its calculation formula is . Among them, represents the degree of attention to the shape loss, which prevents excessive attention to the shape loss in the calculation and reduces the movement of the predicted bounding box by selecting an appropriate aspect ratio between the predicted bounding box and the ground truth bounding box. Among them, , . , represents the length and width of the predicted bounding box; , represents the length and width of the ground truth bounding box; the IoU loss is the intersection over union of the predicted bounding box and the ground truth bounding box, and the calculation formula is: , where, is the predicted bounding box, is the ground truth bounding box. Finally, the calculation formula of the SIoU loss function is .
[0035] Further, the specific steps of step 4 are as follows: The experimental environment is the Ubuntu20.04 system, the graphics card is NVIDIA GetForce RTX3080, the Pycharm version is 22.3, the python version is 3.8, the pytorch version is 1.10.0, and the CUDA version is 11.3. The experiment of the present invention uses a YOLO-format dataset to train the apple leaf disease detection model, and the input image size is 640×640. Through multiple experiments, it is found that the model can converge within 100 rounds. The parameters of the model are set as follows: epoch=100, batch_size=8; the Adam optimizer is used, and the initial learning rate is set to 0.01.
[0036] Comparison of model test data before and after improvement.
[0037] P(%) r(%) mAP (%) Single-image detection speed (ms) YOLOv7 84.5 76.3 87 15 YOLO_ours 89.4 81.5 90.5 12
[0038] p is the precision, r is the recall rate, and mAP represents the mean average precision of recognition. It can be seen that the improved YOLOv7 network model of the present application has a high recognition effect and recognition precision for disease targets.
[0039] The above are only the preferred examples of the present invention and are not used to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for detecting apple tree leaf diseases based on improved YOLOv7, characterized in that: The following steps are involved: Step 1. Use a mobile phone or camera to collect pictures of apple tree leaf diseases (scab, powdery mildew, rust and frog eye disease) and mark the pictures.
2. Step 2: Screen the disease images annotated in step 1 and divide them into training set, test set and validation set.
3. Step 3: Use the training set to train the improved YOLOv7 model to obtain an apple tree leaf disease detection model.
4. Step 4: Use the obtained apple tree leaf disease detection model to detect apple tree leaf diseases.
5. A method for detecting apple tree leaf diseases based on improved YOLOv7 as claimed in claim 1, characterized in that: In step 1, common leaf diseases in apple orchards include scab, powdery mildew, rust, and frog eye disease, and the LaneImg tool is used to annotate the images.
6. A method for detecting apple tree leaf diseases based on improved YOLOv7 as claimed in claim 1, characterized in that: In step 2, remove the images in the dataset that are poorly presented due to lighting and shooting techniques, and divide them into training set, test set, and validation set according to the ratio of 8:1:
1.
7. A method for detecting apple tree leaf diseases based on improved YOLOv7 as claimed in claim 1, characterized in that: In step 3, a new feature fusion module cat_BiFPN is designed. The BiFPN structure is added to the YOLOv7 network in a cascaded manner and combined with the feature fusion module in the detection network. It enhances the feature position information while taking into account the extraction of deeper feature information, and can accurately extract features of different scales.
8. A method for detecting apple tree leaf diseases based on improved YOLOv7 as claimed in claim 1, characterized in that: In step 3, the ECA attention mechanism is added after the ELAN and ELAN-H modules of the YOLOv7 network structure to enhance the extraction of important features. This attention mechanism can improve the accuracy of model detection without increasing the complexity of the model.
9. A method for detecting apple tree leaf diseases based on improved YOLOv7 as claimed in claim 1, characterized in that: In step 3, the loss function CIOU in the YOLOv7 network is replaced with SIOU to improve the prediction box regression speed and accelerate the convergence of the model, thereby improving the detection accuracy.
10. A method for detecting apple tree leaf diseases based on improved YOLOv7 as claimed in claim 1, characterized in that: In step 3, the training parameters of the improved YOLOv7 model are set to: epoch=100, batch_size=8; the Adam optimizer is used, and the initial learning rate is set to 0.01.