Crop recognition method and system based on contrast learning

CN122990450APending Publication Date: 2026-10-27CHENGDU VOCATIONAL COLLEGE OF AGRI SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410725830.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-06
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

导致现有农作物识别算法准确度不高,限制了此技术的进一步推广和发展

Benefits of technology

[0062]其有益效果在于,通过采用注意力机制网络结构,构建特征提取模块,强化农作物全局的特征信息,然后采用多模态CLIP进行图像编码,构建对比特征,利用对比学习,学习同一物种不同状态下的特征差异以及相似物种的特征差异,最后采用相似对比交叉熵损失进行模型训练。本发明通过注意力机制,强化全局特征信息,同时利用对比学习,学习同一物种不同状态下的特征差异以及相似物种的特征差异,能够有效避免由于病害,光照等因素干扰,导致同一物种特征存在差异的问题,从而提升对于农作物识别的准确度,在实际应用中更具有鲁棒性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122990450A_ABST
    Figure CN122990450A_ABST
Patent Text Reader

Abstract

The application discloses a crop recognition method and system based on contrast learning, adopts an attention mechanism network structure to construct a feature extraction module, strengthens the global feature information of crops, then adopts a multi-modal CLIP to perform image coding, constructs contrast features, utilizes contrast learning to learn feature differences under different states of the same species and feature differences of similar species, and finally adopts a similar contrast cross-entropy loss to perform model training. Through the attention mechanism, the global feature information is strengthened, and at the same time, the contrast learning is utilized to learn the feature differences under different states of the same species and the feature differences of similar species, so that the problem that the same species features exist differences due to interference factors such as diseases and light can be effectively avoided, and the accuracy of crop recognition is improved, and the method has more robustness in actual application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image recognition, and in particular to a crop recognition method and system based on contrastive learning. Background Technology

[0002] Crop classification and identification is a method based on image processing and pattern recognition technologies, designed to accurately identify different types of crops. With the development of agricultural technology and the increasing variety of crops, rapid and accurate crop identification has become increasingly important for agricultural production and management. In traditional crop identification methods, manual judgment is the primary means. However, this method suffers from subjectivity, time-consuming nature, and high labor costs.

[0003] In recent years, with the rapid development of computer vision technologies, computer vision has become a core technology for crop identification. It involves steps such as image acquisition, preprocessing, feature extraction, and classification. Image acquisition can be performed using devices such as drones, satellite remote sensing, or smartphones to obtain high-quality crop images. The preprocessing stage includes image denoising, enhancement, and correction to improve image quality and reduce the impact of noise. Feature extraction involves extracting features from the image that are relevant to crop classification, such as texture, shape, and color. Finally, classification algorithms use these features to assign images to different crop categories.

[0004] Machine learning plays a crucial role in crop classification and identification. By training on a large number of crop image samples, machine learning algorithms can learn and recognize the characteristic patterns of different crops. Common machine learning algorithms include Support Vector Machines (SVM), Artificial Neural Networks (ANN), and Random Forests. These algorithms can classify images based on input feature vectors and output the corresponding crop categories. The application potential of crop classification and identification technology is extensive. It can help farmers and agricultural professionals accurately identify crop types in farmland, thereby optimizing agricultural management and decision-making. Furthermore, crop classification and identification technology can also be used to monitor pests and diseases, measure crop growth status, and predict crop yields, providing strong support for agricultural production.

[0005] However, due to the vast variety of crops and the small differences between them, different crops share a certain degree of similarity, such as chili peppers and small red chili peppers. Within a single crop, however, there are significant differences. Even within the same crop, variations in characteristics can occur due to different diseases; for example, some three-cherry peppers may have fruits infected with anthracnose, leaf blight, purple spot, or sunscald. This results in low accuracy for existing crop identification algorithms, limiting the further promotion and development of this technology. The focus of this invention is to improve the accuracy of crop identification while simultaneously recognizing different growth stages of crops. Summary of the Invention

