Tomato leaf disease and pest detection method based on improved YOLOv8

By improving the YOLOv8 model, adopting GhostNet and RFA attention mechanisms, and combining the Wise IOU loss function, the problem of insufficient small target detection performance of YOLOv8 in tomato leaf pest and disease detection was solved, achieving more efficient and accurate pest and disease detection.

CN120070960BActive Publication Date: 2026-07-21YANCHENG INST OF TECH +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
YANCHENG INST OF TECH
Filing Date
2025-01-17
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

The existing YOLOv8 model has problems with insufficient small target detection performance and real-time performance in the detection of diseases and pests on tomato leaves, especially in resource-constrained agricultural scenarios where the processing speed is not ideal.

Method used

We employ the lightweight GhostNet network and RFA attention mechanism, combined with the Wise IOU loss function, to improve the YOLOv8 model, enhance its feature extraction and attention capabilities, and optimize small object detection.

Benefits of technology

The model's ability to detect small targets and complex backgrounds has been improved, enhancing detection accuracy and recall, and enabling faster and more accurate pest and disease detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120070960B_ABST
    Figure CN120070960B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of disease and pest detection, and particularly discloses a tomato leaf disease and pest detection method based on an improved YOLOv8, which comprises the following steps: constructing a tomato leaf image dataset containing each type of disease and pest; fusing a GhostNet and an RFA attention mechanism, modifying a loss function into a Wise IOU, and constructing an improved YOLOv8 model; configuring training hyperparameters, updating model weights based on the tomato leaf image dataset, and obtaining a trained improved YOLOv8 model; performing disease and pest detection on a to-be-detected tomato leaf image based on the trained improved YOLOv8 model, and obtaining a disease and pest detection result of the to-be-detected tomato leaf image; and the method can improve the efficiency and real-time performance of the model, reduce the number of parameters, enhance the attention ability of the model to features, and improve the detection precision, so that more accurate disease and pest detection can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of pest and disease detection technology, and in particular to a method for detecting pests and diseases on tomato leaves based on an improved YOLOv8. Background Technology

[0002] Tomatoes are a widely cultivated economic crop, but their growth is susceptible to various pests and diseases, affecting yield, quality, and safety. Traditional algorithms based on feature extraction and classifiers, while easy to implement and performing reasonably well on small datasets, fall short when handling small targets and complex background features, making it difficult to extract potential information from the data. Convolutional Neural Networks (CNNs) have become mainstream detection methods, such as YOLO and Faster R-CNN, significantly improving detection accuracy and the ability to handle diverse images. However, in tomato leaf pest and disease detection, traditional target detection models rely on deep CNNs (such as VGG and ResNet) to improve accuracy, but this increases the computational burden due to the increased number of layers and parameters, reducing real-time performance and resulting in poor performance in resource-constrained environments and agricultural scenarios requiring rapid response. YOLOv8 is an improvement on YOLOv5, mainly composed of a backbone network, a neck network, and a head network. The backbone network uses CSPNet to extract features in stages for efficient representation; the neck network integrates the advantages of FPN and PAN, effectively fusing multi-scale features to improve the detection of small targets; the head network uses decoupling technology to separate classification and detection, and the loss function uses positive and negative sample matching. The features extracted from its backbone network are fused through the neck to form a multi-scale feature representation, and finally the head completes the target detection, which is more advantageous in the detection of tomato diseases and pests.

[0003] This design significantly improves YOLOv8's speed and accuracy, but it still has certain limitations in small object detection. Furthermore, the increased model complexity may affect its real-time performance in some applications, leading to slower-than-expected processing speeds. Therefore, improvements are needed to enhance YOLOv8's performance and real-time capabilities in small object detection.

[0004] Therefore, this invention proposes a method for detecting diseases and pests on tomato leaves based on an improved YOLOv8. Summary of the Invention

[0005] This invention provides a method for detecting pests and diseases on tomato leaves based on an improved YOLOv8. It utilizes the lightweight GhostNet network and its efficient feature extraction mechanism to reduce the number of parameters and computational load, enabling YOLOv8 to perform object detection faster while maintaining high accuracy. An attention mechanism, RFA, is introduced to enhance the model's ability to focus on features; this is also incorporated into the feature pyramid network's feature fusion process, allowing the model to adaptively focus on important feature regions, enhancing its ability to detect small objects and complex backgrounds. Furthermore, the loss function is replaced with Wise IOU to improve detection accuracy and optimize the recognition of small objects. This also better handles the bounding box regression problem in object detection, improving both accuracy and recall. Ultimately, this results in more accurate pest and disease detection.

[0006] This invention provides a method for detecting diseases and pests on tomato leaves based on an improved YOLOv8, comprising:

[0007] S1: Construct a dataset of tomato leaf images containing each type of pest and disease;

[0008] S2: By integrating GhostNet and RFA attention mechanisms and modifying the loss function to Wise IOU, an improved YOLOv8 model is constructed.

[0009] S3: Configure training hyperparameters and update model weights based on tomato leaf image dataset to obtain a well-trained improved YOLOv8 model;

[0010] S4: Based on the trained improved YOLOv8 model, perform pest and disease detection on the tomato leaf images to be detected, and obtain the pest and disease detection results of the tomato leaf images to be detected.

[0011] Preferably, the improved YOLOv8-based method for detecting diseases and pests on tomato leaves, S2: integrates GhostNet and RFA attention mechanisms, modifies the loss function to Wise IOU, and constructs an improved YOLOv8 model, including:

[0012] By loading pre-trained weights from YOLOv8, integrating the RFA attention mechanism into the YOLOv8 feature extraction network, replacing the traditional convolution in the neck structure with GhostConv, replacing the feature fusion module in the neck structure with C2fGhost, and replacing the loss function with Wise IOU, an improved YOLOv8 model is constructed.

[0013] Preferably, the tomato leaf disease and pest detection method based on improved YOLOv8 integrates the RFA attention mechanism into the YOLOv8 feature extraction network, including:

[0014] The RFA attention mechanism is introduced during the feature fusion process of the feature pyramid network. RFAConv has a 3×3 convolutional kernel and uses Group Conv to extract receptive field features. It aggregates information through AvgPool, performs information interaction through 1×1 group convolution operations, and emphasizes feature importance through softmax. C2f_RFAConv contains two convolutional layers and multiple Bottleneck_RFAConv modules. The Bottleneck_RFAConv module contains two convolutional layers. The first convolutional layer reduces the number of input channels, and the second convolutional layer uses RFAConv for processing and supports shortcut connections.

[0015] Preferably, the Wise IOU formula for detecting tomato leaf diseases and pests based on the improved YOLOv8 is:

[0016]

[0017] L WIoU =εR WIoU

[0018] In the formula, R WIoU The degree of overlap between the anchor box and the target box is given by exp(), which is an exponential function with the natural constant e as the base, where e is 2.71828. x is the x-coordinate of the anchor box's center point, and y is the y-coordinate of the anchor box's center point. gt The x-coordinate of the center point of the target bounding box is y. gt W represents the ordinate of the center point of the bounding box. g H is the width of the target bounding box. g L is the height of the target bounding box. WIoU ε is the output loss value of Wise IOU, and ε is the weighting factor.

[0019] Preferably, the tomato leaf disease and pest detection method based on improved YOLOv8, S3: Configure training hyperparameters and update model weights based on the tomato leaf image dataset to obtain a trained improved YOLOv8 model, including:

[0020] The tomato leaf image dataset was divided into training, validation, and test sets based on a partitioning ratio of 8:1:1.

[0021] Data augmentation is performed on the training set to obtain an optimized training set, and the test and validation sets are standardized or normalized to obtain a standard test set and a standard validation set.

[0022] Configure training hyperparameters, set batch size to 32 and iteration count to 300 rounds, and train the improved YOLOv8 model using the optimized training set. In each training iteration, calculate the loss and update the model weights, while monitoring the performance metrics on the standard test set until the latest improved YOLOv8 model is obtained.

[0023] The confusion matrix is ​​plotted by calculating the recognition results of the latest improved YOLOv8 model on the test set and the true labels of the test set. Based on the confusion matrix, the accuracy and loss value of the latest improved YOLOv8 model on the test set are calculated as the model evaluation results of the latest improved YOLOv8 model.

