Lightweight unbalanced pest image recognition method based on multi-branch contrast learning
By adopting a multi-branch comparison learning method in pest image recognition, using EfficientNet-B0 and logic calibration and contrast learning frameworks, the low recognition accuracy caused by category imbalance and morphological variability is solved, and higher pest image recognition accuracy and model generalization ability are achieved.
Patent Information
- Application Number
- CN202510243181.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-06-20
AI Technical Summary
When existing pest image recognition methods face category imbalance and insect morphological variability, the model recognition accuracy is low, making it difficult to effectively capture representative features.
A lightweight unbalanced pest image recognition method based on multi-branch contrast learning is adopted, and a multi-branch network is built using EfficientNet-B0 as the backbone, and the performance and feature extraction capabilities of a few classes are improved through logical calibration and comparison learning framework.
It improves the accuracy of identification of unbalanced agricultural pests, enhances the model's focus on different categories of problems and identification diversity, and is suitable for the field of agricultural intelligent information processing.
Smart Images

Figure CN120182780A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of agricultural intelligent information processing, and in particular to a lightweight unbalanced pest image recognition method based on multi-branch contrastive learning, aiming to solve the problems of low model recognition accuracy caused by class imbalance in the pest image dataset and insect morphological variability. Background Art
[0002] At present, with the booming development of agricultural technology, pest recognition has become an indispensable key link in precision agriculture, which is of great significance for ensuring the healthy growth of crops and realizing the sustainable development of agricultural production. However, in the actual research and application process of pest image recognition, many thorny problems have seriously hindered the effective promotion of the technology.
[0003] On the one hand, due to the significant differences in the occurrence frequency, distribution area and living habits of different pests, it is difficult to obtain image samples of various pests, and thus the constructed dataset often shows a serious class imbalance phenomenon. For example, the number of image samples of some common pests may be extremely rich, while the samples of some rare pests are very few. This imbalance poses a huge challenge to the training of the model, easily leading the model to overemphasize the majority-class samples during the learning process, thereby seriously affecting the recognition accuracy of the minority-class pests.
[0004] On the other hand, the great morphological variability of insects greatly increases the difficulty for the model to capture representative features. At different growth stages of insects, such as the larval and adult stages, their morphological structures will change significantly; even at the same growth stage, affected by environmental factors (such as temperature, humidity, food resources, etc.), the appearance characteristics of insects may also vary greatly. Traditional pest image classification methods often seem inadequate in the face of these complex situations. They usually lack effective strategies for dealing with class imbalance problems and pay insufficient attention to minority-class samples; at the same time, when dealing with insect morphological variations, it is difficult to accurately extract stable and discriminative features, and there is generally a problem of large computational complexity, which not only limits the application efficiency of the model in actual agricultural production scenarios, but also places too high requirements on hardware devices, and is not conducive to the wide promotion and application of the technology. Summary of the Invention
[0005] Aiming at the technical problems that the current pest recognition methods have poor recognition effects on minority classes and the model is not easy to capture representative features, the present invention proposes a lightweight unbalanced image recognition method based on multi-branch contrastive representation learning. The publicly available unbalanced agricultural pest dataset is used to train and test the proposed model. An EfficientNet-B0 is used as the backbone to construct a multi-branch contrastive learning network, and the logical values output by each branch are calibrated to improve the performance of minority classes. At the same time, a contrastive representation learning framework is introduced. By data augmentation to construct views, process features, and optimize the loss, the feature extraction ability of the model is enhanced.
[0006] To achieve the above object, the technical solution of the present invention is realized as follows:
[0007] A lightweight unbalanced pest image recognition method based on multi-branch contrastive learning, the steps are as follows:
[0008] Step 1: Preprocess the pest images in the pest dataset: including image resolution adjustment and data augmentation;
[0009] Step 2: Construct a multi-branch network based on the EfficientNet-B0 model, and use the preprocessed pest dataset to train the multi-branch network;
[0010] Step 3: Logical calibration: Calibrate the output features of the fully connected layer of each branch according to the class prior information, and calculate the logical calibration loss of each branch;
[0011] Step 4: Contrastive learning: Process the output features of the pooling layer of each branch through a projection head and a prediction head to obtain the final pest image features; then use negative cosine similarity as the contrastive learning loss to minimize the Euclidean distance of the pest image features under different augmented views;
[0012] Step 5: Fuse the logical calibration loss and the contrastive learning loss as the total loss function. When the value of the total loss function no longer significantly decreases after multiple iterations, the training is completed, and the optimal multi-branch network model is obtained;
[0013] Step 6: Input the preprocessed pest dataset into the optimal multi-branch network model for testing to obtain the output features of the fully connected layer of each branch, and add the output features of all branches to obtain the final prediction output.
[0014] Preferably, the method for preprocessing the pest images in the pest dataset includes:
[0015] Image resolution adjustment: Adjust all images to images of the same size in pixels;
[0016] Data augmentation: Perform weak data augmentation and strong data augmentation on the adjusted images; weak data augmentation includes cropping, horizontal flipping, rotation, and color jitter; strong data augmentation is processed using the RandAug technique.
[0017] Preferably, the network structure of the multi-branch network is as follows:
[0018] The input image sequentially undergoes convolutional operations of the Conv2D-I module, MBConv1 module, 2 MBConv6-I modules, 2 MBConv6-II modules, 3 MBConv6-III modules, 3 MBConv6-IV modules, and 4 MBConv6-V modules to obtain intermediate feature I; intermediate feature I is respectively input into the first branch, the second branch, and the third branch to obtain three output features; and the network structures of the first branch, the second branch, and the third branch are: MBConv6-VI module — Conv2D-II module — pooling layer — fully connected layer; among them, the convolutional kernel size of the Conv2D-I module is 3×3, the stride of the convolutional kernel is 2, and the number of output channels is 32; the convolutional kernel size of the MBConv1 module is 3×3, the number of input channels is 32, and the number of output channels is 16; the convolutional kernel size of the MBConv6-I module is 3×3, the number of input channels is 16, and the number of output channels is 24; the convolutional kernel size of the MBConv6-II module is 5×5, the number of input channels is 24, and the number of output channels is 40; the convolutional kernel size of the MBConv6-III module is 3×3, the number of input channels is 40, and the number of output channels is 80; the convolutional kernel size of the MBConv6-IV module is 5×5, the number of input channels is 80, and the number of output channels is 112; the convolutional kernel size of the MBConv6-V module is 5×5, the number of input channels is 112, and the number of output channels is 192; the convolutional kernel size of the MBConv6-VI module is 3×3, the number of input channels is 192, and the number of output channels is 320; the convolutional kernel size of the Conv2D-II module is 1×1, the number of input channels is 320, and the number of output channels is 1280;
[0019] Perform global average pooling and flattening on the features output by the Conv2D-II module, compress the feature maps of each channel into a single value to obtain a 1280-dimensional feature vector; finally, input the 1280-dimensional feature vector into the fully connected layer to obtain the output feature; among them, the number of output neurons of the fully connected layer is 102.
[0020] Preferably, the method for calibrating the output features of the fully connected layer of each branch according to the class prior information is:
[0021] Add an offset related to the class prior to the output logic value of each branch, and control the degree of adjustment through the temperature scaling coefficient; specifically, the calculation loss of the adjusted logic value is shown in formula (1):
[0022]
[0023] where y represents the class label, and g y (x) represents the logic value that the sample x belongs to the class y, L represents the set of classes, τ represents the temperature coefficient, and π y represents the prior probability estimate of the class y;
[0024] According to formula (1), the three branches are respectively calibrated with different logics, and each branch is made good at identifying different types of classes by adjusting the logic values; set the temperature scaling coefficients of the three branches to τ1, τ2, τ3, then the logic calibration softmax losses L1, L2, L3 of the three branches are:
[0025]
[0026] Therefore, the total supervised training loss is:
[0027] L sup = L1 + L2 + L3 (3);
[0028] where L sup represents the total supervised training loss.
[0029] Preferably, the specific implementation method of the contrastive learning is:
[0030] First, construct the original image Xi into two different views through weak data augmentation and strong data augmentation, which are respectively represented as X a , X b , input X a , X b into the multi-branch network, and output features through the pooling layer of the multi-branch network Map to a low-dimensional space through a projection head to obtain feature representations and Then, transform and through a prediction head to output the final feature representations and Minimize the negative cosine similarity of different views:
[0031]
[0032] To prevent crashes, a stop-gradient operation is used in the similarity loss; Stochastic Gradient Descent is used as the optimizer, and the similarity loss functions for the three branches are defined as:
[0033]
[0034] Among them, L sim represents the total similarity loss, stopgrad(·) represents the stop gradient, and sim(·) represents the similarity function.
[0035] Preferably, the total loss function is expressed as:
[0036] L total = L sup + λL sim (6);
[0037] Among them, λ is a regulation factor.
[0038] Advantages of the present invention:
[0039] (1) The present invention solves the problems that the existing agricultural pest recognition network has poor performance in minority classes and is not easy to capture representative features, realizes the recognition of unbalanced agricultural pests, improves the classification accuracy of agricultural pests, can be applied to the field of agricultural intelligent information processing, and is conducive to promoting crop protection.
[0040] (2) The present invention uses EfficientNet-B0 as the backbone network, and this network has the characteristics of being lightweight and efficient.
[0041] (3) On the basis of EfficientNet-B0, the present invention constructs a multi-branch structure including three independent later layers. Each branch serves as a branch network, focusing on learning the feature representations of different classes in the dataset, improving the focus of the model on different class problems, and enhancing the recognition diversity between models through adaptive Logit calibration to enhance the recognition performance of unbalanced pest images.
[0042] (4) The present invention introduces a contrastive learning framework. Based on two different views, feature representations are obtained through processing by a projection head and a prediction head; then, by minimizing the negative cosine similarity between the feature representations of different views, more robust and generalized feature representations are learned. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0044] Figure 1 This is the flowchart of the present invention.
[0045] Figure 2 This is the structural diagram of the multi-branch network constructed for the present invention. Detailed implementation manners
[0046] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0047] As Figure 1 shown, the embodiments of the present invention provide a lightweight unbalanced pest image recognition method based on multi-branch contrastive learning. By constructing a multi-branch logic calibration network, each branch focuses on learning the feature representations of different categories in the dataset, and further optimizes the feature representations through a contrastive representation learning framework to enhance the generalization ability of the model. The specific steps are as follows:
[0048] Step 1: Preprocess the pest images in the pest dataset: including image resolution adjustment and data augmentation;
[0049] Dataset selection: Use the IP102 pest dataset, which contains more than 75,000 images covering 102 different pest and disease categories.
[0050] Image resolution adjustment: Resize all images to 224×224 pixels to meet the model input requirements.
[0051] Data augmentation: Perform weak data augmentation (including cropping, horizontal flipping, rotation, and color jitter) and strong data augmentation (using the RandAug technique) on the images to increase the diversity of the data and the generalization ability of the model.
[0052] Step 2: Construct a multi-branch network based on the EfficientNet-B0 model, and use the preprocessed pest dataset to train the multi-branch network;
[0053] To make the model have lightweight characteristics, select EfficientNet-B0 as the backbone network. Considering that the early layers of the CNN tend to encode general low-level features, adopt the idea of transfer learning to make all three branches share the earlier layer f θ, these early layers are mainly responsible for extracting general low-level features of the image, such as basic information like edges and textures. By sharing these layers, on the one hand, it reduces computational redundancy and avoids repeating the same basic feature extraction work on different branches; on the other hand, it ensures that each branch can perform subsequent specific-category feature learning based on the same basic features at the initial stage, laying a foundation for the stability and consistency of the entire model. On the basis of sharing the early layers, a multi-branch structure containing three independent later layers is further constructed. Each branch is closely connected to the backbone network, receives data from the shared early layers, and further processes and conducts feature learning on the data in the independent later layers. These independent later layers focus on capturing specific-category feature representations. According to the logic calibration and temperature scaling coefficients set for different branches, they can specifically conduct in-depth mining and learning of the features of different categories of pest images, enabling each branch to be good at identifying different types of pest categories. Specifically, 3 independent later layers are retained to capture specific-category features.
[0054] such as Figure 2As shown in the figure, specifically, the processing flow of the multi-branch network based on the EfficientNet-B0 model is as follows: The input image sequentially undergoes convolutional operations of the Conv2D-I module, the MBConv1 module, 2 MBConv6-I modules, 2 MBConv6-II modules, 3 MBConv6-III modules, 3 MBConv6-IV modules, and 4 MBConv6-V modules to obtain the intermediate feature I; The intermediate feature I is respectively input into the first branch, the second branch, and the third branch to obtain three output features; And the network structures of the first branch, the second branch, and the third branch are: MBConv6-VI module - Conv2D-II module - pooling layer - fully connected layer; Among them, the convolutional kernel size of the Conv2D-I module is 3×3, the stride of the convolutional kernel is 2, and the number of output channels is 32; The convolutional kernel size of the MBConv1 module is 3×3, the number of input channels is 32, and the number of output channels is 16; The convolutional kernel size of the MBConv6-I module is 3×3, the number of input channels is 16, and the number of output channels is 24; The convolutional kernel size of the MBConv6-II module is 5×5, the number of input channels is 24, and the number of output channels is 40; The convolutional kernel size of the MBConv6-III module is 3×3, the number of input channels is 40, and the number of output channels is 80; The convolutional kernel size of the MBConv6-IV module is 5×5, the number of input channels is 80, and the number of output channels is 112; The convolutional kernel size of the MBConv6-V module is 5×5, the number of input channels is 112, and the number of output channels is 192; The convolutional kernel size of the MBConv6-VI module is 3×3, the number of input channels is 192, and the number of output channels is 320; The convolutional kernel size of the Conv2D-II module is 1×1, the number of input channels is 320, and the number of output channels is 1280.
[0055] Perform global average pooling and flattening processing on the features output by the Conv2D-II module, compress the feature maps of each channel into a single value to obtain a 1280-dimensional feature vector; Finally, input the 1280-dimensional feature vector into the fully connected layer to obtain the output feature; Among them, the number of output neurons in the fully connected layer is 102.
[0056] Step three: Logical calibration: Calibrate the output features of the fully connected layer of each branch according to the class prior information, and calculate the logical calibration loss of each branch; The present invention sets multiple branch models, and each branch is responsible for learning the feature representations of the majority classes and minority classes in the dataset. Through different degrees of logical calibration, the performance of the model on minority classes is improved. This way of division of labor and cooperation enables each branch network to more deeply explore the internal laws of the classes it is responsible for.
[0057] Existing pest and disease identification models face challenges in processing large-scale imbalanced pest and disease image classification tasks. For minority classes, the recognition accuracy is often low. Therefore, by setting up three branches to improve the model's focus on different category problems, and enhancing the recognition diversity among models through adaptive Logit calibration to enhance the recognition performance of imbalanced pest images.
[0058] To increase the difference between different branches, an offset related to the class prior is added to the output logit of each branch, and the degree of adjustment is controlled by the temperature scaling coefficient; specifically, the adjusted logit is calculated as shown in formula (1):
[0059]
[0060] where y represents the class label, g y (x) represents the logit that the sample x belongs to class y, L represents the set of classes, τ represents the temperature coefficient, and π y represents the prior probability estimate of class y.
[0061] According to formula (1), the three branches are respectively calibrated with different logics. By adjusting the logits, each branch is made good at recognizing different types of classes. Finally, the prediction results of these branches are integrated to achieve a wider, more diverse, and more accurate recognition effect. In this embodiment, the temperature scaling coefficients of the three branches are set to τ1, τ2, τ3 (in this embodiment, the temperature scaling coefficients of the three branches are respectively set to -1, 0, 2), then the logical calibration softmax losses L1, L2, L3 of the three branches are:
[0062]
[0063] This method effectively improves the model's ability to recognize imbalanced distribution pest images by combining the strengths of multiple experts.
[0064] Therefore, the total supervised training loss is:
[0065] L sup = L1 + L2 + L3 (3);
[0066] where L sup represents the total supervised training loss.
[0067] Step 4: Contrastive learning: The output features of the pooling layer of each branch are processed through a projection head and a prediction head to obtain the final pest image features; then the negative cosine similarity is used as the contrastive learning loss to minimize the Euclidean distance of the pest image features under different augmented views.
[0068] Due to the large differences within crop pest categories, it is difficult to extract features. Inspired by self-supervised learning, which improves representations by learning additional pretext tasks, a standard supervised task and a self-supervised task are used to train the encoder in a multi-task learning manner. In this embodiment, a contrastive learning framework is introduced to further optimize the feature representation by minimizing the Euclidean distance between pest features of different views in the feature space. Specifically, first, the original image Xi is constructed into two different views through weak data augmentation (WeakAugment, WA) and strong data augmentation (StrongAugment, SA), which are respectively denoted as X a and X b . Then, X a and X b are input into a multi-branch network, and the features are output through the pooling layer of the multi-branch network . Then, through the projection head (fully connected layer), is mapped to a low-dimensional space to obtain the feature representations and . Then, through the prediction head (fully connected layer), and are transformed to output the final feature representations and . Minimize the negative cosine similarity of different views:
[0069]
[0070] . To prevent collapse, the stop-gradient operation is used in the similarity loss. When training the model, Stochastic Gradient Descent (SGD) is used as the optimizer, with a momentum of 0.9 and a weight decay of 0.0002; the initial learning rate is set to 0.01 and adjusted using the cosine decay strategy; the batch size is set to 128; the training is performed on a computer with a single NVIDIA GeForce RTX 4090 graphics card
[0071] . The similarity loss function for the three branches is defined as:
[0072]
[0073] . Among them, L sim represents the total similarity loss, stopgrad(·) represents the stop gradient, and sim(·) represents the similarity function
[0074] . Step five: After fusing the logical calibration loss and the contrastive learning loss as the total loss function, when the value of the total loss function no longer significantly decreases after multiple iterations, the training is completed, and the optimal multi-branch network model is obtained
[0075] . The total loss function is expressed as:
[0076] L total = L sup + λL sim (6);
[0077] Where λ is the adjustment factor between the supervised loss and the similarity loss; by default, it is 5 in this embodiment.
[0078] Step Six: Input the preprocessed pest dataset into the optimal multi-branch network model for testing to obtain the output features of the fully connected layers of each branch, and add the output features of all branches to obtain the final predicted output.
[0079] Table 1 shows the performance comparison results of the method of the present invention and some state-of-the-art methods on the IP102 dataset. The evaluation metrics include accuracy, number of parameters, and computational complexity. The method of the present invention can achieve relatively good results in these three metrics, indicating that the lightweight unbalanced pest image classification system based on multi-branch contrastive representation learning proposed by the present invention realizes efficient and accurate pest image classification on the unbalanced dataset.
[0080] Table 1 Comparison of Different Methods on the IP102 Dataset
[0081]
[0082]
[0083] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A lightweight unbalanced pest image recognition method based on multi-branch contrastive learning, characterized in that: The steps are as follows: Step 1: Preprocess the pest images in the pest dataset: including image resolution adjustment and data enhancement; Step 2: Build a multi-branch network based on the EfficientNet-B0 model and train the multi-branch network using the preprocessed pest dataset; Step 3: Logical calibration: calibrate the output features of the fully connected layer of each branch according to the category prior information, and calculate the logical calibration loss of each branch; Step 4: Contrastive learning: The output features of the pooling layer of each branch are processed by the projection head and the prediction head to obtain the final pest image features; then the negative cosine similarity is used as the contrastive learning loss to minimize the Euclidean distance of the pest image features under different enhanced views; Step 5: The logistic calibration loss and contrastive learning loss are combined as the total loss function. When the value of the total loss function no longer decreases significantly after multiple iterations, the training is completed and the optimal multi-branch network model is obtained. Step 6: Input the preprocessed pest dataset into the optimal multi-branch network model for testing, obtain the output features of the fully connected layer of each branch, and add the output features of all branches to get the final prediction output.
2. The lightweight unbalanced pest image recognition method based on multi-branch contrastive learning according to claim 1 is characterized in that: The method for preprocessing the pest images in the pest dataset comprises: Image resolution adjustment: adjust all images to the same pixel size; Data enhancement: Weak and strong data enhancement are performed on the adjusted image; weak data enhancement includes cropping, horizontal flipping, rotation and color jittering; strong data enhancement is processed using RandAug technology.
3. The lightweight unbalanced pest image recognition method based on multi-branch contrastive learning according to claim 1 is characterized in that: The network structure of the multi-branch network is: The input image is sequentially convolved through the Conv2D-I module, the MBConv1 module, two MBConv6-I modules, two MBConv6-II modules, three MBConv6-III modules, three MBConv6-IV modules, and four MBConv6-V modules to obtain the intermediate feature I. The intermediate feature I is input into the first branch, the second branch and the third branch respectively to obtain three output features; and the network structure of the first branch, the second branch and the third branch is: MBConv6-VI module—Conv2D-II module—pooling layer—fully connected layer; among them, the convolution kernel size of the Conv2D-I module is 3×3, the step size of the convolution kernel is 2, and the number of output channels is 32; the convolution kernel size of the MBConv1 module is 3×3, the number of input channels is 32, and the number of output channels is 16; the convolution kernel size of the MBConv6-I module is 3×3, the number of input channels is 16, and the number of output channels is 24; the convolution kernel size of the MBConv6-II module is 5×5 , the number of input channels is 24, and the number of output channels is 40; the convolution kernel size of the MBConv6-III module is 3×3, the number of input channels is 40, and the number of output channels is 80; the convolution kernel size of the MBConv6-IV module is 5×5, the number of input channels is 80, and the number of output channels is 112; the convolution kernel size of the MBConv6-V module is 5×5, the number of input channels is 112, and the number of output channels is 192; the convolution kernel size of the MBConv6-VI module is 3×3, the number of input channels is 192, and the number of output channels is 320; the convolution kernel size of the Conv2D-II module is 1×1, the number of input channels is 320, and the number of output channels is 1280; The features output by the Conv2D-II module are globally pooled and flattened, and the feature map of each channel is compressed into a numerical value to obtain a 1280-dimensional feature vector; finally, the 1280-dimensional feature vector is input into the fully connected layer to obtain the output features; the number of output neurons in the fully connected layer is 102.
4. The lightweight unbalanced pest image recognition method based on multi-branch contrastive learning according to claim 3 is characterized in that: The method for calibrating the output features of the fully connected layer of each branch according to the category prior information is: An offset related to the category prior is added to the output logic value of each branch, and the degree of adjustment is controlled by the temperature scaling coefficient; specifically, the loss of the adjusted logic value calculation is shown in formula (1): Among them, y represents the category label, g y (x) represents the logical value of sample x belonging to category y, L represents the category set, τ represents the temperature coefficient, π y Represents the probability prior estimate of category y; According to formula (1), the three branches are calibrated with different logics respectively, and each branch is made good at identifying different types of categories by adjusting the logic value; the temperature scaling coefficients of the three branches are set to τ1, τ2, and τ3, and the logic calibration softmax losses of the three branches are L1, L2, and L3: Therefore, the total supervised training loss is: <h2 style=";text-align:left;direction:ltr">L<h2 style=";text-align:left;direction:ltr"> sup <h2 style=";text-align:left;direction:ltr"> (L1+L2+L3 (3)) Among them, L sup represents the total supervised training loss.
5. The lightweight unbalanced pest image recognition method based on multi-branch contrastive learning according to claim 4 is characterized in that: The specific implementation method of the contrastive learning is: First, the original image Xi is constructed into two different views through weak data enhancement and strong data enhancement, which are represented as X a , X b , X a , X b Input the multi-branch network and output features through the pooling layer of the multi-branch network Through the projection head Map to low-dimensional space to get feature representation and Then, by predicting the head pair and Transform to output the final feature representation and Minimize the negative cosine similarity of different views: To prevent collapse, a stop gradient operation is used in the similarity loss; stochastic gradient descent is used as the optimizer, and the similarity loss function of the three branches is defined as: Among them, L sim represents the total similarity loss, stopgrad(·) represents the stop gradient, and sim(·) represents the similarity function.
6. The lightweight unbalanced pest image recognition method based on multi-branch contrastive learning according to claim 5 is characterized in that: The total loss function is expressed as: THE total =L sup +λL sim (6); Among them, λ is the adjustment factor.