[0006] The purpose of this invention is to solve the above problems by designing a crop identification method and system based on contrastive learning.

[0007] To achieve the above objectives, the technical solution of the present invention further includes the following steps in the above-mentioned crop identification method based on contrastive learning:

[0008] Obtain crop image data from the database, perform data preprocessing on the crop image data, and obtain target crop image data;

[0009] A crop identification model is established, which includes at least an attention mechanism fusion module, an attention mechanism feature extraction module, a contrast feature group, and a similarity contrast cross-entropy loss function.

[0010] The input feature map is input into the attention mechanism fusion module to obtain an attention feature map; the attention feature map and the input feature map are multiplied to generate an attention fusion feature.

[0011] The similarity-contrast cross-entropy loss function is used to learn the features of similar species and the feature differences of different infections of the same species. The loss function includes multi-class cross loss and contrast loss.

[0012] The target crop image data is input into the crop recognition model, and the species category with the highest prediction probability is output to obtain the crop prediction result.

[0013] In one optional approach, the step of acquiring crop image data from a database and performing data preprocessing on the crop image data to obtain target crop image data includes:

[0014] Collect different crop image data in the system, including images of the same crop infected by different diseases, and label them with the corresponding crop labels to obtain labeled crop image data;

[0015] The crop label includes at least images of normal San Ying pepper, images of San Ying pepper with anthracnose, images of San Ying pepper with leaf blight, and images of San Ying pepper with purple blotch.

[0016] The labeled crop image data is normalized by setting its size to 512x512 pixels and converting the pixel value range from 0 to 255 to 0 to 1. The normalization formula is as follows:

[0017]

[0018] Where, xi Let x represent the value of the i-th pixel in the image, and max(x) and min(x) represent the maximum and minimum values ​​of the pixels in the image, respectively.

[0019] In one alternative approach, the attention mechanism fusion module includes:

[0020] An attention mechanism fusion module is constructed, which processes the input feature map through a global max pooling layer based on width and a global average pooling layer based on height.

[0021] The features output by the multilayer perceptron (MLP) are summed and then processed by the sigmoid activation function to generate the final attention feature map.

[0022] The attention feature map and the input feature map are multiplied to generate the attention fusion feature, which is represented by the following formula:

[0023]

[0024] Where F represents the input features, Representing the fused features, AvgPool(F) denotes the global max pooling layer operation based on width, and MaxPool(F) denotes the global average pooling layer operation based on height; Conv 3*3 (F) indicates that a 3x3 convolution operation is used.

[0025] In one alternative embodiment, the attention mechanism feature extraction module includes:

[0026] Construct an attention mechanism feature extraction module, the network structure of which includes at least a convolutional layer, a downsampling layer, an attention mechanism fusion layer, a fully connected layer, and a softmax layer;

[0027] The convolutional layer consists of a 3*3 convolutional kernel, a BN normalization layer, and a ReLU activation function, and the downsampling layer consists of an average pooling layer.

[0028] The attention mechanism is used to enhance the globality of features of different species through the fusion layer. Finally, a fully connected layer of size 1*1024 and a softmax layer of size 1*n are added to perform classification and recognition, where n is the total number of agricultural species categories.

[0029] In one alternative approach, the comparison feature set includes:

[0030] Construct a contrastive feature set, and use multimodal CLIP for image feature encoding during the training phase of the crop identification model to extract feature vectors V of the same species under different infection states. K V K+ and VK- ;

[0031] Among them, V K V represents the characteristics of the current input species. K+ Indicates with V K Characteristics of the same species under different infection states, V K- Indicates with V K Different species share similar characteristics.

[0032] In one alternative approach, the similarity-contrast cross-entropy loss function includes:

[0033] A similarity-contrast cross-entropy loss function is constructed, utilizing contrastive features to build a contrastive loss, learning the features of similar species and the feature differences of different infections of the same species. The formula for calculating the loss function is as follows:

[0034] Part 1: Multi-class Crossover Loss L cls Based on the softmax layer, the softmax loss L is calculated. cls Assuming there are n species categories, the softmax layer has an n-dimensional output vector, where the value of the i-th output vector represents the probability value of the i-th species category.

[0035]

[0036] Among them, y i S represents the true species category of the i-th species, which is labeled using one-hot encoding. i This indicates the probability of predicting the i-th species category;

[0037] Part Two: Comparison of Losses L con The input sample V is calculated based on the constructed contrast feature set. K V between positive samples K+ The correlation and the difference V compared with negative samples. K- The calculation formula is as follows:

[0038]

[0039] Where K represents the number of species that are the same as the input sample but have different infection states, and L represents the number of species that are different from the input sample but have a high degree of similarity;

[0040] The total loss value is:

[0041]

[0042] In one alternative approach, inputting the target crop image data into the crop recognition model and outputting the species category with the highest predicted probability to obtain the crop prediction result includes:

[0043] The target crop image data is input into the crop recognition model, and the parameters of the crop recognition model are optimized using the Adam algorithm.

[0044] The crop identification model is set to have 10,000 iterations, an initial learning rate of 0.001, and a weight decay of 0.0005.

[0045] Every 50 iterations of the crop identification model, the learning rate is reduced to 1 / 10 of its original value until the model converges and outputs the species category with the highest predicted probability, thus obtaining the crop prediction result.

[0046] In one alternative approach, an image data processing module is used to acquire crop image data from a database, perform data preprocessing on the crop image data, and obtain target crop image data.

[0047] An attention mechanism fusion module is used to feed the input feature map to the attention mechanism fusion module to obtain an attention feature map; and to perform a multiplication operation between the attention feature map and the input feature map to generate an attention fusion feature.

[0048] An attention mechanism feature extraction module is used to include at least a convolutional layer, a downsampling layer, an attention mechanism fusion layer, a fully connected layer, and a softmax layer;

[0049] The contrast feature group module is used to perform image feature encoding using multimodal CLIP to extract feature vectors of the same species under different infection states.

[0050] The Similarity Contrast Cross-Entropy Loss Function module is used to construct a contrastive loss using contrastive features, and to learn the features of similar species and the feature differences of different infections of the same species.

[0051] The image data recognition module is used to input the target crop image data into the crop recognition model, output the species category with the highest prediction probability, and obtain the crop prediction result.

[0052] In one alternative embodiment, the image data processing module includes the following sub-modules:

[0053] The collection submodule is used to collect different crop image data in the system. The crop image data includes images of the same crop infected by different diseases. The corresponding crop label is labeled to obtain labeled crop image data.

[0054] The label submodule is used to determine that the crop label includes at least the images of normal San Ying pepper, anthracnose San Ying pepper, leaf blight San Ying pepper, and purple spot disease San Ying pepper.

[0055] The normalization submodule is used to normalize the labeled crop image data, setting the size of the labeled crop image data to 512x512 pixels and converting the range of image pixel values ​​from 0 to 255 to 0 to 1. The normalization formula is as follows:

[0056]

[0057] Where, x i Let x represent the value of the i-th pixel in the image, and max(x) and min(x) represent the maximum and minimum values ​​of the pixels in the image, respectively.

[0058] In one alternative approach, the image data recognition module includes the following steps:

[0059] The input submodule is used to input the target crop image data into the crop recognition model and optimize the parameters of the crop recognition model using the Adam algorithm.

[0060] The settings submodule is used to set the number of iterations of the crop recognition model to 10,000, the initial learning rate to 0.001, and the weight decay to 0.0005.

[0061] A submodule is obtained, which is used to reduce the learning rate to 1 / 10 of the original rate every 50 iterations of the crop identification model until the model converges, and outputs the species category with the highest prediction probability to obtain the crop prediction result.