[0024] If the evaluation result of the latest improved YOLOv8 model meets the requirements, the improved YOLOv8 model is considered as a trained improved YOLOv8 model. Otherwise, the latest improved YOLOv8 model is trained and tested until a trained improved YOLOv8 model that meets the requirements is obtained.

[0025] Preferably, the tomato leaf disease and pest detection method based on improved YOLOv8, S4: Detecting diseases and pests in the tomato leaf image based on the trained improved YOLOv8 model, obtaining the disease and pest detection results of the tomato leaf image, including:

[0026] The tomato leaf image to be detected is subjected to first-level super-resolution reconstruction and divided into S×S grids. Each grid is input into the trained improved YOLOv8 model to predict B bounding boxes in each grid and calculate the center coordinates, width and height of each bounding box.

[0027] x=σ(t x )+c x

[0028] y=σ(t y )+c y

[0029]

[0030] In the formula, x is the x-coordinate of the center of the bounding box, y is the y-coordinate of the center of the bounding box, σ() is the sigmoid function, and t x t represents the lateral offset of the bounding box center relative to its grid cell. y c is the vertical offset of the bounding box center relative to its grid. x c is the x-coordinate of the center point of the grid corresponding to the currently calculated bounding box. yHere is the ordinate of the center point of the grid corresponding to the currently calculated bounding box, w is the width of the bounding box, and p is the center point of the grid. w Let be the width of the prior bounding box, e be the natural constant with a value of 2.71828, and t be the width of the prior bounding box. w The relative change in the width of the bounding box is given by p, where h is the height of the bounding box and p is the height of the bounding box. h Let t be the height of the prior bounding box. h This represents the relative adjustment amount for the bounding box height;

[0031] The intersection-over-union (IoU) ratio between the predicted and ground truth bounding boxes is determined based on the center coordinates, width, and height of each bounding box, and the confidence level of each bounding box is calculated based on the IoU ratio.

[0032] C = P(object) · IoU truth

[0033] In the formula, C represents the confidence level of the bounding box, and IoU... truth This is the intersection-union ratio between the predicted bounding box and the ground truth bounding box;

[0034] The final target bounding box is selected based on the nonmaximum suppression algorithm;

[0035] Based on the confidence level, the probability distribution of each target bounding box for each type of pest or disease is predicted:

[0036]

[0037] In the formula, P(i|box) is the probability of the target bounding box for the i-th type of pest or disease, e is the natural constant with a value of 2.71828, and z i z is the original prediction score of the target bounding box for the i-th type of pest or disease. j Let C be the original prediction score of the target bounding box for the j-th type of pest or disease, and C be the total number of pest or disease types.

[0038] Based on the probability distribution of all target bounding boxes in all grids of the tomato leaf image to be detected for each type of pest or disease, the pest and disease detection results of the tomato leaf image to be detected are obtained.

[0039] Preferably, the tomato leaf disease and pest detection method based on the improved YOLOv8 obtains the disease and pest detection results of the tomato leaf image based on the probability distribution of all target bounding boxes in all grids of the tomato leaf image for each disease and pest type, including:

[0040] Based on the probability distribution of all target bounding boxes in all grids of the tomato leaf image to be detected for each type of pest and disease, pest and disease detection annotation is performed on the tomato leaf to be detected, and the non-minimal target pest and disease detection annotation results and the minimal target pest and disease detection fine annotation results of the tomato leaf image to be detected are obtained.

[0041] Based on the non-minimal target pest and disease detection annotation results and the minimal target pest and disease detection fine annotation results of the tomato leaf image to be detected, the pest and disease detection results of the tomato leaf image to be detected are obtained.

[0042] Preferably, the tomato leaf disease and pest detection method based on the improved YOLOv8 obtains the disease and pest detection results of the tomato leaf image based on the non-minimal target disease and pest detection annotation results and the minimal target disease and pest detection fine annotation results of the image to be detected, including:

[0043] Based on the non-minimal target pest and disease detection annotation results and the minimal target pest and disease detection fine annotation results of the tomato leaf image to be detected, the pest and disease detection evaluation value of the tomato leaf image to be detected is obtained.

[0044] Based on the pest and disease detection evaluation value of the tomato leaf image to be detected, the pest and disease detection results of the tomato leaf image to be detected are obtained.

[0045] Preferably, the tomato leaf pest and disease detection method based on the improved YOLOv8 calculates the pest and disease detection evaluation value of the tomato leaf image based on the coordinate information of all minimal pest and disease detection boxes and all non-minimal pest and disease detection boxes in the corresponding clean annotation results of non-minimal pest and disease detection in the super-resolution image of the tomato leaf to be detected, including:

[0046] Based on the coordinate information of all the minimum target pest detection boxes in the super-resolution image of the tomato leaf to be detected and all the non-minimum target pest detection boxes in the corresponding clean annotation results of the non-minimum target pest detection, the shortest distance between each minimum target pest detection box and each corresponding non-minimum target pest detection box in the super-resolution image of the tomato leaf to be detected is determined.

[0047] Based on the shortest distance between each minimum target pest detection box and its corresponding non-minimum target pest detection box in the super-resolution image of the tomato leaf to be detected, the pest detection evaluation value of the tomato leaf image to be detected is calculated:

[0048]

[0049] In the formula, P is the pest and disease detection evaluation value of the tomato leaf image to be detected, n is the total number of minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected, m is the total number of non-minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected, and max(n,m) is the maximum value between the total number of minimum target pest and disease detection boxes and the total number of non-minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected. m To determine the standard similarity between the total number of detection frames for extremely small target pests and diseases and the total number of detection frames for non-extremely small target pests and diseases, l ij P represents the shortest distance between the i-th minimal target pest detection box and the j-th non-minimal target pest detection box. l The similarity between the standard distribution of all minimal target pest detection frames and all non-minimal target pest detection frames.

[0050] Preferably, the tomato leaf disease and pest detection method based on the improved YOLOv8 obtains the disease and pest detection results of the tomato leaf image based on the disease and pest detection evaluation value of the image, including:

[0051] If the pest and disease detection evaluation value of the tomato leaf image to be detected is not less than the preset evaluation threshold, then all the minimum target pest and disease detection boxes and all the non-minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected will be marked to obtain the pest and disease detection result of the tomato leaf image to be detected.

[0052] If the pest and disease detection evaluation value of the tomato leaf image to be detected is less than the preset evaluation threshold, then the tomato leaf image to be detected will undergo second-level super-resolution reconstruction processing and pest and disease detection until the latest obtained evaluation value of the smallest target pest and disease detection is not less than the preset evaluation threshold. Then, all the smallest target pest and disease detection boxes and all the non-smallest target pest and disease detection boxes in the latest obtained super-resolution image of the tomato leaf to be detected will be labeled to obtain the pest and disease detection result of the tomato leaf image to be detected.

[0053] The beneficial effects of this invention compared to existing technologies are as follows: This method employs the lightweight GhostNet network, which, through its efficient feature extraction mechanism, reduces the number of parameters and computational load, enabling YOLOv8 to perform object detection faster while maintaining high accuracy. An attention mechanism, RFA, is introduced to enhance the model's ability to focus on features; this is also incorporated into the feature fusion process of the feature pyramid network, allowing the model to adaptively focus on important feature regions, enhancing its detection capabilities for small targets and complex backgrounds. Furthermore, the loss function is replaced with Wise IOU to improve detection accuracy and optimize the recognition of small objects, better handling the bounding box regression problem in object detection, and improving the accuracy and recall of object detection. This results in more accurate pest and disease detection.

[0054] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in this application.

[0055] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0056] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:

[0057] Figure 1 This is a flowchart of the tomato leaf disease and pest detection method based on the improved YOLOv8 in an embodiment of the present invention;

[0058] Figure 2 This is a flowchart illustrating the implementation of tomato leaf disease and pest detection based on the improved YOLOv8 algorithm in this embodiment of the invention.

[0059] Figure 3 This is a network structure diagram of a YOLOv8 algorithm in an embodiment of the present invention;

