Grape disease detection method based on window attention and MDPIOU
By introducing the window attention module and the improved MDPIoU loss function in the YOLOv8 model, the WAMF-YOLO model is formed, which solves the shortcomings in the existing technology for grape disease image recognition and classification, and achieves more efficient and accurate disease detection.
Patent Information
- Application Number
- CN202411865610.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-04-08
AI Technical Summary
The prior art is difficult to effectively identify and classify grape disease images with poor quality, especially distinguishing pests and diseases with similar traits, and the accuracy of small target detection is insufficient.
Based on the YOLOv8 model, a window attention module and an improved MDPIoU loss function are introduced to form a WAMF-YOLO model. The model improves feature extraction capabilities through window attention mechanisms and alleviates the problem of category imbalance through improved loss functions.
The accuracy and recall rate of grape disease detection were significantly improved, and compared with the original YOLOv8 model, it increased by 2.1%, 1.1% and 3.5% on mAP50, mAP50-95 and Recall, respectively, and reduced the number of parameters and calculations of the model.
Smart Images

Figure CN119782765A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of computer technology and relates to a target detection method for grape disease images, and in particular to a grape disease detection method based on window attention and MDPIoU. Background Art
[0002] As a characteristic economic industry, grapes are of great significance in promoting local economic growth. However, in the process of grape cultivation, the knowledge of pest control is not fully popularized and the management is improper, which makes grapes vulnerable to pests and diseases, thus affecting the yield and quality, causing serious economic losses. With the development of computer technology, deep learning is widely used in image recognition and processing. In the process of grape cultivation, the use of artificial intelligence can achieve rapid and accurate identification and classification of pests and diseases, thereby improving the efficiency of pest and disease management and reducing losses caused by delayed prevention and control. At present, some work has achieved certain results in the detection of plant diseases and insect pests. Sun Fenggang et al. proposed an apple fruit disease recognition method based on improved YOLOv5s and transfer learning (Sun Fenggang, Wang Yunlu, Lan Peng, et al. Apple fruit disease recognition method based on improved YOLOv5s and transfer learning [J]. Transactions of the Chinese Society of Agricultural Engineering, 2022, 38(11): 171-179.), using TR2 as the detection head to enhance the model's ability to obtain global information, and finally combined with transfer learning to improve the convergence speed. However, this method is only suitable for plant disease and insect pest detection with high data quality and obvious category distinction. How to deal with poor quality data and distinguish diseases and insect pests with similar traits is still a very challenging task. In addition, the accuracy of small target detection is also a direction worthy of attention. Summary of the invention
[0003] In view of the problems existing in the prior art, the present invention proposes a new grape disease small target detection model WAMF-YOLO based on the currently more advanced target detection model YOLOv8. The present invention can not only effectively identify small targets in grape diseases, but also effectively alleviate the problem of category imbalance and better distinguish grape diseases with similar traits. Through this method, growers can more efficiently and accurately identify and locate grape diseases and pests, thereby scientifically carrying out prevention and control management and reducing the economic losses caused by diseases and pests.
[0004] In order to achieve the above object, the technical solution adopted by the present invention is:
[0005] A grape disease detection method based on window attention and MDPIoU. The grape disease detection method first constructs a grape disease dataset, and performs data enhancement and annotation. Secondly, inspired by swin-transformer, in order to effectively identify small targets in grape diseases and alleviate the problem of class imbalance, a window attention module is introduced to effectively improve the detection accuracy without introducing too much calculation. Thirdly, the CIoU loss function in YOLOv8 is improved to an MDPIoU loss function with focal loss, and named WAMF-YOLO, which further improves the detection accuracy. Finally, the effectiveness of the model is verified by a large number of experiments and result analysis on the constructed grape typical disease dataset. Compared with the original YOLOv8, the WAMF-YOLO provided by the present invention improves mAP50, mAP50-95 and Recall by 2.1%, 1.1% and 3.5%, respectively. Compared with YOLOv5, YOLOv6, YOLOv9 and YOLOv10, the mAP50 is improved by 2.8%, 4.1%, 2.5% and 2.5% respectively. The specific steps include:
[0006] In order to achieve the above object, the technical solution adopted by the present invention is:
[0007] Step 1: Collect data on common grape pests and diseases;
[0008] Step 2: Enhance and annotate the collected data;
[0009] Step 3, improve the network structure of YOLOv8;
[0010] Step 4, improve the loss function of YOLOv8;
[0011] Step 5: Use the improved YOLOv8 to train the enhanced and labeled data.
[0012] Furthermore, the step 1, collecting data on common grape pests and diseases, is specifically as follows:
[0013] In the study of grape pests and diseases, data is often difficult to obtain. The data used in this paper integrates some pictures of grape diseases in the plant disease dataset of the open source data platform Plant Village and the open source dataset (IDADP), including five typical grape disease categories, namely black rot, measles, blight, powdery mildew, and ulcer.
[0014] Furthermore, in step 2, the collected data is enhanced and annotated, specifically:
[0015] Since the disease data categories in the data set are uneven, in order to balance the number of samples of each category in the data set, the present invention performs data enhancement on the five types of data collected. In the selection of data enhancement strategies, three data enhancement methods are used: flipping, cutting, and exposure. Next, the labelimg tool is used for manual labeling, and finally 70% of the labeled data is used as the training set, and the rest is used as the test set.
[0016] Furthermore, in step 3, the network structure of YOLOv8 is improved, specifically:
[0017] YOLOv8 can be mainly divided into three parts: Backbone network, Neck network and Head network.
[0018] The Backbone network is the basis of the model and is responsible for extracting features from the input image. These features are the basis for subsequent network layers to perform target detection. In YOLOv8, the backbone network adopts a structure similar to CSPDarknet.
[0019] The head network is the decision-making part of the target detection model, responsible for generating the final detection result. Here, the model is divided into three branches, allowing the model to perform target detection at different scales.
[0020] The Neck network is located between the backbone network and the head network, and its function is to perform feature fusion and enhancement.
[0021] Next, let's introduce the detailed modules in YOLOv8: CBS: Contains convolutional layers (Conv), batch normalization (BN) and activation functions (SiLU), mainly used for feature extraction. Bottleneck: Connects several CBS modules in series, and increases network depth through residual connections while maintaining efficiency. SPPF: The features after CBS are passed through three maximum pooling layers (MP) to obtain features of different levels, and then these features of different levels are concatenated (Concat), and finally an additional CBS layer is used to deeply fuse and enhance the representation ability of features. C2f: C2f enriches the tributaries during gradient backpropagation by introducing more branches (each branch is connected to a bottleneck) and jump connections, which not only improves the convergence speed and effect of the model, but also helps to improve the expression ability of the entire network model.
[0022] In order to better learn additional attention information and improve the detection of small pest targets, the present invention is inspired by the window attention mechanism in swin-transformer and improves YOLOv8 by using window attention.
[0023] Window attention: Window attention means that in the swin transformer, the input image is divided into multiple non-overlapping windows, and then independent attention calculations are performed between each window. This limits the scope of attention and effectively reduces the amount of calculation compared to ViT.
[0024] In the improved strategy of the present invention, since the present invention replaces the second C2f in YOLOv8backbone with window attention, what is input into the swin-transformer is a stack of several feature maps (the feature map is the output of the convolutional layer in the convolutional neural network. In the convolutional layer, the features of the input data are extracted by convolution operations, and these features are organized into multiple channels, each channel corresponding to a feature map. In the present invention, the output of each CBS layer in YOLOv8 is a feature map of different sizes) instead of the original image. Based on this, the present invention divides the window attention into four parts: Patch Merging, window division, self-attention calculation, and reorganization window. Specifically:
[0025] The patch merging operation is mainly responsible for reducing the resolution of the feature map and increasing the dimension of the feature. The specific method is: first, the feature map is divided into several patches, and then the adjacent patches are merged, which is similar to the downsampling operation in the convolutional neural network. There are many specific merging methods, and this article uses the average value for merging.
[0026] The window division is as follows: first, the input feature map is divided into multiple windows of fixed size (non-overlapping), covering the entire feature map, and then self-attention is calculated in each window. The window division can be expressed as:
[0027]
[0028] Among them, H and W represent the height and width of an image, h and w represent the height and width of the window, s represents the step size of the window movement, and F_(i,j) is the feature in the window located in the i-th row and j-th column, which is extracted from the original feature map.
[0029] The self-attention calculation described above: In each window, multi-head self-attention (MHSA) is used for calculation. MHSA allows the model to perform attention calculations in different subspaces, thereby enhancing the model's expressiveness. The calculation method of MHSA is as follows:
[0030]
[0031] Among them, Q, K and V are query, key and value matrices respectively. In window attention, they are the features of several windows segmented by formula (1), and d_k represents the dimension of the key vector.
[0032] The reorganized window is the inverse process of window division, which merges the local self-attention results into the original feature map. It is worth noting that the size of the original feature map has not changed after a series of operations such as window division, self-attention calculation and reorganized window.
[0033] Furthermore, in step 4, the loss function of YOLOv8 is improved, specifically:
[0034] Step 4.1, CIoU in YOLOv8 still has certain limitations, that is, when the predicted bounding box and the true bounding box have the same aspect ratio, but different width and height values, CIoU loss will lose its effectiveness, and the convergence speed and accuracy will be limited. In this regard, the present invention selects MPDIoU as the IoU loss to improve YOLOv8, and the formula is as follows:
[0035]
[0036] Among them, A and B represent the real box (the real box refers to the bounding box of the target object manually annotated in the data set, which represents the real position and size of the target object in the image) and the predicted box (the predicted box refers to the bounding box generated by the target detection model after a given input image, which represents the model's prediction of the target position and size). A∩B represents the area size of the intersection of the two boxes, and A∪B represents the area size of the union of the two boxes. They represent the upper left corner and lower right corner coordinates of the real box and the predicted box respectively, which is the same as formula (1). W and H represent the width and height of an image respectively.
[0037] From the above formulas (3), (4), and (5), we can see that the optimization goal of IoU is to make the coordinates of the upper left corner and the lower right corner of the two boxes closer and closer. Although the idea is relatively simple, it has proven its excellence in standard datasets such as MSCOCO.
[0038] Step 4.2, although MPDIoU has a certain improvement in grape disease detection compared to other IoU losses, the problem of imbalanced disease detection categories can still be found in the experiment. The accuracy is very high in some categories, but relatively low in some categories. The possible reasons are: the uneven quality of data in different categories and the long-tail effect of data. Although data enhancement has been performed before, the long-tail effect of data may still occur. In order to alleviate this phenomenon, this paper further introduces the improved focal loss based on MPDIoU.
[0039] Different from the original focal loss, the present invention only introduces a focusing parameter γ to adjust the loss weight. The formula is as follows:
[0040]
[0041] Step 4.3, finally, when calculating the IoU loss function, the focal point calculated by formula (6) is used as the weight on MDPIoU:
[0042] boxloss=focal*(1-MDPIoU)#(7)
[0043] Furthermore, in step 5, the enhanced and labeled data is trained using the improved YOLOv8, specifically:
[0044] Use steps 3 and 4 to train the improved YOLOv8 model using the grape pest and disease related data annotated in step 2.
[0045] The experiment of the present invention verifies the detection accuracy of grape diseases, so the evaluation index used refers to the self-target detection, while considering the calculation performance of the model. The specific indicators include: recall rate, average precision, parameter quantity and floating point operation quantity as the evaluation indicators of the model.
[0046] Recall is an important indicator of model performance, and its calculation formula is as follows:
[0047]
[0048] Among them, TP represents the number of samples correctly predicted as positive by the model, and FN represents the number of positive samples incorrectly predicted as negative by the model. From formula (8), we can see that the higher the recall rate, the lower the probability of false detection in the task, and the more reliable the detection result is.
[0049] The mean average precision (mAP) is a core indicator in the performance evaluation of target detection models. It measures the average accuracy of the model on multiple categories. The calculation of mAP involves AP (Average Precision). AP is obtained by calculating the average value of the precision at different recall levels, while mAP is the average of AP values of all categories. In target detection tasks, two indicators are generally used to reflect mAP: mAP50 and mAP50-95. The main difference between mAP50 and mAP50-95 is that they consider different IoU threshold ranges. mAP50 only calculates AP when the IoU threshold is 0.5, while mAP50-95 calculates AP in the range of 0.5 to 0.95.
[0050] The number of parameters refers to the total number of parameters in the model, usually in millions (M). The number of floating-point operations (FLOPs) refers to the number of floating-point operations required to process an image. Both the number of parameters and the number of floating-point operations are important indicators for measuring model complexity.
[0051] The above is the use of grape disease images as input, target detection through WAML-YOLO, and effective positioning and prevention of grape diseases. It can not only help farmers take timely measures to prevent and control diseases, but also optimize agricultural management strategies by collecting data on disease occurrence, such as adjusting irrigation, fertilization, and pesticide use. In addition, the automated disease detection system can also reduce dependence on chemical pesticides and promote the development of sustainable agriculture.
[0052] The innovative analysis of the present invention is as follows: (1) First, the second C2f of the backbone in YOLOv8 is replaced with window attention, which can effectively improve the model's ability to capture image features in the shallow layer with richer features. (2) The loss function of the model is changed to MPDIoU with the introduction of focal loss, which effectively improves the class imbalance problem and improves the detection accuracy.
[0053] The beneficial effects of the present invention are:
[0054] The present invention enhances the feature extraction capability by introducing window attention in the early stage of the YOLOv8 model. It is worth noting that while introducing window attention, the number of model parameters and floating-point operations will not be increased too much to meet the needs of deployment on edge devices. Secondly, the model training loss function is improved by introducing focal loss and MPDIoU to improve the accuracy of small disease target detection and alleviate the problem of category imbalance. Specifically, the present invention replaces the second C2f of the backbone in YOLOv8 with window attention, so that the model can more effectively capture the key features in the image in the shallow feature extraction stage, which enhances the model's ability to capture image features. At the same time, the introduction of improvements in focal loss and MPDIoU loss functions effectively solves the problem of category imbalance and improves detection accuracy. These improvements enable the model to more accurately identify and locate grape diseases when processing images with richer features, thereby significantly improving the performance of target detection and providing strong technical support for disease management in agricultural production. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 This is the network structure diagram of WAMF-YOLO;
[0056] Figure 2 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0057] The following is a further description of the embodiments of the present invention in conjunction with the pictures in the data set.
[0058] A grape disease detection method based on window attention and MDPIoU is implemented in the following steps:
[0059] The step 1 is to collect data on common grape pests and diseases, specifically:
[0060] In the study of grape pests and diseases, data is often difficult to obtain. The data used in this paper integrates some pictures of grape diseases in the plant disease dataset of the open source data platform Plant Village and the open source dataset (IDADP), including five typical grape disease categories, namely black rot, measles, blight, powdery mildew, and ulcer.
[0061] Furthermore, in step 2, the collected data is enhanced and annotated, specifically:
[0062] Since the disease data categories in the data set are uneven, in order to balance the number of samples of each category in the data set, the present invention performs data enhancement on the five types of data collected. In the selection of data enhancement strategies, three data enhancement methods are used: flipping, cutting, and exposure. Next, the labelimg tool is used for manual labeling, and finally 70% of the labeled data is used as the training set, and the rest is used as the test set.
[0063] Furthermore, in step 3, the network structure of YOLOv8 is improved, specifically:
[0064] YOLOv8 can be mainly divided into three parts: Backbone network, Neck network and Head network.
[0065] The Backbone network is the basis of the model and is responsible for extracting features from the input image. These features are the basis for subsequent network layers to perform target detection. In YOLOv8, the backbone network adopts a structure similar to CSPDarknet.
[0066] The head network is the decision-making part of the target detection model, responsible for generating the final detection result. Here, the model is divided into three branches, allowing the model to perform target detection at different scales.
[0067] The Neck network is located between the backbone network and the head network, and its function is to perform feature fusion and enhancement.
[0068] Next, let's introduce the detailed modules in YOLOv8: CBS: Contains convolutional layers (Conv), batch normalization (BN) and activation functions (SiLU), mainly used for feature extraction. Bottleneck: Connects several CBS modules in series, and increases network depth through residual connections while maintaining efficiency. SPPF: The features after CBS are passed through three maximum pooling layers (MP) to obtain features of different levels, and then these features of different levels are concatenated (Concat), and finally an additional CBS layer is used to deeply fuse and enhance the representation ability of features. C2f: C2f enriches the tributaries during gradient backpropagation by introducing more branches (each branch is connected to a bottleneck) and jump connections, which not only improves the convergence speed and effect of the model, but also helps to improve the expression ability of the entire network model.
[0069] In order to better learn additional attention information and improve the detection of small pest targets, the present invention is inspired by the window attention mechanism in swin-transformer and improves YOLOv8 by using window attention.
[0070] Window attention: Window attention means that in the swin transformer, the input image is divided into multiple non-overlapping windows, and then independent attention calculations are performed between each window. This limits the scope of attention and effectively reduces the amount of calculation compared to ViT.
[0071] In the improved strategy of the present invention, since the present invention replaces the second C2f in YOLOv8backbone with window attention, what is input into the swin-transformer is a stack of several feature maps (the feature map is the output of the convolutional layer in the convolutional neural network. In the convolutional layer, the features of the input data are extracted by convolution operations, and these features are organized into multiple channels, each channel corresponding to a feature map. In the present invention, the output of each CBS layer in YOLOv8 is a feature map of different sizes) instead of the original image. Based on this, the present invention divides the window attention into four parts: Patch Merging, window division, self-attention calculation, and reorganization window. Specifically:
[0072] The patch merging operation is mainly responsible for reducing the resolution of the feature map and increasing the dimension of the feature. The specific method is: first, the feature map is divided into several patches, and then the adjacent patches are merged, which is similar to the downsampling operation in the convolutional neural network. There are many specific merging methods, and this article uses the average value for merging.
[0073] The window division is as follows: first, the input feature map is divided into multiple windows of fixed size (non-overlapping), covering the entire feature map, and then self-attention is calculated in each window. The window division can be expressed as:
[0074]
[0075] Among them, H and W represent the height and width of an image, h and w represent the height and width of the window, s represents the step size of the window movement, and F_(i,j) is the feature in the window located in the i-th row and j-th column, which is extracted from the original feature map.
[0076] The self-attention calculation described above: In each window, multi-head self-attention (MHSA) is used for calculation. MHSA allows the model to perform attention calculations in different subspaces, thereby enhancing the model's expressiveness. The calculation method of MHSA is as follows:
[0077]
[0078] Among them, Q, K and V are query, key and value matrices respectively. In window attention, they are the features of several windows segmented by formula (1), and d_k represents the dimension of the key vector.
[0079] The reorganized window is the inverse process of window division, which merges the local self-attention results into the original feature map. It is worth noting that the size of the original feature map has not changed after a series of operations such as window division, self-attention calculation and reorganized window.
[0080] Furthermore, in step 4, the loss function of YOLOv8 is improved, specifically:
[0081] Step 4.1, CIoU in YOLOv8 still has certain limitations, that is, when the predicted bounding box and the true bounding box have the same aspect ratio, but different width and height values, CIoU loss will lose its effectiveness, and the convergence speed and accuracy will be limited. In this regard, the present invention selects MPDIoU as the IoU loss to improve YOLOv8, and the formula is as follows:
[0082]
[0083] Among them, A and B represent the real box (the real box refers to the bounding box of the target object manually annotated in the data set, which represents the real position and size of the target object in the image) and the predicted box (the predicted box refers to the bounding box generated by the target detection model after a given input image, which represents the model's prediction of the target position and size). A∩B represents the area size of the intersection of the two boxes, and A∪B represents the area size of the union of the two boxes. They represent the upper left corner and lower right corner coordinates of the real box and the predicted box respectively, which is the same as formula (1). W and H represent the width and height of an image respectively.
[0084] From the above formulas (3), (4), and (5), we can see that the optimization goal of IoU is to make the coordinates of the upper left corner and the lower right corner of the two boxes closer and closer. Although the idea is relatively simple, it has proven its excellence in standard datasets such as MSCOCO.
[0085] Step 4.2, although MPDIoU has a certain improvement in grape disease detection compared to other IoU losses, the problem of imbalanced disease detection categories can still be found in the experiment. The accuracy is very high in some categories, but relatively low in some categories. The possible reasons are: the uneven quality of data in different categories and the long-tail effect of data. Although data enhancement has been performed before, the long-tail effect of data may still occur. In order to alleviate this phenomenon, this paper further introduces the improved focal loss based on MPDIoU.
[0086] Different from the original focal loss, the present invention only introduces a focusing parameter γ to adjust the loss weight. The formula is as follows:
[0087]
[0088] Step 4.3, finally, when calculating the IoU loss function, the focal point calculated by formula (6) is used as the weight on MDPIoU:
[0089] boxloss=focal*(1-MDPIoU)#(7)
[0090] Furthermore, in step 5, the enhanced and labeled data is trained using the improved YOLOv8, specifically:
[0091] Use steps 3 and 4 to train the improved YOLOv8 model using the grape pest and disease related data annotated in step 2.
[0092] The experimental platform configuration of the experiment of the present invention is as follows: the operating system is Ubuntu 22.4. The CPU is a 13th Gen Intel(R) Core(TM) i9-13900K, the graphics card is an NVIDIA GeForce RTX 3090, and the memory is 24G. The python version is 3.8, the pytorch version is 2.0.1, and the CUDA version is 12.2.
[0093] The experiment of the present invention verifies the detection accuracy of grape diseases, so the evaluation index used refers to the self-target detection, while considering the calculation performance of the model. The specific indicators include: recall rate, average precision, parameter quantity and floating point operation quantity as the evaluation indicators of the model.
[0094] Recall is an important indicator of model performance, and its calculation formula is as follows:
[0095]
[0096] Among them, TP represents the number of samples correctly predicted as positive by the model, and FN represents the number of positive samples incorrectly predicted as negative by the model. From formula (8), we can see that the higher the recall rate, the lower the probability of false detection in the task, and the more reliable the detection result is.
[0097] The mean average precision (mAP) is a core indicator in the performance evaluation of target detection models. It measures the average accuracy of the model on multiple categories. The calculation of mAP involves AP (Average Precision). AP is obtained by calculating the average value of the precision at different recall levels, while mAP is the average of AP values of all categories. In target detection tasks, two indicators are generally used to reflect mAP: mAP50 and mAP50-95. The main difference between mAP50 and mAP50-95 is that they consider different IoU threshold ranges. mAP50 only calculates AP when the IoU threshold is 0.5, while mAP50-95 calculates AP in the range of 0.5 to 0.95.
[0098] Parameter count refers to the total number of parameters in the model, usually in millions (M). FLOPs refers to the number of floating-point operations required to process an image. Both parameter count and floating-point operations are important indicators for measuring model complexity.
[0099] Specific application examples are as follows:
[0100] The effect of the present invention is illustrated by using a self-constructed data set.
[0101] (1) Effect comparison
[0102] Table 1 Comparative test of different models
[0103]
[0104] It can be seen from the results in Table 1 that the WAMF-YOLO proposed in the present invention is superior to the more advanced target detectors currently available. Compared with the original YOLOv8, WAMF-YOLO has improved by 2.1%, 1.1% and 3.5% in mAP50, mAP50-95 and Recall, respectively. Compared with YOLOv10, the best target detector currently on MSCOCO, it has improved by 2.5%, 1.7% and 5.0%, respectively. In addition, by comparing the number of parameters and the amount of floating-point operations, it can be found that WAMF-YOLO does not add too much additional computational complexity, and is even lower in terms of parameters than the original YOLOv8 model. The above experimental results show that the model of the present invention has better performance and can meet the requirements of the environment when the equipment conditions are limited during actual production.
[0105] In this invention, an improved YOLOv8 model is proposed. By integrating the window attention mechanism in the early stage, the invention effectively enhances the feature extraction capability, while keeping the model parameters and the amount of calculation simple, meeting the requirements of deployment on edge devices. In addition, the invention also introduces the focal loss and MPDIoU loss functions to optimize the model training process, improve the detection accuracy of small target diseases, and effectively solve the problem of class imbalance. These technical improvements significantly improve the performance of the model in the grape disease identification task, and provide an innovative technical method for the precise management and prevention of agricultural diseases.
[0106] The above examples are only embodiments of the present invention and do not limit the protection scope of the present invention. It should be noted that for those skilled in the art, various modifications and improvements can be made without departing from the concept of the present invention, and these modifications and improvements are within the protection scope of the present invention.
Claims
1. A grape disease detection method based on window attention and MDPIoU, characterized in that: The grape disease detection method first constructs a grape typical disease dataset, and performs data enhancement and annotation; secondly, in order to effectively identify small targets in grape diseases and alleviate the class imbalance problem, a window attention module is introduced; thirdly, the CIoU loss function in YOLOv8 is improved to the MDPIoU loss function with focal loss, and named WAMF-YOLO to improve the detection accuracy; finally, the effectiveness of the model is verified by the grape typical disease dataset; specifically, the following steps are included: In order to achieve the above object, the technical solution adopted by the present invention is: Step 1: Collect data on common grape pests and diseases; Step 2: Enhance and annotate the collected data; Step 3: Improve the network structure of YOLOv8 using window attention. Step 4, improve the loss function of YOLOv8; Step 5: Use the improved YOLOv8 to train the enhanced and labeled data.
2. The grape disease detection method based on window attention and MDPIoU according to claim 1, characterized in that: In the step 1, the collected grape disease and insect pest data is integrated with some pictures about grape diseases in the plant disease dataset of the open source data platform Plant Village and the open source dataset IDADP, including five typical grape disease categories.
3. The grape disease detection method based on window attention and MDPIoU according to claim 2 is characterized in that: The step 2 is to enhance and annotate the collected data, specifically: In order to balance the number of samples in each category in the data set, three methods are used to enhance the data of the five categories collected, namely flipping, cropping, and exposure; then manual labeling is performed and the labeled data is divided into training set and test set.
4. The grape disease detection method based on window attention and MDPIoU according to claim 3 is characterized in that: In the step 3, the network structure of YOLOv8 is improved by using window attention. The YOLOv8 network structure includes: Backbone network, Neck network and Head network. The improvement is as follows: The window attention replaces the second C2f in the YOLOv8 backbone. The input to the swin-transformer is a stack of several feature maps, which are the outputs of the convolutional layer in the convolutional neural network. The output of each CBS layer in YOLOv8 is a feature map of different sizes. Based on this, the window attention is divided into four parts: Patch Merging, Window Division, Self-Attention Calculation, and Reorganization Window.
5. The grape disease detection method based on window attention and MDPIoU according to claim 4, characterized in that: The Patch Merging described above: the feature map is divided into several patches, and then adjacent patches are merged to reduce the resolution of the feature map and increase the dimension of the feature; The window division is as follows: the input feature map is divided into multiple fixed-size non-overlapping windows that cover the entire feature map, and then self-attention is calculated in each window; The self-attention calculation described above: In each window, multi-head self-attention MHSA is used for calculation, and MHSA allows the model to calculate attention in different subspaces; The reorganized window described above is the inverse process of window division when reorganizing the window, merging the local self-attention results into the original feature map; The size of the original feature map does not change after window division, self-attention calculation and reorganization window operations.
6. The grape disease detection method based on window attention and MDPIoU according to claim 5, characterized in that: The window division is expressed as: Among them, H and W represent the height and width of an image, h and w represent the height and width of the window, s represents the step size of the window movement, and F_(i,j) is the feature in the window located in the i-th row and j-th column, which is extracted from the original feature map; In the self-attention calculation described above, MHSA is calculated as follows: Among them, Q, K and V are query, key and value matrices respectively. In window attention, they are the features of several windows segmented by formula (1), and d_k represents the dimension of the key vector.
7. The grape disease detection method based on window attention and MDPIoU according to claim 4, characterized in that: In step 4, the loss function of YOLOv8 is improved, specifically: Step 4.1, select MPDIoU as the IoU loss for improving YOLOv8; Step 4.2, introduce a focusing parameter γ to adjust the loss weight; Step 4.3: When calculating the IoU loss function, the focal point calculated by formula (6) is used as a weight on MDPIoU.
8. The grape disease detection method based on window attention and MDPIoU according to claim 7, characterized in that: The improvements are specifically as follows: Step 4.1, select MPDIoU as the IoU loss of improved YOLOv8, the formula is as follows: Among them, A and B represent the real box respectively. The real box refers to the bounding box of the target object manually annotated in the data set, which represents the real position and size of the target object in the image. The predicted box refers to the bounding box generated by the target detection model after a given input image, which represents the model's prediction of the target position and size. A∩B represents the area size of the intersection of two boxes; A∪B represents the area size of the union of two boxes. Represent the coordinates of the upper left corner and lower right corner of the real box and the predicted box respectively, which is the same as formula (1). W and H represent the width and height of an image respectively; Step 4.2, introduce a focusing parameter γ to adjust the loss weight, the formula is as follows: Step 4.3, when calculating the IoU loss function, the focal point calculated by formula (6) is used as a weight on MDPIoU: boxloss=focal*(1-MDPIoU)#(7).
9. The grape disease detection method based on window attention and MDPIoU according to claim 7, characterized in that: The evaluation indicators used verify the detection accuracy of the improved YOLOv8 for grape diseases.
10. The grape disease detection method based on window attention and MDPIoU according to claim 9, characterized in that: The evaluation indicators include recall rate, average precision, parameter quantity, and floating point operation quantity.