[0062] Its beneficial effects lie in the fact that by employing an attention-based network structure to construct a feature extraction module, it strengthens the global feature information of crops. Then, it uses multimodal CLIP for image encoding to construct comparative features. Through contrastive learning, it learns the feature differences of the same species under different states and the feature differences of similar species. Finally, it uses similarity-contrast cross-entropy loss for model training. This invention strengthens global feature information through an attention mechanism, and at the same time, it uses contrastive learning to learn the feature differences of the same species under different states and the feature differences of similar species. This effectively avoids the problem of feature differences of the same species caused by interference from factors such as disease and light, thereby improving the accuracy of crop identification and making it more robust in practical applications. Attached Figure Description

[0063] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention.

[0064] Figure 1This is a schematic diagram of the first embodiment of a crop identification method based on contrastive learning according to the present invention;

[0065] Figure 2 This is a schematic diagram of the first embodiment of a crop identification system based on contrastive learning according to the present invention;

[0066] Figure 3 This is a schematic diagram of a crop identification network model for a crop identification method based on contrastive learning in an embodiment of the present invention.

[0067] Figure 4 This is a schematic diagram of the attention mechanism fusion module of a crop identification method based on contrastive learning in an embodiment of the present invention. Detailed Implementation

[0068] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0069] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the word “comprising” as used in this specification means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not preclude the presence and addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0070] The present invention will now be described in detail with reference to the accompanying drawings, such as... Figure 1 As shown, a crop identification method based on contrastive learning includes the following steps:

[0071] Step 101: Obtain crop image data from the database, perform data preprocessing on the crop image data, and obtain target crop image data;

[0072] Specifically, in this embodiment, data collection involves collecting image data of different crops, including images of the same crop infected with different diseases, and labeling them with their corresponding crop labels. For example, the collected images of San Ying peppers include normal ones, as well as those infected with anthracnose, leaf blight, and purple blotch.

[0073] Data preprocessing. Image normalization is performed, setting the image size to 512x512. This transforms the pixel value range from 0-255 to 0-1, which helps speed up model training. The formula is as follows:

[0074]

[0075] Where x i Let x represent the value of the i-th pixel in the image, and max(x) and min(x) represent the maximum and minimum values ​​of the pixels in the image, respectively.

[0076] Step 102: Establish a crop identification model. The crop identification model shall include at least an attention mechanism fusion module, an attention mechanism feature extraction module, a contrast feature group, and a similarity contrast cross-entropy loss function.

[0077] Specifically, this embodiment constructs an attention mechanism fusion module. The input feature map is passed through a global max pooling layer based on width and a global average pooling layer based on height, and then through a multilayer perceptron (MLP). The features output by the MLP are summed and then processed by a sigmoid activation function to generate the final attention feature map. This attention feature map is then multiplied by the input feature map to generate the attention fusion feature. Its formula is as follows:

[0078]

[0079] Where F represents the input features. The fused features are represented by AvgPool(F), which represents the global max pooling operation based on width, and MaxPool(F), which represents the global average pooling operation based on height. 3*3 (F) indicates that a 3x3 convolution operation is used.

[0080] An attention mechanism feature extraction module is constructed. Its network structure mainly consists of convolutional layers, downsampling layers, an attention mechanism fusion layer, fully connected layers, and softmax layers. The convolutional layers primarily use 3x3 convolutional kernels, Batch Normalization (BN) layers, and ReLU activation functions. The downsampling layers mainly use average pooling layers. An attention mechanism fusion model is proposed by constructing the attention mechanism fusion module to enhance the globality of features from different species, such as interference caused by local variations. Finally, a 1x1024 fully connected layer and a 1xn softmax layer are added for classification and recognition, where n is the total number of agricultural species categories.

[0081] Construct contrastive feature sets. During the training phase, multimodal CLIP is used for image feature encoding to extract feature vectors V from different infection states of the same species. K V K+ and V K- V K V represents the characteristics of the current input species. K+ Indicates with VK Characteristics of the same species under different infection states. V K- Indicates with V K Different species share similar characteristics.