[0060] Figure 4 This is a schematic diagram of GhostNet in an embodiment of the present invention;

[0061] Figure 5 This is a schematic diagram of the Ghostconv structure in an embodiment of the present invention;

[0062] Figure 6 This is a schematic diagram of the structure of GhostBottleneck in an embodiment of the present invention;

[0063] Figure 7This is a schematic diagram of the structure of C2fGhost in an embodiment of the present invention;

[0064] Figure 8 This is a schematic diagram illustrating the transformation of spatial features to obtain the spatial features of the receiving field in an embodiment of the present invention.

[0065] Figure 9 This is a schematic diagram of the structure of RFAConv in an embodiment of the present invention;

[0066] Figure 10 This is a schematic diagram of the network structure of the improved YOLOv8 algorithm in an embodiment of the present invention. Detailed Implementation

[0067] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.

[0068] Example 1:

[0069] This invention provides a method for detecting diseases and pests on tomato leaves based on an improved YOLOv8, referencing... Figure 1 and Figure 2 ,include:

[0070] S1: Construct a dataset of tomato leaf images containing each type of pest and disease;

[0071] S2: By integrating GhostNet and RFA attention mechanisms and modifying the loss function to Wise IOU, an improved YOLOv8 model is constructed.

[0072] S3: Configure training hyperparameters and update model weights based on tomato leaf image dataset to obtain a well-trained improved YOLOv8 model;

[0073] S4: Based on the trained improved YOLOv8 model, perform pest and disease detection on the tomato leaf images to be detected, and obtain the pest and disease detection results of the tomato leaf images to be detected.

[0074] In this embodiment, the network structure diagram of the YOLOv8 algorithm is as follows: Figure 3 As shown, the features extracted by the backbone network are fused through the neck to form a rich multi-scale feature representation, which is then used for target detection by the head. This design significantly improves both speed and accuracy for YOLOv8, but it still has certain limitations in small target detection. Furthermore, due to the increased model complexity, its real-time performance may be affected in some application scenarios, resulting in slower processing speeds than expected. Therefore, to improve the performance and real-time capabilities of YOLOv8 in small target detection, further improvements are needed.

[0075] In the YOLOv8 network architecture, two convolutional kernel sizes, 1×1 and 3×3, are used. In the backbone network, to enhance the network's feature learning ability while maintaining the original gradient path, YOLOv8 introduces a module called the Cross-Stage Partial (CSP) module. This module improves the network's performance through cross-stage feature fusion. Furthermore, YOLOv8 combines other modules (such as convolutions and activation functions) to further enhance feature extraction capabilities. In the Head section, YOLOv8 employs the concepts of FPN and PAN to perform multiple fusions and re-extractions on the generated feature layers from top to bottom and bottom to top, ultimately generating feature maps of different sizes: 20×20, 40×40, and 80×80, for detecting large, medium, and small targets in images.

[0076] The generated feature map is first divided into S×S grids. Each grid is responsible for detecting objects within its region. For each grid, YOLOv8 predicts B bounding boxes, each containing five parameters: center coordinates (x, y), width w, height h, and confidence score C. Specifically, the center coordinates (x, y) of the box are the offset relative to the grid position. In addition, YOLOv8 generates a probability distribution associated with the target class for each predicted box.

[0077] Finally, YOLOv8 uses the Non-Maximum Suppression (NMS) algorithm to filter the final target bounding boxes. NMS removes boxes with excessive overlap with high-confidence bounding boxes by setting a threshold, ensuring that the final output bounding boxes are unique and have the highest confidence. Through these steps, YOLOv8 can efficiently process feature maps for target classification and localization, thus achieving accurate target detection in various complex scenarios.

[0078] In this embodiment, the system for detecting tomato leaf diseases and pests based on the improved YOLOv8 tomato leaf disease and pest detection method using GhostNet network and RFA module includes the following modules:

[0079] Image preprocessing module: This module is responsible for capturing tomato leaf images and performing necessary preprocessing operations to reduce the impact of external factors on image quality.

[0080] The image recognition module contains four sub-modules, including the following:

[0081] Dataset building module: Constructs a dataset of tomato leaf images containing different types of pests and diseases to ensure the comprehensiveness and representativeness of the data.

[0082] Improved YOLOv8 detection model module: Integrate GhostNet and RFA (Residual Feature Attention) attention mechanisms, modify the loss function to Wise IOU, and build an efficient YOLOv8 model to enhance the model's ability to focus on features, especially in the detection of small objects.

[0083] Model training module: Trains the improved YOLOv8 model and improves the model's detection performance by optimizing parameters.

[0084] Image detection module: Uses a trained model to detect pests and diseases in tomato leaf images and identify different types of pests and diseases.

[0085] The specific implementation process is as follows:

[0086] Step 1: Data Preparation

[0087] Using a publicly available dataset of tomato leaf diseases and pests, the dataset was divided into training, validation, and test sets in an 8:1:1 ratio. The system configuration included an i7-12700H CPU, a 64-bit Windows 11 operating system, and an NVIDIA RTX 3050Ti GPU. Additionally, the experimental environment included a GPU server equipped with an NVIDIA Tesla A404 8GB 300W GPU card.

[0088] Step 2: Data Preprocessing

[0089] Data augmentation is performed on the training set to expand the training data, including operations such as random rotation, scaling, flipping, and brightness adjustment, to increase the model's generalization ability. The validation and test sets are standardized or normalized to ensure that the pixel values ​​of the images are within the same scale range.

[0090] Step 3: Model Building

[0091] By loading pre-trained weights from YOLOv8, integrating the RFA attention mechanism into the YOLOv8 feature extraction network, using GhostNet in the feature fusion network, and replacing the loss function with Wise IOU, an improved YOLOv8 model is constructed to enhance the ability to identify key features.

[0092] Step 4: Model Training

[0093] Configure the training hyperparameters, setting the batch size to 32 and the number of iterations to 300 epochs, and begin training the model using the training set data. In each training iteration, calculate the loss and update the model weights, while simultaneously monitoring performance metrics on the validation set to prevent overfitting.

[0094] Step 5: Model Evaluation

[0095] The model is then evaluated using a test set. Metrics such as accuracy and F1 score on the test set are calculated, and a confusion matrix is ​​plotted for visualization to assess the model's performance in real-world applications.

[0096] The detailed flowchart is as follows: Figure 2 .

[0097] In this embodiment, the tomato leaf image dataset is created as follows: a collection containing various tomato leaf images with clearly labeled pest and disease types for each image. This dataset is used to train and test an improved YOLOv8 model to detect and analyze tomato leaf pests and diseases. For example, it could consist of 1000 tomato leaf images in different pest and disease states, covering various pest and disease types such as leaf mold and wilt.

[0098] In this embodiment, the trained improved YOLOv8 model is a high-performance improved YOLOv8 model obtained through a series of training and optimization processes. It performs excellently on the training, validation, and test sets, accurately detecting tomato leaf diseases and pests with high accuracy and low loss value. For example, after multiple parameter adjustments and training iterations, the improved YOLOv8 model achieves a 92% accuracy rate in detecting diseases and pests on the test set, with a loss value of only 0.15.

[0099] In this embodiment, the pest and disease detection results of the tomato leaf image to be detected are the conclusions drawn after processing and analyzing the tomato leaf image using a trained improved YOLOv8 model. This includes detailed information such as the detected pest and disease types, locations (marked by bounding boxes), and the probability of each pest and disease type. For example, the detection results show that the leaf to be detected has anthracnose with a probability of 0.75, and the bounding box accurately marks the extent of the disease on the leaf.

[0100] The beneficial effects of the above technologies are as follows: (Reference) Figure 10 This method employs the lightweight GhostNet network, leveraging its efficient feature extraction mechanism to reduce the number of parameters and computational cost, enabling YOLOv8 to perform object detection faster while maintaining high accuracy. An attention mechanism, RFA, is introduced to enhance the model's ability to focus on features; this is incorporated into the feature pyramid network's feature fusion process, allowing the model to adaptively focus on important feature regions, enhancing its detection capabilities for small targets and complex backgrounds. Furthermore, the loss function is replaced with Wise IOU to improve detection accuracy and optimize the recognition of small objects, better handling the bounding box regression problem in object detection and improving both accuracy and recall. This results in more accurate pest and disease detection.

