Grape leaf disease detection method, equipment and program product
By improving the YOLOv8 lightweight algorithm, the global feature capture capability and detection head design of the grape leaf disease detection model are enhanced, and the problems of large computing resources and low detection efficiency of the existing model are solved, and efficient and accurate grape leaf disease detection is achieved.
Patent Information
- Application Number
- CN202510565987.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-08-12
AI Technical Summary
The existing target detection model is difficult to detect when detecting grape leaves, consumes huge computing resources, has low computing efficiency, and has similar target characteristics of small targets in grape leaves, which increases the detection difficulty.
The improved YOLOv8 lightweight grape leaf disease detection algorithm is adopted, and the model's global feature capture capability is enhanced through the Non-Local attention mechanism, a lightweight detection head is designed, and a Side Loss loss function is introduced to optimize the classification loss, so as to achieve lightweight and efficient detection of the model.
Under the conditions of limited computing resources, high detection accuracy is maintained, detection efficiency is improved, and efficient identification of grape leaf diseases is achieved.
Smart Images

Figure CN120472218A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image detection technology, and in particular to a grape leaf disease detection method, equipment, and program product. Background Art
[0002] Early detection of crop diseases and insect pests is fundamental to effective prevention and control, and is crucial for agricultural production management and decision-making. Grapes are susceptible to climate, environmental factors, and pests during their growth process, leading to diseases such as black rubella, black rot, downy mildew, and leaf blight, which can severely impact yield and quality. Traditional grape disease detection relies on grower experience or expert guidance, which is time-consuming, labor-intensive, and susceptible to subjective factors. With the development of computer vision and agricultural machinery, the application of object detection technology in agriculture has increased, making plant disease detection more efficient and accurate, and providing a new solution for grape leaf disease detection.
[0003] However, since grape leaf spots usually present small target features and the shapes and colors of different types of spots are relatively similar, the existing target detection models are difficult to use when applied to grape leaf detection, require huge computing resources, and have low computational efficiency. Summary of the Invention
[0004] The main purpose of this application is to provide a grape leaf disease detection method, equipment and program product, aiming to solve the technical problem that the existing target detection model is difficult to detect when applied to grape leaf detection.
[0005] To achieve the above objectives, the present application proposes a grape leaf disease detection method, which comprises: Acquire a data image of a grape leaf to be detected; Obtaining a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on an improved YOLOv8 lightweight grape leaf disease detection algorithm; The data image is input into the leaf disease detection model for identification to obtain a disease detection result.
[0006] In one embodiment, the step of training the leaf disease detection model includes: Obtain a dataset of labeled disease images of grape leaves; A first leaf disease detection model is trained based on the labeled disease image dataset.
[0007] In one embodiment, the first leaf disease detection model includes: an input end, a feature extraction backbone network, a feature fusion neck network, and a detection head; The step of detecting and training the first leaf disease detection model based on the labeled disease image dataset includes: The input end obtains the labeled disease images in the labeled disease image dataset and transmits the labeled disease images to the feature extraction backbone network; The feature extraction backbone network extracts features from the labeled disease image, and transmits the disease image features obtained by the feature extraction to the feature fusion neck network; The feature fusion neck network performs feature fusion on the disease image features and transmits the disease fusion features obtained by the feature fusion to the detection head; The detection head performs reasoning based on the disease fusion features to obtain a detection result; Performing a loss assessment based on the detection result and the labeling result of the labeled disease image to obtain a loss assessment result; iterating the first leaf disease detection model based on the loss assessment result to obtain an iterated first leaf disease detection model; If the first leaf disease detection model after iteration does not meet the iteration termination condition, the process returns to the step of obtaining the labeled disease images in the labeled disease image dataset from the input end.
[0008] In one embodiment, the feature extraction backbone network includes: a convolution module, a fusion module, and a non-local attention module; The step of extracting features from the labeled disease image by the feature extraction backbone network and transmitting the disease image features obtained by the feature extraction to the feature fusion neck network includes: The convolution module performs a convolution operation on the input data to obtain a first image feature; the input data includes: an annotated disease image or the first image feature or the second image feature; The fusion module performs fusion enhancement on the input first image feature to obtain a second image feature; The non-local attention module adjusts the attention weight based on the first image feature of the predecessor convolution module to obtain the disease image feature; The disease image features are transmitted to the feature fusion neck network.
[0009] In one embodiment, the detection head includes: an input module, a lightweight convolution layer, a shared convolution module, and a regression prediction module; The step of the detection head performing reasoning based on the disease fusion features to obtain a detection result includes: The input module obtains disease fusion feature inputs of different scales; The lightweight convolution layer performs feature extraction on the disease fusion feature to obtain a convolution disease feature; The shared convolution module performs feature enhancement on the convolved disease feature to obtain an enhanced disease feature; The regression prediction module performs regression prediction on the enhanced disease characteristics to obtain a detection result.
[0010] In one embodiment, the step of performing loss assessment based on the detection result and the labeling result of the labeled disease image to obtain the loss assessment result includes: Performing a binary cross entropy loss evaluation based on the detection result and the labeling result of the labeled disease image to obtain a binary cross entropy loss; Supplementary loss evaluation is performed based on binary cross entropy loss and sample weight to obtain the loss evaluation result.
[0011] In addition, to achieve the above-mentioned purpose, the present application also proposes a grape leaf disease detection device, which comprises: A data acquisition module, used for acquiring data images of grape leaves to be detected; A model management module is used to obtain a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on an improved YOLOv8 lightweight grape leaf disease detection algorithm; The disease detection module is used to input the data image into the leaf disease detection model for identification to obtain a disease detection result.
[0012] In addition, to achieve the above-mentioned purpose, the present application also proposes a grape leaf disease detection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the grape leaf disease detection method described above.
[0013] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium. A computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the grape leaf disease detection method described above are implemented.
[0014] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the steps of the grape leaf disease detection method as described above.
[0015] One or more technical solutions proposed in this application have at least the following technical effects: This application involves obtaining a data image of a grape leaf to be inspected; obtaining a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on an improved YOLOv8 lightweight grape leaf disease detection algorithm; and inputting the data image into the leaf disease detection model for recognition, thereby obtaining a disease detection result. Because disease detection is performed using a leaf disease detection model constructed based on the improved YOLOv8 lightweight grape leaf disease detection algorithm, lightweightness is achieved while maintaining high detection accuracy, improving detection efficiency and enabling efficient grape leaf detection even under conditions of limited computing resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following is a brief introduction to the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0018] Figure 1 A schematic diagram of the process flow provided in Example 1 of the grape leaf disease detection method of the present application; Figure 2 This is a schematic diagram of the structure of the YOLOv8 model in this application; Figure 3 A schematic diagram of the structure of the first leaf disease detection model provided in Example 2 of the grape leaf disease detection method of this application; Figure 4 This is a schematic diagram of the Non-Local network structure in one implementation of the grape leaf disease detection method of this application; Figure 5 This is a schematic diagram of the network structure of the detection head GNSH in one implementation of the grape leaf disease detection method of the present application; Figure 6 A flow chart illustrating a third embodiment of the grape leaf disease detection method of the present application; Figure 7 Schematic diagram of the comparison of mAP@0.5 before and after improvement; Figure 8 Schematic diagram of the comparison of Loss curves before and after improvement; Figure 9 This is a schematic diagram of the module structure of the grape leaf disease detection device according to an embodiment of the present application; Figure 10 Schematic diagram of the device structure of the hardware operating environment involved in the grape leaf disease detection method in the embodiment of the present application.
[0019] The purpose, features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0020] It should be understood that the specific embodiments described herein are merely used to explain the technical solutions of the present application and are not intended to limit the present application.
[0021] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0022] The main solution of the embodiment of the present application is: obtaining a data image of the grape leaves to be detected; obtaining a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on the improved YOLOv8 lightweight grape leaf disease detection algorithm; inputting the data image into the leaf disease detection model for identification to obtain the disease detection result.
[0023] Currently, there are relatively few studies on grape leaf disease detection, which still faces many challenges and deficiencies and urgently needs further improvement and perfection: (1) Most existing methods have a large number of model parameters, which require huge computing resources and have low computational efficiency; (2) Grape leaf lesions usually have small target characteristics, and the morphology and color of different types of lesions are relatively similar, which greatly increases the difficulty of detection; (3) The model should have real-time detection capabilities and be able to achieve efficient processing with limited computing resources.
[0024] This application provides a lightweight grape leaf disease detection algorithm (YOLOv8-Non-GNSH) based on an improved YOLOv8. The improved model maintains a relatively high detection accuracy while achieving lightweightness, improving detection efficiency, and enabling it to still operate efficiently under conditions of limited computing resources.
[0025] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication, and program execution capabilities, such as a computer or server, or an electronic device or virtual device capable of implementing the aforementioned functions. This embodiment and the following embodiments will be described below using a grape leaf disease detection device (hereinafter referred to as the detection device) as an example.
[0026] Based on this, the present application embodiment provides a grape leaf disease detection method, referring to Figure 1 , Figure 1 This is a flow chart of Example 1 of the grape leaf disease detection method of this application.
[0027] In this embodiment, the grape leaf disease detection method includes: Step S10, obtaining a data image of the grape leaf to be detected; Step S20: Obtain a pre-trained leaf disease detection model.
[0028] Among them, the leaf disease detection model is trained based on the lightweight grape leaf disease detection algorithm of improved YOLOv8.
[0029] It is understandable that by acquiring data images of grape leaves to be detected and performing disease detection based on the data images, it is possible to promptly detect whether the grape leaves have diseases, and then promptly prevent and control the existing diseases.
[0030] It should be understood that the YOLOv8 network model is a detection model for target detection, and its model structure can be as follows: Figure 2 As shown, Figure 2 Schematic diagram of the structure of the YOLOv8 model in this application. The YOLOv8 network model has the advantages of high detection accuracy and fast detection speed, and can adapt to a variety of application scenarios and detection tasks. Among them, the YOLOv8 network model has launched multiple versions, including n, s, m, l and x, which increase in model complexity, computing resource requirements and detection accuracy, aiming to meet the needs of different scenarios. YOLOv8n is the version with the smallest number of parameters and computational complexity and the fastest detection speed in the YOLOv8 series, achieving a good balance between accuracy and efficiency. For ease of description, YOLOv8n is used as a benchmark model in the embodiment of this application as an example to describe the solution of this application in detail.
[0031] It should be noted that the above-mentioned pre-trained leaf disease detection model is a neural network model obtained by training the lightweight grape leaf disease detection algorithm based on the improved YOLOv8. In the embodiment of the present application, by replacing the C2f module in the P5 layer of the backbone network of the YOLOv8 model with the non-local attention mechanism Non-Local, the model's ability to capture global features is enhanced, more comprehensive contextual information is generated, and the accuracy of small target detection is improved while reducing the complexity of the model. Secondly, a lightweight detection head GNSH is designed in the leaf disease detection model of the embodiment of the present application. By introducing normalization technology, shared convolution, and dynamic scaling mechanisms, weights are shared between different detection layers, reducing the number of model parameters and computational costs, and achieving a good balance between model lightweighting and detection accuracy. In addition, the Side Loss loss function is introduced in the leaf disease detection model of the present application to optimize the classification loss. By adaptively adjusting the weight distribution of samples, the model can pay more attention to samples that are difficult to distinguish, thereby improving the recognition effect of different disease categories. Through multiple sets of ablation experiments and comparative experiments, the effectiveness of the lightweight grape leaf disease detection algorithm based on improved YOLOv8 and the leaf disease detection model proposed in this application were verified.
[0032] In a specific implementation, the detection device of the embodiment of the present application improves the YOLOv8 algorithm and obtains a leaf disease detection model based on pre-training of the improved algorithm. The pre-trained leaf disease detection model can realize the detection of data images of grape leaves to be detected, thereby realizing grape leaf disease detection and identification.
[0033] Step S30: input the data image into the leaf disease detection model for identification to obtain a disease detection result.
[0034] It can be understood that by inputting the data image into the pre-trained leaf disease detection model, the data image is recognized by the leaf disease detection model to determine whether the grape leaves to be detected have diseases and the type of disease if diseases exist.
[0035] In an embodiment of the present application, the step of training the leaf disease detection model includes: obtaining a dataset of labeled disease images of grape leaves; and training a first leaf disease detection model based on the dataset of labeled disease images.
[0036] It can be understood that the above-mentioned first leaf disease detection model is also the initial model constructed based on the lightweight grape leaf disease detection algorithm of the improved YOLOv8. By training this initial model, a leaf disease detection model with advantages such as high precision and high efficiency can be obtained.
[0037] It should be noted that the aforementioned grape leaf disease-labeled image dataset may include image data corresponding to common grape leaf diseases such as black rubella, black rot, downy mildew, and leaf blight. These image data may be captured in advance or obtained from various datasets, and this embodiment of the present application is not limited thereto.
[0038] It is understood that to ensure the quality of the disease image data, the collected images can be further screened to identify each disease to ensure the accuracy of the disease type. At the same time, the screened disease image data can be subjected to data enhancement operations such as random brightness contrast adjustment, horizontal flipping, and rotation to achieve data image expansion and data balancing.
[0039] It should be noted that the processed disease image data can be manually annotated using an annotation tool to ensure that the diseased area can be accurately marked in each disease image. The annotation tool used can be LabelImg, Labelme, etc., and this embodiment of the application does not limit this.
[0040] It is understandable that when the disease image data is labeled, a labeled disease image dataset is obtained. The labeled disease image data in the labeled image dataset can be saved in a txt file in YOLO format.
[0041] In some implementations of the embodiments of the present application, the above-mentioned labeled disease image dataset can be divided into a training set, a validation set, and a test set. The specific division ratio can be 7:2:1, 6:3:1, etc., and the embodiments of the present application are not limited to this.
[0042] This embodiment of the application obtains a data image of a grape leaf to be inspected; obtains a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on a lightweight grape leaf disease detection algorithm using an improved YOLOv8; and then inputs the data image into the leaf disease detection model for recognition, thereby obtaining a disease detection result. Because disease detection is performed using the leaf disease detection model constructed based on the lightweight grape leaf disease detection algorithm using the improved YOLOv8, it achieves lightweightness while maintaining high detection accuracy, improving detection efficiency and enabling efficient grape leaf detection even under conditions of limited computing resources.
[0043] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above embodiment 1 can be referred to the above introduction and will not be described in detail later. Figure 3 , Figure 3 This is a structural diagram of the first leaf disease detection model provided in Example 2 of the grape leaf disease detection method of this application.
[0044] like Figure 3 As shown, in the embodiment of the present application, in order to train and obtain the first leaf disease detection model, the first leaf disease detection model includes: an input end (Input), a feature extraction backbone network (Backbone), a feature fusion neck network (Neck) and a detection head (Head); The step of detecting and training the first leaf disease detection model based on the labeled disease image dataset includes: Step S100, the input end obtains the labeled disease images in the labeled disease image dataset, and transmits the labeled disease images to the feature extraction backbone network; Step S200: the feature extraction backbone network extracts features from the labeled disease image, and transmits the disease image features obtained by the feature extraction to the feature fusion neck network.
[0045] It can be understood that the above-mentioned input end is also a functional unit for inputting the received labeled disease image into the feature extraction backbone network.
[0046] In some implementations of the embodiments of the present application, the input end may use Mosaic's data augmentation technology to generate new training samples by randomly cropping and splicing images, thereby increasing the diversity of training data.
[0047] It should be noted that in the YOLOv8 network model, the feature extraction backbone network is improved based on CSPDarknet, using the C2f module to replace the C3 module, reducing the number of parameters and increasing skip-layer connections, thereby improving computational efficiency.
[0048] In some implementations of the present invention, grape leaf disease detection tasks involve small lesions that are easily masked by background noise, leading to missed detections and false detections. The YOLOv8 model relies heavily on local information about small objects during feature extraction and lacks the ability to calibrate global information. This embodiment of the present invention introduces a non-local attention mechanism, replacing the C2f module in the P5 layer of the backbone network, to reduce model complexity while improving the detection accuracy of small grape leaf lesions.
[0049] Specifically, the feature extraction backbone network in the embodiment of the present application includes: a convolution module (Conv), a fusion module (C2f), and a non-local attention module (Non-Local). The number, distribution, and connection method of each module in the feature extraction backbone network can be referred to Figure 3 Specifically, the feature extraction backbone network extracts features from the labeled disease image, and transmits the disease image features obtained by feature extraction to the feature fusion neck network, including: the convolution module performs a convolution operation on the input data to obtain a first image feature; the input data includes: a labeled disease image or a first image feature or a second image feature; the fusion module performs fusion enhancement on the input first image feature to obtain a second image feature; the non-local attention module adjusts the attention weight based on the first image feature of the predecessor convolution module to obtain a disease image feature; and transmits the disease image feature to the feature fusion neck network.
[0050] It is understandable that in the feature extraction backbone network, the convolution module can receive the input data sent by the predecessor module and perform a convolution operation on the input data to obtain the first image feature. For different convolution modules, their predecessor modules may be different. Figure 3 As shown, the predecessor module of the first convolution module is the input end, and the predecessor module of the second convolution module is the first convolution module. The specific details can be shown in the figure, and this embodiment of the present application will not be elaborated on.
[0051] It should be understood that the above-mentioned first image feature is also the image feature obtained through the convolution operation, and the above-mentioned second image feature is also the image feature obtained through the fusion enhancement operation, and no specific restrictions are imposed on them in the embodiments of the present application.
[0052] It is understandable that the aforementioned precursor convolution module is also the precursor module of the non-local attention module. The aforementioned non-local attention module, a functional module built based on the non-local attention mechanism, can effectively capture global information and model the relationship between all pixels in the first image feature input to the non-global attention module, thereby forming comprehensive contextual information. This global perspective significantly enhances the model's ability to detect small targets, especially in the case of coefficient features, helping to reduce missed detections of small targets and improving the model's detection capabilities.
[0053] In the embodiment of the present application, the network structure of the non-local attention module Non-Local can refer to Figure 4 , Figure 4 This is a schematic diagram of the Non-Local network structure (a single sample is used as an example).
[0054] like Figure 4 As shown, the non-local attention module can receive the feature tensor from the predecessor convolution module , which can be achieved through three convolutional layers calculate , the formula can be shown as follows (1), (2), (3): (1) (2) (3) in, Indicates the index of the output position, that is, the position where the response needs to be calculated, represents the index of all possible positions in the input feature map, is a learnable weight matrix that is transformed from the input feature map through convolution operation Extract the value features from In order to reduce the complexity of subsequent calculations, the convolution layer can use the maximum pooling layer (Maxpool2d) for downsampling, and finally obtain the feature map tensor The calculated feature map tensor is converted to the feature map tensor obtained by Reshape and Permute operations. , feature map tensor Get the feature map tensor through the Reshape operation .Will and (Can be regarded as and ) Similarity calculation based on Softmax function is obtained , then normalized and compared with Perform weighted aggregation to obtain the final feature of position i , as shown in the following formulas (4), (5), and (6): , (4) (5) ; (6) It is understandable that by Reshape back to Features with the same spatial dimension Finally, the features of all samples are weighted and aggregated, and the input Perform residual connection to obtain the final output :
[0055] In some implementations of the present application, the final output may be further By performing SPPF pooling, the disease image features that need to be output can be obtained.
[0056] It's important to note that in grape leaf disease detection, diseases often exhibit long-range spatial dependencies. This means that lesions or leaf damage may be associated with other parts of the leaf. However, the YOLOv8 model is limited by its local receptive field and struggles to capture long-range features. Non-Local computes the similarity between all spatial locations, capturing long-range dependencies across different regions of the image. It leverages global information to enhance fine-grained feature extraction and improve lesion identification accuracy. Furthermore, Non-Local adapts to visual changes in diseases under various transformations, such as rotation, scale, and shape, effectively handling complex transformations.
[0057] In the specific implementation, the embodiment of the present application optimizes the structure of the model backbone network by introducing the non-local attention mechanism to replace the C2f module of the P5 layer in the backbone network. The improved model reduces the number of parameters and the amount of calculation while improving the accuracy of grape leaf disease detection.
[0058] Step S300, the feature fusion neck network performs feature fusion on the disease image features, and transmits the disease fusion features obtained by the feature fusion to the detection head; Step S400: the detection head performs inference based on the disease fusion features to obtain a detection result; It should be noted that the feature fusion neck network can combine the structure of the feature pyramid (FPN) and the path aggregation network (PANet) to enhance multi-scale feature fusion capabilities and optimize computational overhead. The feature fusion neck network can be used to fuse features based on disease image features to obtain disease fusion features.
[0059] It should be explained that in grape leaf disease detection, the performance of the detection head can directly affect the detection efficiency and accuracy. The embodiment of the present application uses the detection head to infer the disease fusion features, and then obtains the detection results of the labeled disease images input into the model.
[0060] It should be noted that in the YOLOv8n network model, the detection head can adopt an anchor-free mechanism, using multiple independent convolutional layers to handle regression and classification tasks respectively. This results in a large number of parameters and high memory requirements, increases computational complexity, and affects the performance of resource-constrained devices. In addition, the independent convolution and feature splicing operations increase the forward propagation computational complexity, reducing the real-time inference speed. At the same time, YOLOv8n lacks flexibility when handling targets of different scales, and its detection effect on small targets in complex scenarios is poor. The complex detection head structure increases the difficulty of implementation and debugging, and is prone to introducing noise during training, affecting model convergence.
[0061] In some implementations of the present application, to address the aforementioned issues, the YOLOv8n model detection head is lightweighted and improved. Specifically, the detection head comprises an input module (Input), a lightweight convolutional layer (ConvGN), a shared convolution module, and a regression prediction module. The detection head performs reasoning based on the fusion defect features to obtain a detection result, including the following steps: the input module obtains fusion defect feature inputs of different scales; the lightweight convolutional layer extracts features from the fusion defect features to obtain convolution defect features; the shared convolution module enhances the convolution defect features to obtain enhanced defect features; and the regression prediction module performs regression prediction on the enhanced defect features to obtain a detection result.
[0062] It should be noted that the improved detection head GNSH in the embodiment of the present application adopts a shared convolution structure, and multiple detection layers share convolution weights, thereby reducing the number of parameters and computational costs. In addition, the embodiment of the present application introduces a dynamic scaling mechanism to adaptively adjust the output feature size, enhance the detection capability of targets of different scales, and improve the detection accuracy of small targets. In the embodiment of the present application, the improved lightweight detection head network structure can be referred to Figure 5 , Figure 5 This is a schematic diagram of the network structure of the detection head GNSH in one implementation of the grape leaf disease detection method of the present application.
[0063] It should be noted that the lightweight convolutional layer described above can be a standard convolutional module designed with Group Normalization (GN) technology. First, the input tensor is convolved, and features are extracted using the Conv2d module. Then, group normalization is performed on the convolution output. The GroupNorm module groups channels and normalizes the internal features of each group, accelerating convergence and improving training stability. Finally, the normalized features are transformed nonlinearly using the SiLU activation function to further enhance the model's expressiveness.
[0064] In some implementations of the embodiments of the present application, the specific implementation of the lightweight convolution layer may be: input feature tensor , where N is the batch size, C is the number of channels, H and W are the height and width of the feature map respectively. The channels are divided into G groups, each group contains channels; calculate each group The mean and variance , the calculation formula can be shown as follows (8) and (9): (8) (9) Among them, is the number of elements in each group, Indicates the All channel indices in the group, It is The i-th element in the group. For each element , normalized using the mean and variance of the corresponding group, which can be shown in the following formula (10): (10) in, is a small constant used to avoid division by zero errors. Finally, to increase the expressive power of the model, a learnable scaling parameter is introduced and translation parameters , perform linear transformation on each channel, the specific implementation is shown in formula (11), where and It is an independent parameter for each channel, and the final output It is the feature after normalization and linear transformation.
[0065] (11) By performing mean-variance normalization on each group of channels and applying scaling and translation, the expressiveness and stability of the model are enhanced, helping to accelerate convergence and improve the robustness of the model.
[0066] It should be noted that in the YOLOv8n model (Head module in Figure 2), feature maps of different scales usually have their own independent convolution layer processing. This means that each detection head will be configured with a separate set of convolution layer parameters for feature maps of different scales, which are used to extract features and fuse information from the feature maps of that scale. Although this design is effective, it will result in a large number of parameters and high computational complexity. This application improves the detection head by making it lightweight. The detection head receives feature map inputs from three different scales. The feature maps of each scale usually have different resolutions and numbers of channels. The input disease fusion features are extracted through independent lightweight convolution layers (for specific sources, please refer to Figure 3 As shown in Figure 5 ). The feature map of each disease fusion feature first undergoes a 1x1 convolution operation to linearly map the number of input feature channels to the target number of channels, thereby unifying the number of channels in each feature map while preserving the spatial resolution of the features. Furthermore, the processed feature map is input into the shared convolution module (as indicated by the dashed box in the middle of Figure 5 ). Two 3x3 convolution operations are performed through two lightweight convolutional layers. The first convolution operation expands the local receptive field of the input features, captures local information in the feature map, and performs a preliminary nonlinear transformation on the features. The second convolution operation further expands the receptive field, captures more contextual information, and further enhances the expressive power of the feature map. Subsequently, the feature maps output by the shared convolution module are input into subsequent different regression and classification branches for detection according to the spatial resolution.
[0067] It should be noted that the core of the shared convolution module in the embodiment of the present application lies in the sharing of convolution kernel parameters, that is, feature maps of different scales reuse the convolution kernel parameters in the shared convolution module. By sharing the convolution kernel parameters, the module can learn consistent feature patterns in feature maps of different scales, such as unified local feature extraction methods such as edges and textures, and realize the sharing of the same feature extraction logic between feature maps of different scales. Shared convolution not only reduces the number of parameters and computational overhead of the model, but also ensures that multi-scale feature maps can be fused and uniformly represented in the same feature space, thereby improving the inference speed and making the model more efficient and lightweight.
[0068] In some implementations of the embodiments of the present application, shared convolution may, to a certain extent, ignore the differential expression of feature maps of different scales, thereby weakening the ability to express features of a specific scale. The embodiments of the present application can also enhance the model's adaptability to features of different scales by introducing a Scale layer (as indicated by the dotted box on the right side of Figure 5) into the detection head and dynamically adjusting the feature map after shared convolution processing. The Scale layer is a dynamic scaling mechanism based on a learnable factor. It dynamically linearly scales the input feature map through a learnable scaling factor to adjust the amplitude of the feature map, thereby improving the flexibility of the model in multi-scale feature processing. Specifically, it can be shown in the following formula (12): (12) in The scale factor is a learnable factor that is optimized by gradient descent. The model can learn the best scale factor based on the feature maps of different scales, thereby achieving differentiation of feature expression based on shared convolution. and Matrix dot multiplication to obtain the dynamically adjusted feature map This design can effectively alleviate the problem of shared convolution weakening the ability to express features at specific scales, helping the model automatically adjust the response strength of feature maps at different levels, enhancing or suppressing the feature response of specific channels, thereby making the output of each detection head more adaptable to targets at various scales, and achieving dynamic redistribution of the importance of feature maps, improving the convergence speed and stability of the model, and enhancing the detection performance of the model.
[0069] Step S500, performing a loss assessment based on the detection result and the labeling result of the labeled disease image to obtain a loss assessment result; Step S600, iterating the first leaf disease detection model based on the loss assessment result to obtain the iterated first leaf disease detection model; Step S700: If the iterated first leaf disease detection model does not meet the iteration termination condition, then return to the step of obtaining the labeled disease images in the labeled disease image dataset from the input end.
[0070] It is understood that for labeled disease images, which may include annotation results (e.g., disease type and disease area), a loss assessment can be performed based on the detection and annotation results to obtain a loss assessment result for iteration. If the first leaf disease detection model does not meet the iteration termination criteria, the iteration can return to the step of obtaining labeled disease images from the labeled disease image dataset at the input end and continue until the iteration termination criteria are met. If the first leaf disease detection model meets the iteration termination criteria, the first leaf disease detection model completed with the iteration can be used as the trained leaf disease detection model.
[0071] It should be noted that the above-mentioned iteration termination condition can be that the number of iterations is greater than the preset number of iterations, or that the confidence of the detection result reaches a preset confidence threshold. The embodiment of the present application does not limit this.
[0072] By introducing normalization technology, shared convolution, and a dynamic scaling mechanism, the embodiments of this application achieve a good balance between model lightweighting and performance improvement. Compared with the original model, the improved model reduces the number of parameters, floating-point calculations, and model size by 21.6%, 19.8%, and 21.7%, respectively, and improves mAP@0.5 by 0.4%. This achieves model lightweighting while maintaining high detection accuracy. This not only reduces computational workload and memory usage, but also speeds up inference, improves the model's adaptability in resource-constrained environments, and enhances the detection capabilities of small and multi-scale targets, providing better support for grape leaf disease detection tasks in resource-constrained environments.
[0073] Based on the first embodiment and / or the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the first embodiment and / or the second embodiment can be referred to the above introduction and will not be described in detail later. Figure 6 , Figure 6 This is a flow chart of Example 3 of the grape leaf disease detection method of this application.
[0074] like Figure 6 As shown, in the embodiment of the present application, the step of performing loss assessment based on the detection result and the labeling result of the labeled disease image to obtain the loss assessment result includes: Step S510, performing a binary cross entropy loss evaluation based on the detection result and the labeling result of the labeled disease image to obtain a binary cross entropy loss; Step S520 , performing a supplementary loss assessment based on the binary cross entropy loss and the sample weight to obtain a loss assessment result.
[0075] It should be noted that in the original YOLOv8n model, the BCE Loss binary cross entropy loss is still used in its classification branch. The calculation method of the binary cross entropy loss can be shown in the following formula (13): (13) in, is the true label of the i-th sample (0 or 1), It is i The predicted probability of the sample (the probability value obtained after the sigmoid activation function). When it is 1, the loss Effectively, calculate the loss when the model predicts the positive class, when the true label When it is 0, the loss Effectively, calculate the loss when the model predicts a negative class. The logarithmic function is used to convert the probability value into the loss value, so that the loss function has a larger gradient when the probability is close to 0 or 1, thereby more effectively guiding model training.
[0076] It should be noted that BCE Loss directly combines the unnormalized prediction value (logits) with the target label, which can effectively deal with the problem of class imbalance. However, when facing small targets, this loss function often cannot fully capture the subtle features of the target, resulting in insufficient sensitivity of the model and prone to missed detection and false detection. In the embodiment of the present application, the Slide Loss loss function is used to supplement the classification loss function. Its specific formula can be shown as follows (14): (14) (15) In the above formula (14), N represents the number of samples, specifically the total number of samples processed in one training iteration. Represents the dynamic weight of the i-th sample, and the calculation formula is shown in (15), which is used to adjust the contribution of the sample to the total loss. The calculation of the weight can be based on the loss value of the sample, with the purpose of making the model pay more attention to samples that are difficult to detect during training, while maintaining sensitivity to the true label of each sample and the model output. is the true label of the i-th sample, is a dynamically adjusted threshold.
[0077] It's important to note that Slide Loss introduces a sliding window mechanism that dynamically adjusts weights based on the sample's loss, thereby increasing the model's focus on difficult-to-detect samples. This allows the model to more effectively capture target features in the presence of small objects or noise, improving detection sensitivity.
[0078] The embodiments of this application use Slide Loss for further loss evaluation, which not only optimizes the model training process but also assigns higher weights to samples with low IoU (i.e., difficult-to-detect samples), making these samples account for a larger proportion of the loss calculation. This allows the model to pay more attention to these difficult examples during training, thereby improving their detection capabilities. Slide Loss assigns lower weights to samples with high IoU (i.e., easy-to-detect samples), reducing their impact on the loss and preventing the model from overfitting to easy-to-detect samples. This improves the model's detection accuracy in grape leaf disease detection tasks, addresses the imbalance between easy and difficult samples, and enables the model to more effectively capture the characteristics of tiny lesions, thereby achieving more accurate grape leaf disease identification.
[0079] In some implementations of the present application, to verify the effectiveness of the improved model, the present application may select multiple evaluation indicators to comprehensively evaluate the model. Specifically, the evaluation indicators may include: precision P (Precision), recall R (Recall), mean average precision mAP@0.5 (Mean Average Precision), model parameters (Parameters, Para), floating point operations (Float Point Operations, FLOPs), model size (ModelSize, Msize), frame rate (Frames Per Second, FPS), etc., which are not limited in the present application. These evaluation indicators can be used to measure the detection accuracy and performance of the model.
[0080] In the examples of this application, the improved algorithm model of this application is compared with the algorithm model before the improvement, taking the mean average precision (mAP@0.5) as an example. The mean average precision (mAP@0.5) represents the average precision of all categories when the intersection-over-union (IoU) threshold is 0.5. A higher mAP value indicates better overall accuracy of the model detection.
[0081] like Figure 7 and Figure 8 As shown, Figure 7 This is a comparison diagram of mAP@0.5 before and after improvement. Figure 8 Schematic diagram of the comparison of Loss curves before and after improvement. Figure 7 In the figure, the horizontal axis represents the iteration cycle, and the vertical axis represents the mean average precision mAP@0.5; Figure 8 In the figure, the horizontal axis represents the iteration cycle and the vertical axis represents the loss value.
[0082] Compared to the original model, the improved model proposed in this paper reduces the number of parameters by 27.9%, the model weight file size by 28.3%, the number of floating-point calculations by 21.0%, and improves mAP@0.5 by 1.1%. This effective reduction in model parameters and computational complexity while improving detection accuracy demonstrates the effectiveness of the improved method in improving various aspects of model performance.
[0083] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the grape leaf disease detection method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0084] This application also provides a grape leaf disease detection device, please refer to Figure 9 , Figure 9 This is a schematic diagram of the module structure of the grape leaf disease detection device according to an embodiment of the present application. The grape leaf disease detection device includes: The data acquisition module 10 is used to acquire the data image of the grape leaves to be detected; The model management module 20 is used to obtain a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on an improved YOLOv8 lightweight grape leaf disease detection algorithm; The disease detection module 30 is used to input the data image into the leaf disease detection model for identification to obtain a disease detection result.
[0085] The grape leaf disease detection device provided in this application utilizes the grape leaf disease detection method of the aforementioned embodiment, resolving the technical issue of the difficulty of detecting grape leaves when using existing target detection models. Compared to the prior art, the grape leaf disease detection device provided in this application achieves the same beneficial effects as the grape leaf disease detection method of the aforementioned embodiment. Other technical features of the grape leaf disease detection device are the same as those disclosed in the aforementioned embodiment and are not further elaborated here.
[0086] The present application provides a grape leaf disease detection device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the grape leaf disease detection method of the above-mentioned embodiment 1.
[0087] Reference below Figure 10, which shows a schematic diagram of the structure of a grape leaf disease detection device suitable for implementing embodiments of the present application. The grape leaf disease detection device in the embodiments of the present application can include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 10 The grape leaf disease detection device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0088] like Figure 10 As shown, the grape leaf disease detection device may include a processing device 1001 (e.g., a central processing unit, graphics processing unit, etc.), which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 1002 or programs loaded from a storage device 1003 into a random access memory (RAM) 1004. RAM 1004 also stores various programs and data required for the operation of the grape leaf disease detection device. Processing device 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems may be connected to I / O interface 1006: input devices 1007, such as a touch screen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008, such as a liquid crystal display (LCD), speaker, vibrator, etc.; storage device 1003, such as a magnetic tape or hard disk; and communication devices 1009. Communication device 1009 allows the grape leaf disease detection device to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a grape leaf disease detection device with various systems, it should be understood that it is not required to implement or include all of the systems shown. More or fewer systems may be implemented or included instead.
[0089] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0090] The grape leaf disease detection device provided in this application utilizes the grape leaf disease detection method of the aforementioned embodiment, resolving the technical issue of the difficulty of detecting grape leaves when using existing target detection models. Compared to the prior art, the grape leaf disease detection device provided in this application achieves the same beneficial effects as the grape leaf disease detection method of the aforementioned embodiment. Other technical features of this grape leaf disease detection device are the same as those disclosed in the aforementioned embodiment and are not further elaborated here.
[0091] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0092] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
[0093] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, a computer program) stored thereon, wherein the computer-readable program instructions are used to execute the grape leaf disease detection method in the above-mentioned embodiment.
[0094] The computer-readable storage medium provided herein may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems, or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including, but not limited to, wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0095] The computer-readable storage medium may be included in the grape leaf disease detection device; or it may exist independently without being assembled into the grape leaf disease detection device.
[0096] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the grape leaf disease detection device, the grape leaf disease detection device: Acquire a data image of a grape leaf to be detected; Obtaining a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on an improved YOLOv8 lightweight grape leaf disease detection algorithm; The data image is input into the leaf disease detection model for identification to obtain a disease detection result.
[0097] Computer program code for performing the operations of the present application may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0098] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0099] The modules described in the embodiments of the present application may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.
[0100] The computer-readable storage medium provided in this application stores computer-readable program instructions (i.e., a computer program) for executing the grape leaf disease detection method described above. This computer-readable storage medium can address the technical issue of existing target detection models being difficult to detect when applied to grape leaf disease detection. Compared to the prior art, the beneficial effects of the computer-readable storage medium provided in this application are similar to those of the grape leaf disease detection method provided in the aforementioned embodiment, and are not further elaborated here.
[0101] The present application also provides a computer program product, comprising a computer program, which implements the steps of the above-mentioned grape leaf disease detection method when executed by a processor.
[0102] The computer program product provided in this application can address the technical issue of existing object detection models being difficult to detect when applied to grape leaf disease. Compared to the prior art, the computer program product provided in this application offers the same beneficial effects as the grape leaf disease detection method provided in the aforementioned embodiments, and will not be further elaborated here.
[0103] The above description is only part of the embodiments of the present application and does not limit the patent scope of the present application. All equivalent structural transformations made by using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for detecting grape leaf diseases, characterized in that: The method comprises: Acquire a data image of a grape leaf to be detected; Obtaining a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on an improved YOLOv8 lightweight grape leaf disease detection algorithm; The data image is input into the leaf disease detection model for identification to obtain a disease detection result.
2. The grape leaf disease detection method according to claim 1, wherein The step of training the leaf disease detection model comprises: Obtain a dataset of labeled disease images of grape leaves; A first leaf disease detection model is trained based on the labeled disease image dataset.
3. The grape leaf disease detection method according to claim 2, wherein The first leaf disease detection model includes: an input end, a feature extraction backbone network, a feature fusion neck network and a detection head; The step of detecting and training the first leaf disease detection model based on the labeled disease image dataset includes: The input end obtains the labeled disease images in the labeled disease image dataset and transmits the labeled disease images to the feature extraction backbone network; The feature extraction backbone network extracts features from the labeled disease image, and transmits the disease image features obtained by the feature extraction to the feature fusion neck network; The feature fusion neck network performs feature fusion on the disease image features and transmits the disease fusion features obtained by the feature fusion to the detection head; The detection head performs reasoning based on the disease fusion features to obtain a detection result; Performing a loss assessment based on the detection result and the labeling result of the labeled disease image to obtain a loss assessment result; iterating the first leaf disease detection model based on the loss assessment result to obtain an iterated first leaf disease detection model; If the first leaf disease detection model after iteration does not meet the iteration termination condition, the process returns to the step of obtaining the labeled disease images in the labeled disease image dataset from the input end.
4. The grape leaf disease detection method according to claim 3, wherein: The feature extraction backbone network includes: a convolution module, a fusion module and a non-local attention module; The step of extracting features from the labeled disease image by the feature extraction backbone network and transmitting the disease image features obtained by the feature extraction to the feature fusion neck network includes: The convolution module performs a convolution operation on the input data to obtain a first image feature; the input data includes: an annotated disease image or the first image feature or the second image feature; The fusion module performs fusion enhancement on the input first image feature to obtain a second image feature; The non-local attention module adjusts the attention weight based on the first image feature of the predecessor convolution module to obtain the disease image feature; The disease image features are transmitted to the feature fusion neck network.
5. The grape leaf disease detection method according to claim 3, wherein: The detection head includes: an input module, a lightweight convolution layer, a shared convolution module and a regression prediction module; The step of the detection head performing reasoning based on the disease fusion features to obtain a detection result includes: The input module obtains disease fusion feature inputs of different scales; The lightweight convolution layer performs feature extraction on the disease fusion feature to obtain a convolution disease feature; The shared convolution module performs feature enhancement on the convolved disease feature to obtain an enhanced disease feature; The regression prediction module performs regression prediction on the enhanced disease characteristics to obtain a detection result.
6. The grape leaf disease detection method according to claim 3, wherein: The step of performing loss assessment based on the detection result and the labeling result of the labeled disease image to obtain a loss assessment result includes: Performing a binary cross entropy loss evaluation based on the detection result and the labeling result of the labeled disease image to obtain a binary cross entropy loss; Supplementary loss evaluation is performed based on binary cross entropy loss and sample weight to obtain the loss evaluation result.
7. A grape leaf disease detection device, characterized in that: The grape leaf disease detection device comprises: A data acquisition module, used for acquiring data images of grape leaves to be detected; A model management module is used to obtain a pre-trained leaf disease detection model; wherein the leaf disease detection model is trained based on an improved YOLOv8 lightweight grape leaf disease detection algorithm; The disease detection module is used to input the data image into the leaf disease detection model for identification to obtain a disease detection result.
8. A grape leaf disease detection device, characterized in that: The device includes: a memory, a processor, and a grape leaf disease detection program stored in the memory and executable on the processor, wherein the grape leaf disease detection program is configured to implement the steps of the grape leaf disease detection method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium stores a grape leaf disease detection program, which, when executed by the processor, implements the steps of the grape leaf disease detection method according to any one of claims 1 to 6.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the grape leaf disease detection method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Battery CT image defect detection method based on improved YOLOv8
CN118587158A
Apple leaf disease detection method based on improved YOLOv8
CN119888479A
Cited By
Tea insect pest quadrat intelligent statistical method based on improved instance segmentation network
CN122368777A