[0082] Construct a similarity-contrast cross-entropy loss function. Utilize contrastive features to build a contrastive loss function, learning the characteristics of similar species and the feature differences between different infections of the same species. The formula for calculating the loss function is as follows:

[0083] Part 1: Multi-class Cross-Entropy Loss L cls Based on the softmax layer, the softmax loss is calculated. Assuming there are n species categories, the softmax layer has an n-dimensional output vector. The value of the i-th output vector represents the probability value of the i-th species category.

[0084]

[0085] Where y i S represents the true species category of the i-th species, which is labeled using one-hot encoding. i This represents the probability of predicting the i-th species category.

[0086] Part Two: Comparison of Losses L con Based on the constructed contrast feature set, the input sample V is calculated. K Positive sample V K+ The correlation between them, and with negative sample V K- The difference in comparison. The calculation formula is as follows:

[0087]

[0088] Where K represents the number of species with the same species as the input sample but different infection states, and L represents the number of species with different species as the input sample but with a high degree of similarity.

[0089] The total loss value is:

[0090]

[0091] Step 103: Input the input feature map into the attention mechanism fusion module to obtain the attention feature map; multiply the attention feature map and the input feature map to generate the attention fusion feature.

[0092] Step 104: Use the similarity-contrast cross-entropy loss function to learn the features of similar species and the feature differences of different infections of the same species. The loss function includes multi-class cross loss and contrast loss.

[0093] Step 105: Input the target crop image data into the crop recognition model, output the species category with the highest prediction probability, and obtain the crop prediction result.

[0094] Specifically, in this embodiment, the target crop image data is input into the crop recognition model, and the parameters of the crop recognition model are optimized using the Adam algorithm. The number of iterations of the crop recognition model is set to 10,000, the initial learning rate is 0.001, and the weight decay is 0.0005. When the crop recognition model goes through 50 iterations, the learning rate decays to 1 / 10 of the original value until the model converges and outputs the species category with the highest prediction probability, thus obtaining the crop prediction result.

[0095] Specifically, in this embodiment, the Adam (Adaptive Moment Estimation) algorithm is a commonly used gradient optimization algorithm in deep learning. It is a comprehensive upgrade of RMSProp and momentum algorithms, combining the advantages of both to achieve adaptive adjustment of the learning rate, thus performing excellently in many complex tasks. The following are some core features of the Adam algorithm and possible optimization directions:

[0096] Core features of the Adam algorithm:

[0097] Adaptive learning rate: For each parameter, Adam dynamically adjusts its learning rate based on the historical gradient information of that parameter. This means that each parameter can have a different learning rate, which is very effective for dealing with sparse gradients or parameters with different scales.

[0098] Momentum term: The idea of ​​exponential weighted averaging is combined to estimate the first moment (i.e. the momentum of the gradient) and the second moment (the momentum of the squared gradient), which helps to accelerate convergence and reduce oscillations.

[0099] Bias correction: Since the denominator (estimated second moment) is 0 or close to 0 during initialization, the initial learning rate may be too high. Adam solves this problem with a simple bias correction formula.

[0100] Optimization directions for the Adam algorithm:

[0101] Warm-up strategy: Use a small learning rate to warm up the training process in the early stages, and then gradually increase it to the predetermined learning rate. This can help stabilize the initial training process and avoid instability caused by initial estimation bias.

[0102] Decay Strategy: Learning rate decay is a common optimization strategy that gradually reduces the learning rate during training. This helps the model finer-tune weights later on, improving model performance. Common decay methods include time decay and exponential decay.

[0103] AdamW: The original Adam algorithm directly subtracts the learning rate multiplied by the estimated values ​​of the first and second moments when updating the weights, which can lead to weight decay. AdamW is a modification of Adam that explicitly separates weight decay (L2 regularization) from momentum updates, thereby improving generalization performance.