[0101] Example 2:

[0102] Based on Example 1, an improved YOLOv8-based method for detecting diseases and pests on tomato leaves is proposed. S2: This method integrates GhostNet and RFA attention mechanisms, modifies the loss function to Wise IOU, and constructs an improved YOLOv8 model, including:

[0103] By loading pre-trained weights from YOLOv8, integrating the RFA attention mechanism into the YOLOv8 feature extraction network, replacing the traditional convolution in the neck structure with GhostConv, replacing the feature fusion module in the neck structure with C2fGhost, and replacing the loss function with Wise IOU, an improved YOLOv8 model is constructed.

[0104] In this embodiment, GhostNet is a lightweight convolutional neural network architecture designed to reduce computational complexity and model parameters while maintaining high classification accuracy. Figure 4 As shown, the GhostNet process mainly includes two key steps: feature extraction and feature generation. First, the network extracts preliminary features from the input image through standard convolutional layers. Next, the Ghost module uses linear operations to generate additional feature maps, and finally, a concat operation is used to generate the final feature map. These steps enhance the network's expressive power while maintaining computational efficiency.

[0105] exist Figure 5 In GhostNet, Ghostconv is a convolutional module specifically designed as a staged convolutional computation module. It generates a large number of feature maps through parallel execution of feature extraction and cost-effective linear operations, thus demonstrating its computational efficiency. This process begins with Ghostconv generating half of the feature map, using a convolutional kernel size half that of the original convolution. Next, a 5×5 convolutional kernel and a linear operation with a stride of 1 are applied to obtain the remaining half of the feature map. Finally, the two feature maps are concatenated to generate the complete feature map.

[0106] Figure 6 The GhostBottleneck operation is demonstrated. First, the number of channels is increased by using the initial GhostConv layer as an extension layer. Then, regularization and a Sigmoid linear unit (SiLU) are applied to the feature map. Next, a second GhostConv layer is used to reduce the number of channels in the output feature map to match the number of input channels. Finally, the feature map obtained in the previous stage is incorporated for feature fusion.

[0107] Figure 7The C2fGhost module is demonstrated, which replaces all bottleneck components in the original C2f module with GhostBottleneck units. This architecture combines a cross-stage feature fusion strategy and truncated gradient flow techniques to enhance the diversity of learned features across different network layers, reduce the impact of redundant gradient information, and thus improve learning capabilities.

[0108] The beneficial effects of the above techniques are as follows: Loading YOLOv8 pre-trained weights accelerates training and improves performance. Integrating the RFA attention mechanism allows the model to focus on key features, improving detection accuracy. Replacing the traditional convolutional layer in the neck structure with GhostConv reduces computational complexity and parameters, improving computational efficiency; replacing the feature fusion module with C2fGhost enhances feature diversity and improves learning ability. Changing the loss function to Wise IOU optimizes training and makes predictions more accurate. These improvements make the model more accurate, efficient, and lightweight, which is beneficial for practical detection applications.

[0109] Example 3:

[0110] Based on Example 2, an improved YOLOv8-based method for detecting tomato leaf diseases and pests integrates the RFA attention mechanism into the YOLOv8 feature extraction network, including:

[0111] The RFA attention mechanism is introduced during the feature fusion process of the feature pyramid network. RFAConv has a 3×3 convolutional kernel and uses Group Conv to extract receptive field features. It aggregates information through AvgPool, performs information interaction through 1×1 group convolution operations, and emphasizes feature importance through softmax. C2f_RFAConv contains two convolutional layers and multiple Bottleneck_RFAConv modules. The Bottleneck_RFAConv module contains two convolutional layers. The first convolutional layer reduces the number of input channels, and the second convolutional layer uses RFAConv for processing and supports shortcut connections.

[0112] In this embodiment, in the detection of pests and diseases on tomato leaves, RFA (Receptive Field Attention) addresses issues such as insufficient receptive field, multi-scale feature fusion, and contextual information capture. By dynamically adjusting the receptive field, it enhances the ability to focus on features at different scales and adaptively extracts contextual information related to the target, thereby improving the accuracy and robustness of detection. RFA can be viewed as a lightweight, plug-and-play module. Its designed convolution operation (RFAConv) combines spatial attention mechanisms with convolution operations, optimizing the working method of the convolution kernel, especially when processing spatial features within the receptive field. RFAConv focuses on spatial features within the receptive field, enabling the network to more effectively understand and process local regions of the image, thereby improving the accuracy of feature extraction. Its designed C2f_RFAConv module, through multi-scale feature fusion, can effectively integrate feature information from different levels, allowing the model to accurately identify pests and diseases even when dealing with complex backgrounds or occlusions.

[0113] Receptive field spatial features refer to the features within the input image region that each convolutional operation can perceive. These features can include basic visual elements such as color, shape, and texture. Receptive field spatial features are specifically designed for the convolution kernel and are dynamically generated based on the kernel size. For example... Figure 8 As shown, a 3×3 convolution kernel is used as an example. In the figure below, "Spatial Feature" refers to the original feature map. "Receptive-Field Spatial Feature" is a feature map transformed from spatial features, composed of non-overlapping sliding windows. Each 3×3 window in the receptive field spatial feature represents a receptive field slider.

[0114] The receptive field attention convolution (RFAConv) has a 3×3 kernel, and its overall structure is as follows: Figure 7 As shown, RFAConv employs a fast method for extracting receptive field spatial features: Group Conv. As mentioned earlier, when using a 3×3 convolution kernel for feature extraction, each 3×3 window represents a receptive field slider in the receptive field spatial features. After extracting the receptive field features using Group Conv, the original features are mapped to new features. This method is fast and efficient.

[0115] For RFAConv, learning attention maps by interacting with receptive field feature information can enhance network performance. However, interacting with each receptive field feature may lead to additional computational overhead. Therefore, to minimize computational overhead and the number of parameters, AvgPool is used to aggregate global information from each receptive field feature. Then, 1×1 group convolution operations are used for information interaction. Finally, softmax is used to emphasize the importance of each feature within the receptive field features. In general, the computation of RFA can be represented as:

[0116] F = Softmax(g l×l (AvgPool(X)))×ReLU(Norm(g k×k (X)))=A rf ×F rf

[0117] In the formula, g l×l and g k×k These represent grouped convolutions of size l×l and k×k, respectively, where l and k represent the kernel size, Norm() represents normalization, X represents the input feature map, and F is derived from attention diagram A. rf With the transformed receptive field spatial features F rf Multiplying them together yields the result.

[0118] C2f_RFAConv comprises two convolutional layers and multiple Bottleneck_RFAConv modules. First, the input undergoes channel expansion through the first convolutional layer, splitting the output into two parts. Then, multiple Bottleneck_RFAConv modules process one part, and finally, all features are concatenated and passed through a second convolutional layer to obtain the final output. This design improves the efficiency and accuracy of feature extraction. The Bottleneck_RFAConv module acts as a bottleneck structure, containing two convolutional layers. The first convolutional layer reduces the number of input channels to the number of hidden channels, while the second convolutional layer uses RFAConv for processing. This module supports shortcut connections; when the number of input and output channels is equal, the input and output can be directly added, thereby enhancing the network's feature representation capabilities.

[0119] To better extract target features, this paper introduces RFA into the target detection network. RFAConv and C2f_RFAConv are specifically integrated into the YOLOv8 backbone structure. In this way, RFA can effectively enhance the network's ability to extract features from targets at different scales and locations, improving the expressive performance of the feature maps.

