Crop disease and insect pest model training method
By combining the mutual attention learning module and the text encoder, attention maps and feature vectors are generated, the model training process is optimized, and the accuracy problem of pest and disease identification in complex farmland scenarios is solved, achieving efficient identification of pests and diseases.
Patent Information
- Application Number
- CN202510889059.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-11-07
AI Technical Summary
Existing technologies struggle to effectively identify crop diseases and pests in complex farmland scenarios, especially due to the unbalanced distribution of disease and pest samples, severe interference from background information, and the difficulty in sample collection, resulting in low accuracy in disease and pest identification.
A mutual attention learning module is used to generate attention maps, which reduces background interference and highlights crop information. Combined with a text encoder, the text description of pests and diseases is transformed into feature vectors, which are then fused with image feature vectors. The model is optimized through a total loss function to generate enhanced training data, thereby improving the accuracy of localization and classification of pest and disease areas.
By accurately locating disease and pest areas and generating enhanced training data, the model's ability to capture the lesion features of small targets is improved, effectively addressing the problem of sample distribution imbalance and enhancing the accuracy and learning efficiency of crop disease and pest image classification.
Smart Images

Figure CN120912944A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of crop disease and pest identification, and particularly to a model training method for crop disease and pest. BACKGROUND
[0002] In the modern agricultural production process, the growth stage of crops determines the management focus and technical application means at different stages. As the crops mature, it is necessary to pay attention to the prevention and control management of diseases and pests.
[0003] However, in the current disease and pest monitoring task, there is often only a slight difference between diseased crops and healthy crops, and the morphology of diseased crops and healthy crops is similar, resulting in poor inter-class separability. In addition, the diseased area is usually small and not concentrated, and other crop factors in the background interfere seriously, which is easily overwhelmed by background information. At the same time, the sample distribution in the actual farmland scene is seriously unbalanced, and the proportion of healthy crop samples is usually large, while the early disease and pest sample collection is difficult and the quantity is scarce, further aggravating the neglect of weak pathological characteristics. Therefore, the current monitoring scheme is difficult to identify diseases and pests in complex farmland scenes. SUMMARY
[0004] In view of the defects in the prior art, the model training method for crop disease and pest provided by the present application can more effectively identify diseases and pests in farmland.
[0005] The present application provides a model training method for crop disease and pest, the model training method comprising:
[0006] inputting an original image of a crop into a mutual attention learning module of an artificial intelligence model;
[0007] outputting an image feature vector and an attention map of the original image based on the mutual attention learning module, wherein the attention map reduces the background information of the original image and highlights the crop information;
[0008] inputting a text description of a disease and pest into a text encoder of the artificial intelligence model to obtain a text feature vector;
[0009] obtaining a classification result related to the disease and pest in the original image based on the text feature vector and the image feature vector;
[0010] calculating a total loss function according to the classification result and a preset disease and pest class true value, and obtaining a new image with a disease and pest area according to the attention map;
[0011] enhancing training of the artificial intelligence model using the new image, and optimizing the classification network of the artificial intelligence model using the loss function.
[0012] In one aspect, the step of calculating the total loss function according to the classification result and the preset disease and pest category true value comprises:
[0013] The discriminative triplet loss function, the adaptive focal loss function and the cross-entropy loss function are calculated according to the classification result and the preset disease and pest category true value, and the total loss function comprises the discriminative triplet loss function, the adaptive focal loss function and the cross-entropy loss function.
[0014] In one aspect, the total loss function is defined as L total , the discriminative triplet loss function is L tri , the adaptive focal loss function is L foc , the cross-entropy loss function is L ce , λ tri is the weight of the discriminative triplet loss function, λ foc is the weight of the adaptive focal loss function, and λ ce is the weight of the cross-entropy loss function, and the following is satisfied:
[0015] L total = λ tri × L tri + λ foc × L foc + λ ce × L ce .
[0016] In one aspect,
[0017]
[0018]
[0019]
[0020] wherein α is a dynamically adjusted boundary parameter, f r represents the feature vector of an anchor point, f p represents the feature vector of a positive sample, f n represents the feature vector of a negative sample, N is the total number of samples, C is the total number of categories, p c is the predicted probability of the model for a category c, γ c is a dynamically adjusted modulation factor, p c is a category true value.
[0021] In one aspect, the step of obtaining a new image with a disease and pest area according to the attention map comprises:
[0022] The original image is cropped according to the attention map to obtain a new image with a disease and pest area.
[0023] In one aspect, the step of inputting the text description of the plant disease and pest into the text encoder of the artificial intelligence model to obtain a text feature vector comprises:
[0024] inputting the text description of at least one of the color change of the leaf of the crop, the color change of the rootstock, the spatial distribution characteristics of the lesion spot, and the surface structure of different growth stages into the text encoder;
[0025] converting the text description into a text feature vector using a pre-trained model.
[0026] In one aspect, the step of obtaining a classification result related to the plant disease and pest in the original image based on the text feature vector and the image feature vector comprises:
[0027] inputting the text feature vector and the image feature vector into a mutual attention learning module to determine local features related to the plant disease and pest in the original image, and outputting a classification result according to the local features.
[0028] In one aspect, the mutual attention learning module comprises a perception unit and a feature fusion unit.
[0029] The perception unit is provided in multiple, and the multiple perception units are arranged in layers from shallow to deep. The perception unit in the shallow layer is used to capture image details, the perception unit in the deep layer is used to obtain semantic details, and the perception unit in the lower layer is also used to inherit the prior knowledge of the perception unit in the upper layer.
[0030] The feature fusion unit comprises a convolution layer, a class activation map, and a global maximum pooling layer, and the convolution layer, the class activation map, and the global maximum pooling layer are one-to-one correspondingly arranged.
[0031] In one aspect, the step of inputting the original image of the crop into the mutual attention learning module of the artificial intelligence model comprises:
[0032] obtaining an original image of a crop planting area, normalizing the size of the original image, and inputting the processed original image into the mutual attention learning module of the artificial intelligence model.
[0033] In one aspect, after the step of using the new image to enhance the training of the artificial intelligence model, comprises:
[0034] deleting the new image to release the storage space.
[0035] The beneficial effects of the present application are embodied in that the mutual attention learning module generates an attention map highlighting crop information and reducing background interference, accurately locates the disease and pest area through the attention map, and cuts to generate enhanced training data, and improves the ability to capture small target disease characteristics through new images; the text encoder converts the disease and pest text description into a feature vector, and after fusion with the image feature vector, guides the model to pay attention to the local features corresponding to the text description to distinguish subtle differences; the total loss function optimizes the classification network of the artificial intelligence model, effectively deals with the imbalance problem of disease and pest and healthy samples, improves the learning efficiency of the model on disease and pest characteristics, and thus improves the accuracy of crop disease and pest image classification under complex background. BRIEF DESCRIPTION OF DRAWINGS
[0036] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the specific embodiments or prior art description will be briefly introduced below. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, each element or part is not necessarily drawn according to the actual scale.
[0037] Figure 1 The flow step schematic diagram of the model training method for crop diseases and pests of the present application;
[0038] Figure 2 The flow step schematic diagram of the model training method for crop diseases and pests of the present application in calculating the total loss function and obtaining new images;
[0039] Figure 3 The flow step schematic diagram of the model training method for crop diseases and pests of the present application in converting the text description into a text feature vector;
[0040] Figure 4 The flow step schematic diagram of the model training method for crop diseases and pests of the present application in outputting the disease and pest classification results according to the local features;
[0041] Figure 5 The flow step schematic diagram of the model training method for crop diseases and pests of the present application in normalizing the original image;
[0042] Figure 6 The flow step schematic diagram of the model training method for crop diseases and pests of the present application in deleting new images;
[0043] Figure 7 The architecture schematic diagram of the model for crop diseases and pests of the present application;
[0044] Figure 8 The schematic diagram of the original image and the attention map in the model training method for crop diseases and pests of the present application. DETAILED DESCRIPTION
[0045] The embodiments of the technical solution of the present invention will now be described in detail with reference to the accompanying drawings. These embodiments are merely illustrative of the technical solution of the present invention and are therefore intended to limit the scope of protection of the present invention.
[0046] It should be noted that, unless otherwise stated, the technical or scientific terms used in this invention should have the ordinary meaning as understood by one of ordinary skill in the art.
[0047] Please refer to Figure 1 As shown, this embodiment of the invention provides a model training method for crop diseases and pests. The model training method includes:
[0048] Step S10: Input the original images of the crops into the mutual attention learning module of the artificial intelligence model. Original images can be obtained by using drones equipped with high-definition cameras to collect images of large areas of farmland, suitable for large-scale pest and disease monitoring. Alternatively, fixed image acquisition devices can be set up in key areas of the farmland to capture images of crop growth status in real time or at set intervals. Or, portable devices such as smartphones and digital cameras can be used to take close-up photos of specific crop plants or areas to obtain high-resolution local images.
[0049] Step S20: Based on the mutual attention learning module, output the image feature vector and attention map of the original image. The attention map reduces the background information of the original image and highlights the crop information. The mutual attention learning module outputs two parts: the image feature vector and the attention map.
[0050] Image feature vectors contain a comprehensive feature representation of crops and background in an image; attention maps highlight crop areas, such as leaves and stems, by suppressing background information, such as soil and weeds, and locate key areas in the image that are potentially related to pests and diseases.
[0051] Step S30: Input the text description of pests and diseases into the text encoder of the artificial intelligence model to obtain the text feature vector; input the text description of pests and diseases into the text encoder of the artificial intelligence model. The text encoder converts the structured text information into text feature vectors through semantic understanding and feature extraction, realizing the numerical expression of the semantic information of pests and diseases, and providing semantic guidance for cross-modal feature fusion.
[0052] Step S40, obtain a classification result related to the plant diseases and insect pests in the original image based on the text feature vector and the image feature vector; specifically, the text feature vector and the image feature vector can be input into the mutual attention learning module, and the association between the text semantics and the local region of the image is established through the attention mechanism. The artificial intelligence model screens out the local features strongly related to the plant diseases and insect pests, such as the color and texture features of the lesion region, based on the association result, and outputs the final classification result of the plant diseases and insect pests, thereby realizing semantic mapping from features to categories.
[0053] Step S50, calculate a total loss function according to the classification result and the preset plant disease and insect pest category true value, and obtain a new image with a plant disease and insect pest region according to the attention map; compare the classification result with the preset plant disease and insect pest category true value, and calculate the total loss function, which is used to measure the deviation between the model prediction and the true value.
[0054] Based on the attention map generated in step S20, the original image is cropped to extract a new image containing the plant disease and insect pest region. The new image focuses on the lesion features and can be used as an enhanced sample for model training to alleviate the problems of sample imbalance and small target detection. Referring to Figure 8 As shown in the figure, the left side is the original image, and the right side is the attention map.
[0055] Step S60, use the new image to enhance the training of the artificial intelligence model, and use the loss function to optimize the classification network of the artificial intelligence model. The new image obtained by cropping is input into the artificial intelligence model to supplement the diversity of the plant disease and insect pest samples and strengthen the learning of the artificial intelligence model on the lesion features. The parameters of the model classification network are adjusted by using the back propagation mechanism of the total loss function to reduce the prediction error. Through iteration of this process, the artificial intelligence model gradually improves the classification accuracy and generalization ability for crop plant diseases and insect pests in complex backgrounds.
[0056] In this embodiment, the mutual attention learning module generates an attention map highlighting crop information and reducing background interference, accurately locates the plant disease and insect pest region through the attention map, and crops to generate enhanced training data. The new image improves the ability to capture small target lesion features; the text encoder converts the text description of the plant diseases and insect pests into a feature vector, which is fused with the image feature vector to guide the model to focus on the local features corresponding to the text description to distinguish subtle differences; the total loss function optimizes the classification network of the artificial intelligence model, effectively deals with the imbalance between the plant disease and insect pest samples and the healthy samples, improves the learning efficiency of the model on the plant disease and insect pest features, and thus improves the accuracy of crop plant disease and insect pest image classification in complex backgrounds.
[0057] As Figure 2 shown, the step of calculating the total loss function according to the classification result and the preset plant disease and insect pest category true value includes:
[0058] Step S510, according to the classification result and the preset pest and disease category true value, a discriminative triplet loss function, an adaptive focal loss function and a cross-entropy loss function are calculated, and a total loss function includes the discriminative triplet loss function, the adaptive focal loss function and the cross-entropy loss function.
[0059] The discriminative triplet loss function is based on a triplet structure including an anchor point, a positive sample and a negative sample, and optimizes a feature space through a dynamic boundary parameter, so that features of samples of the same class are gathered and features of samples of different classes are separated. The discriminative triplet loss function enhances the class separability, especially for subtle differences between diseased and healthy crops, and improves the distinguishing ability of the model for easily confused classes.
[0060] The adaptive focal loss function introduces a dynamic modulation factor and a sample weight, and gives higher weight to difficult samples and minority class samples, and reduces the attention to simple samples. The adaptive focal loss function can alleviate the problem of unbalanced sample distribution, force the model to focus on scarce pest and disease features, and avoid training bias towards the majority class.
[0061] The cross-entropy loss function measures the overall classification error of the model by calculating the probability distribution difference between the classification result and the true value. The cross-entropy loss function can provide basic classification loss, stabilize the training process, and ensure the global rationality of the model's prediction for each class.
[0062] In an embodiment of the present application, the total loss function is defined as L total , the discriminative triplet loss function is L tri , the adaptive focal loss function is L foc , the cross-entropy loss function is L ce , λ tri is the weight of the discriminative triplet loss function, λ foc is the weight of the adaptive focal loss function, and λ ce is the weight of the cross-entropy loss function, and it satisfies:
[0063] L total =λ tri ×L tri +λ foc ×L foc +λ ce ×L ce In this embodiment, λ tri = 0.7, λ foc = 1.2, and λ ce = 0.5.
[0064] In an embodiment of the present application,
[0065] The discriminative triplet loss function minimizes the distance between positive samples and query samples while maximizing the distance between negative samples and query samples, thus ensuring that the model can better distinguish between similar and dissimilar samples. Through comparative learning using anchor samples, positive samples, and negative samples, it constrains the clustering of similar samples and the separation of dissimilar samples in the feature space.
[0066] The discriminative triplet loss function in this application sets a relatively large boundary α = 0.5 in the initial stage to force the model to quickly establish preliminary separability; as training progresses, it linearly decays to α = 0.2 to avoid excessive constraints that could lead to feature space collapse. Secondly, a data mining strategy is employed: first, based on feature similarity calculations, difficult negative samples are selected for optimization. Specifically, for each anchor sample, the top-30% of negative samples with the highest similarity from the same batch are selected to construct triplets, improving the ability to distinguish easily confused categories.
[0067]
[0068] The adaptive focus loss function is mainly aimed at the class imbalance problem that is common in agricultural images, such as the proportion of healthy crop samples being significantly higher than that of diseased samples. Through a difficulty-aware weight allocation mechanism, the model is strengthened to pay attention to difficult samples and minority classes.
[0069]
[0070] Cross-entropy loss provides a global optimization direction, ensuring the model maintains stable convergence characteristics during complex multi-objective optimization processes. Unlike single cross-entropy loss, the cross-entropy loss term in this application uses weighting coefficients, λ... ce =0.5, participates in joint optimization, mainly constrains the overall distribution of the feature space, and prevents triple loss from excessively pursuing local separability and destroying the global structure; secondly, it provides a stable gradient signal to alleviate the training instability of focus loss under extreme sample distribution.
[0071] Where α is a dynamically adjusted boundary parameter, f r f represents the feature vector of the anchor point. p The feature vector of positive samples, f n Let N be the feature vector of the negative samples, C be the total number of samples, and p be the total number of classes. c γ represents the predicted probability of the model for class c. c p is a dynamically adjusted modulation factor. c This is the true value for the category.
[0072] Further reading Figure 2 As shown, the steps for obtaining a new image of an area with pests and diseases based on an attention map include:
[0073] Step S520: The original image is cropped based on the attention map to obtain a new image containing the diseased and pest-affected areas. The attention map is generated by the mutual attention learning module, which suppresses background information and highlights areas related to crop diseases and pests, intuitively reflecting the most discriminative location for classification in the image. For example, if a leaf in the image has a lesion, the attention map will highlight that area while weakening the background area.
[0074] Cropping the original image can be done by setting a threshold based on the pixel value distribution of the attention map, or by automatically identifying high-attention areas through an algorithm and performing geometric cropping on the original image.
[0075] For example, firstly, the connected regions with pixel values higher than a threshold in the attention map are extracted and mapped back to the corresponding positions in the original image; based on the spatial distribution of the attention map, the minimum bounding rectangle or polygon region is generated, and the content within this region in the original image is cropped to obtain a new image containing only the pest-related regions.
[0076] The new images focus on key features of pests and diseases, and can be used as new training samples to alleviate the problem of insufficient model learning caused by the scarcity of early pest and disease samples and the small size of lesion areas. It forces the model to directly learn the high-discriminative regions after cropping during training, avoids background interference, and improves the sensitivity to subtle lesion features. In addition, the size of the cropped image is usually smaller than the original image, which can reduce the amount of computation.
[0077] Step S520 and step S20 form a closed loop, which involves locating features through attention maps, pruning and enhancing features, and then inputting them back into the model for training, thus forming an iterative optimization path of "feature discovery - feature enhancement - feature learning".
[0078] The combination of steps S520 and S60 enables the new image to be used as input for model training. Combined with the optimization of the total loss function, this further improves the model's classification accuracy for pests and diseases in complex backgrounds.
[0079] like Figure 3 As shown, the steps for inputting a text description of pests and diseases into the text encoder of an artificial intelligence model to obtain text feature vectors include:
[0080] Step S310, input the text description of at least one of the color change of the leaves of the crop, the color change of the rhizome, the spatial distribution characteristics of the disease spot, and the surface structure at different growth stages into the text encoder; the input content focuses on the key morphological features and growth stage features of the disease and pest, which can include: color change of leaves or rhizomes, such as leaf yellowing, rhizome browning, and other color abnormalities, which directly reflect the physiological state of the disease; spatial distribution characteristics of disease spots, such as the size, shape, density, and distribution position of disease spots on the plant, which reflect the transmission mode of the disease; surface structure at different growth stages, such as leaf shrinkage at the seedling stage, fruit spot at the mature stage, and the like, which reflect the specific performance of the disease at different growth cycles.
[0081] Through structured text description, the domain knowledge of diseases and pests is converted into model processable input, making up for the possible missing semantic details in image data.
[0082] Step S320, convert the text description into a text feature vector using a pre-trained model. Utilize a pre-trained language model (such as BERT) to encode the text description: split the text into subwords, such as "leaf vein yellowing" into "leaf vein" and "yellowing", and convert them into low-dimensional dense vectors through a word embedding layer; deep semantic extraction, based on the bidirectional attention mechanism of the Transformer architecture, captures the context association between words, such as the spatial relationship between "disease spot" and "round", and generates a text feature vector containing global semantics; match the dimensions of the text feature vector and the image feature vector through linear transformation, which facilitates subsequent cross-modal fusion.
[0083] Among them, the pre-trained model learns through massive texts and has the ability to capture the deep semantics of professional terms, such as distinguishing the subtle differences between "water stain-like disease spots" and "mold layer disease spots"; the text feature vector acts as a "semantic pointer" to guide the model to focus on the areas corresponding to the text description in the image in the mutual attention learning module, and suppress irrelevant background interference; for rare diseases and pests, virtual feature vectors can be generated through text descriptions to alleviate the "data scarcity" problem and improve the model's generalization ability to unseen classes.
[0084] Steps S310 and S320 build a cross-modal association bridge, mapping "text semantics" and "image visual features" to the same feature space, realizing the joint learning of "text description guiding image understanding", and solving the class confusion problem caused by traditional image classification relying only on visual clues.
[0085] As shown in Figure 4 the step of obtaining a classification result related to the disease and pest in the original image based on the text feature vector and the image feature vector, comprising:
[0086] Step S410, input the text feature vector and the image feature vector into the mutual attention learning module, determine the local features related to the plant diseases and insect pests in the original image, and output the classification result according to the local features. Step S410 realizes the deep fusion of the text semantic and the image visual features through the cross-modal attention mechanism: the plant disease and insect pest semantic feature vector output by the text encoder and the image feature vector are input into the mutual attention learning module, the module takes the text feature as a query vector, generates attention weights by calculating the similarity with the image region features, thereby focusing on the local region in the image that is strongly related to the text semantic and suppressing the background noise; the fused local features not only retain the visual details but also carry the semantic labels, after being mapped to the category space through the full connection layer, the prediction result of the plant disease and insect pest type is output, the sensitivity to the subtle disease characteristics and the inter-class discrimination ability of the model are improved through the semantic guided feature screening, which is especially suitable for the precise classification of crop plant diseases and insect pests in complex background. Among them, the text feature vector is input as Query, and the image feature vector is input as Key and Value. The plant disease and insect pest description semantic features extracted through the BERT encoder have a dimension of dt, and the image feature vector has a dimension of dv. Let the text feature vector be Query, the image feature vector be Key and Value, and the cross-modal attention mechanism be Attention, the text feature vector is mapped to the key-value space through the linear layer, and the image Key and Value vectors are projected to realize dimension alignment. The weighted image features are as follows: Image feature K, The text Query vector is mapped to the key-value space through the linear layer The image Key and Value vectors are projected, respectively, and The output of the cross-attention module is: output=LayerNorm(Attention(Q,K,V)+V), and the output is obtained through the full connection layer to obtain the classification result.
[0087]
[0088] Among them, a is a scaling factor.
[0089] The output of the cross-attention module is: output=LayerNorm(Attention(Q,K,V)+V), and the output is obtained through the full connection layer to obtain the classification result.
[0090] Referring to Figure 7 As shown, in an embodiment of the present application, the mutual attention learning module includes a perception unit and a feature fusion unit. The perception unit is provided with multiple layers, and the multiple layers are arranged from shallow to deep. The shallow layer perception unit is used to capture image details, and the deep layer perception unit is used to obtain semantic details. The lower layer perception unit is also used to inherit the prior knowledge of the upper layer perception unit. The perception unit adopts a multi-level hierarchical architecture. The shallow layer perception unit, such as the early convolutional layer based on ResNet-50, is responsible for capturing low-level details of the image. The deep layer perception unit, such as the high-level convolutional layer of ResNet-50, extracts high-level semantic features. Each layer unit realizes knowledge inheritance through cross-layer connection, that is, the lower layer unit can receive the prior features of the upper layer unit, forming progressive feature learning from details to semantics, and avoiding the separation of shallow features and deep semantics.
[0091] The feature fusion unit includes a convolutional layer, a class activation map, and a global maximum pooling layer, which are one-to-one correspondingly arranged. Each perception unit is equipped with an independent convolutional layer, a global maximum pooling layer, and a class activation map (CAM). The convolutional layer reduces the number of feature channels through 1x1 convolution, reducing the computational complexity. The global maximum pooling layer extracts global discriminative information in the feature map to generate a structured global descriptor. The class activation map generates attention weights based on the feature map, locates the key regions related to the class, and outputs an attention map through normalization processing, which is used to guide the model to focus on the crop disease and pest area and suppress background interference. Through the hierarchical feature extraction of the perception unit and the attention mechanism of the feature fusion unit, not only can the multi-level features be fused to improve the classification accuracy, but also the interpretable attention region can be generated unsupervised, providing support for data enhancement and model optimization, effectively solving the problem that the lesion features are easily submerged and the class separability is poor in a complex background.
[0092] Specifically, the feature fusion unit includes a 1x1 convolutional layer, a global maximum pooling layer, and a class activation map. The intermediate feature map generated by the i-th perception unit is denoted as F i , which has a height H i , a width W i , and a channel number C i . These feature maps reflect information from low-level to high-level at different levels. In order to extract effective information from these feature maps, a set of functions is used to compress the feature map of each perception unit into a one-dimensional vector descriptor. For example, through a set of mapping functions g i and h i , each feature map F i is compressed into a one-dimensional vector descriptor z i and α i :
[0093] z i = g i (F i), a i = h i (F i ),
[0094] where z i ∈ R d is the structured global descriptor of the i-th feature perception unit, g i represents the global max pooling; a i ∈ R d is the corresponding attention weight representation, which is used to guide the focus on the region of interest, h i represents the operator for calculating the attention weight. This process is realized by convolution and global max pooling operation, which reduces the spatial dimension of the feature. Through these operations, the generated intermediate feature map provides support for the subsequent attention region generation, so as to extract the feature vector of the image and the attention map related to the category.
[0095] As shown in FIG. 1, the step of inputting the original image of the crop into the mutual attention learning module of the artificial intelligence model includes: Figure 5 In step S110, the original image of the crop planting area is obtained, the size of the original image is normalized, and the processed original image is input into the mutual attention learning module of the artificial intelligence model. Through unmanned aerial vehicle aerial photography, field fixed camera or artificial handheld device, etc., high-resolution images of crop planting areas are collected, covering crops in different growth stages, varieties and environmental conditions, forming an original data set containing healthy and pest samples.
[0096] Through scaling operation, using bilinear interpolation, nearest neighbor interpolation and other algorithms, the original images of different resolutions are uniformly adjusted to the input size preset by the model, such as 224x224 pixels, 299x299 pixels, etc. For example, if the model is based on ResNet architecture design, the image is usually scaled to 224x224 pixels to match the network input specification. For images with inconsistent aspect ratio, the main body area can be retained after center cropping and scaling, or the proportion can be maintained after edge padding and scaling, to avoid feature distortion caused by image distortion.
[0097] Because different collection devices or shooting distances will result in different image sizes, normalization processing can avoid feature extraction deviation caused by inconsistent pixel sizes. Artificial intelligence models generally require fixed input size, and normalization processing ensures that images can be correctly input into the convolution layer, pooling layer and other structures of the model, avoiding calculation errors caused by dimension mismatch. Uniform size can also optimize memory usage and computational complexity during model inference.
[0098]
[0099] After the normalized image input is input into the mutual attention learning module, the hierarchical perception unit of the module can stably capture low-level features such as textures and edges, and the deep perception unit can extract high-level semantics based on the uniform size feature map, avoiding feature level confusion caused by size fluctuations.
[0100] Step S110 solves the compatibility problem of data input by standardizing the size of the original image, especially for the unified processing of multi-source images in complex agricultural scenes.
[0101] As shown in Figure 6 After the step of using new images to enhance the training of the artificial intelligence model, it includes:
[0102] Step S70, delete the new image, release the storage space. In step S520, the new images generated based on the attention map are only used as enhancement data for this round of training. After the single round of training is completed, the mission of these new images has been accomplished, and they are deleted in batches to release the hard disk storage space and avoid the accumulation of redundant data.
[0103] Storage resource optimization: agricultural images usually have high resolution, and the new images generated by single training may occupy a large amount of storage. Regular deletion can prevent storage explosion and ensure the sustainability of the training environment, especially for long-term iterative training of large-scale farmland data sets.
[0104] Deleting redundant data can reduce file index overhead and speed up data loading. For example, if the training data directory contains a large number of historical enhanced images, the data reader needs to traverse more files, and after deletion, the data preprocessing time can be shortened and the training efficiency can be improved.
[0105] The new image as "temporary enhancement data" only assists the model in learning the local features of the pest area in this round of training, and its value decreases as the training round progresses. The deletion mechanism ensures that the attention map generated by the latest model is used to dynamically generate enhancement data for each round of training, rather than repeatedly using old data, forming a virtuous cycle of "generation-use-deletion-regeneration".
[0106] Step S70 realizes efficient use of storage resources by timely cleaning up temporary enhancement data without affecting the training effect of the model, and at the same time, through the training mechanism of forced dependence on the original image, the generalization and stability of model learning are guaranteed, which is an important engineering design to balance data utilization and resource consumption.
[0107] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit the present application; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can still be modified, or some or all of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application, and they should be covered in the scope of the claims and the description of the present application.
Claims
1. A method for training a model of crop diseases and pests, characterized in that, The model training method comprises: inputting an original image of crops into a mutual attention learning module of an artificial intelligence model; outputting an image feature vector and an attention map of the original image based on the mutual attention learning module, wherein the attention map reduces background information of the original image and highlights crop information; inputting a text description of a disease and pest into a text encoder of the artificial intelligence model to obtain a text feature vector; obtaining a classification result related to the disease and pest in the original image based on the text feature vector and the image feature vector; calculating a total loss function according to the classification result and a preset disease and pest category true value, and obtaining a new image with a disease and pest area according to the attention map; enhancing training of the artificial intelligence model using the new image, and optimizing a classification network of the artificial intelligence model using the loss function.
2. The model training method of claim 1, wherein, The step of calculating a total loss function according to the classification result and a preset disease and pest category true value comprises: calculating a discriminative triplet loss function, an adaptive focal loss function and a cross-entropy loss function according to the classification result and the preset disease and pest category true value, and the total loss function comprises the discriminative triplet loss function, the adaptive focal loss function and the cross-entropy loss function.
3. The model training method of claim 2, wherein, The total loss function is defined as L total , the discriminative triplet loss function is L tri , the adaptive focal loss function is L foc , the cross-entropy loss function is L ce , λ tri is a weight of the discriminative triplet loss function, λ foc is a weight of the adaptive focal loss function, and λ ce is a weight of the cross-entropy loss function, and the following is satisfied: L total = λ tri × L tri + λ foc × L foc + λ ce × L ce .
4. The model training method according to claim 3, wherein where a is a dynamically adjusted boundary parameter, f r feature vector representing an anchor point, f p feature vector of a positive sample, f n feature vector of a negative sample, N is the total number of samples, C is the total number of classes, p c is the predicted probability of the model for class c, γ c is a dynamically adjusted modulation factor, p c is the class true value.
5. The model training method of claim 1, wherein, The step of obtaining a new image with a disease and pest area according to the attention map comprises: cropping the original image according to the attention map to obtain the new image with the disease and pest area.
6. The model training method of claim 1, wherein, The step of inputting a text description of a disease and pest into a text encoder of the artificial intelligence model to obtain a text feature vector comprises: inputting a text description of at least one of color change of leaves, color change of roots and stems, spatial distribution characteristics of disease spots and surface structure of different growth stages into the text encoder; using a pre-trained model to convert the text description into the text feature vector.
7. The model training method of claim 1, wherein, The step of obtaining a classification result related to the disease and pest in the original image based on the text feature vector and the image feature vector comprises: inputting the text feature vector and the image feature vector into a mutual attention learning module to determine local features related to the disease and pest in the original image, and outputting the classification result according to the local features.
8. The model training method of any one of claims 1-7, wherein, The mutual attention learning module comprises a perception unit and a feature fusion unit; The perception unit is provided in plurality, and the plurality of perception units are arranged in layers from shallow to deep, the shallow layer perception unit is used to capture image details, the deep layer perception unit is used to obtain semantic details, and the lower layer perception unit is also used to inherit prior knowledge of the upper layer perception unit; The feature fusion unit comprises a convolution layer, a class activation map and a global maximum pooling layer, and the convolution layer, the class activation map and the global maximum pooling layer are arranged one by one.
9. The model training method of claim 1, wherein, The step of inputting an original image of crops into a mutual attention learning module of an artificial intelligence model comprises: obtaining an original image of a crop planting area, normalizing the size of the original image, and inputting the processed original image into the mutual attention learning module of the artificial intelligence model. 10.The model training method of claim 1, wherein, After the step of enhancing training of the artificial intelligence model with the new image, comprising: deleting the new image, freeing up storage space.