[0104] AMSGrad: To address the issue that Adam may not converge to the optimum, the AMSGrad algorithm was proposed. It restricts the update of the second-order moment estimate, ensuring that it does not decrease due to fluctuations in historical gradients, thus providing a better convergence guarantee.

[0105] **Nadam (Nesterov-accelerated Adaptive Moment Estimation):** This method combines the concept of Nesterov momentum and pre-calculates the direction of the gradient, theoretically allowing for faster convergence.

[0106] Parameter tuning and optimization: Adjusting the hyperparameters β1 (smoothing coefficient for the first moment), β2 (smoothing coefficient for the second moment), and ε (a small constant to prevent division by zero) in Adam is also crucial for performance optimization. Typically, β1 is recommended to be set to 0.9 and β2 to 0.999, but the optimal values ​​may need to be adjusted based on the task and dataset.

[0107] In summary, the Adam algorithm is already a relatively efficient optimizer, and its performance on specific tasks can be further improved through the optimization strategies and adjustments described above. In practical applications, choosing appropriate optimization strategies and adjusting parameters are crucial.

[0108] Its beneficial effects lie in the fact that by employing an attention-based network structure to construct a feature extraction module, it strengthens the global feature information of crops. Then, it uses multimodal CLIP for image encoding to construct comparative features. Through contrastive learning, it learns the feature differences of the same species under different states and the feature differences of similar species. Finally, it uses similarity-contrast cross-entropy loss for model training. This invention strengthens global feature information through an attention mechanism, and at the same time, it uses contrastive learning to learn the feature differences of the same species under different states and the feature differences of similar species. This effectively avoids the problem of feature differences of the same species caused by interference from factors such as disease and light, thereby improving the accuracy of crop identification and making it more robust in practical applications.

[0109] The above describes an embodiment of the crop identification method based on contrastive learning according to the present invention. Please refer to [link / reference]. Figure 2 In a crop identification system based on contrastive learning, the system includes the following modules:

[0110] The image data processing module is used to acquire crop image data from the database, perform data preprocessing on the crop image data, and obtain target crop image data.

[0111] The attention mechanism fusion module is used to feed the input feature map to the attention mechanism fusion module to obtain the attention feature map; and to perform a multiplication operation between the attention feature map and the input feature map to generate the attention fusion feature.

[0112] An attention mechanism feature extraction module is used to include at least a convolutional layer, a downsampling layer, an attention mechanism fusion layer, a fully connected layer, and a softmax layer;

[0113] The contrast feature group module is used to perform image feature encoding using multimodal CLIP to extract feature vectors of the same species under different infection states.

[0114] The Similarity Contrast Cross-Entropy Loss Function module is used to construct a contrastive loss using contrastive features, and to learn the features of similar species and the feature differences of different infections of the same species.

[0115] The image data recognition module is used to input the target crop image data into the crop recognition model, output the species category with the highest prediction probability, and obtain the crop prediction result.

[0116] Please see Figure 3 A schematic diagram of a crop identification network model for a crop identification method based on contrastive learning in an embodiment of the present invention.

[0117] Specifically, in this embodiment, the crop identification model includes at least an attention mechanism fusion module, an attention mechanism feature extraction module, a comparison feature group, and a similarity comparison cross-entropy loss function.

[0118] Please see Figure 4 A schematic diagram of the attention mechanism fusion module of a crop identification method based on contrastive learning in an embodiment of the present invention.

[0119] Specifically, this embodiment constructs an attention mechanism fusion module. The input feature map is passed through a global max pooling layer based on width and a global average pooling layer based on height, and then through a multilayer perceptron (MLP). The features output by the MLP are summed and then processed by a sigmoid activation function to generate the final attention feature map. This attention feature map is then multiplied by the input feature map to generate the attention fusion feature. Its formula is as follows:

[0120]