[0120] The beneficial effects of the above technologies include: introducing the RFA attention mechanism into the feature fusion process of the feature pyramid network enhances the ability to focus on and fuse features at different scales. RFAConv uses 3×3 convolutional kernels and GroupConv to extract receptive field features, improving the speed and efficiency of feature extraction. AvgPool aggregates information, 1×1 group convolutional operations facilitate information interaction, and softmax emphasizes feature importance, optimizing feature processing and attention allocation. C2f_RFAConv contains multiple modules and convolutional layers, improving the efficiency and accuracy of feature extraction and enhancing the network's feature representation capabilities. The design of the Bottleneck_RFAConv module reduces computational overhead and the number of parameters while reducing the number of channels and using RFAConv. Introducing RFA into the YOLOv8 backbone structure improves the ability to extract features from targets at different scales and locations, thereby improving detection accuracy. Addressing issues such as insufficient receptive field, RFA can dynamically adjust the receptive field and adaptively extract contextual information, enhancing detection accuracy and robustness. When dealing with complex backgrounds or occlusions, the C2f_RFAConv module effectively integrates feature information to achieve accurate pest and disease identification. Overall, these improvements make the tomato leaf pest and disease detection model more efficient, accurate, and reliable, contributing to improved effectiveness and practicality of pest and disease detection.

[0121] Example 4:

[0122] Based on Example 2, and using the improved YOLOv8 method for detecting tomato leaf diseases and pests, the Wise IOU formula is as follows:

[0123]

[0124] L WIoU =εR WIoU

[0125] In the formula, R WIoU The degree of overlap between the anchor box and the target box (R) WIoU ∈[1,e), exp() is an exponential function with the natural constant e as the base and the natural constant e has a value of 2.71828, x is the x-coordinate of the center point of the anchor frame, y is the y-coordinate of the center point of the anchor frame, x gt The x-coordinate of the center point of the target bounding box is y. gt W represents the ordinate of the center point of the bounding box. g H is the width of the target bounding box. g L is the height of the target bounding box. WIoU ε is the output loss value of Wise IOU, and ε is a weighting factor (ε∈[0,1], used to significantly reduce its focus on the distance to the center point when the anchor box and the target box are well aligned).

[0126] In this embodiment, to prevent R WIoU This generates a gradient that hinders convergence, causing W to... g H g Separate from the computational graph. Because it effectively eliminates factors that hinder convergence, no new metrics, such as aspect ratio, are introduced.

[0127] In this embodiment, IOU (Intersection over Union) is a commonly used evaluation metric for object detection models, used to measure the degree of overlap between the predicted bounding box and the ground truth bounding box. However, the IOU evaluation results may be biased when dealing with objects of different sizes. For example, when dealing with small objects, even if the predicted bounding box has a high degree of overlap with the ground truth bounding box, the IOU value may be low, which may lead to insufficient attention to small objects during model training.

[0128] Wise IOU (WIoU) is an improved IOU calculation method that considers the shape and size of the bounding box and introduces a weighting factor to balance the evaluation metrics' focus on small and large objects. It aims to improve the generalization ability of object detection models, especially when training data inevitably contains low-quality examples. Traditional geometric metrics (such as distance and aspect ratio) often exacerbate the penalty for low-quality anchor boxes, leading to a decline in the model's generalization performance. Wise IOU, by introducing a distance attention mechanism, can significantly weaken the penalty of geometric metrics when the anchor box and the target box have good overlap, thereby reducing interference with low-quality examples and improving the model's overall generalization ability.

[0129] The beneficial effects of the above techniques are as follows: Introducing Wise IOU into YOLOv8 can better handle the relationship between anchor boxes and target boxes, thereby improving the accuracy and robustness of object detection. Wise IOU combines weighted IOU and traditional IOU, taking into account the distance between anchor boxes and target boxes, which allows the model to reduce penalties when encountering low-quality anchor boxes and avoid negative impacts on training. This design not only improves the detection capability for small objects and complex scenes, but also enhances the overall generalization performance of the model.

[0130] Example 5:

[0131] Based on Example 1, an improved YOLOv8-based method for detecting diseases and pests on tomato leaves is described in S3: This involves configuring training hyperparameters and updating model weights based on the tomato leaf image dataset to obtain a trained improved YOLOv8 model, including:

[0132] The tomato leaf image dataset was divided into training, validation, and test sets based on a partitioning ratio of 8:1:1.

[0133] Data augmentation is performed on the training set to obtain an optimized training set, and the test and validation sets are standardized or normalized to obtain a standard test set and a standard validation set.

[0134] Configure training hyperparameters, set batch size to 32 and iteration count to 300 rounds, and train the improved YOLOv8 model using the optimized training set. In each training iteration, calculate the loss and update the model weights, while monitoring the performance metrics on the standard test set until the latest improved YOLOv8 model is obtained.

[0135] The confusion matrix is ​​plotted by calculating the recognition results of the latest improved YOLOv8 model on the test set and the true labels of the test set. Based on the confusion matrix, the accuracy and loss value of the latest improved YOLOv8 model on the test set are calculated as the model evaluation results of the latest improved YOLOv8 model.

[0136] If the evaluation result of the latest improved YOLOv8 model meets the requirements, the improved YOLOv8 model is considered as a trained improved YOLOv8 model. Otherwise, the latest improved YOLOv8 model is trained and tested until a trained improved YOLOv8 model that meets the requirements is obtained.

[0137] In this embodiment, the confusion matrix is ​​a matrix table used to evaluate the performance of a classification model. In tomato leaf pest and disease detection, it shows the matching between the pest and disease categories predicted by the model and the actual pest and disease categories. The rows of the matrix represent the actual pest and disease categories, the columns represent the pest and disease categories predicted by the model, and each element in the matrix represents the number of samples that are actually of one category but were predicted by the model to be of another category.

[0138] In this embodiment, the model is evaluated with respect to the training set (Train_Accuracy) and the loss value (Train_Loss), and with respect to the test set (Val_Accuracy) and the loss value (Val_Loss).

[0139] The accuracy rate mentioned therein is:

[0140]

[0141] Wherein, TP represents the number of instances correctly classified as positive, that is, the number of instances that are actually positive and classified as positive by the classifier; TN represents the number of instances correctly classified as negative, that is, the number of instances that are actually negative and classified as negative by the classifier; FP represents the number of instances incorrectly classified as positive, that is, the number of instances that are actually negative but classified as positive by the classifier; and FN represents the number of instances incorrectly classified as negative, that is, the number of instances that are actually positive but classified as negative by the classifier.

[0142] The loss value mentioned above is:

[0143]

[0144] In the formula, N is the total number of samples, i represents one of the output samples, and y i It is the actual value, x i It is the predicted value, and ln is the logarithmic function with the natural constant e as the base.

[0145] In this embodiment, the network structure of YOLOv8 can be replaced with a weighted bidirectional feature pyramid network (WBFPN) to achieve multi-scale feature extraction and fusion, thereby improving the detection accuracy of the model.

[0146] In this embodiment, data augmentation is performed on the training set to obtain an optimized training set, and standardization or normalization is performed on the test and validation sets to obtain standard test and validation sets. By applying data augmentation techniques such as flipping, rotating, and cropping to the training set, the diversity and richness of the data are increased, thus obtaining an optimized training set. Simultaneously, standardization or normalization is performed on the test and validation sets, mapping the feature values ​​of the data to a specific range or distribution to obtain standard test and validation sets, making the data comparable and consistent across different dimensions. For example, for tomato leaf images in the training set, random horizontal flipping, rotation at a certain angle, and random cropping of some areas are performed to expand the training data. The image pixel values ​​in the test and validation sets are standardized so that their mean is 0 and their variance is 1.

[0147] In this embodiment, training hyperparameters are configured: these are parameters used to control the training process and affect model performance during model training. These parameters include, but are not limited to, batch size, number of iterations, and learning rate. For example, the batch size is set to 32, the number of iterations is set to 300 rounds, and the initial learning rate is set to 0.01, which is then adjusted according to a certain strategy during training.

[0148] In this embodiment, the loss is calculated and the model weights are updated, while performance metrics on the standard test set are monitored until the latest improved YOLOv8 model is obtained: In each training iteration, the loss value is calculated based on the prediction results and the true labels, and then the model's weight parameters are updated according to the loss value using a specific optimization algorithm. Simultaneously, performance metrics on the standard test set, such as accuracy and recall, are continuously monitored, and the model is continuously optimized until the currently trained improved YOLOv8 model is obtained. For example: in each iteration, the cross-entropy loss is calculated, and the weights are updated using the stochastic gradient descent algorithm. Every 10 rounds, the accuracy is calculated on the standard test set; if the accuracy continues to rise, training continues; otherwise, training stops and the current model is saved.

