A method for identifying plant leaf diseases based on FasterNet
By improving the image embedding module and feature extraction process of the FasterNet model and combining it with multi-label learning technology, the problems of feature loss and imbalance in the identification of plant leaf diseases in the FasterNet model were solved, and efficient and accurate identification of multiple diseases was achieved.
Patent Information
- Application Number
- CN202411337914.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2044-09-25
AI Technical Summary
The existing FasterNet model suffers from feature loss and unbalanced feature extraction in plant leaf disease identification, which affects the accuracy of identification. At the same time, the target box annotation step is time-consuming, making it difficult to efficiently identify multiple diseases.
The FasterNet model is improved by adding convolutional layers and SE_Block blocks to the image embedding module. Combined with multi-label learning techniques, the feature extraction and prediction layers are optimized to reduce feature loss and improve the accuracy of disease identification.
It enables efficient identification of plant leaf diseases, reduces the time cost of target box annotation, and improves the accuracy and efficiency of multi-disease identification.
Smart Images

Figure CN119295926B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of plant leaf disease identification and computer vision, specifically relating to a plant leaf disease identification method based on FasterNet. Background Technology
[0002] Plant leaf diseases can seriously affect plant growth. Accurate and effective identification of plant leaf diseases can enable precise prevention and control of leaf diseases, reduce pesticide use, and reduce pollution to soil, water sources, and ecosystems (Hu Qiuxia. Research on Plant Leaf Disease Identification Method Based on Image Analysis [D]. Northwest A&F University, 2013.). Traditional plant leaf disease identification is mainly carried out by farmers or domain experts through visual observation and experience. Using lightweight deep learning methods for plant leaf disease identification can improve efficiency. The literature of Hu et al. (Hu Y, Liu G, Chen Z, et al. Lightweight one-stage maize leaf disease detection model with knowledge distillation [J]. Agriculture, 2023, 13(9).) proposes a relatively efficient plant leaf disease identification method. This method combines the lightweight image classification model FasterNet and the YOLOv5 algorithm, which can accurately identify multiple diseases on a plant leaf while keeping the model small. However, this method depends on the target box annotation step. According to the research of Everingham et al. (Everingham M, Eslami SMA, Van Gool L, et al. The Pascalvisual object classes challenge: A retrospective[J]. International Journal of Computer Vision, 2015, 111: 98-136.), the target bounding box annotation step is relatively time-consuming. Meanwhile, the FasterNet model used in Hu et al.'s paper emphasizes general recognition.According to the research of Qian et al. (Qian S, Shao H, Zhu Y, et al. Blending anti-aliasing into vision transformer[C] / / Proceedings of the 35th Conference on Neural Information Processing Systems.2021,7:5416-5429.) and Xiao et al. (Xiao T, Singh M, Mintun E, et al. Early convolutions help transformers see better[C] / / Proceedings of the 35th Conference on Neural Information Processing Systems.2021,36:30392-30400.), the image embedding module in the FasterNet model causes the loss of some features in the original image input to the model. When applied to plant leaf disease identification, due to the large feature distribution range and complex features of plant leaf disease images, the image embedding module in the FasterNet model will affect the accuracy of plant leaf disease identification to a certain extent. Meanwhile, the feature extraction module in the FasterNet model does not use an attention mechanism, which makes it difficult to effectively adjust the model's attention to different regions in the image during feature extraction. This causes some regions in the image that are irrelevant to classification to become noise, affecting the accuracy of plant leaf disease identification (Wang Q, Wu B, Zhu P, et al. ECA-Net: Efficient channel attention for deep convolutional neural networks[C] / / Proceedings of the 2020IEEE / CVF Conference on Computer Vision and Pattern Recognition.2020:11531-11539.). Therefore, researching how to improve the FasterNet model to enhance the efficiency of plant leaf disease identification has significant theoretical and practical value. Summary of the Invention
[0003] The main objective of this invention is to overcome the shortcomings and deficiencies of the prior art and provide a plant leaf disease identification method based on FasterNet. By improving the FasterNet model and combining it with multi-label learning technology, the accuracy of plant leaf disease identification is further improved and the time cost of the target box annotation is reduced.
[0004] To achieve the above objectives, the present invention adopts the following technical solution:
[0005] A method for identifying plant leaf diseases based on FasterNet includes the following steps:
[0006] Determine the classification label type for identifying leaf diseases of the target plant, construct a set of plant leaf disease identification feature category names, and construct a set of plant leaf disease identification image category names based on the set of plant leaf disease identification feature category names. Obtain the original plant leaf disease identification images corresponding to the categories in the set of plant leaf disease identification image category names to obtain the original plant leaf disease identification image set.
[0007] Based on the category names in the plant leaf disease identification image category name set, create image folders corresponding to the categories; store the images in the obtained original plant leaf disease identification image set according to the image category into the corresponding category image folders to obtain the plant leaf disease identification image dataset before preprocessing.
[0008] In each category of image folder, a training folder, a validation folder, and a test folder are created simultaneously. Using Python, the original plant leaf disease recognition images in each category of the preprocessed plant leaf disease recognition image dataset are traversed and divided into training images, validation images, and test images according to the proportion. The training images are stored in the training folder of the corresponding category of image folder, the validation images are stored in the validation folder of the corresponding category of image folder, and the test images are stored in the test folder of the corresponding category of image folder.
[0009] Preprocess the images in all training, validation, and test folders to obtain preprocessed training images, preprocessed validation images, and preprocessed test images, thus obtaining a plant leaf disease recognition image dataset.
[0010] The original FasterNet model is constructed and improved to obtain FasterNet. Improved The model is represented as: TPLb = FasterNet Improved (TInput,ω FI ), where TPLb is FasterNet Improved The model's predicted label tensor, TInput is the input tensor, ω FI For model parameter tensors;
[0011] Get FasterNet Improved The model requires model parameter tensors for iterative training and validation.
[0012] Initialize the FasterNet Improved model;
[0013] Use the pre - processed training images in all training folders and the pre - processed validation images in all validation folders to iteratively train and validate the FasterNet Improved model to obtain the optimal model parameter tensor ω FI and save it;
[0014] Test the trained and validated FasterNet Improved model.
[0015] As a preferred technical solution, the specific method for obtaining the original plant leaf disease recognition image set is as follows:
[0016] Determine the type of leaf disease recognition classification label tyLabl ∈ {0, 1} of the target plant according to requirements. When tyLabl = 0, it means that each image in the original plant leaf disease recognition image set will be single - labeled, and when tyLabl = 1, it means that each image in the original plant leaf disease recognition image set will be multi - labeled;
[0017] Determine the number of plant leaf disease recognition feature categories nmCFt and the set of plant leaf disease recognition feature category names neCFt = neHCFt ∪ neDCFt; where, neHCFt = {neCFt1} is the set of healthy feature category names, and neDCFt = {neCFt i |i ∈ {2,…,nmCFt}} is the set of disease feature category names; Let neSDCFt = {neCFt j1 ,…,neCFt j|neSDCFt| |2 ≤ j1 < … < j|neSDCFt| ≤ nmCFt} be the non - empty and non - single - element ordered subset of neDCFt, where neCFt j1 is the j1 - th element in neCFt, and |neSDCFt| is the length of neSDCFt;
[0018] When tyLabl = 0, the number of plant leaf disease recognition image categories is nmCIm = nmCFt; when tyLabl = 1, the number of plant leaf disease recognition image categories is nmCIm = 2 (nmCFt-1) , then the set of plant leaf disease recognition image category names is:
[0019] where is an empty set, ∨ is logical or, and ∧ is logical and;
[0020] For each plant leaf, identify the image category name neCIm. k ∈neCIm, where 1≤k≤nmCIm, and nmOIm is obtained through image acquisition equipment or the Internet. k Zhang's original leaf disease identification images of this category of plants, and the collected or acquired images... All original images were saved in JPG format, resulting in an original image set for identifying plant leaf diseases. Where 1≤t≤nmOIm, and nmOIm is the number of images in OImg.
[0021] As a preferred technical solution, the preprocessed plant leaf disease identification image dataset specifically comprises:
[0022] Create nmCIm image folders using the image category names from neCIm as folder names; store the images from the obtained OImg according to their respective image categories into the corresponding image folders to obtain the preprocessed plant leaf disease identification image dataset.
[0023] As a preferred technical solution, the obtained plant leaf disease identification image dataset specifically comprises:
[0024] First, create a folder named "train" for training images, a folder named "val" for validation images, and a folder named "test" for test images within each of the nmCIm image folders. Then, iterate through each of the nmCIm image folders and use Python's random library to generate the image set OImg from the iterated folders. k The original images in the P are all in accordance with P train :P val :P test The original images are divided into training images, validation images, and test images according to the corresponding image categories. The training images, validation images, and test images are then moved to the train folder, val folder, and test folder under the image folder of the corresponding category, respectively.
[0025] The Torchvision library in Python is used to resize the original images in all train, val, and test folders, reducing their size to 3*H*W pixels, where H is the height and W is the width. This yields preprocessed training images, preprocessed validation images, and preprocessed test images.
[0026] The preprocessed training set PTrDast is obtained, which consists of all preprocessed training images and their corresponding image category names; the preprocessed validation set PVADast is obtained, which consists of all preprocessed validation images and their corresponding image category names; the preprocessed test set PTeDast is obtained, which consists of all preprocessed test images and their corresponding image category names; PTrDast, PVADast, and PTeDast are set together and operated on to obtain the plant leaf disease recognition image dataset PFast, where PFast = PTrDast ∪ PVADast ∪ PTeDast.
[0027] As a preferred technical solution, the method involves constructing the original FasterNet model and improving it to obtain FasterNet. Improved The model, specifically:
[0028] The original FasterNet model was constructed based on existing technologies;
[0029] An improved image embedding module is obtained by improving the image embedding module in the original FasterNet model, which is to add three convolutional layers with different parameters before the image embedding module in the original FasterNet model.
[0030] A squeeze and excitation block of SE_Block is constructed according to existing technology, and the values of dim and reduction parameters of the SE_Block block are set. An improved FasterNetBlock block is obtained by adding the constructed and parameter-set SE_Block block after the FasterNetBlock block of the original FasterNet model.
[0031] By adding a sigmoid function and a rounding operation after the prediction layer of the original FasterNet model, an improved prediction layer is obtained, ultimately resulting in FasterNet. Improved Model.
[0032] As a preferred technical solution, the three convolutional layers with different parameters are conv1, conv2, and conv3; the outputs of conv1, conv2, and conv3 are summed and then input into the image embedding module of the original FasterNet model to obtain the output of the improved image embedding module, as shown below:
[0033] Embed Improved (TInput) = Embed Original(conv1(TInput)+conv2(TInput)+conv3(TInput)),
[0034] Among them, Embed Improved This indicates an improved image embedding module, Embed Original This represents the image embedding module of the original FasterNet model.
[0035] As a preferred technical solution, the improved FasterNet Block is represented as follows:
[0036] FNB Improved (TFInput) = SE_Block(FNB) Original (TFInput)),
[0037] Among them, FNB Improved The block is an improved FasterNet Block, TFInput is the input tensor of the improved FasterNetBlock block, SE_Block is the squeeze and excitation block, and FNB... Original The block is the FasterNet Block from the original FasterNet model.
[0038] As a preferred technical solution, the improved prediction layer is represented as follows:
[0039] Prediction Improved (TPInput)=round(Sigmoid(Prediction Original (TPInput))),
[0040] Among them, Prediction Improved This represents the improved prediction layer, where TPInput is the input tensor of the improved prediction layer, and Prediction is... Original This represents the prediction layer of the original FasterNet model; when the value of the input tensor of round is less than 0.5, round outputs 0, and when the value of the input tensor of round is not less than 0.5, round outputs 1.
[0041] As a preferred technical solution, the FasterNet is obtained. Improved The model parameter tensors that require iterative training and validation are specifically:
[0042] Combining the parameters of the original FasterNet model (which requires iterative training and validation), the parameters of three convolutional layers with different parameters (which also require iterative training and validation), and the parameters of the squeeze and activation blocks (SE_Block) (which also require iterative training and validation) results in FasterNet.Improved The model requires iterative training and validation of the model parameter tensor ω. FI =[ω FO ,ω conv ,ω SK ], where ω FO ω is the parameter tensor of the original FasterNet model that requires iterative training and validation. conv To add three convolutional layers with different parameters, the parameter tensors ω need to be iteratively trained and validated. SK The parameter tensors required for squeezing and activating the SE_Block need to be iteratively trained and validated.
[0043] As a preferred technical solution, the FasterNet... Improved The model is initialized as follows:
[0044] Based on existing technologies, FasterNet Improved The parameter settings in the model are inherited from the original FasterNet model and initialized to their initial values.
[0045] As a preferred technical solution, the specific process of iterative training and verification is as follows:
[0046] Using Python, convert all preprocessed training images in the preprocessed training set PTrDast into training image tensors of size [nmPTrIm, 3, H, W]; convert all preprocessed validation images in the preprocessed validation set PVADast into validation image tensors of size [nmPVaIm, 3, H, W]; where nmPTrIm is the number of preprocessed training images in the preprocessed training set PTrDast, nmPVaIm is the number of preprocessed validation images in the preprocessed validation set PVADast, H is the height of the image, and W is the width of the image; convert the image category names of the preprocessed training images into ground truth label tensors of the preprocessed training images; convert the image category names of the preprocessed validation images into ground truth label tensors of the preprocessed validation images; using Python, normalize the training image tensors to obtain normalized training image tensors, and normalize the validation image tensors to obtain normalized validation image tensors;
[0047] Configure FasterNet ImprovedThe model's optimizer algorithm, learning rate, batch size, and number of training and validation epochs are determined. The number of training batches containing the normalized training image tensor and its ground truth label tensor, as well as the number of validation batches containing the normalized validation image tensor and its ground truth label tensor, are obtained. Minibatch technology is used to batch the normalized training image tensor, the preprocessed training image ground truth label tensor, the normalized validation image tensor, and the preprocessed validation image ground truth label tensor.
[0048] In each training and validation round of iterative training and validation, for each training batch: first, the training image tensor of that batch is used as the input tensor TInput and passed through FasterNet. Improved The model calculates the predicted label tensor for this batch of preprocessed training images. Next, it calculates the binary cross-entropy loss value for this batch using the binary cross-entropy loss formula. Finally, it updates the model parameter tensor ω using the backpropagation algorithm. FI ;
[0049] In each training and validation round of iterative training and validation, for each validation batch: the validation image tensor of that batch is used as the input tensor TInput and passed through FasterNet. Improved The model calculates the predicted label tensor of the preprocessed verification images in this batch and compares it with the true label tensor of the preprocessed verification images in this batch to calculate the number of correctly predicted images in this batch.
[0050] In each training and validation epoch: First, the number of correctly predicted images in all validation batches of the current epoch is accumulated, and the accumulated value is divided by the total number of preprocessed validation images to obtain the accuracy of the current epoch; Second, if the accuracy of the current epoch is the highest accuracy among all iterated and currently iterating training and validation epochs, the model parameter tensor ω of the current epoch is saved as a file. FI Then, the model parameter tensor ω saved in the file after all training and validation rounds are completed. FI As the optimal model parameter tensor ω FI .
[0051] As a preferred technical solution, the trained and validated FasterNet... Improved The specific process of testing the model is as follows:
[0052] Save the optimal model parameter tensor ω FI Load into FasterNet Improved In the model;
[0053] Use Python to convert all preprocessed test images in the preprocessed test set PTeDast into a test image tensor of size [nmPTeIm, 3, H, W], where nmPTeIm is the number of preprocessed test images in the preprocessed test set PTeDast; convert the image category names of the preprocessed test images into the ground truth label tensor of the preprocessed test images; use Python to normalize the test image tensor to obtain the normalized test image tensor;
[0054] The normalized test image tensor was used as the tensor ω loaded with the optimal model parameters. FI FasterNet Improved The model is input; the predicted label tensor of the preprocessed test image is calculated; the method of the present invention is evaluated using the true label tensor of the preprocessed test image and an evaluation metric.
[0055] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0056] 1. The plant leaf disease identification method based on FasterNet proposed in this invention can use images that have only been labeled with categories to train and validate the model, and can simultaneously identify multiple different disease features in a single image, which helps to reduce the workload of creating datasets.
[0057] 2. The FasterNet constructed in this invention Improved The model can reduce feature loss when embedding original plant leaf disease images, and the addition of squeezing and excitation blocks during feature extraction gives the model the ability to adjust the weights of different channels, which helps to improve the performance of plant leaf disease recognition.
[0058] 3. The plant leaf disease identification method based on FasterNet designed in this invention can assist in the identification of plant leaf diseases, which helps to reduce the workload of plant leaf disease identification. Attached Figure Description
[0059] Figure 1 This is an overall flowchart of sugarcane leaf disease identification based on FasterNet in an embodiment of the present invention.
[0060] Figure 2 FasterNet in this embodiment of the invention Improved A schematic diagram of the model's structure.
[0061] Figure 3 Embed in the embodiments of the present invention Improved A schematic diagram of the image embedding module.
[0062] Figure 4 FNB in the embodiment of the present invention Improved A schematic diagram of the block's structure.
[0063] Figure 5 Prediction in this embodiment of the invention Improved A schematic diagram of the prediction layer.
[0064] Figure 6 This embodiment of the invention is based on FasterNet. Improved Confusion matrix diagram of sugarcane leaf disease identification model. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be described in further detail below.
[0066] Example 1
[0067] This embodiment selects sugarcane as the target plant to describe the method of the present invention in detail, such as... Figure 1 As shown, the specific steps are as follows:
[0068] S1. Determine the classification label type tyLabl for sugarcane leaf disease identification, determine the number of sugarcane leaf disease identification feature categories nmCFt, construct the sugarcane leaf disease identification feature category name set neCFt, and construct the sugarcane leaf disease identification image category name set neCIm based on the sugarcane leaf disease identification feature category name set. For each category in the sugarcane leaf disease identification image category name set, obtain the original sugarcane leaf disease identification image for that category, and obtain the original sugarcane leaf disease identification image set OImg.
[0069] Furthermore, in this embodiment, the steps for obtaining the original sugarcane leaf disease identification image set OImg are as follows:
[0070] S101. First, the target plant is determined to be sugarcane. The classification label type for sugarcane leaf disease identification is multi-label, i.e., tyLabl=1.
[0071] S102. Determine the number of sugarcane leaf disease identification feature categories nmCFt = 4 and the sugarcane leaf disease identification feature category name set neCFt = neHCFt ∪ neDCFt = {Healthy, BS, RS, RR}; where neHCFt = {neCFt1} is the health feature category name set, neCFt1 = Healthy is the health feature name, neDCFt = {neCFt2, neCFt3, neCFt4} is the disease feature category name set, neCFt2 = BS is the sugarcane brown streak disease feature name, neCFt3 = RS is the sugarcane ring spot disease feature name, and neCFt4 = RR is the sugarcane red rot disease feature name.
[0072] S103, The number of image categories for sugarcane leaf disease identification is nmCIm=2 (4-1) =8, then the set of image category names for sugarcane leaf disease identification is: neCIm={neCIm k |1≤k≤8}={Healthy,BS,RS,RR,BS_RS,BS_RR,RS_RR,BS_RS_RR}, where the underscore “_” represents a single image that simultaneously contains features corresponding to two or more feature categories connected by _.
[0073] S104. Select iPhone SE, iPhone 13, and iPhone 14 Pro smartphones, and a Canon EOS digital camera as image acquisition devices. Acquire 608 original sugarcane leaf disease identification images for each of the following categories: Healthy, 666 BS, 750 RS, 716 RR, 738 BS_RS, 560 BS_RR, 696 RS_RR, and 700 BS_RS_RR. Then, upload the acquired images... All original sugarcane leaf disease identification images with slightly different resolutions were saved in JPG format to obtain the original sugarcane leaf disease identification image set.
[0074] S2. Create eight image folders using the eight image category names from neCIm as folder names; store the images from the obtained OImg according to their respective image categories into the corresponding image folders, that is, store the image set OImg. k All images in the file are stored in the image folder neCIm k In this process, a dataset of sugarcane leaf disease identification images before preprocessing was obtained.
[0075] S3. Obtain the sugarcane leaf disease identification image dataset. The specific steps are as follows:
[0076] S301. First, in each of the eight image folders from step S2, create a folder named "train" to store training images, a folder named "val" to store validation images, and a folder named "test" to store test images. Then, iterate through each of the eight image folders from step S2, and use the random library in Python to generate the image set OImg from the iterated image folder. k The original images in the P are all in accordance with P train :P val :P test =6:2:2 ratio to divide the corresponding image categories into nmTrIm kZhang training original image TrImg k 、nmVaIm k Zhang verified the original image VaImg k and nmTeIm k Zhang test original image TeImg k ,Right now All of these resulted in OImg k =TrImg k ∪VaImg k ∪TeImg k , where nmTrIm k =|TrImg k |=nmOIm k *(3 / 5), nmVaIm k =|VaImg k |=nmOIm k *(1 / 5), nmTeIm k =|TeImg k |=nmOIm k *(1 / 5). Therefore, the total number of training images is: The total number of original images is verified to be: The total number of original test images is: Then the original training image TrImg k Verify the original image VaImg k and the original test image TeImg k Move them to the folder neCIm respectively k The folders are named train, val, and test.
[0077] S302. Use the Torchvision library in Python to resize 5434 original images in all train, val, and test folders, scaling them to 3*H*W pixels, where H=448 and W=448; thus obtaining the preprocessed training images. Preprocessed verification image and preprocessed test images
[0078] S303. Obtain the preprocessed training set PTrDast, where PTrDast = {(PTrImg1,neCIm1), ...,(PTrImg...} nmPTrIm ,neCIm8)}, nmPTrIm=3264 is the number of images contained in PTrDast; the preprocessed validation set PVADast is obtained, where PVADast={(PVaImg1,neCIm1),…,(PVaImgnmPVaIm ,neCIm8)}, nmPVaIm=1085 is the number of images contained in PVADast; the preprocessed test set PTeDast is obtained, where PTeDast={(PTeImg1,neCIm1),…,(PTeImg nmPTeIm ,neCIm8)}, nmPTeIm=1085 is the number of images contained in PTeDast. PTrDast, PVADast, and PTeDast are set together and operated on to obtain the sugarcane leaf disease identification image dataset PFast, where PFast=PTrDast∪PVaDast∪PTeDast, and nmPIm=nmPTrIm+nmPVaIm+nmPTeIm=3264+1085+1085=5434 is the number of images contained in PFast.
[0079] S4. Construct the original FasterNet model. Original And FasterNet Original Improvements were made to obtain FasterNet Improved The model is represented as: TPLb = FasterNet Improved (TInput,ω FI ), where TPLb is FasterNet Improved The model's predicted label tensor, TInput is the input tensor, ω FI For example, the model parameter tensor. Figure 2 As shown, the specific steps are as follows:
[0080] S401. Construct the original FasterNet model FasterNet according to the method described in the paper by Chen et al. (Chen J, Kao SH, He H, et al. Run, don't walk: Chasing higher FLOPS for faster neural networks[C] / / Proceedings of the 2023 IEEE / CVF Conference on Computer Vision and Pattern Recognition. 2023:12021-12031.). Original .
[0081] S402, FasterNet Original Image embedding module in Embed Original Improvements were made to obtain the improved image embedding module, Embed. Improved .like Figure 3 As shown, the specific steps are as follows:
[0082] First, in FasterNet Original Image embedding module in Embed Original Three convolutional layers, conv1, conv2, and conv3, with different parameters are added before the network. Then, the outputs of conv1, conv2, and conv3 are summed and input into FasterNet. Original Image embedding module Embed Original An improved image embedding module, Embed, was obtained. Improved The output is represented as:
[0083] Embed Improved (TInput) = Embed Original (conv1(TInput)+conv2(TInput)+conv3(TInput)),
[0084] The parameters of conv1, conv2, and conv3 all include the kernel size, dilation rate, stride, padding rate, and the number of input and output channels. The parameters of conv1 are: kernel1=5, dilation1=1, stride1=1, padding1=2, channel1=3; the parameters of conv2 are: kernel2=3, dilation2=2, stride2=1, padding2=2, channel2=3; and the parameters of conv3 are: kernel3=3, dilation3=1, stride3=1, padding3=1, channel3=3.
[0085] S403, such as Figure 4 As shown, firstly, referring to the paper by Hu et al. (Hu J, Shen L, Sun G. Squeeze-and-excitation networks[C] / / Proceedings of the 31st Meeting of the IEEE / CVFConference on Computer Vision and Pattern Recognition.2018:7132-7141.), an SE_Block squeezing and excitation block is constructed, and the value of the dim parameter of the SE_Block block is set to the FNB connected to the SE_Block block. Original The number of channels in the block's output tensor, and the value of the reduction parameter for the SE_Block block set to 8. Next, in the FNB...Original Add an SE_Block block with the constructed and parameter values set after the block to obtain the FNB. Improved A block is represented as:
[0086] FNB Improved (TFInput) = SE_Block(FNB) Original (TFInput)),
[0087] Among them, FNB Improved The block is an improved FasterNet Block, and TFInput is FNB. Improved The input tensor of the block, SE_Block, is the squeeze and excitation block, FNB Original The block is FasterNet Original The FasterNet Block in the context of FasterNet.
[0088] S404, such as Figure 5 As shown, in FasterNet Original Prediction layer Original Later, the Sigmoid function and rounding operation were added to obtain the improved prediction layer, Prediction. Improved , is represented as:
[0089] Prediction Improved (TPInput)=round(Sigmoid(Prediction Original (TPInput))),
[0090] Wherein, TPInput is Prediction Improved The input tensor, round(TRInput) = {0|TRInput<0.5; 1|TRInput≥0.5}, TRINput = Sigmoid(Prediction) Original (TPInput) is the input tensor of round.
[0091] Prediction Improved The output of FasterNet Improved The model's output, i.e., TPLb = Prediction Improved (TPInput).
[0092] S5, Obtain FasterNet Improved The model requires model parameter tensors for iterative training and validation, for FasterNet. Improved The model is initialized. The specific steps are as follows:
[0093] First, combine FasterNet Original The model requires parameters for iterative training and validation, the three convolutional layers with different parameters require parameters for iterative training and validation, and the SE_Block block requires parameters for iterative training and validation to obtain FasterNet. Improved The model requires iterative training and validation of the model parameter tensor ω. FI =[ω FO ,ω conv ,ω SK Then, referring to the paper by Chen et al. (Chen J, Kao SH, He H, et al. Run, don't walk: Chasing higher FLOPS for faster neural networks[C] / / Proceedings of the 2023IEEE / CVFConference on Computer Vision and Pattern Recognition.2023:12021-12031.), FasterNet was analyzed. Improved Inherited from FasterNet Original The parameter settings are initialized as follows: embed_dim is 96, feature_dim is 1280, patch_size is 8, patch_stride is 8, drop_path_rate is 0.05, norm_layer is BN, act_layer is RELU, n_div is 4, and num_classes is 4.
[0094] S6. Use the preprocessed training images PTrImg from all training folders and the preprocessed validation images PVAImg from all validation folders to train FasterNet. Improved The model undergoes iterative training and validation to obtain the optimal model parameter tensor ω. FI And save it. The specific process of iterative training and verification is as follows:
[0095] S601. Using Python, convert all preprocessed training images PTrImg in the preprocessed training set PTrDast obtained in step S303 into training image tensors of size [3264, 3, 448, 448]. All preprocessed verification images PVAImg in the preprocessed verification set PVADast obtained in step S303 are converted into verification image tensors of size [1085, 3, 448, 448]. The image category name of the preprocessed training image PTrImg Convert to the true label tensor of the preprocessed training image PTrImg Among them, neCI (PTrImg) m ) is the image PTrImg m The name of the parent folder of the training folder. For multi-hot tag tensors, The size of TRTLb is [3264, 4]. Using the same conversion method as the ground truth label tensor TRTLb of the preprocessed training image PTrImg, the image category names of the preprocessed validation image PVAImg are converted into the ground truth label tensor of the preprocessed validation image PVAImg. TVTLb p For the multi-hot label tensor, TVTLb has a size of [1085, 4]. Using the `Normalize` function from the `torchvision` library in Python, the image mean parameter is set to `mean = [0.485, 0.456, 0.406]`, and the image standard deviation parameter is set to `std = [0.229, 0.224, 0.225]`. The `Normalize` function is then called to normalize the training image tensor `TTrImg`, resulting in the normalized training image tensor. The Normalize function is called to normalize the verification image tensor TVaImg, resulting in the normalized verification image tensor.
[0096] S602, Configure FasterNet Improved The optimizer algorithm for the model is an adaptive motion estimation algorithm, with a learning rate lr = 0.0002, a batch size szbt = 128, and 100 training and validation epochs. The normalized training image tensors are obtained. The number of training batches for its true label tensor TRTLb: and the normalized verification image tensor The number of validation batches of its true label tensor TVTLb: The normalized training image tensors are processed using the minibatch technique. The ground truth label tensor TRTLb of the preprocessed training images, and the normalized validation image tensor And the preprocessed verification image's true label tensor TVTLb is batched:
[0097] in TRTLb represents the training image tensor of the s-th batch. s Let represent the true label tensor of the preprocessed training images in the s-th batch. TVTLb represents the verification image tensor of the u-th batch. u Let represent the true label tensor of the preprocessed verification images in the u-th batch.
[0098] S603, in each training and validation round of iterative training and validation In the middle, for each training batch ① First, process the tensors of this batch of training images. As the input tensor TInput, and through TRPLb s =TPLb=FasterNet Improved (TInput,ω FI Calculate the predicted label tensor TRPLb of the preprocessed training images in this batch. s ② Secondly, the binary cross-entropy loss value calculation formula is adopted. Calculate the binary cross-entropy loss value BCELoss for this batch. s , where nim s This represents the number of images in the batch. For TRTLb s The true label tensor of the (ε+1)th image, For TRPLb s The predicted label tensor of the (ε+1)th image. For tensor The value of the β-th element in the middle. For tensor The value of the β-th element. ③ Then, based on the calculated BCELoss... s The model parameter tensor ω is updated using the backpropagation algorithm. FI ;
[0099] S604. In each training and validation round of iterative training and validation In the process, for each verification batch The batch of verification image tensors As the input tensor TInput, and through TVPLb u =TPLb=FasterNet Improved (TInput,ω FI Calculate the predicted label tensor TVPLb for this batch of preprocessed verification images. u and compared with the true label tensor TVTLb of the preprocessed verification images in this batch. uThe comparison is performed to calculate the number of correctly predicted images in the batch. Furthermore, an image is considered correctly predicted only if its predicted label tensor is exactly the same as its true label tensor.
[0100] S605, in each training and validation round of iterative training and validation In the training and validation round: First, sum the number of correctly predicted images from all 9 validation batches in the current x-th training and validation round, and divide the sum by the total number of preprocessed validation images to obtain the accuracy of the current x-th training and validation round. Second, if the accuracy of the current x-th training and validation round is the highest accuracy among all iterated and currently iterating training and validation rounds, then save the tensor ω of the current x-th training and validation round as a file. FI That is, if the model.pt file does not exist, it will be created and the tensor ω will be... FI Save it to this file. If a model.pt file already exists and the accuracy of the current x-th training and validation epoch is higher than the accuracy recorded in the model.pt file, then save the tensor ω from the current x-th training and validation epoch. FI Save the data to the model.pt file by overwriting the existing data. Then, after completing all 100 training and validation rounds, save the tensor ω from the model.pt file. FI As the optimal model parameter tensor ω FI .
[0101] S7. For the trained and validated FasterNet Improved The model was tested, and the specific process was as follows:
[0102] S701. Transfer the optimal model parameter tensor ω saved in the model.pt file. FI FasterNet loaded with the initial values set in step S5 Improved In the model.
[0103] S702. Using Python, convert all preprocessed test images PTeImg in the preprocessed test set PTeDast obtained in step S303 into test image tensors of size [1085, 3, 448, 448]. Using the same conversion method as the ground truth label tensor TRTLb of the preprocessed training image PTrImg in step S601, the image category names of the preprocessed test image PTeImg are converted into the ground truth label tensor of the preprocessed test image PTeImg. Among them TETLb qThe test image tensor TTeImg is a multi-hot label tensor with a size of [1085, 4]. Using the Normalize function from the torchvision library in Python, the mean parameter and the standard deviation parameter std are set according to the values in step S601. The Normalize function is then called to normalize the test image tensor TTeImg, resulting in the normalized test image tensor.
[0104] S703, Normalize the test image tensor As the tensor ω loaded with the optimal model parameters FI FasterNet Improved The model's input. Then, via TPLb = FasterNet. Improved (TInput,ω FI Calculate the predicted label tensor TEPLb of the preprocessed test image PTeImg. Then, using the true label tensor TETLb of the preprocessed test image PTeImg obtained in step S702, and employing accuracy, precision, recall, F1 score, and model size as evaluation metrics, the method of this invention is evaluated. The evaluation results are shown in Table 1 and... Figure 6 As shown, where Figure 6 In the `Predict` property, `Predict` represents the predicted image category name, and `GroundTruth` represents the true image category name. The value before the " / " in the second row of each cell indicates the number of images predicted to have the category name corresponding to the cell's vertical axis. The value after the " / " in the second row of each cell indicates the number of images whose true image category name corresponds to the category name corresponding to the cell's horizontal axis. The value in the first row of each cell is the result of dividing the second row, rounding to four decimal places, and converting to percentage form. It can be seen that based on FasterNet... Improved The overall accuracy of sugarcane leaf disease identification is higher than 80%, and the accuracy is higher than 70% when identifying images with combined disease types BS_RS, BS_RR, RS_RR, and BS_RS_RR. Furthermore, the model size is relatively small, only 57.6 MB. Therefore, the plant leaf disease identification method based on FasterNet proposed in this invention has good identification performance when applied to sugarcane leaf disease identification.
[0105] Table 1 is based on FasterNet. Improved Evaluation of the effectiveness of sugarcane leaf disease identification
[0106] Evaluation indicators Evaluation index values Accuracy 84.88% Accuracy 88.98% Recall rate 84.92% F1 value 78.77% Model size 57.6MB
Claims
1. A method for identifying plant leaf diseases based on FasterNet, characterized in that, Includes the following steps: Determine the classification label type for identifying leaf diseases of the target plant, construct a set of plant leaf disease identification feature category names, and construct a set of plant leaf disease identification image category names based on the set of plant leaf disease identification feature category names. Obtain the original plant leaf disease identification images corresponding to the categories in the set of plant leaf disease identification image category names to obtain the original plant leaf disease identification image set. Create image folders corresponding to image categories; store the images in the original plant leaf disease identification image set according to image category into the corresponding category image folders to obtain the plant leaf disease identification image dataset before preprocessing; In each category of image folder, a training folder, a validation folder, and a test folder are created simultaneously. Using Python, the original plant leaf disease recognition images in each category of the preprocessed plant leaf disease recognition image dataset are traversed and divided into training original images, validation original images, and test original images according to the proportions and stored in the corresponding folders. The images in all training folders, validation folders, and test folders are preprocessed to obtain the plant leaf disease recognition image dataset. Construct the original FasterNet model and improve upon it to obtain... FasterNet Improved The model is represented as: TPLb = FasterNet Improved ( TInput , ω FI ),in TPLb for FasterNet Improved The model's predicted label tensor TInput For the input tensor, ω FI For model parameter tensors; get FasterNet Improved The model requires model parameter tensors for iterative training and validation. right FasterNet Improved The model is initialized; Using all preprocessed training images and all preprocessed validation images to... FasterNet Improved The model undergoes iterative training and validation to obtain the optimal model parameter tensor. ω FI And save; For trained and validated FasterNet Improved The model was tested; The process involves constructing the original FasterNet model and then improving it. FasterNet Improved The model, specifically: Add three convolutional layers with different parameters before the image embedding module in the original FasterNet model; Build a SE_Block Squeeze and excite the block and on it SE_Block block dim Parameters and reduction Set the parameter values; add a constructed and configured parameter value after the FasterNet Block of the original FasterNet model. SE_Block The block is obtained as an improved FasterNet Block; Add after the prediction layer of the original FasterNet model Sigmoid Functions and rounding operations round This leads to an improved prediction layer, ultimately resulting in... FasterNet Improved Model; The three convolutional layers with different parameters are conv 1. conv 2 and conv 3; will conv 1. conv 2 and conv The outputs of step 3 are summed and then input into the image embedding module of the original FasterNet model to obtain the output of the improved image embedding module, which is represented as: Embed Improved ( TInput ) = Embed Original ( conv 1( TInput ) + conv 2( TInput ) + conv 3( TInput )), in, Embed Improved This indicates an improved image embedding module. Embed Original This represents the image embedding module of the original FasterNet model; The improved FasterNet Block is represented as follows: FNB Improved ( TFInput ) = SE_Block ( FNB Original ( TFInput )), in, FNB Improved The block is an improved FasterNet Block. TFInput For the input tensor of the FasterNet Block, SE_Block For extrusion and excitation blocks, FNB Original The block is the FasterNet Block from the original FasterNet model; The improved prediction layer is represented as follows: Prediction Improved ( TPInput ) = round ( Sigmoid ( Prediction Original ( TPInput ))), in, Prediction Improved This indicates an improved prediction layer. TPInput For the input tensor of the prediction layer, Prediction Original This represents the prediction layer of the original FasterNet model; when round When the value of the input tensor is less than 0.5 round Output 0 when round When the value of the input tensor is not less than 0.5 round Output 1.
2. The plant leaf disease identification method based on FasterNet according to claim 1, characterized in that, The obtained original plant leaf disease identification image set is specifically as follows: Determine the type of leaf disease identification and classification label for the target plant based on requirements. tyLabl ∈ {0, 1}, when tyLabl =0 indicates that each image in the original plant leaf disease identification image set will be labeled with a single label. tyLabl = 1 indicates that each image in the original plant leaf disease identification image set will be labeled with multiple tags; Determine the number of identification feature categories for plant leaf diseases nmCFt and a set of names for the identification characteristics of plant leaf diseases neCFt = neHCFt ∪ neDCFt ;in, neHCFt = { neCFt 1} represents the set of health characteristic category names. neDCFt = { neCFt i | i ∈ {2, ⋯, nmCFt }} represents a set of disease characteristic category names; let neSDCFt = { neCFt j1 , ⋯, neCFt j|neSDCFt| | 2 ≤ j 1 < ⋯ < j | neSDCFt | ≤ nmCFt }for neDCFt A non-empty and non-single-element ordered subset of , where neCFt j1 for neCFt The Middle j 1 element, | neSDCFt |for neSDCFt Length; when tyLabl When = 0, the number of image categories for plant leaf disease identification is nmCIm = nmCFt ;when tyLabl When = 1, the number of image categories for plant leaf disease identification is nmCIm = 2 (nmCFt-1) The set of image category names for plant leaf disease identification is as follows: neCIm = { neCIm k | 1 ≤ k ≤ nmCIm } = neCFt ∪ {∅ | ( tyLabl = 0) ∨ ( tyLabl = 1 ∧ nmCFt = 2); { neCFt j1 , ⋯, neCFt j|neSDCFt| | ∀ neSDCFt } | ( tyLabl = 1 ∧ nmCFt ≥ 3)}, where ∅ is the empty set, ∨ is logical OR, and ∧ is logical AND; Identify the image category name for each plant leaf disease. neCIm k ∈ neCIm , where 1 ≤ k ≤ nmCIm Acquired through image acquisition equipment or the Internet nmOIm k Zhang's original leaf disease identification images of this category of plants, and the collected or acquired images... All original images were saved in JPG format, resulting in an original image set for identifying plant leaf diseases. OImg = = { OImg 1, ⋯, OImg t , ⋯, OImg nmOIm }, where 1 ≤ t ≤ nmOIm , nmOIm for OImg The number of images in the file.
3. The plant leaf disease identification method based on FasterNet according to claim 2, characterized in that, The obtained plant leaf disease identification image dataset is specifically as follows: First of all, nmCIm In each of the image folders, create a folder named "train" to store training images, a folder named "val" to store validation images, and a folder named "test" to store test images; then, iterate through... nmCIm For each image folder within a given image folder, use Python's random library to retrieve the image sets from that folder. OImg k The original images in the data are all in accordance with P train : P val : P test The original images are divided into training images, validation images, and test images according to the corresponding image categories. The training images, validation images, and test images are then moved to the train folder, val folder, and test folder under the image folder of the corresponding category, respectively. The Torchvision library in Python was used to resize the original images in all train, val, and test folders, reducing their size to 3*. H * W Pixel size, of which H For the height of the image, W Given the width of the image, we obtain the preprocessed training image, the preprocessed validation image, and the preprocessed test image. Obtain the preprocessed training set PTrDast ,in PTrDast The validation set consists of all preprocessed training images and their corresponding image category names; this yields the preprocessed validation set. PVaDast ,in PVaDast The test set consists of all preprocessed validation images and their corresponding image category names; this yields the preprocessed test set. PTeDast ,in PTeDast It consists of all preprocessed test images and their corresponding image category names; PTrDast , PVaDast and PTeDast The dataset for identifying plant leaf diseases was obtained by performing set union operations. PDast ,in PDast = PTrDast ∪ PVaDast ∪ PTeDast .
4. The plant leaf disease identification method based on FasterNet according to claim 1, characterized in that, The obtained FasterNet Improved The model parameter tensors that require iterative training and validation are specifically: Combining the original FasterNet model requires iterative training and validation of the parameters; the three convolutional layers with different parameters require iterative training and validation of the parameters along with the squeeze and activation blocks. SE_Block The parameters that need to be iteratively trained and validated are obtained FasterNet Improved The model requires model parameter tensors for iterative training and validation. ω FI = [ ω FO , ω conv , ω SK ],in, ω FO The parameter tensors for the original FasterNet model that require iterative training and validation. ω conv Adding three convolutional layers with different parameters requires iterative training and validation of parameter tensors. ω SK For extrusion and excitation blocks SE_Block Parameter tensors that require iterative training and validation.
5. The method for identifying plant leaf diseases based on FasterNet according to claim 1, characterized in that, The specific process of iterative training and verification is as follows: Using Python, the preprocessed training set PTrDast All preprocessed training images are converted to a size of [ nmPTrIm , 3, H , W The training image tensor; the preprocessed validation set PVaDast All preprocessed verification images are converted to a size of [ nmPVaIm , 3, H , W The verification image tensor; where, nmPTrIm For the preprocessed training set PTrDast The number of preprocessed training images in the process. nmPVaIm The preprocessed validation set PVaDast The number of preprocessed verification images in the process. H For the height of the image, W The width of the image is given; the image category names of the preprocessed training images are converted into the ground truth label tensors of the preprocessed training images; the image category names of the preprocessed validation images are converted into the ground truth label tensors of the preprocessed validation images; using Python, the training image tensors are normalized to obtain normalized training image tensors, and the validation image tensors are normalized to obtain normalized validation image tensors. set up FasterNet Improved The optimizer algorithm, learning rate, batch size, and training / validation rounds of the model are used to obtain the normalized training image tensor and the number of training batches of its true label tensor, as well as the normalized validation image tensor and the number of validation batches of its true label tensor. The minibatch technique is used to batch the normalized training image tensor, the preprocessed training image true label tensor, the normalized validation image tensor, and the preprocessed validation image true label tensor. In each training and validation round of iterative training and validation, for each training batch: first, the training image tensor of that batch is used as the input tensor. TInput and through FasterNet Improved The model calculates the predicted label tensor for the preprocessed training images in this batch. Next, it calculates the binary cross-entropy loss value for this batch using the binary cross-entropy loss formula. Finally, it updates the model parameter tensor using the backpropagation algorithm. ω FI ; In each training and validation round of iterative training and validation, for each validation batch: the validation image tensor of that batch is used as the input tensor. TInput and through FasterNet Improved The model calculates the predicted label tensor of the preprocessed verification images in this batch and compares it with the true label tensor of the preprocessed verification images in this batch to calculate the number of correctly predicted images in this batch. In each training and validation epoch: First, the number of correctly predicted images in all validation batches of the current epoch is accumulated, and the accumulated value is divided by the total number of preprocessed validation images to obtain the accuracy of the current epoch; Second, if the accuracy of the current epoch is the highest accuracy among all iterated and currently iterating training and validation epochs, the model parameter tensor of the current epoch is saved as a file. ω FI Then, the model parameter tensors saved in the file after all training and validation rounds are completed. ω FI tensor as the optimal model parameter ω FI .
6. The plant leaf disease identification method based on FasterNet according to claim 1, characterized in that, The training and validation completed FasterNet Improved The specific process of testing the model is as follows: Save the optimal model parameter tensor ω FI Load to FasterNet Improved In the model; Use Python to process the preprocessed test set PTeDast All preprocessed test images are converted to a size of [ nmPTeIm , 3, H , W The test image tensor, where nmPTeIm For the preprocessed test set PTeDast The number of preprocessed test images; converting the image category names of the preprocessed test images into the true label tensors of the preprocessed test images; Use Python to normalize the test image tensor to obtain the normalized test image tensor; The normalized test image tensor was used as the tensor loaded with the optimal model parameters. ω FI of FasterNet Improved The model's input; Calculate the predicted label tensor of the preprocessed test image; use the true label tensor of the preprocessed test image and an evaluation metric to evaluate the plant leaf disease identification method.
Citation Information
Patent Citations
Litchi fruit identification method based on deep learning
CN117058669A
Pest recognition method and device based on improved lightweight network, and storage medium
CN117994651A