[0121] Where F represents the input features. The fused features are represented by AvgPool(F), which represents the global max pooling layer operation based on width, and MaxPool(F), which represents the global average pooling layer operation based on height. 3*3 (F) indicates that a 3x3 convolution operation is used.

[0122] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely preferred examples and are not intended to limit the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of the present invention is defined by the appended claims and their equivalents.

Claims

1. A crop identification method based on contrastive learning, characterized in that, The crop identification method based on contrastive learning includes the following steps: Obtain crop image data from the database, perform data preprocessing on the crop image data, and obtain target crop image data; A crop identification model is established, which includes at least an attention mechanism fusion module, an attention mechanism feature extraction module, a contrast feature group, and a similarity contrast cross-entropy loss function. The input feature map is input into the attention mechanism fusion module to obtain an attention feature map; the attention feature map and the input feature map are multiplied to generate an attention fusion feature. The similarity-contrast cross-entropy loss function is used to learn the features of similar species and the feature differences of different infections of the same species. The loss function includes multi-class cross loss and contrast loss. The target crop image data is input into the crop recognition model, and the species category with the highest prediction probability is output to obtain the crop prediction result.

2. The crop identification method based on contrastive learning as described in claim 1, characterized in that, The process of acquiring crop image data from the database and performing data preprocessing on the crop image data to obtain target crop image data includes: Collect different crop image data in the system, including images of the same crop infected by different diseases, and label them with the corresponding crop labels to obtain labeled crop image data; The crop label includes at least images of normal San Ying pepper, images of San Ying pepper with anthracnose, images of San Ying pepper with leaf blight, and images of San Ying pepper with purple blotch. The labeled crop image data is normalized by setting its size to 512x512 pixels and converting the pixel value range from 0 to 255 to 0 to 1. The normalization formula is as follows: Where, x i Let x represent the value of the i-th pixel in the image, and max(x) and min(x) represent the maximum and minimum values ​​of the pixels in the image, respectively.

3. The crop identification method based on contrastive learning as described in claim 1, characterized in that, The attention mechanism fusion module includes: An attention mechanism fusion module is constructed, which processes the input feature map through a global max pooling layer based on width and a global average pooling layer based on height. The features output by the multilayer perceptron (MLP) are summed and then processed by the sigmoid activation function to generate the final attention feature map. The attention feature map and the input feature map are multiplied to generate the attention fusion feature, which is represented by the following formula: Where F represents the input features, Representing the fused features, AvgPool(F) denotes the global max pooling layer operation based on width, and MaxPool(F) denotes the global average pooling layer operation based on height; Conv 3*3 (F) indicates that a 3x3 convolution operation is used.

4. The crop identification method based on contrastive learning as described in claim 1, characterized in that, The attention mechanism feature extraction module includes: Construct an attention mechanism feature extraction module, the network structure of which includes at least a convolutional layer, a downsampling layer, an attention mechanism fusion layer, a fully connected layer, and a softmax layer; The convolutional layer consists of a 3*3 convolutional kernel, a BN normalization layer, and a ReLU activation function, and the downsampling layer consists of an average pooling layer. The attention mechanism is used to enhance the globality of features of different species through the fusion layer. Finally, a fully connected layer of size 1*1024 and a softmax layer of size 1*n are added to perform classification and recognition, where n is the total number of agricultural species categories.

5. The crop identification method based on contrastive learning as described in claim 1, characterized in that, The comparison feature set includes: Construct a contrastive feature set, and use multimodal CLIP for image feature encoding during the training phase of the crop identification model to extract feature vectors V of the same species under different infection states. K V K+ and V K- ; Among them, V K V represents the characteristics of the current input species. K+ Indicates with V K Characteristics of the same species under different infection states, V K- Indicates with V K Different species share similar characteristics.