[0149] In this embodiment, the true label of the test set refers to the actual pest or disease category corresponding to each tomato leaf image in the test set. For example, for a certain tomato leaf image in the test set, its true label is "infected with black spot disease".

[0150] The beneficial effects of the above techniques are as follows: Dividing the tomato leaf image dataset proportionally provides a clear and reasonable allocation of datasets for model training, validation, and testing. Data augmentation of the training set increases data diversity, which helps improve the model's generalization ability. Standardization or normalization of the test and validation sets ensures data consistency and comparability. Configuring appropriate training hyperparameters, such as batch size and number of iterations, improves training efficiency and effectiveness. Calculating loss and updating model weights during training continuously optimizes model performance. Evaluating the model by plotting a confusion matrix and calculating accuracy and loss values ​​provides a comprehensive and intuitive metric for model performance. Determining whether the model meets the requirements based on the evaluation results ensures that the final optimal model has good performance.

[0151] Example 6:

[0152] Based on Example 1, a method for detecting tomato leaf diseases and pests based on an improved YOLOv8 model is described in S4: The improved YOLOv8 model is used to detect diseases and pests in the tomato leaf image to be detected, obtaining the detection results, including:

[0153] The tomato leaf image to be detected is subjected to first-level super-resolution reconstruction and divided into S×S grids. Each grid is input into the trained improved YOLOv8 model to predict B bounding boxes in each grid and calculate the center coordinates, width and height of each bounding box.

[0154] x=σ(t x )+c x

[0155] y=σ(t y)+c y

[0156]

[0157] In the formula, x is the x-coordinate of the center of the bounding box, y is the y-coordinate of the center of the bounding box, σ() is the sigmoid function, and t x t represents the lateral offset of the bounding box center relative to its grid cell. y c is the vertical offset of the bounding box center relative to its grid. x c is the x-coordinate of the center point of the grid corresponding to the currently calculated bounding box. y Here is the ordinate of the center point of the grid corresponding to the currently calculated bounding box, w is the width of the bounding box, and p is the center point of the grid. w Let be the width of the prior bounding box, e be the natural constant with a value of 2.71828, and t be the width of the prior bounding box. w The relative change in the width of the bounding box is given by p, where h is the height of the bounding box and p is the height of the bounding box. h Let t be the height of the prior bounding box. h This represents the relative adjustment amount for the bounding box height;

[0158] The intersection-over-union (IoU) ratio between the predicted and ground truth bounding boxes is determined based on the center coordinates, width, and height of each bounding box, and the confidence level of each bounding box is calculated based on the IoU ratio.

[0159] C = P(object) · IoU truth

[0160] In the formula, C represents the confidence level of the bounding box, and IoU... truth This is the intersection-union ratio between the predicted bounding box and the ground truth bounding box;

[0161] The final target bounding box is selected based on the non-maximum suppression (NMS) algorithm;

[0162] Based on the confidence level, the probability distribution of each target bounding box for each type of pest or disease is predicted:

[0163]

[0164] In the formula, P(i|box) is the probability of the target bounding box for the i-th type of pest or disease, e is the natural constant with a value of 2.71828, and z i z is the original prediction score of the target bounding box for the i-th type of pest or disease. j Let C be the original prediction score of the target bounding box for the j-th type of pest or disease, and C be the total number of pest or disease types.

[0165] Based on the probability distribution of all target bounding boxes in all grids of the tomato leaf image to be detected for each type of pest or disease, the pest and disease detection results of the tomato leaf image to be detected are obtained.

[0166] In this embodiment, YOLOv8 uses the Non-Maximum Suppression (NMS) algorithm to filter the final target bounding boxes. The NMS process removes boxes with excessive overlap with high-confidence boxes by setting a threshold, ensuring that the final output bounding boxes are unique and have the highest confidence. Through these steps, YOLOv8 can efficiently process feature maps for target classification and localization, thereby achieving accurate target detection in various complex scenarios.

[0167] In this embodiment, a first-level super-resolution reconstruction process is performed on the tomato leaf image to be detected: using a specific algorithm or technique, an initial super-resolution reconstruction operation is performed on the tomato leaf image with pests and diseases to be detected, aiming to improve the image's clarity and detail for more accurate subsequent pest and disease detection. For example, using a deep learning-based super-resolution reconstruction algorithm, the original resolution of the tomato leaf image to be detected (640×480) is improved to a clarity of 1280×960.

[0168] In this embodiment, the intersection-union ratio (IUR) between the predicted and ground truth bounding boxes is determined based on the center coordinates, width, and height of each bounding box. Using the calculated center coordinates, width, and height of each predicted bounding box, and the corresponding parameters of the known ground truth bounding boxes (i.e., the actually labeled boxes), a specific mathematical formula or calculation method is used to derive the overlap ratio between the predicted and ground truth bounding boxes. For example, assuming the center coordinates of the predicted bounding box are (100, 100), the width is 50, and the height is 50, while the center coordinates of the ground truth bounding box are (80, 80), the width is 60, and the height is 60, the IUR is calculated to be 0.6.

[0169] The beneficial effects of the above techniques include: performing first-level super-resolution reconstruction on the tomato leaf images to be detected, improving image quality and detail, and helping the model to detect pests and diseases more accurately. Dividing the image into a grid and inputting it into a trained improved YOLOv8 model for prediction allows for more refined analysis of different regions of the image. Calculating the center coordinates, width, and height of the bounding boxes using explicit mathematical formulas makes the determination of the bounding boxes more accurate and scientific. Calculating the confidence of the bounding boxes based on the intersection-over-union ratio (IoU) effectively measures the reliability of the bounding boxes. Using the non-maximum suppression (NMS) algorithm to filter out the final target bounding boxes reduces duplicate and redundant detection boxes, improving detection accuracy. Predicting the probability distribution of the target bounding boxes for each type of pest and disease based on the confidence score provides a quantitative basis for pest and disease classification. Finally, obtaining the detection results based on the probability distribution of the target bounding boxes in all grids makes the detection results more comprehensive and reliable. These steps and calculation methods improve the accuracy, precision, and reliability of tomato leaf pest and disease detection, helping to promptly detect and address pest and disease problems.

[0170] Example 7:

[0171] Based on Example 6, the tomato leaf disease and pest detection method based on the improved YOLOv8 obtains the disease and pest detection results of the tomato leaf image based on the probability distribution of all target bounding boxes in all grids of the tomato leaf image for each disease and pest type, including:

[0172] Based on the probability distribution of all target bounding boxes in all grids of the tomato leaf image to be detected for each type of pest and disease, pest and disease detection annotation is performed on the tomato leaf to be detected, and the non-minimal target pest and disease detection annotation results and the minimal target pest and disease detection fine annotation results of the tomato leaf image to be detected are obtained.

[0173] Based on the non-minimal target pest and disease detection annotation results and the minimal target pest and disease detection fine annotation results of the tomato leaf image to be detected, the pest and disease detection results of the tomato leaf image to be detected are obtained.

[0174] In this embodiment, pest and disease detection annotation is performed on the tomato leaf image to be detected based on the probability distribution of all target bounding boxes in all grids for each type of pest and disease. This yields the non-minimum target pest and disease detection annotation results and the fine annotation results for minimum target pest and disease detection in the tomato leaf image. The annotation process is performed on the leaf based on the probability distribution of each target bounding box corresponding to each type of pest and disease in all grids of the tomato leaf image. During this process, the following results are obtained: non-minimum target pest and disease detection annotation results (annotations of relatively obvious or large-area pest and disease areas); and fine annotation results for minimum target pest and disease detection (more detailed and accurate annotations for smaller or less obvious pest and disease areas). For example, for a tomato leaf image to be detected, after analyzing the pest and disease probability distribution of the target bounding boxes in its grid, the large black spot disease area on the leaf is annotated (non-minimum target pest and disease detection annotation result), and the very small spot disease area at the leaf edge is also finely annotated (minimum target pest and disease detection fine annotation result).

