A small sample plant disease identification method, device, medium and product
Patent Information
- Application Number
- CN202410702798.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-03
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2044-06-03
AI Technical Summary
在植物病害识别任务中,由于病害种类多样,需要专家进行标注,标注成本较高,且许多病害比较罕见,获取大量人工标注的病害样本非常困难且耗时
[0045]本发明实施例基于深度最近邻神经网络构建植物病害识别模型,深度最近邻神经网络中的双向加权特征融合模块采用金字塔融合方式对输入图像进行多个尺度的特征融合,得到高级语义特征图和低级特征图,更好的聚合细粒度特征,增强网络对复杂病害图像的表示能力;情景注意力模块根据高级语义特征图和低级特征图确定与输入图像中植物所在场景相关的注意力特征图,有效降低不相关背景信息带来的影响;度量模块用于根据注意力特征图计算输入图像与各个病害类别之间的相似度,确定输入图像中植物的病害类别,这种结构的深度最近邻神经网络能够在训练数据较少(即小样本)的情况下训练得到高性能的植物病害识别模型,因此,本发明能在标记样本较少的情况下实现植物病害识别。
Smart Images

Figure CN118587591B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of plant disease identification, and in particular to a method, apparatus, medium, and product for identifying plant diseases in small samples. Background Technology
[0002] Crop diseases are among the most significant agricultural disasters, often leading to substantial declines in crop yield and quality. In the past, farmers and agricultural experts largely relied on personal experience to identify crop diseases, a method that was inefficient and easily influenced by subjective factors. Due to the diversity of plant diseases and crop types, coupled with the influence of natural environmental elements such as sunlight, shading, and vibration, there are significant differences between diseases in different crops. Furthermore, different diseases exhibited by the same type of crop often appear quite similar, necessitating the capture of subtle regional differences, which presents a severe challenge to achieving accurate crop disease classification.
[0003] In recent years, deep learning methods have been widely applied to image-based plant disease identification tasks. However, existing excellent methods heavily rely on large amounts of labeled training data, especially as network depth increases and the number of trainable parameters grows, making data even more crucial. In plant disease identification tasks, due to the diversity of disease types, expert labeling is required, which is costly. Furthermore, many diseases are rare, making it very difficult and time-consuming to obtain a large number of manually labeled disease samples. Insufficient sample size can lead to overfitting and performance degradation. Therefore, how to identify plant diseases with limited labeled samples has become an important research task. Summary of the Invention
[0004] The purpose of this invention is to provide a method, apparatus, medium, and product for identifying plant diseases in small samples, so as to achieve plant disease identification when there are few labeled samples.
[0005] To achieve the above objectives, the present invention provides the following solution:
[0006] A method for identifying plant diseases in a small sample, the method comprising:
[0007] Acquire the target image; the target image is an image of the disease of the plant to be identified;
[0008] The target image is input into the plant disease identification model to obtain the disease category of the plant to be identified;
[0009] The plant disease identification model is obtained by training a deep nearest neighbor neural network using training data; the deep nearest neighbor neural network includes a bidirectional weighted feature fusion module, a context attention module, and a metric module connected in sequence.
[0010] The bidirectional weighted feature fusion module is used to perform multi-scale feature fusion on the input image using a pyramid fusion method to obtain a high-level semantic feature map and a low-level feature map. The bidirectional weighted feature fusion module includes a backbone network, an upsampling branch, and a downsampling branch. The backbone network includes four sequentially connected network layers. The outputs of the first three network layers are connected to the upsampling branch. The upsampling branch is connected to the downsampling branch. The outputs of the first two network layers are connected to the residuals of the downsampling branch. The upsampling branch is used for weighted summation and upsampling operations. The downsampling branch is used for weighted summation and downsampling operations. The first network layer serves as the input to the bidirectional weighted feature fusion module. The feature map output by the last network layer is the high-level semantic feature map. The feature map output by the downsampling branch is the low-level feature map.
[0011] The contextual attention module is used to determine an attention feature map related to the scene in which the plants are located in the input image based on the high-level semantic feature map and the low-level feature map;
[0012] The measurement module is used to calculate the similarity between the input image and each disease category based on the attention feature map, and to determine the disease category of the plant in the input image based on the similarity.
[0013] Optionally, the method for determining the plant disease identification model specifically includes:
[0014] The training data is divided into a training set and a test set;
[0015] The training set is input into the deep nearest neighbor neural network, and meta-learning is used to train it with the goal of minimizing the class marginal loss function, resulting in the trained deep nearest neighbor neural network; the class marginal loss function is a loss function that incorporates cosine margin and L2 regularization term;
[0016] The test set is input into the trained deep nearest neighbor neural network for testing, and the tested deep nearest neighbor neural network is determined as the plant disease identification model.
[0017] Optionally, the context attention module includes a first channel attention submodule and a second channel attention submodule; the first channel attention submodule and the second channel attention submodule are used to perform channel attention operations;
[0018] The calculation formula for the contextual attention module is as follows:
[0019]
[0020] Where X represents the high-level semantic feature map; Y represents the low-level feature map; X+Y is the input of the first channel attention submodule; Z is the input of the second channel attention submodule; M(X,Y) represents the attention feature map output by the context attention module when X and Y are input; a(l) represents performing channel attention operation on l; l takes X+Y or Z.
[0021] Optionally, the calculation formula for the channel attention operation is:
[0022]
[0023] G(l)=β(C1(δ(β(C1(F Max (l))))));
[0024] L(l)=β(C2(δ(β(C2(F Avg (l))))));
[0025] Where G(l) represents the output of the global context channel; L(l) represents the output of the local context channel; Sigmoid represents the activation function; δ represents the ReLU activation function; C1 represents dilated convolution; C2 represents point convolution; β represents batch normalization; F Max (l) indicates global max pooling of l; F Avg (l) indicates that global average pooling is performed on l.
[0026] Optionally, the expression for the category marginal loss function is:
[0027]
[0028] in, Represents the learnable parameters in a deep nearest neighbor neural network. The corresponding category marginal loss function; Represents the learnable parameters in a deep nearest neighbor neural network. The corresponding loss function before the introduction of the L2 regularization term; It is determined by introducing the cosine margin; λ represents the penalty term coefficient.
[0029] Optionally, the expression for the loss function before introducing the L2 regularization term is:
[0030]
[0031] Among them, L CMLLet C represent the loss function before introducing the L2 regularization term; C represents the number of disease categories in the support set; N represents the number of samples in the query set; C disease categories are randomly selected from the finite training set, and K samples are selected from each selected disease category to form the support set; N samples are randomly selected again from these C disease categories as the query set; This represents the local descriptor used for training, determined based on the attention feature query map of the nth sample in the query set; the attention feature query map is the attention feature map output by the context attention module after the nth sample in the query set is input into the context attention module. express With support for the concentrated disease category c f The similarity between them; express With support for the concentrated disease category c t The similarity between them; S represents the cosine margin; S = m × K × D, where m represents the number of local descriptors used for training, D represents the distance added to the similarity between samples in the query set and disease categories in the support set; s represents the scale parameter.
[0032] Optionally, the upsampling branch includes: a first fusion unit, a first upsampling unit, a second fusion unit, a second upsampling unit, and a third fusion unit; the downsampling branch includes: a fourth fusion unit, a first downsampling unit, a fifth fusion unit, a second downsampling unit, a sixth fusion unit, and a third downsampling unit;
[0033] The output of the first network layer in the backbone network is connected to the fourth fusion unit through the first fusion unit; the output of the second network layer is connected to the fifth fusion unit through the second fusion unit; the second fusion unit is connected to the first fusion unit through the first upsampling unit; the fourth fusion unit is connected to the fifth fusion unit through the first downsampling unit; the output of the third network layer is connected to the sixth fusion unit through the third fusion unit; the third fusion unit is connected to the second fusion unit through the second upsampling unit; the fifth fusion unit is connected to the sixth fusion unit through the second downsampling unit; the third downsampling unit is used to output a low-level feature map;
[0034] The first fusion unit, the second fusion unit, the third fusion unit, the fourth fusion unit, the fifth fusion unit, and the sixth fusion unit are all used to perform weighted summation;
[0035] The calculation formula for the second fusion unit is as follows:
[0036]
[0037] This indicates the output of the second fusion unit to the third fusion unit; This represents the output of the second network layer; This represents the output of the third network layer; This represents the weights corresponding to the output of the second network layer; Upsample indicates the upsampling operation.
[0038] The calculation formula for the fifth fusion unit is:
[0039]
[0040] This represents the output of the fifth fusion unit to the second downsampling unit; This indicates the weight corresponding to the output of the first downsampling unit; Downsample indicates the downsampling operation. This indicates the output of the fourth fusion unit to the first downsampling unit.
[0041] The present invention also provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described method for identifying small sample plant diseases.
[0042] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method for identifying small sample plant diseases.
[0043] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method for identifying small sample plant diseases.
[0044] According to specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0045] This invention constructs a plant disease identification model based on a deep nearest neighbor neural network. The bidirectional weighted feature fusion module in the deep nearest neighbor neural network uses a pyramid fusion method to perform multi-scale feature fusion on the input image, obtaining high-level semantic feature maps and low-level feature maps. This better aggregates fine-grained features and enhances the network's ability to represent complex disease images. The contextual attention module determines attention feature maps related to the scene in which the plant is located in the input image based on the high-level semantic feature maps and low-level feature maps, effectively reducing the influence of irrelevant background information. The metric module calculates the similarity between the input image and each disease category based on the attention feature maps, determining the disease category of the plant in the input image. This structure of the deep nearest neighbor neural network can train a high-performance plant disease identification model with limited training data (i.e., small samples). Therefore, this invention can achieve plant disease identification with a small number of labeled samples. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 This is a schematic diagram of the small sample plant disease identification method provided in Embodiment 1 of the present invention;
[0048] Figure 2 This is a schematic diagram of the structure of the bidirectional weighted feature fusion module provided in Embodiment 1 of the present invention;
[0049] Figure 3 This is a schematic diagram of the context attention module provided in Embodiment 1 of the present invention;
[0050] Figure 4 This is a schematic diagram of the structure of the deep nearest neighbor neural network provided in Embodiment 1 of the present invention;
[0051] Figure 5 This is a schematic diagram of feature space clustering and category marginal loss provided in Embodiment 1 of the present invention;
[0052] Figure 6 This is a schematic diagram of the training process of the deep nearest neighbor neural network provided in Embodiment 1 of the present invention;
[0053] Figure 7 This is a schematic diagram showing the significance comparison of experimental results provided in Embodiment 1 of the present invention;
[0054] Figure 8 This is a diagram of the internal structure of a computer device. Detailed Implementation
[0055] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0056] Few-shot learning is a new research direction inspired by the rapid learning ability of humans. It can quickly generalize to new categories using limited labeled data without needing to re-collect data and retrain the model. Few-shot learning has been successfully applied to computer vision tasks. Applying it to disease image classification is a promising area, still in its early stages. Few-shot learning can directly classify disease categories not present in the training set, saving significant costs associated with labeled images and retraining. Current few-shot methods primarily target natural scenes, but the differences between disease images and natural scenes are substantial. In natural scenes, plant diseases often have similar backgrounds, and different diseases within the same category share similar characteristics.
[0057] The purpose of this invention is to provide a method, device, medium, and product for identifying plant diseases in small samples, aiming to achieve plant disease identification when the number of labeled samples is small.
[0058] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0059] Example 1
[0060] like Figure 1 As shown, the small-sample plant disease identification method in this embodiment includes:
[0061] Step 101: Obtain the target image; the target image is an image of the disease of the plant to be identified.
[0062] Step 102: Input the target image into the plant disease identification model to obtain the disease category of the plant to be identified; wherein, the plant disease identification model is obtained by training a deep nearest neighbor neural network using training data; the deep nearest neighbor neural network includes: a bidirectional weighted feature fusion module, a context attention module and a metric module connected in sequence.
[0063] The deep nearest neighbor neural network in this embodiment is a multi-scale attention fusion and discrimination enhancement deep nearest neighbor neural network (MAFDE-DN4) based on DN4.
[0064] The bidirectional weighted feature fusion module is used to perform multi-scale feature fusion on the input image using a pyramid fusion method to obtain a high-level semantic feature map and a low-level feature map. The context attention module is used to determine an attention feature map related to the scene in which the plant is located in the input image based on the high-level semantic feature map and the low-level feature map; the metric module is used to calculate the similarity between the input image and each disease category based on the attention feature map, and determine the disease category of the plant in the input image based on the similarity.
[0065] The specific structure of each module in the aforementioned deep nearest neighbor neural network is described below.
[0066] (1) Bidirectional weighted feature fusion module.
[0067] See Figure 2 The bidirectional weighted feature fusion module includes: a backbone network, an upsampling branch, and a downsampling branch.
[0068] The backbone network comprises four sequentially connected network layers (Layer 1-Layer 4); the outputs of the first three network layers are connected to the upsampling branch; the upsampling branch is connected to the downsampling branch; the outputs of the first two network layers are connected to the residuals of the downsampling branch; the upsampling branch is used for weighted summation and upsampling operations; the downsampling branch is used for weighted summation and downsampling operations; the first network layer serves as the input to the bidirectional weighted feature fusion module; the feature map output by the last network layer is the high-level semantic feature map X; the feature map output by the downsampling branch is the low-level feature map Y.
[0069] like Figure 2 As shown, the upsampling branch, from left to right, includes: a first fusion unit, a first upsampling unit, a second fusion unit, a second upsampling unit, and a third fusion unit. The downsampling branch, from left to right, includes: a fourth fusion unit, a first downsampling unit, a fifth fusion unit, a second downsampling unit, a sixth fusion unit, and a third downsampling unit.
[0070] The output of the first network layer in the backbone network is connected to the fourth fusion unit through the first fusion unit; the output of the second network layer is connected to the fifth fusion unit through the second fusion unit; the second fusion unit is connected to the first fusion unit through the first upsampling unit; the fourth fusion unit is connected to the fifth fusion unit through the first downsampling unit; the output of the third network layer is connected to the sixth fusion unit through the third fusion unit; the third fusion unit is connected to the second fusion unit through the second upsampling unit; the fifth fusion unit is connected to the sixth fusion unit through the second downsampling unit; the third downsampling unit is used to output a low-level feature map.
[0071] The first fusion unit, the second fusion unit, the third fusion unit, the fourth fusion unit, the fifth fusion unit, and the sixth fusion unit are all used to perform weighted summation.
[0072] The calculation formula for the second fusion unit is as follows:
[0073]
[0074] This indicates the output of the second fusion unit to the third fusion unit; This represents the output of the second network layer; This represents the output of the third network layer; This indicates the weights corresponding to the output of the second network layer; Upsample indicates the upsampling operation.
[0075] The calculation formula for the fifth fusion unit is:
[0076]
[0077] This represents the output of the fifth fusion unit to the second downsampling unit; This indicates the weight corresponding to the output of the first downsampling unit; Downsample indicates the downsampling operation. This indicates the output of the fourth fusion unit to the first downsampling unit.
[0078] (2) Contextual attention module.
[0079] The context attention module assigns different weights to local feature descriptors, making the network focus more on features important to the current task and less on the influence of background information. See also Figure 3 The context attention module includes a first channel attention submodule and a second channel attention submodule; the first channel attention submodule and the second channel attention submodule are used to perform channel attention operations.
[0080] The calculation formula for the contextual attention module is as follows:
[0081]
[0082] Where X represents the high-level semantic feature map; Y represents the low-level feature map; X+Y is the input of the first channel attention submodule; Z is the input of the second channel attention submodule; M(X,Y) represents the attention feature map output by the context attention module when X and Y are input; a(l) represents performing channel attention operation on l; l takes X+Y or Z.
[0083] The calculation formula for the channel attention operation is as follows:
[0084]
[0085] G(l)=β(C1(δ(β(C1(F Max (l)))))) (6)
[0086] L(l)=β(C2(δ(β(C2(F Avg (l)))))) (7)
[0087] Where G(l) represents the output of the global context channel; L(l) represents the output of the local context channel; Sigmoid represents the activation function; δ represents the ReLU activation function; C1 represents dilated convolution; C2 represents point convolution; β represents batch normalization; F Max (l) indicates global max pooling of l; F Avg (l) indicates that global average pooling is performed on l.
[0088] (3) Measurement module.
[0089] The metrics module is used to measure the similarity between disease images and class representations in each query set.
[0090] See Figure 4 A bidirectional weighted feature fusion module for learning local feature representations and the contextual attention module used to generate attention feature maps Constructing a deep embedded module Deeply Embedded Module It is a multi-branch feature extraction and fusion structure.
[0091] To address the characteristics of high inter-class similarity and significant intra-class differences in plant diseases, this embodiment proposes a category marginal loss and a deep embedding module. By learning the feature representations of all training samples, all samples are embedded into the feature space, and class representations are generated using samples in the support set S.
[0092] Specifically, through deep embedding modules The resulting attention feature map M(X,Y) (also known as the depth feature descriptor) is an h×w×d tensor, where h, w, and d correspond to its width, height, and number of channels, respectively. It can be viewed as a local descriptor of m = h×w dimensions, as described below:
[0093]
[0094] Where m represents the number of local descriptors. Then, the metrics module is used. This measures the similarity between each disease image and each class representation in the query set. Based on these similarities, the meta-learner generates a classification loss for each point in the current query set. Then, the gradient of the total loss for all query samples is backpropagated. Specifically, for each image in a given query set Q, m local descriptors x are obtained through the embedding module. i Then find the k nearest neighbors from each class. Then, K-NN is used to calculate the cosine similarity between the query image and each category, x. i and The formula for calculating the similarity between them is as follows:
[0095]
[0096] in x represents the similarity between the nth sample (disease image) in the query set and the given support set category c. i This represents the i-th local descriptor of the n-th sample in the query set.
[0097] Based on these similarities, the meta-learner generates a classification loss for each sample in the current query set, and then backpropagates the gradient of the total loss for all query samples. The widely used classification loss function, softmax loss, is shown below:
[0098]
[0099] Where p n Let C represent the classification probability of disease images in the query set, C represent the number of disease categories in the support set, and N represent the number of samples in the query set. C disease categories are randomly selected from the finite training set, and K samples are selected from each selected disease category to form the support set. N samples are then randomly selected again from these C disease categories as the query set. In the metric module, the category score of the query image is typically calculated by weighted sum of cosine distances between local descriptors. To enhance feature discriminativity and better separate similar classes in the feature space, an additional margin should be introduced into the softmax loss function. This helps increase the inter-class distance in the embedding space, allowing the embedding function to better represent the base class data. The similarity metric module can more accurately predict sample categories, improving the accuracy of metric learning. Therefore, this embodiment proposes a Class Marginal Loss (CML) for few-shot learning. An additional interval was defined to add extra discriminative distance to each category.
[0100] Specifically, in order to match each query set image x with class c based on the local descriptor in this embodiment... fThe cosine similarity between the samples is increased by the distance S = m × K × D, where each sample image has m local descriptors and K is the class c. f The number of samples included, D, represents the distance added to the similarity between samples in the query set and disease categories in the support set. Finally, since the cosine value ranges from [-1, 1], a scale parameter s is added to amplify the value. The value is used to increase the diversity of the distribution and improve the convergence speed. The improved CML is as follows:
[0101]
[0102] Among them, L CML represents the loss function before introducing L2 regularization; C represents the number of disease categories in the support set; N represents the number of samples in the query set; f and t are both disease category numbers; c is the number of the f-th disease category. f With the t-th disease category c t The difference lies in the following: C disease categories are randomly selected from a finite training set, and K samples are selected from each selected disease category to form a support set; N samples are then randomly selected from these C disease categories as the query set. This represents the local descriptor used for training, determined based on the attention feature query map of the nth sample in the query set; the attention feature query map is the attention feature map output by the context attention module after the nth sample in the query set is input into the context attention module. express With support for the concentrated disease category c f The similarity between them; express With support for the concentrated disease category c t The similarity between them; S represents the cosine margin; S = m × K × D, where m represents the number of local descriptors used for training, D represents the distance added to the similarity between samples in the query set and disease categories in the support set; s represents the scale parameter.
[0103] Figure 5 The example illustrates feature space clustering and category marginal loss. This embodiment adds an extra discriminative distance for each category through an additional margin. The margin is then integrated into the classification loss, making similar classes more separable within the embedding space.
[0104] For few-shot learning methods, overfitting can occur when generalizing to new classes during the testing phase due to the small number of samples in the support set. This embodiment introduces an L2 regularization constraint (also known as weight decay) on top of the improved class marginal loss. This process aims to reduce model complexity by adding a penalty coefficient λ to the loss function, thereby encouraging better generalization to unseen data. The specific expression for the loss function with the L2 regularization term is as follows:
[0105]
[0106] in, Represents the learnable parameters in a deep nearest neighbor neural network. The corresponding category marginal loss function; Represents the learnable parameters in a deep nearest neighbor neural network. The corresponding loss function before the introduction of the L2 regularization term; It is determined by introducing the cosine margin; λ represents the penalty term coefficient.
[0107] The formula for the derivative of backpropagation is:
[0108]
[0109] Gradient descent formula before adding L2 regularization:
[0110]
[0111] Gradient descent formula after adding L2 regularization:
[0112]
[0113] Here, α is the learning rate. When a regularization term is added, the weight decay of the parameters causes the network weights to decrease continuously, which enhances the model's robustness against disturbances and reduces overfitting under conditions of data variability.
[0114] In one example, based on the above description of each module, the method for determining the plant disease identification model specifically includes:
[0115] (1) Divide the training data into a training set and a test set. Randomly select C disease categories from the limited training set, and select K samples from each selected disease category to form a support set; then randomly select N samples from these C disease categories as the query set.
[0116] (2) Input the training set into the deep nearest neighbor neural network and train it using meta-learning with the goal of minimizing the class marginal loss function to obtain the trained deep nearest neighbor neural network; the class marginal loss function is a loss function that incorporates cosine margin and L2 regularization term. The expression of the class marginal loss function is shown in formula (13). The expression of the loss function before incorporating L2 regularization term in formula (13) is shown in formula (12).
[0117] The training process may include, for example, the following:
[0118] The FSL dataset is trained using a classification task built on the base class data, and then tested using a new classification task built on the new class data. The FSL dataset consists of the base class data Dbase and Dnovel, where the classes in Dbase and Dnovel are mutually exclusive, meaning that the data used in testing was not seen during training. Each classification task is set as N-way, K-shot, using a scenario-based training approach. For each episode, C disease categories are randomly selected from the finite dataset, and K samples are selected from each selected disease category to form a support set (S). Simultaneously, a certain number of samples are randomly selected from these C disease categories to form a query set (Q).
[0119] During training, an episode is extracted from the training data as input data. For each episode, there are N=5 classes, but each class has only K=1 labeled samples, which is called the N-way K-shot task. The network parameters are updated by decreasing the loss function, and a similar approach is used in subsequent validation and testing. Unlike updating parameters during training, the validation set is only used to select the optimal hyperparameters, and the test set is only used to evaluate the model performance.
[0120] (3) Input the test set into the trained deep nearest neighbor neural network for testing, and determine the tested deep nearest neighbor neural network as the plant disease identification model.
[0121] To obtain rich, fine-grained information about plant diseases, the small-sample plant disease identification method in this embodiment designs a bidirectional weighted feature fusion module to fuse shallow features and enhance feature diversity. Upsampling and downsampling branches are embedded into the existing backbone network, demonstrating good feature extraction capabilities. A scene attention module is designed to obtain scene-category-related attention maps, dividing deep local descriptors into scene-related and irrelevant parts, thereby effectively reducing the influence of irrelevant background information. The softmax loss function in the original DN4 is improved by introducing cosine margins to push different categories apart, enhancing the representation ability of local descriptors on base class data, learning a more discriminative feature space, and adding L2 regularization constraints to stabilize the training process. The MAFDE-DN4 network model is used to identify and classify plant leaf disease images, determining the category to which the leaf disease belongs, achieving plant disease identification even with a small number of labeled samples.
[0122] The following is combined with Figure 6 This paper introduces a specific implementation process of the above-mentioned small sample plant disease identification method in practical application and verifies the effectiveness of the method.
[0123] Deep learning-based methods for accurately identifying plant diseases can effectively improve crop yields. However, their high detection performance largely relies on large-scale, manually labeled datasets, which presents significant technical and economic challenges. Addressing the scarcity of plant disease data, the complexity of real-world disease leaf distribution, and the significant intra-class and inter-class differences and similarities among plant disease types, this specific example utilizes an improved multi-scale attention fusion and discriminative enhancement deep nearest neighbor neural network (MAFDE-DN4) based on DN4 to categorize plant leaf diseases. The bidirectional weighted feature fusion module, which enhances feature relevance, better aggregates fine-grained features, enhancing the network's ability to represent complex disease images. To address the issue of sparse feature descriptors being susceptible to irrelevant noise under small sample conditions, a contextual attention module is employed to obtain scene-category-related attention maps, effectively reducing the impact of irrelevant background information. An additional spacing is introduced between class boundaries to improve the original softmax loss function, amplifying inter-class differences and reducing intra-class distances, and an L2 regularization constraint is added to stabilize the training process.
[0124] To simulate different real-world scenarios, different dataset settings were configured. Under 1-shot and 5-shot settings, this embodiment achieved 59.61% and 81.41% accuracy under the intra-domain strategy, and 36.54% and 51.23% accuracy under the cross-domain strategy. Experimental results show that, regardless of whether the dataset has a single background or a real-world field dataset with complex backgrounds, the method in this embodiment outperforms existing related work in the field of plant disease identification. MAFDE-DN4, based on few-shot learning, significantly reduces the data requirements for new categories of plant diseases. A specific implementation process is as follows:
[0125] 1. Preparation of experimental materials
[0126] To simulate data samples collected in a real-world environment, the plant disease dataset was divided into three parts for training, validation, and testing. According to FSL requirements, the classes in the training, validation, and testing sets are non-overlapping. 22 classes from PVG were used for training, 6 for validation, and 10 tomato classes for testing. In PV-FG-Setting, 28 classes from PVG were used for training, and 6 for testing. To simulate data samples collected in a real-world environment, a dataset photographed in a real-world scene was used. 1000 samples from each of the 10 classes in FGVC8 were used for testing. All samples in FGVC8 were photographed in real-world scenes, possessing more complex background information than the training set, and all categories belong to apple leaf diseases, a subclass classification task.
[0127] See Figure 6 The MAFDE-DN4 few-shot learning algorithm employs an episodic training approach. The training process is similar to the standard meta-learning process, consisting of two phases: meta-training and meta-testing. In the meta-training phase, an episodic training method is used. For each set, a small training and test set is sampled from the entire base class dataset to construct a small classification task. In the meta-testing phase, the trained model is used to identify samples from new classes. Specifically, in each set of meta-training, N-way, K-shot samples are extracted from the base class data as classification samples. The metric-based meta-learning method (DN4) embeds samples into a feature space, clusters all samples separately around each class, and then uses these class representations as labels for test samples. Finally, a metric module measures the similarity between query samples and each class representation in the embedding space.
[0128] 2. Shallow feature extraction from image samples
[0129] See Figure 2The deep embedding module includes a bidirectional weighted feature fusion module and a context attention module. Layers 1-4 represent the traditional backbone network in the bidirectional weighted feature fusion module, such as ResNet12 or Conv4. The pyramid feature fusion structure in the bidirectional weighted feature fusion module includes downsampling and upsampling branches, which are constructed based on residual structures and feature fusion units. Residual structures are used for cross-layer connections on the first and second layer feature maps, specifically manifested as follows: Figure 1 middle and In the diagram, N represents the number of samples, C represents the number of channels, and H and W represent the height and width, respectively. The feature information extracted by the bidirectional weighted feature fusion module includes two outputs: a high-level semantic feature map X from the feature pyramid and a low-level feature map Y that deeply fuses the information from the first three shallow layers. X and Y are broadcast-added to obtain input X, which is then processed by the contextual attention module to obtain the attention feature map. (See [link to relevant documentation]). Figure 3 The context attention module includes a global context channel and a local context channel. The global context channel includes global max pooling and dilated convolution, while the local context channel includes global average pooling and point convolution.
[0130] Invalid information from local branches is removed using global average pooling, and a lightweight pointwise convolution is used as a local channel context extractor to perform channel information interaction point-by-point at each spatial location. For global branches, global max pooling is used to extract global features. Compared to global average pooling, max pooling captures salient features of specific regions by selecting the maximum value within a region, thus better capturing object contour features. Dilated convolution is introduced to quickly expand the receptive field without introducing additional parameters, reducing feature information loss. Considering that the quality of the initial ensemble features may affect the final fusion weights, the initial input features X and Y are directly used as the fusion input for the second stage to avoid the influence of channel attention on the quality of the initial features.
[0131] Understandably, compared to the complex feature extraction process in traditional algorithms, image feature extraction modules based on deep learning technology can quickly and easily extract image features, including color, texture, and shape. In image detection problems, multi-layer image feature extraction modules extract rich detail information from low-level features and rich semantic information from high-level features, resulting in better feature robustness.
[0132] refer to Figure 2From left to right, the diagram shows the three fusion processes of the bidirectional weighted feature fusion module, and the final fusion output after passing through the context attention module. This experiment uses heatmaps to compare the extraction performance of the improved deep embedding module on plant disease image features, comparing the performance on four types of plant diseases. The method described in this experiment extracts disease information at multiple scales, allowing for the focus on more disease areas and effectively reducing the impact of background noise. Figure 7 As shown, Figure 7 Part (A) represents the original input image. Figure 7 Part (B) represents the output of the baseline model. Figure 7 Part (C) shows, from left to right, the outputs of different layers in the three fusion processes of the bidirectional weighted feature fusion module. Figure 7 The (D) part represents the final fusion output after passing through the contextual attention module. As the network depth increases, the model's focus area shifts from localized edges to the location of leaf diseases. The rightmost part is the final output, which accurately locates the disease area. For example, in the fourth row, for apple powdery mildew, the method in this embodiment effectively enhances the leaf area and reduces the influence of similar backgrounds. The above results show that the method in this embodiment can effectively highlight the discriminative features of the target in the recognition task compared to the baseline model, thereby improving the model's recognition accuracy.
[0133] Example 2
[0134] A computer device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the small sample plant disease identification method of Example 1.
[0135] Example 3
[0136] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the small sample plant disease identification method of Example 1.
[0137] Example 4
[0138] A computer program product includes a computer program that, when executed by a processor, implements the small sample plant disease identification method of Example 1.
[0139] Example 5
[0140] A computer device, the internal structure of which can be shown in the diagram below. Figure 8As shown, the computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database stores pending transactions. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements the small-sample plant disease identification method in Example 1.
[0141] It should be noted that the object information (including but not limited to object device information, object personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this invention are all information and data authorized by the object or fully authorized by all parties.
[0142] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided by this invention can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided by this invention may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided by this invention may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, etc., and are not limited to these.
[0143] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0144] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for identifying plant diseases in a small sample, characterized in that, The method includes: Acquire the target image; the target image is an image of the disease of the plant to be identified; The target image is input into the plant disease identification model to obtain the disease category of the plant to be identified; The plant disease identification model is obtained by training a deep nearest neighbor neural network using training data; the deep nearest neighbor neural network includes a bidirectional weighted feature fusion module, a context attention module, and a metric module connected in sequence. The bidirectional weighted feature fusion module is used to perform multi-scale feature fusion on the input image using a pyramid fusion method to obtain a high-level semantic feature map and a low-level feature map. The bidirectional weighted feature fusion module includes a backbone network, an upsampling branch, and a downsampling branch. The backbone network includes four sequentially connected network layers. The outputs of the first three network layers are connected to the upsampling branch. The upsampling branch is connected to the downsampling branch. The outputs of the first two network layers are connected to the residuals of the downsampling branch. The upsampling branch is used for weighted summation and upsampling operations. The downsampling branch is used for weighted summation and downsampling operations. The first network layer serves as the input to the bidirectional weighted feature fusion module. The feature map output by the last network layer is the high-level semantic feature map. The feature map output by the downsampling branch is the low-level feature map. The contextual attention module is used to determine an attention feature map related to the scene in which the plants are located in the input image based on the high-level semantic feature map and the low-level feature map; The measurement module is used to calculate the similarity between the input image and each disease category based on the attention feature map, and to determine the disease category of the plant in the input image based on the similarity.
2. The method for identifying small-sample plant diseases according to claim 1, characterized in that, The method for determining the plant disease identification model specifically includes: The training data is divided into a training set and a test set; The training set is input into the deep nearest neighbor neural network, and meta-learning is used to train it with the goal of minimizing the class marginal loss function, resulting in the trained deep nearest neighbor neural network; the class marginal loss function is a loss function that incorporates cosine margin and L2 regularization term; The test set is input into the trained deep nearest neighbor neural network for testing, and the tested deep nearest neighbor neural network is determined as the plant disease identification model.
3. The method for identifying small-sample plant diseases according to claim 1, characterized in that, The contextual attention module includes a first channel attention submodule and a second channel attention submodule; the first channel attention submodule and the second channel attention submodule are used to perform channel attention operations; The calculation formula for the contextual attention module is as follows: Where X represents the high-level semantic feature map; Y represents the low-level feature map; X+Y is the input of the first channel attention submodule; Z is the input of the second channel attention submodule; M(X,Y) represents the attention feature map output by the context attention module when X and Y are input; a(l) represents performing channel attention operation on l; l takes X+Y or Z.
4. The method for identifying small-sample plant diseases according to claim 3, characterized in that, The calculation formula for the channel attention operation is as follows: a(l)=Sigmoid(G(l)⊕L(l)); G(l)=β(C1(δ(β(C1(F Max (l)))))); L(l)=β(C2(δ(β(C2(F Avg (l)))))); Where G(l) represents the output of the global context channel; L(l) represents the output of the local context channel; Sigmoid represents the activation function; δ represents the ReLU activation function; C1 represents dilated convolution; C2 represents point convolution; β represents batch normalization; F Max (l) indicates global max pooling of l; F Avg (l) indicates that global average pooling is performed on l.
5. The method for identifying small-sample plant diseases according to claim 2, characterized in that, The expression for the category marginal loss function is: in, Represents the learnable parameters in a deep nearest neighbor neural network. The corresponding category marginal loss function; Represents the learnable parameters in a deep nearest neighbor neural network. The corresponding loss function before the introduction of the L2 regularization term; It is determined by introducing the cosine margin; λ represents the penalty term coefficient.
6. The method for identifying small-sample plant diseases according to claim 5, characterized in that, The expression for the loss function before introducing the L2 regularization term is: Among them, L CML Let C represent the loss function before introducing the L2 regularization term; C represents the number of disease categories in the support set; N represents the number of samples in the query set; C disease categories are randomly selected from the finite training set, and K samples are selected from each selected disease category to form the support set; N samples are randomly selected again from these C disease categories as the query set; This represents the local descriptor used for training, determined based on the attention feature query map of the nth sample in the query set; the attention feature query map is the attention feature map output by the context attention module after the nth sample in the query set is input into the context attention module. express With support for the concentrated disease category c f The similarity between them; express With support for the concentrated disease category c t The similarity between them; S represents the cosine margin; S = m × K × D, where m represents the number of local descriptors used for training, D represents the distance added to the similarity between samples in the query set and disease categories in the support set; s represents the scale parameter.
7. The method for identifying small-sample plant diseases according to claim 1, characterized in that, The upsampling branch includes: a first fusion unit, a first upsampling unit, a second fusion unit, a second upsampling unit, and a third fusion unit; the downsampling branch includes: a fourth fusion unit, a first downsampling unit, a fifth fusion unit, a second downsampling unit, a sixth fusion unit, and a third downsampling unit; The output of the first network layer in the backbone network is connected to the fourth fusion unit through the first fusion unit; the output of the second network layer is connected to the fifth fusion unit through the second fusion unit; the second fusion unit is connected to the first fusion unit through the first upsampling unit; the fourth fusion unit is connected to the fifth fusion unit through the first downsampling unit; the output of the third network layer is connected to the sixth fusion unit through the third fusion unit; the third fusion unit is connected to the second fusion unit through the second upsampling unit; the fifth fusion unit is connected to the sixth fusion unit through the second downsampling unit; the third downsampling unit is used to output a low-level feature map; The first fusion unit, the second fusion unit, the third fusion unit, the fourth fusion unit, the fifth fusion unit, and the sixth fusion unit are all used to perform weighted summation; The calculation formula for the second fusion unit is as follows: This indicates the output of the second fusion unit to the third fusion unit; This represents the output of the second network layer; This represents the output of the third network layer; This represents the weights corresponding to the output of the second network layer; Upsample indicates the upsampling operation. The calculation formula for the fifth fusion unit is: This represents the output of the fifth fusion unit to the second downsampling unit; This indicates the weight corresponding to the output of the first downsampling unit; Downsample indicates the downsampling operation. This indicates the output of the fourth fusion unit to the first downsampling unit.
8. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the small sample plant disease identification method according to any one of claims 1-7.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the small sample plant disease identification method according to any one of claims 1-7.
10. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the small sample plant disease identification method according to any one of claims 1-7.