An apple leaf disease detection method based on an improved YOLOX-S algorithm
By improving the YOLOX-S algorithm, embedding the ODCSP structure, and introducing ASFF feature fusion, the loss function was optimized to Focalloss, which solved the problem of low detection accuracy of apple leaf diseases and achieved efficient and accurate disease detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-06
- Publication Date
- 2026-03-10
AI Technical Summary
Existing apple leaf disease detection algorithms are not accurate and perform poorly, making it difficult to meet the needs of efficient detection.
The YOLOX-S algorithm is improved by replacing the CSP structure of the backbone network and the feature fusion network with the ODCSP structure embedded with ODConv, and ASFF is introduced for feature fusion. The loss function is optimized to Focalloss, which improves detection accuracy and reduces computation.
It improves the accuracy and performance of apple leaf disease detection, reduces the number of model parameters and computational load, improves feature inconsistency and label category imbalance, and enhances detection results.
Smart Images

Figure CN116363517B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer vision target detection, and particularly relates to an apple leaf disease detection method based on an improved YOLOX-S algorithm. BACKGROUND
[0002] There are many studies on apple leaf disease detection at home and abroad. With the rapid development of target detection technology, there are mainly two types of algorithms in the field of target detection, one is the one-stage YOLO series algorithm and SSD algorithm, and the other is the two-stage R-CNN algorithm. The emergence of these algorithms effectively improves the precision, accuracy and speed of plant disease detection. However, the current apple leaf disease detection algorithm has the problems of low precision and poor performance, so under this condition, it is of great significance to develop a high-performance and high-precision target detection algorithm to improve the yield and quality of apples and even promote the development of agricultural modernization and intelligence. SUMMARY
[0003] Therefore, the present application aims to provide an apple leaf disease detection method based on an improved YOLOX-S algorithm to solve the problems of low precision and poor performance of the existing apple leaf disease detection algorithm.
[0004] In order to achieve the above purpose, the present application provides an apple leaf disease detection method based on an improved YOLOX-S algorithm, which comprises the following steps:
[0005] Step one, obtain the apple leaf disease public dataset, and pretreat the public dataset;
[0006] Step two, for the main network CSPDarknet and the neck feature fusion network PAFPN of the single-stage target detection model YOLOX-S, use the dynamic cross-stage local network structure (ODCSP) embedded with ODConv (full-dimensional dynamic convolution) to replace all cross-stage local networks (CSP) of the main network and the feature fusion network of the YOLOX-S model, to obtain a locally improved single-stage target detection model;
[0007] Step three, for the locally improved single-stage target detection model, introduce ASFF (adaptive feature fusion method) to fuse features of different feature scales on the basis of the feature pyramid structure PAFPN, to obtain an improved single-stage target detection model;
[0008] Step four, optimize the loss function of the improved single-stage target detection model according to the actual dataset, to obtain an optimized single-stage target detection model;
[0009] Step five, train the optimized single-stage target detection model;
[0010] Step 6: Use the trained model to detect diseased apple leaves and obtain information on the type and location of the disease.
[0011] Preferably, in step one, the public dataset includes the FGVC8 apple leaf disease public dataset downloaded from the Kaggle competition and the apple leaf pathology dataset downloaded from Baidu PaddlePaddle.
[0012] Preferably, in step one, the preprocessing includes labeling the public dataset, performing data augmentation by adjusting contrast, flipping vertically, flipping horizontally, and adjusting chroma, and dividing the dataset into training and test sets in an 8:2 ratio.
[0013] Preferably, in step two, replacing all cross-stage local networks of the YOLOX-S model backbone network and feature fusion network with a dynamic cross-stage local network structure of full-dimensional dynamic convolution specifically includes:
[0014] Replace all CSP1_X and CSP2_X structures of the YOLOX-S model backbone network and feature fusion network with ODCSP1_X and ODCSP2_X structures that embed ODConv. Both ODCSP1_X and ODCSP2_X structures include two branches. After the input information enters the ODCSP1_X structure, one branch is processed by ODConv and the residual structure, and then concatenates with another branch processed by ODConv before being processed by ODConv again. After the input information enters the ODCSP2_X structure, one branch is processed by ODConv and the base convolution BaseConv, and then concatenates with another branch processed by ODConv before being processed by ODConv again.
[0015] Preferably, in step three, the adaptive fusion method includes identical scaling of the feature map and adaptive fusion of the features.
[0016] Preferably, in step four, the loss function of the optimized and improved single-stage target detection model includes:
[0017] Focalloss is introduced to replace the confidence loss in the total model loss with BCEWithLogits Loss (binary cross-entropy loss).
[0018] Preferably, training the optimized single-stage object detection model includes:
[0019] Step S51, YOLOX-S model selection;
[0020] Step S52: Initialize YOLOX-S model parameters.
[0021] Preferably, the YOLOX-S model selection includes:
[0022] Modify the configuration file to set the network depth to 0.33 and the network width to 0.5.
[0023] Preferably, the initialization of YOLOX-S model parameters includes:
[0024] SILU was chosen as the activation function, with a weight decay coefficient of 0.0005, Epoch set to 300, and Mosaic augmentation metric set to (0.5, 1.5). Mixup augmentation was disabled, and Mosaic data augmentation was disabled in the last 100 training epochs.
[0025] The beneficial effects of this invention are:
[0026] 1. Increase the detection accuracy of the model and reduce the number of parameters and computational cost: This invention improves the backbone network and neck feature fusion network of YOLOX, and proposes an ODCSP structure that embeds ODConv to replace the original CSP structure of the backbone network and neck feature fusion network, thereby improving the detection accuracy of the model and greatly reducing the additional parameters and computational cost introduced into the model.
[0027] 2. Improves the impact of inconsistency between features at different scales in the YOLOX model feature pyramid: This invention introduces ASFF to solve the impact of inconsistency between feature maps at different scales in the feature pyramid, reduces the inference overhead required for computation, and improves the problem of feature information loss of targets at different scales, thereby improving the average accuracy of the model.
[0028] 3. Improved label class imbalance problem: This invention replaces the confidence loss with BCEWithLogits Loss in the loss function with Focal loss, thereby improving the impact of the imbalance in the number of label classes in the dataset and enabling the model to have better performance.
[0029] 4. When compared with other commonly used target detection algorithms on apple leaf disease datasets, this invention also shows excellent detection performance. Attached Figure Description
[0030] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only for this invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1This is a schematic diagram of the process of the present invention;
[0032] Figure 2 This is a structural diagram of the YOLOX-S of the present invention;
[0033] Figure 3 This is a schematic diagram of the improved ODCSP1_X and ODCSP2_X structures of the present invention;
[0034] Figure 4 This is a schematic diagram illustrating the principle of dynamic convolution ODConv in this invention;
[0035] Figure 5 This is a schematic diagram illustrating the principle of the adaptive feature fusion method ASFF of the present invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments.
[0037] like Figure 1 As shown in the embodiments of this specification, a method for detecting apple leaf diseases based on the improved YOLOX-S algorithm is provided, including the following steps:
[0038] Step 1: Obtain a public dataset of apple leaf diseases and preprocess the public dataset;
[0039] First, the FGVC8 apple leaf disease public dataset was downloaded from the Kaggle competition. However, this dataset only included apple rust, gray spot, powdery mildew, and black spot, lacking another common apple leaf disease: apple leaf mosaic. Therefore, the Baidu Pulse image dataset of apple leaf pathology was also used. A total of 2381 images were collected: 556 for gray spot, 375 for mosaic, 480 for powdery mildew, 182 for early-stage powdery mildew, 445 for rust, and 343 for black spot. Since the number of images for early-stage powdery mildew, mosaic, and black spot was still insufficient, this invention further crawled images of black spot, mosaic, and early-stage powdery mildew from the internet, expanding the mosaic to 494 images, the early-stage powdery mildew to 390 images, and the black spot to 420 images, bringing the total to 2785 images. However, the dataset was still insufficient. This invention augmented the dataset by adjusting contrast, flipping vertically, rotating horizontally, and adjusting color, increasing the number of images for each disease by six times, bringing the total to 16,710 images. Finally, the dataset was divided into training and testing sets in an 8:2 ratio.
[0040] Step 2: For the backbone network CSPDarknet and neck feature fusion network PAFPN of the single-stage object detection model YOLOX-S, replace all cross-stage local networks (CSP) of the YOLOX-S model backbone network and feature fusion network with a dynamic cross-stage local network structure (ODCSP) embedded with ODConv (full-dimensional dynamic convolution) to obtain a locally improved single-stage object detection model.
[0041] The YOLOX model mainly consists of four parts: input, backbone, neck, and head. Figure 2 As shown in (a). Figure 2 (b) Specific Composition Principles of Each Structure. The network structure mainly consists of a CBL structure including BaseConv and DWConv basic convolutions, a CSP structure including CSP1_X and CSP2_X, and an SPP structure. At the input of YOLOX, Mosaic and Mixup are combined to enhance the dataset and prevent severe overfitting. The backbone network of YOLOX is CSPDarkent53, which mainly consists of five parts: Focus, Dark2, Dark3, Dark4, and Dark5. The neck network uses a Path Aggregation Network (PAN) structure + a Feature Pyramid Network (FPN) structure. The detection layer separates regression and classification into two parts through a decoupling head, integrating them during prediction, thus improving the convergence speed and accuracy of the algorithm. Compared with other YOLO series algorithms, the YOLOX algorithm has faster detection speed, higher accuracy, and higher model generalization ability.
[0042] There are two types of CSP structures in the YOLOX-S network: CSP1_X and CSP2_X, as shown below. Figure 2(b) is illustrated in parts VII and VIII. The principle is to divide the input into two branches. One branch propagates the input information backward through a residual module like CSP1_X or a feature extraction module based on the basic convolution in CSP2_X. The other branch, after halving the number of input channels through a cross-stage hierarchical structure, directly merges it with the output of the feature extraction module, thus achieving richer gradient combinations. Since a deeper backbone network is prone to information loss during convolution, CSP1_X with residuals is mainly applied to the backbone feature extraction network to reduce the loss of input information during convolution. CSP2_X is applied to the tail and neck feature fusion networks of the backbone feature extraction network. Because the CSP1_X and CSP2_X structures in this model use the same network structure and parameters for all input data, but the inputs at different locations are different, the feature extraction and information capture capabilities cannot reach their optimal state when processing these inputs, and there are still many redundant parameters and computational overhead. To address this, this invention replaces all CSP1_X and CSP2_X structures in the backbone and feature fusion networks of the YOLOX-S model with ODCSP1_X and ODCSP2_X structures embedded with full-dimensional dynamic convolutions. This improves the flexibility of the CSP structure, enhances the feature extraction capability of CSP1_X and the information capture capability of CSP2_X, and reduces unnecessary parameters. The improved ODCSP structure is shown below. Figure 3 (a) and Figure 3 As shown in (b), the structures of ODCSP1_X and ODCSP2_X both include two branches. After the input information enters the ODCSP1_X structure, one branch is processed by ODConv and the residual structure, and then concatenates with another branch processed by ODConv before being processed by ODConv again. After the input information enters the ODCSP2_X structure, one branch is processed by ODConv and the base convolution BaseConv, and then concatenates with another branch processed by ODConv before being processed by ODConv again.
[0043] As one implementation method, the principle of ODConv is as follows: Figure 4 As shown, x represents the input, y represents the output, GAP represents global average pooling, FC represents fully connected, and ReLU represents the rectified linear activation function. W i α represents the convolution kernel. s Branching represents adding a weight scalar in space (the spatial location of the squared size of the convolution kernel). α c The branch represents adding a weight scalar to each input channel. α f Branching represents adding a weight scalar to each output channel (the entire filter). α wThe branch represents adding weight scalars to all convolutional kernels. These four weight scalars are α. s ,α c ,a f ,α w The specific calculation process is as follows: First, the input x is compressed into a feature vector with the length of the input channels using global average pooling (GAP) per channel. This is followed by a fully connected (FC) layer and a Rectified Linear Activation Function (ReLU). The FC layer maps the compressed feature vector to a low-dimensional space with a reduction ratio of r. Finally, there are four head branches, each with a FC layer of output size k×k (space), cin×1 (input channels), cout×1 (output channels), and n×1 (number of convolutional kernels), followed by a Sigmoid activation function to generate normalized weight scalars α. s ,α c ,α f and α w In principle, these four attention weights complement each other and are multiplied sequentially by the convolution kernel W. i This makes the convolution operations of all spaces, all input channels, all output channels, and all convolution kernels of the input x different, thereby improving the information extraction capability of the structure and greatly reducing the additional parameters and computational cost introduced into the final model.
[0044] Step 3: For the locally improved single-stage target detection model, ASFF is introduced on the basis of the feature pyramid structure PAFPN to fuse features at different feature scales, thereby obtaining an improved single-stage target detection model. This makes fuller use of features at different feature scales and reduces the interference of invalid features in the complex background of apple leaves on detection.
[0045] As one implementation method, the adaptive fusion approach includes identical scaling of the feature map and adaptive fusion of the features, wherein the feature fusion part is illustrated by the ASFF-3 example formula as follows: Figure 5 As shown, it is:
[0046]
[0047] in, This represents the feature vector at the corresponding position in the feature map output from each channel. This represents the weights learned in the feature map at the th layer. X 2→1 , This represents the output of a feature map at a certain location.
[0048] Step 4: Optimize and improve the loss function of the single-stage object detection model based on the actual dataset to obtain the optimized single-stage object detection model;
[0049] Specifically, the total loss of the YOLOX-S model consists of prediction classification loss, localization loss, and confidence loss. The classification confidence loss is BCEWithLogits Loss. Due to class imbalance in the experimental dataset—with the number of labels for mosaic disease and powdery mildew being less than a quarter of the number of labels for gray spot, black spot, and rust—after applying the cross-entropy loss function, the loss from a large number of simple samples dominates the total loss and controls the model's gradient. This invention introduces Focalloss to address the class imbalance problem. Focalloss is essentially a dynamically scalable cross-entropy loss, allowing the model to focus more on complex samples, thereby reducing the proportion of simple sample loss in the total loss and making the total loss of the model more reasonable. The Focalloss formula is as follows:
[0050] Focalloss = -a t (1-pt) γ log(pt))
[0051] Where α t To balance the proportion of positive and negative samples, a balance factor of (1-pt) is used. γ A balance factor that balances simple and complex samples.
[0052] Step 5: Train the optimized single-stage target detection model;
[0053] Step 6: Use the trained model to detect diseased apple leaves and obtain information on the type and location of the disease.
[0054] As one implementation method, step five, training the optimized single-stage object detection model, includes:
[0055] Step S51, YOLOX-S model selection: Modify the configuration file, set the network depth to 0.33 and the network width to 0.5.
[0056] Step S52, YOLOX-S model parameter initialization:
[0057] SILU was chosen as the activation function, with a weight decay coefficient of 0.0005, Epoch set to 300, and Mosaic augmentation metric set to (0.5, 1.5). Mixup augmentation was disabled, and Mosaic data augmentation was disabled in the last 100 training epochs.
[0058] This model uses Mean Average Precision (mAP), a commonly used performance evaluation metric in target detection algorithms, for evaluation.
[0059] The experimental environment for this invention is as follows: System: Ubuntu 18.04 64bit; Processor: Intel(R) Xeon(R) Gold6240R CPU@2.4GHz; Memory: 16GB; Graphics Card: NVIDIA Tesla A100 40G; Deep learning framework: PyTorch version 1.8.0; Compiler: Python version 3.8.13; CUDA version 11.1; CuDNN version 8.0.5.
[0060] Using the improved YOLOX model designed in this invention, the system can detect disease information on the leaves based on the trained model after the user provides an image of an apple leaf.
[0061] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of the invention (including the claims) is limited to these examples; within the framework of the invention, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of the different aspects of the invention as described above, which are not provided in the details for the sake of brevity.
[0062] This invention is intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. An apple leaf disease detection method based on an improved YOLOX-S algorithm, characterized in that, The method comprises the following steps: Step one, obtain the apple leaf disease public dataset, and pretreat the public dataset; Step two, for the backbone network CSPDarknet and the neck feature fusion network PAFPN of the single-stage target detection model YOLOX-S, use the ODCSP structure embedded with ODConv to replace all CSPs of the backbone network and the feature fusion network of the YOLOX-S model to obtain a locally improved single-stage target detection model; specifically comprising: Replace all CSP1_X and CSP2_X structures of the backbone network and the feature fusion network of the YOLOX-S model with the ODCSP1_X and ODCSP2_X structures in which the original three BaseConv of the CSP1_X and the CSP2_X structure in the model are replaced with ODConv, wherein the structures of the ODCSP1_X and the ODCSP2_X both include two branches, after the input information enters the ODCSP1_X structure, one branch is processed through the ODConv and the residual structure, and then the other branch processed through the ODConv is concatenated and processed through the ODConv again, after the input information enters the ODCSP2_X structure, one branch is processed through the ODConv and the basic convolution BaseConv, and then the other branch processed through the ODConv is concatenated and processed through the ODConv again; Step three, for the locally improved single-stage target detection model, introduce ASFF to fuse features of different feature scales based on the feature pyramid structure PAFPN to obtain an improved single-stage target detection model; Step four, optimize the loss function of the improved single-stage target detection model according to the actual dataset to obtain an optimized single-stage target detection model; Step five, train the optimized single-stage target detection model; Step six, use the trained model to detect apple leaves with diseases to obtain disease types and location information.
2. The apple leaf disease detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that, In step one, the public dataset includes the FGVC8 apple leaf disease public dataset downloaded from the kaggle competition and the apple leaf pathology dataset downloaded from the Baidu Feixi.
3. The apple leaf disease detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that, In step one, the pretreatment includes labeling the public dataset, performing data enhancement in the manner of adjusting contrast, upside-down, left-right flipping, and chroma adjustment, and dividing the dataset into a training set and a test set in a ratio of 8:
2.
4. The apple leaf disease detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that, In step three, the ASFF includes identity scaling of feature maps and adaptive fusion of features.
5. The apple leaf disease detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that, In step four, the loss function of the improved single-stage target detection model comprises: Introducing Focalloss to replace the BCEWithLogits Loss of the classification confidence loss in the total loss of the model.
6. The apple leaf disease detection method based on the improved YOLOX-S algorithm according to claim 1, characterized in that, The training of the optimized single-stage target detection model comprises: Step S51, YOLOX-S model selection; Step S52, YOLOX-S model parameter initialization.
7. The apple leaf disease detection method based on the improved YOLOX-S algorithm according to claim 6, characterized in that, The YOLOX-S model selection comprises: Modify the configuration file, set the network depth to 0.33, and set the network width to 0.
5.
8. The apple leaf disease detection method based on the improved YOLOX-S algorithm according to claim 6, characterized in that, The YOLOX-S model parameter initialization comprises: SILU is selected as the activation function, the weight decay coefficient is 0.0005, Epoch is set to 300, the Mosaic enhancement index is set to (0.5, 1.5), the Mixup enhancement is closed, and the Mosaic data enhancement is closed in the last 100 rounds of training.
Citation Information
Patent Citations
Multi-scale target detection method and system with semantic guidance
CN113076926A
Deformable convolution method for offset decoupling
CN115410146A