[0175] The beneficial effects of the above technology are as follows: By using probability distribution to label tomato leaves for pest and disease detection, the type and location of pests and diseases can be intuitively displayed. Distinguishing between the labeling results for non-minimally small and extremely small targets makes the detection results more detailed and comprehensive. Integrating the labeling results for both non-minimally small and extremely small targets to obtain the final pest and disease detection result improves the accuracy and completeness of the detection. It can more accurately identify pests and diseases of different sizes, providing more targeted guidance for subsequent control measures. This step-by-step labeling and integration method effectively improves the effectiveness and practical value of tomato leaf pest and disease detection.

[0176] Example 8:

[0177] Based on Example 7, and using an improved YOLOv8-based method for detecting pests and diseases in tomato leaves, the pest and disease detection results for the tomato leaf images are obtained based on the non-minimal target pest and disease detection annotation results and the minimal target pest and disease fine annotation results. These results include:

[0178] Based on the non-minimal target pest and disease detection annotation results and the minimal target pest and disease detection fine annotation results of the tomato leaf image to be detected, the pest and disease detection evaluation value of the tomato leaf image to be detected is obtained.

[0179] Based on the pest and disease detection evaluation value of the tomato leaf image to be detected, the pest and disease detection results of the tomato leaf image to be detected are obtained.

[0180] In this embodiment, the pest and disease detection evaluation value of the tomato leaf image to be detected is calculated: Using a specific calculation method and based on the coordinate information of the minimum and non-minimum target pest and disease detection boxes in the tomato leaf image, a numerical value is obtained to measure the effectiveness and accuracy of pest and disease detection in the tomato leaf image. For example, considering the coordinate information such as the distance and distribution between each minimum and non-minimum target pest and disease detection box in the tomato leaf image, after a series of calculations, an evaluation value between 0 and 1 is obtained, such as 0.8, indicating that the pest and disease detection of the image has high accuracy and reliability.

[0181] The beneficial effects of the above technology are as follows: By calculating the pest and disease detection evaluation value through the detection and labeling results of non-minimal and minimal targets, the detection results can be quantitatively evaluated. Obtaining pest and disease detection results based on the evaluation value makes the results more objective and reliable. This quantitative evaluation method helps to accurately judge the quality of the detection results. It can provide a clear basis for subsequent improvement and optimization of detection methods. It improves the scientific rigor and credibility of tomato leaf pest and disease detection results.

[0182] Example 9:

[0183] Based on Example 8, and using an improved YOLOv8-based method for detecting pests and diseases in tomato leaves, the method calculates the pest and disease detection evaluation value of the tomato leaf image based on the coordinate information of all minimal pest and disease detection boxes and all non-minimal pest and disease detection boxes in the corresponding clean annotation results of the super-resolution image of the tomato leaf to be detected. This evaluation value includes:

[0184] Based on the coordinate information of all the minimum target pest detection boxes in the super-resolution image of the tomato leaf to be detected and all the non-minimum target pest detection boxes in the corresponding clean annotation results of the non-minimum target pest detection, the shortest distance between each minimum target pest detection box and each corresponding non-minimum target pest detection box in the super-resolution image of the tomato leaf to be detected is determined.

[0185] Based on the shortest distance between each minimum target pest detection box and its corresponding non-minimum target pest detection box in the super-resolution image of the tomato leaf to be detected, the pest detection evaluation value of the tomato leaf image to be detected is calculated:

[0186]

[0187] In the formula, P is the pest and disease detection evaluation value of the tomato leaf image to be detected, n is the total number of minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected, m is the total number of non-minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected, and max(n,m) is the maximum value between the total number of minimum target pest and disease detection boxes and the total number of non-minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected. m To determine the standard similarity between the total number of detection frames for extremely small target pests and diseases and the total number of detection frames for non-extremely small target pests and diseases, l ij P represents the shortest distance between the i-th minimal target pest detection box and the j-th non-minimal target pest detection box. l The similarity between the standard distribution of all minimal target pest detection frames and all non-minimal target pest detection frames.

[0188] In this embodiment, the standard similarity between the total number of detection frames for extremely small pests and diseases and the total number of detection frames for non-extremely small pests and diseases is a standard measure used to measure how close the total number of detection frames for extremely small pests and diseases and the total number of detection frames for non-extremely small pests and diseases are. For example, the standard similarity might be calculated as 0.71 using a specific formula.

[0189] In this embodiment, the similarity to the standard distribution of all minimal target pest detection boxes and all non-minimal target pest detection boxes is defined as a standard index that assesses the similarity or proximity in spatial distribution between all minimal target pest detection boxes and all non-minimal target pest detection boxes. For example, the similarity to the standard distribution might be calculated as 0.73 using a specific formula.

[0190] The beneficial effects of the above technologies include: by determining the shortest distance between detection frames for extremely small and non-extremely small targets, the positional relationship between the two can be precisely measured. Calculating the pest and disease detection evaluation value based on the shortest distance provides a quantitative and accurate evaluation index for detection effectiveness. Considering the total number of detection frames for both extremely small and non-extremely small targets, as well as the similarity in their distribution, makes the evaluation more comprehensive and integrated. The calculation method of this evaluation value is scientific and reasonable, objectively reflecting the accuracy and consistency of the detection method for detecting pests and diseases of different sizes. It helps to identify potential problems in the detection process, providing a strong basis for further optimization of the detection model and method. It improves the accuracy and reliability of pest and disease detection evaluation on tomato leaves, contributing to the enhancement of the performance and application value of the detection technology.

[0191] Example 10:

[0192] Based on Example 8, an improved YOLOv8-based method for detecting pests and diseases in tomato leaves is used to obtain pest and disease detection results for the tomato leaf images based on pest and disease detection evaluation values. These results include:

[0193] If the pest and disease detection evaluation value of the tomato leaf image to be detected is not less than the preset evaluation threshold, then all the minimum target pest and disease detection boxes and all the non-minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected will be marked to obtain the pest and disease detection result of the tomato leaf image to be detected.

[0194] If the pest and disease detection evaluation value of the tomato leaf image to be detected is less than the preset evaluation threshold, then the tomato leaf image to be detected will undergo second-level super-resolution reconstruction processing and pest and disease detection until the latest obtained evaluation value of the smallest target pest and disease detection is not less than the preset evaluation threshold. Then, all the smallest target pest and disease detection boxes and all the non-smallest target pest and disease detection boxes in the latest obtained super-resolution image of the tomato leaf to be detected will be labeled to obtain the pest and disease detection result of the tomato leaf image to be detected.

[0195] In this embodiment, a preset evaluation threshold is a pre-defined numerical limit used to determine whether the pest and disease detection evaluation value of the tomato leaf image to be tested is qualified or meets specific requirements. For example, if the preset evaluation threshold is set to 0.8, and the calculated pest and disease detection evaluation value of the tomato leaf image to be tested is greater than or equal to 0.8, the detection result is considered qualified; if it is less than 0.8, it is considered unqualified.

[0196] In this embodiment, a second-level super-resolution reconstruction process is performed on the tomato leaf image to be detected: a higher degree or different method of super-resolution reconstruction is performed on the tomato leaf image with pests and diseases to be detected, in order to further improve the image quality and potentially obtain more accurate detection results. For example, the first-level super-resolution reconstruction may increase the image resolution by two times, while the second-level super-resolution reconstruction may increase it by four times, or use a more complex algorithm for processing.

[0197] The beneficial effects of the above technology are as follows: When the evaluation value is not less than the preset threshold, the detection box is directly marked to obtain the detection result, ensuring the reliability and validity of the detection result. For cases where the evaluation value is less than the threshold, a second-level super-resolution reconstruction and re-detection are performed, improving the accuracy and completeness of the detection. Using a preset evaluation threshold to determine the usability of the detection result provides a clear standard for detection quality. This flexible approach based on the evaluation value ensures the accuracy and reliability of the final pest and disease detection results to the greatest extent possible. It effectively improves the accuracy and reliability of tomato leaf pest and disease detection, providing strong support for pest and disease control in tomato cultivation.

[0198] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.

Claims