6. The crop identification method based on contrastive learning as described in claim 1, characterized in that, The similarity comparison cross-entropy loss function includes: A similarity-contrast cross-entropy loss function is constructed, utilizing contrastive features to build a contrastive loss, learning the features of similar species and the feature differences of different infections of the same species. The formula for calculating the loss function is as follows: Part 1: Multi-class Crossover Loss L cls Based on the softmax layer, the softmax loss L is calculated. cls Assuming there are n species categories, the softmax layer has an n-dimensional output vector, where the value of the i-th output vector represents the probability value of the i-th species category. Among them, y i S represents the true species category of the i-th species, which is labeled using one-hot encoding. i This indicates the probability of predicting the i-th species category; Part Two: Comparison of Losses L con The input sample V is calculated based on the constructed contrast feature set. K V between positive samples K+ The correlation and the difference V compared with negative samples. K- The calculation formula is as follows: Where K represents the number of species that are the same as the input sample but have different infection states, and L represents the number of species that are different from the input sample but have a high degree of similarity; The total loss value is:

7. The crop identification method based on contrastive learning as described in claim 1, characterized in that, The step of inputting the target crop image data into the crop recognition model and outputting the species category with the highest predicted probability to obtain the crop prediction result includes: The target crop image data is input into the crop recognition model, and the parameters of the crop recognition model are optimized using the Adam algorithm. The crop identification model is set to have 10,000 iterations, an initial learning rate of 0.001, and a weight decay of 0.0005. Every 50 iterations of the crop identification model, the learning rate is reduced to 1 / 10 of its original value until the model converges and outputs the species category with the highest predicted probability, thus obtaining the crop prediction result.

8. A crop identification system based on contrastive learning, characterized in that, The crop identification system based on contrastive learning includes the following steps: The image data processing module is used to acquire crop image data from the database, perform data preprocessing on the crop image data, and obtain target crop image data. An attention mechanism fusion module is used to feed the input feature map to the attention mechanism fusion module to obtain an attention feature map; and to perform a multiplication operation between the attention feature map and the input feature map to generate an attention fusion feature. An attention mechanism feature extraction module is used to include at least a convolutional layer, a downsampling layer, an attention mechanism fusion layer, a fully connected layer, and a softmax layer; The contrast feature group module is used to perform image feature encoding using multimodal CLIP to extract feature vectors of the same species under different infection states. The Similarity Contrast Cross-Entropy Loss Function module is used to construct a contrastive loss using contrastive features, and to learn the features of similar species and the feature differences of different infections of the same species. The image data recognition module is used to input the target crop image data into the crop recognition model, output the species category with the highest prediction probability, and obtain the crop prediction result.

9. A crop identification system based on contrastive learning as described in claim 8, characterized in that, The image data processing module includes the following sub-modules: The collection submodule is used to collect different crop image data in the system. The crop image data includes images of the same crop infected by different diseases. The corresponding crop label is marked to obtain labeled crop image data. The label submodule is used to determine that the crop label includes at least the images of normal San Ying pepper, anthracnose San Ying pepper, leaf blight San Ying pepper, and purple spot disease San Ying pepper. The normalization submodule is used to normalize the labeled crop image data, setting the size of the labeled crop image data to 512x512 pixels and converting the range of image pixel values ​​from 0 to 255 to 0 to 1. The normalization formula is as follows: Where, x i Let x represent the value of the i-th pixel in the image, and max(x) and min(x) represent the maximum and minimum values ​​of the pixels in the image, respectively.

10. A crop identification system based on contrastive learning as described in claim 8, characterized in that, The image data recognition module includes the following steps: The input submodule is used to input the target crop image data into the crop recognition model and optimize the parameters of the crop recognition model using the Adam algorithm. The settings submodule is used to set the number of iterations of the crop recognition model to 10,000, the initial learning rate to 0.001, and the weight decay to 0.0005. A submodule is obtained, which is used to reduce the learning rate to 1 / 10 of the original rate every 50 iterations of the crop recognition model until the model converges, and outputs the species category with the highest prediction probability to obtain the crop prediction result.