1. A method for detecting diseases and pests on tomato leaves based on an improved YOLOv8, characterized in that, include: S1: Construct a dataset of tomato leaf images containing each type of pest and disease; S2: By integrating GhostNet and RFA attention mechanisms and modifying the loss function to Wise IOU, an improved YOLOv8 model is constructed. S3: Configure training hyperparameters and update model weights based on tomato leaf image dataset to obtain a well-trained improved YOLOv8 model; S4: Perform first-level super-resolution reconstruction on the tomato leaf image to be detected and divide it into S×S grids. Input each grid into the trained improved YOLOv8 model to predict B bounding boxes in each grid and calculate the center coordinates, width, and height of each bounding box. ; ; ; ; In the formula, This represents the x-coordinate of the center of the bounding box. The ordinate value of the center coordinate of the bounding box. For the sigmoid function, This represents the lateral offset of the bounding box center relative to its grid cell. This represents the vertical offset of the bounding box center relative to its grid cell. This represents the x-coordinate of the center point of the grid corresponding to the currently calculated bounding box. This represents the ordinate of the center point of the grid corresponding to the currently calculated bounding box. The width of the bounding box. The width of the prior bounding box. It is a natural constant with a value of 2.71828. This represents the relative change in the width of the bounding box. The height of the bounding box. The height of the prior bounding box. This represents the relative adjustment amount for the bounding box height; The intersection-over-union (IoU) ratio between the predicted and ground truth bounding boxes is determined based on the center coordinates, width, and height of each bounding box, and the confidence level of each bounding box is calculated based on the IoU ratio. ; In the formula, The confidence level of the bounding box. This is the intersection-union ratio between the predicted bounding box and the ground truth bounding box; The final target bounding box is selected based on the nonmaximum suppression algorithm; Based on the confidence level, the probability distribution of each target bounding box for each type of pest or disease is predicted: ; In the formula, For the target bounding box for the first The probability of a certain type of disease or pest. It is a natural constant with a value of 2.71828. For the target bounding box for the first The original predicted scores for each type of disease and pest. For the target bounding box for the first The original predicted scores for each type of disease and pest. The total number of pest and disease types; Based on the probability distribution of all target bounding boxes in all grids of the tomato leaf image to be detected for each type of pest and disease, pest and disease detection annotation is performed on the tomato leaf to be detected, and the non-minimal target pest and disease detection annotation results and the minimal target pest and disease detection fine annotation results of the tomato leaf image to be detected are obtained. Based on the coordinate information of all the minimum target pest detection boxes in the super-resolution image of the tomato leaf to be detected and all the non-minimum target pest detection boxes in the corresponding clean annotation results of the non-minimum target pest detection, the shortest distance between each minimum target pest detection box and each corresponding non-minimum target pest detection box in the super-resolution image of the tomato leaf to be detected is determined. Based on the shortest distance between each minimum target pest detection box and its corresponding non-minimum target pest detection box in the super-resolution image of the tomato leaf to be detected, the pest detection evaluation value of the tomato leaf image to be detected is calculated: ; In the formula, The values ​​represent the pest and disease detection assessment values ​​for the tomato leaf images to be tested. This represents the total number of detection boxes for extremely small pests and diseases contained in the super-resolution image of the tomato leaf to be detected. This represents the total number of non-minimal target pest and disease detection boxes contained in the super-resolution image of the tomato leaf to be detected. The maximum value between the total number of detection boxes for extremely small pests and diseases in the super-resolution image of the tomato leaf to be detected and the total number of detection boxes for non-extremely small pests and diseases in the super-resolution image of the tomato leaf to be detected. The similarity to the standard between the total number of detection frames for extremely small target pests and diseases and the total number of detection frames for non-extremely small target pests and diseases. For the first The detection frame for extremely small target pests and diseases and the first The shortest distance between detection frames for non-minimal target pests and diseases. The similarity between the standard distribution of all detection frames for extremely small pests and diseases and all detection frames for non-extremely small pests and diseases; Based on the pest and disease detection evaluation value of the tomato leaf image to be detected, the pest and disease detection results of the tomato leaf image to be detected are obtained.

2. The method for detecting tomato leaf diseases and pests based on improved YOLOv8 according to claim 1, characterized in that, S2: Integrating GhostNet and RFA attention mechanisms, and modifying the loss function to Wise IOU, an improved YOLOv8 model is constructed, including: By loading pre-trained weights from YOLOv8, integrating the RFA attention mechanism into the YOLOv8 feature extraction network, replacing the traditional convolution in the neck structure with GhostConv, replacing the feature fusion module in the neck structure with C2fGhost, and replacing the loss function with Wise IOU, an improved YOLOv8 model is constructed.

3. The method for detecting tomato leaf diseases and pests based on improved YOLOv8 according to claim 2, characterized in that, Integrating the RFA attention mechanism into the YOLOv8 feature extraction network includes: The RFA attention mechanism is introduced during the feature fusion process of the feature pyramid network. RFAConv has a 3×3 convolutional kernel and uses Group Conv to extract receptive field features. It aggregates information through AvgPool, performs information interaction through 1×1 group convolution operations, and emphasizes feature importance through softmax. C2f_RFAConv contains two convolutional layers and multiple Bottleneck_RFAConv modules. The Bottleneck_RFAConv module contains two convolutional layers. The first convolutional layer reduces the number of input channels, and the second convolutional layer uses RFAConv for processing and supports shortcut connections.

4. The method for detecting tomato leaf diseases and pests based on improved YOLOv8 according to claim 2, characterized in that, The formula for Wise IOU is: ; ; In the formula, This refers to the degree of overlap between the anchor box and the target box. It is an exponential function with the natural constant e as its base, and the natural constant e has a value of 2.71828. The x-coordinate of the center point of the anchor frame. The ordinate of the center point of the anchor frame. The x-coordinate of the center point of the target bounding box. The ordinate of the center point of the target bounding box. The width of the target box. The height of the target bounding box. This is the output loss value of Wise IOU. This is the weighting factor.

5. The method for detecting tomato leaf diseases and pests based on improved YOLOv8 according to claim 1, characterized in that, S3: Configure training hyperparameters and update model weights based on the tomato leaf image dataset to obtain a trained, improved YOLOv8 model, including: The tomato leaf image dataset was divided into training, validation, and test sets based on a partitioning ratio of 8:1:

1. Data augmentation is performed on the training set to obtain an optimized training set, and the test and validation sets are standardized or normalized to obtain a standard test set and a standard validation set. Configure training hyperparameters, set batch size to 32 and iteration count to 300 rounds, and train the improved YOLOv8 model using the optimized training set. In each training iteration, calculate the loss and update the model weights, while monitoring the performance metrics on the standard test set until the latest improved YOLOv8 model is obtained. The confusion matrix is ​​plotted by calculating the recognition results of the latest improved YOLOv8 model on the test set and the true labels of the test set. Based on the confusion matrix, the accuracy and loss value of the latest improved YOLOv8 model on the test set are calculated as the model evaluation results of the latest improved YOLOv8 model. If the evaluation result of the latest improved YOLOv8 model meets the requirements, the improved YOLOv8 model is considered as a trained improved YOLOv8 model. Otherwise, the latest improved YOLOv8 model is trained and tested until a trained improved YOLOv8 model that meets the requirements is obtained.

6. The method for detecting tomato leaf diseases and pests based on improved YOLOv8 according to claim 1, characterized in that, Based on the pest and disease detection evaluation values ​​of the tomato leaf images to be detected, the pest and disease detection results of the tomato leaf images to be detected are obtained, including: If the pest and disease detection evaluation value of the tomato leaf image to be detected is not less than the preset evaluation threshold, then all the minimum target pest and disease detection boxes and all the non-minimum target pest and disease detection boxes in the super-resolution image of the tomato leaf to be detected will be marked to obtain the pest and disease detection result of the tomato leaf image to be detected. If the pest and disease detection evaluation value of the tomato leaf image to be detected is less than the preset evaluation threshold, then the tomato leaf image to be detected will undergo second-level super-resolution reconstruction processing and pest and disease detection until the latest obtained evaluation value of the smallest target pest and disease detection is not less than the preset evaluation threshold. Then, all the smallest target pest and disease detection boxes and all the non-smallest target pest and disease detection boxes in the latest obtained super-resolution image of the tomato leaf to be detected will be labeled to obtain the pest and disease detection result of the tomato leaf image to be detected.