Classification model training methods, classification methods, devices, equipment and media

By combining contrastive learning and an encoder, the problem of low accuracy in face attribute classification when there are few data labels is solved, and high-precision classification is achieved with a small amount of labeled data.

CN116152551BActive Publication Date: 2026-04-21SHENZHEN INTELLIFUSION TECHNOLOGIES CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN INTELLIFUSION TECHNOLOGIES CO LTD
Filing Date
2022-12-30
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

When there are few data labels, existing face attribute classification methods have low accuracy, and how to improve classification accuracy has become an urgent problem to be solved.

Method used

A classification model training method based on contrastive learning is adopted. By obtaining the label values ​​of sample images, a first encoder and a second encoder are compared and learned to determine the first loss. The target encoder is selected from the first encoder for encoding processing. The initial classification model is then trained to construct a training loss function to improve classification accuracy.

Benefits of technology

With limited labeled data, the combination of contrastive learning and an encoder learns the intrinsic consistency information between sample images, improving the discriminative power and classification accuracy of the classification model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116152551B_ABST
    Figure CN116152551B_ABST
Patent Text Reader

Abstract

This invention relates to the field of artificial intelligence technology, and more particularly to a classification model training method, classification method, apparatus, device, and medium. By using a contrastive learning mechanism to train an initial classification model, the loss corresponding to unlabeled sample images and the loss corresponding to labeled sample images are both considered. This achieves the goal of training the initial classification model using a small number of labeled sample images, thereby improving the training accuracy of the classification model with limited data labels. Using the trained classification model, a classification result with high accuracy is obtained. In this invention, the classification model is trained using a combination of the loss from contrastive learning and the loss from the classification model itself. Incorporating contrastive learning into the classification model allows it to learn the inherent consistency information between sample images, improving the distinguishability between corresponding image features in different tasks, thereby enhancing the classification accuracy of the classification model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a classification model training method, classification method, apparatus, device, and medium. Background Technology

[0002] In recent years, facial attribute classification has been increasingly widely used in various fields. Accurate and efficient facial attribute classification results play an important role in assisting law enforcement officers in solving cases and improving human-computer interaction. Currently, facial attribute classification methods are all based on training with labeled data, requiring knowledge of the data's labels to perform training for related tasks. However, most data in the real world is unlabeled, and labeling this unlabeled data consumes a lot of time and manpower. If a small amount of labeled data is used for training facial attribute classification, the accuracy of facial attribute classification is low. Therefore, how to improve the accuracy of facial attribute classification when there are few data labels has become an urgent problem to be solved. Summary of the Invention

[0003] In view of this, embodiments of the present invention provide a classification model training method, classification method, apparatus, device and medium to solve the problem of low classification accuracy when there are few data labels.

[0004] In a first aspect, embodiments of the present invention provide a classification model training method based on contrastive learning, the classification model training method comprising:

[0005] Acquire a sample image, and extract the label value corresponding to the sample image from the sample image;

[0006] The sample image is compared and learned by using a preset first encoder and a preset second encoder to determine the first loss corresponding to the comparison and learning.

[0007] A target encoder is selected from the preset first encoder and the preset second encoder. The target encoder is used to encode the sample image to obtain the image features corresponding to the sample image. The image features are then predicted and classified using an initial classification model to obtain the prediction classification result.

[0008] Using the predicted classification result and the label value corresponding to the sample image, calculate the second loss corresponding to the initial classification model;

[0009] Based on the first loss and the second loss, a training loss function is constructed, and the initial classification model is trained based on the training loss function to obtain a trained classification model.

[0010] Secondly, embodiments of the present invention provide a classification method based on contrastive learning, the classification method comprising:

[0011] Obtain the image to be classified;

[0012] The classification model trained using the classification model training method described in the first aspect above is used to classify the image to be classified, thereby obtaining the classification result corresponding to the image to be classified.

[0013] Thirdly, embodiments of the present invention provide a classification model training device based on contrastive learning, the classification model training device comprising:

[0014] The acquisition module is used to acquire sample images and extract the label values ​​corresponding to the sample images from the sample images;

[0015] The first loss calculation module is used to perform comparative learning on the sample image using a preset first encoder and a preset second encoder, and determine the first loss corresponding to the comparative learning.

[0016] The classification module is used to select a target encoder from the preset first encoder and the preset second encoder, use the target encoder to encode the sample image to obtain the image features corresponding to the sample image, and use an initial classification model to predict and classify the image features to obtain the predicted classification result.

[0017] The second loss calculation module is used to calculate the second loss corresponding to the initial classification model using the predicted classification result and the label value corresponding to the sample image.

[0018] The training module is used to construct a training loss function based on the first loss and the second loss, and to train the initial classification model based on the training loss function to obtain a trained classification model.

[0019] Fourthly, embodiments of the present invention provide a classification device based on contrastive learning, the classification device comprising:

[0020] The image acquisition module is used to acquire images to be classified.

[0021] The classification module is used to classify the image to be classified using the classification model trained by the classification model training method described in the first aspect above, and to obtain the classification result corresponding to the image to be classified.

[0022] Fifthly, embodiments of the present invention provide a computer device, the computer device including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the classification model training method as described in the first aspect or the classification method as described in the second aspect.

[0023] In a sixth aspect, embodiments of the present invention provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the classification model training method as described in the first aspect or the classification method as described in the second aspect.

[0024] The advantages of this invention compared to the prior art are:

[0025] The process involves acquiring sample images, extracting corresponding label values ​​from these images, performing comparative learning on the sample images using a first preset encoder and a second preset encoder, determining the first loss corresponding to the comparative learning, selecting a target encoder from the first and second preset encoders, and using the target encoder to encode the sample images to obtain image features corresponding to the sample images. An initial classification model is then used to predict and classify these image features to obtain a predicted classification result. Using the predicted classification result and the corresponding label values ​​of the sample images, a second loss corresponding to the initial classification model is calculated. Based on the first and second losses, a training loss function is constructed, and the initial classification model is trained using this training loss function to obtain a trained classification model. In this invention, the encoder in comparative learning is used to encode the sample images to obtain corresponding image features, and the classification model is trained using the loss from comparative learning and the loss from the classification model. Adding comparative learning to the classification model allows the learning of inherent consistency information between sample images, improving the distinguishability between corresponding image features in different tasks, thereby improving the classification accuracy of the classification model. Attached Figure Description

[0026] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 This is a schematic diagram of a classification model training method and an application environment of the classification method provided in an embodiment of the present invention;

[0028] Figure 2 This is a flowchart illustrating a classification model training method based on contrastive learning, provided in an embodiment of the present invention.

[0029] Figure 3 This is a flowchart illustrating a training method for a multilayer perceptron according to an embodiment of the present invention;

[0030] Figure 4 This is a flowchart illustrating a classification method based on contrastive learning according to an embodiment of the present invention.

[0031] Figure 5 This is a schematic diagram of the structure of a classification model training device based on contrastive learning according to an embodiment of the present invention;

[0032] Figure 6 This is a schematic diagram of the structure of a classification device based on contrastive learning provided in an embodiment of the present invention;

[0033] Figure 7 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0034] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0035] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of the invention. However, those skilled in the art will understand that the invention can be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods are omitted so as not to obscure the description of the invention with unnecessary detail.

[0036] It should be understood that, when used in this specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0037] It should also be understood that the term “and / or” as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0038] As used in this specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if [described condition or event] is detected" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once [described condition or event] is detected," or "in response to detection of [described condition or event]."

[0039] Furthermore, in the description of this invention and the appended claims, the terms "first," "second," "third," etc., are used only for distinguishing descriptions and should not be construed as indicating or implying relative importance.

[0040] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of the invention include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0041] The embodiments of this invention can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that utilize digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.

[0042] Foundational technologies in artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.

[0043] It should be understood that the sequence number of each step in the following embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0044] To illustrate the technical solution of the present invention, specific embodiments are described below.

[0045] This invention provides a classification model training method and a classification method, which can be applied to, for example... Figure 1In this application environment, the client communicates with the server. The client includes, but is not limited to, handheld computers, desktop computers, laptops, ultra-mobile personal computers (UMPCs), netbooks, cloud terminal devices, and personal digital assistants (PDAs). The server can be a standalone server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0046] See Figure 2 This is a flowchart illustrating a classification model training method based on contrastive learning according to an embodiment of the present invention. The aforementioned classification model training method based on contrastive learning can be applied to... Figure 1 The server-side component is used to train the classification model, such as... Figure 2 As shown, the method for training a classification model based on contrastive learning may include the following steps.

[0047] S201: Obtain the sample image and extract the label value corresponding to the sample image from the sample image.

[0048] In step S201, the corresponding face sample image is obtained from the dataset. The obtained face sample image includes at least two types of attribute information. The label value corresponding to the sample image is extracted from the sample image.

[0049] In this embodiment, corresponding face images are obtained from the face database as sample images. A small number of face images are selected for annotation. During annotation, the sample images are annotated according to the attribute information in the face images to obtain the label values ​​corresponding to different attributes in the face images. Label values ​​greater than 0 are used to annotate different attributes in the face images. The face images without annotation information in the remaining sample images are labeled with the same label value as -1. The label value corresponding to the face images without annotation information is -1. The sample images are determined to be sample images with annotation information based on the attribute of the label value.

[0050] It should be noted that after obtaining the sample image, it can be preprocessed to standardize it and obtain the corresponding standard image. Preprocessing can be done by converting the color face image in the sample image to grayscale to obtain the grayscale image of the face. Then, the grayscale image histogram is equalized to obtain the processed face image. Grayscale processing reduces redundant information in the original face image, making it easier to classify face attributes.

[0051] In this embodiment, face images with and without annotation information are obtained as sample images. A small number of labeled face images are used as sample images, which saves a lot of time and manpower costs.

[0052] When obtaining sample images, they can also be obtained from the open-source CelebA face dataset. The sample images in the CelebA face dataset include corresponding facial attribute information, and the label values ​​corresponding to the attribute information in the sample images can be extracted from the sample images.

[0053] S202: Use a preset first encoder and a preset second encoder to perform comparative learning on the sample images, and determine the first loss corresponding to the comparative learning.

[0054] In step S202, the sample image is subjected to comparative learning. During the comparative learning process, the enhanced image of the sample image is extracted using a preset first encoder and a preset second encoder, and the similarity and difference in the enhanced image are used as the first loss.

[0055] In this embodiment, a preset first encoder and a preset second encoder are obtained. The preset first encoder and the preset second encoder can be Small AlexNet encoders. A Small AlexNet encoder includes 5 convolutional blocks and 3 fully connected layers, and each convolutional block includes a convolutional layer, a batch normalization (BN) layer, a ReLU layer, and a pooling layer. Through comparative learning, the encoders extract image features based on the enhanced sample images, and the first loss is determined by the differences between the enhanced image features.

[0056] In this embodiment, the first loss is calculated through contrastive learning, which solves the problem of the limited number of face images with labeled information in the sample images. At the same time, the individual specificity of the sample and the consistency of the environment are constrained by learning, which ensures the stability and accuracy of subsequent memory classification of the sample images.

[0057] Optionally, the sample images are compared and learned using a preset first encoder and a preset second encoder to determine the first loss corresponding to the comparison and learning, including:

[0058] The sample image is enhanced to obtain the first enhanced image and the second enhanced image corresponding to the sample image;

[0059] The first enhanced image is encoded using a preset first encoder to obtain a first encoded feature, and the second enhanced image is encoded using a preset second encoder to obtain the first encoded feature.

[0060] The first loss is calculated based on the first and second coding features to correspond to the comparative learning.

[0061] In this embodiment, a contrastive learning mechanism is used to learn the inherent consistency information in the sample images. First, the sample images are enhanced, and each sample image is enhanced into two enhanced images similar to the sample image. When enhancing the sample images, occlusion, rotation, color transformation, and other processing can be performed on the sample images. The enhanced images after enhancement are used as new sample images to train the corresponding model. The number of sample images is increased through image enhancement so that the classification model can be trained in the future.

[0062] Two enhanced images obtained by enhancing the same sample image are considered positive examples of each other, and the remaining enhanced images are considered negative examples of each other. Contrastive learning aims to increase the similarity between positive examples and the difference between positive and negative examples.

[0063] During contrastive learning, positive and negative sample pairs are constructed for learning. If a sample image contains N sample images, where N is an integer greater than 1, after image enhancement, 2N enhanced images are obtained. The two enhanced images obtained from the same sample image are used as positive samples, and the remaining enhanced images are used as negative samples. Therefore, the number of negative samples is 2(N-1). Each enhanced image includes one sample image and 2(N-1) negative sample images. When calculating the first loss, a preset first encoder and a preset second encoder are used to extract features from the enhanced images based on the sample image. The first loss is determined based on the differences between the 2N enhanced images.

[0064] When calculating the first loss, a first encoder and a second encoder are used to extract features from the enhanced image based on the sample image to obtain the first encoded features and the second encoded features. The enhanced image can be either a positive sample enhanced image or a negative sample enhanced image.

[0065] In this embodiment, the sample images are enhanced to obtain similar images corresponding to the sample images at multiple scales and angles, which enriches the types of sample images, increases the number of sample images, and divides the enhanced images after enhancement into positive and negative samples to reduce the inter-class similarity and intra-class difference in the sample images.

[0066] Optionally, a first loss corresponding to the contrastive learning is calculated based on the first encoded feature and the second encoded feature, including:

[0067] By using a multilayer perceptron, the first encoded feature and the second encoded feature are projected into the same space to obtain the first feature vector corresponding to the first encoded feature and the second feature vector corresponding to the second encoded feature.

[0068] Calculate the similarity difference between the first feature vector and the second feature vector, and determine the first loss based on the similarity difference.

[0069] In this embodiment, the first encoded feature and the second encoded feature are input into a multilayer perceptron, and the difference between them is calculated using a preset contrastive loss function. The multilayer perceptron includes an activation function for non-linear feature space mapping of the first and second encoded features. The similarity difference between the first and second feature vectors is calculated using the contrastive loss function, and the first loss is determined based on the similarity difference. The formula for calculating the first loss is as follows:

[0070]

[0071]

[0072] Among them, L i The first loss is given by z, where N is the number of sample images. i The first eigenvector, The second eigenvector is a positive example of the first eigenvector. z represents the similarity between the first and second eigenvectors, which are mutually positive examples. j Let S(z) be the j-th eigenvector. i ,z j Let be the similarity between the i-th feature vector and the j-th feature vector, τ be the temperature sparsity, and K be 2N.

[0073] In this embodiment, the multilayer perceptron is used to perform nonlinear feature space transformation on the obtained first and second coded features, and to map the transformed feature space, mapping the first and second coded features into a first feature vector and a second feature vector. Through the mapping by the multilayer perceptron, due to the nonlinear transformation of the multilayer sensor, the coded features are converted into feature vectors, which facilitates the calculation of the similarity difference between the first and second coded features.

[0074] Please see Figure 3 , Figure 3 This is a flowchart illustrating a training method for a multilayer perceptron according to an embodiment of the present invention. To improve the accuracy of the first loss, training is performed on the multilayer perceptron, which includes at least a first fully connected layer and a second fully connected layer, such as... Figure 3 As shown, the training method for this multilayer perceptron may include the following steps:

[0075] S301: Enhance the sample image to obtain the enhanced sample image. Randomly select the first sample and the second sample from the enhanced sample image, and extract the sample features of the first sample and the sample features of the second sample respectively.

[0076] S302: Input the sample features of the first sample and the sample features of the second sample into the multilayer perceptron respectively to obtain the normalized loss of the first sample and the normalized loss of the second sample.

[0077] S303: Determine the contrast loss of the first sample and the second sample, and determine the total loss by the normalized loss of the first sample, the normalized loss of the second sample, and the contrast loss.

[0078] S304: When the total loss does not meet the preset conditions for loss convergence, the stochastic gradient descent method is used for backpropagation. The backpropagation process involves adjusting the parameters of the first fully connected layer and the second fully connected layer in the multilayer perceptron.

[0079] S305: When the total loss meets the preset conditions for loss convergence, determine the multilayer perceptron based on the parameters of the first fully connected layer and the parameters of the second fully connected layer when the preset conditions for loss convergence are met.

[0080] In this embodiment, the sample image is enhanced to obtain an enhanced sample image. A first sample and a second sample are randomly selected from the enhanced sample image, and the sample features of the first sample and the sample features of the second sample are extracted respectively. The first sample and the second sample can be encoded using corresponding encoders to extract the corresponding features.

[0081] A multilayer perceptron includes at least a first fully connected layer and a second fully connected layer. These two layers are used for feature mapping of sample features. Specifically, both the first and second fully connected layers employ activation functions to perform feature mapping transformations on any sample feature vector. Since activation functions can accelerate model convergence and improve the speed and efficiency of model training, in this embodiment, both the first and second fully connected layers use the ReLU activation function to perform feature mapping transformations on any sample feature.

[0082] After feature mapping through the fully connected layer of the multilayer perceptron, the output of the second fully connected layer is input to the normalization layer of the multilayer perceptron. The normalization layer of the multilayer perceptron is mainly used to normalize the input sample features. Based on the label values ​​in the sample images, the normalization loss for the first sample and the normalization loss for the second sample are determined, thus determining the contrastive loss between the first and second samples. The contrastive loss can effectively express the degree of matching between samples and can also be used effectively to train the feature extraction model. It is mainly used for dimensionality reduction. The formula for determining the contrastive loss is as follows:

[0083]

[0084] Among them, L c The first sample represents the contrast loss between the first and second samples, M represents the number of sample images, and y represents the contrast loss between the first and second samples. nThe value is 1 when the first and second samples have the same label category, and 0 when the first and second samples have different label categories, i.e., y n This can represent whether the first sample and the second sample match, where d represents the Euclidean distance between the first sample and the second sample. The specific calculation of the Euclidean distance between the first sample and the second sample will not be detailed here. ij The preset distance threshold, i.e., the pre-set distance threshold, can affect the convergence speed and performance of multilayer perceptron training.

[0085] After obtaining the normalized loss of the first sample, the normalized loss of the second sample, and the contrast loss L of the first and second samples respectively... c Then, the normalized loss of the first sample, the normalized loss of the second sample, and the contrast loss are added to determine the total loss. When the total loss does not meet the preset condition for loss convergence, the parameters of the first fully connected layer and the second fully connected layer in the multilayer perceptron are adjusted through backpropagation using stochastic gradient descent. Stochastic gradient descent is mainly used for weight updates in neural network models, updating and adjusting the model parameters in one direction to minimize the loss function. Backpropagation first calculates the product of the input signals and their corresponding weights in forward propagation, then applies the activation function to the sum of these products. Then, during the backpropagation of the network model, the relevant errors are propagated back, and the weight values ​​are updated using stochastic gradient descent. By calculating the gradient of the error function relative to the weight parameters, the weight parameters are updated in the opposite direction of the gradient of the loss function. Therefore, in this embodiment of the invention, when the total loss L does not meet the preset condition for loss convergence, the parameters of the first fully connected layer and the second fully connected layer of the multilayer perceptron are adjusted through backpropagation using stochastic gradient descent.

[0086] When the total loss meets the preset conditions for loss convergence, the parameters of the first fully connected layer and the second fully connected layer in the last calculation process before meeting the preset conditions for loss convergence are used as the parameters of the first fully connected layer and the second fully connected layer of the multilayer perceptron to determine the multilayer perceptron.

[0087] In this embodiment, a multi-layer sensor is trained to obtain a high-precision multi-layer sensor. This high-precision multi-layer sensor is then used to perform spatial mapping on the first and second encoded features to obtain a high-precision first feature vector and a high-precision second feature vector. Based on the high-precision first and second feature vectors, the accuracy of the first loss is improved.

[0088] S203: Select a target encoder from the preset first encoder and the preset second encoder, use the target encoder to encode the sample image to obtain the image features corresponding to the sample image, and use the initial classification model to predict and classify the image features to obtain the prediction classification result.

[0089] In step S203, any one encoder is selected from the preset first encoder and the preset second encoder as the target encoder. The target encoder is used to encode the sample image. The target encoder is used to encode the sample image in the classification model, extract the features of the sample image, and predict and classify the image features through the initial classification model to obtain the predicted classification result.

[0090] In this embodiment, a second encoder is selected as the target encoder. The target encoder is used to encode the sample image to obtain the image features corresponding to the sample image. The image features are then predicted and classified using an initial classification model to obtain the predicted classification result. The initial classification model is a multi-task classification model.

[0091] The multi-task classification model includes at least one classification head network, with each classification head network corresponding to a classification task. The classification head network is connected to the backbone network in the classification model. It predicts and classifies image features through the initial classification model to obtain the predicted classification result. The classification result corresponds to the task in the classification network. In this embodiment, there are multiple task-specific head networks that use the same encoding to extract image features from the sample image. That is, multiple tasks use the same feature extractor to extract data features. After obtaining the image features, each task uses a classification head network specific to that task to classify the data.

[0092] The backbone network in the classification model is connected to multiple classification head networks to form the corresponding classification model. The backbone network is the remaining part of the lightweight neural network after removing the fully connected layers and the output layer. The classification head network includes: multiple convolutional layers and output layers. The output layer includes: fully connected layers and normalized exponential layers.

[0093] The backbone network can be MobileNetV3. The backbone network is the portion of the lightweight neural network remaining after removing the fully connected layers and the output layer; in other words, the base network is the portion of the lightweight neural network after removing the last stage. The lightweight neural network comprises multiple stages. It should be noted that the output layer can also include convolutional layers.

[0094] In this embodiment, an initial classification model is used to predict and classify image features to obtain a predicted classification result. This predicted classification result can be attribute information from a face image, including global and local attribute information. Global attributes include gender, age, skin color, expression, attractiveness, and / or whether makeup is worn. Local attributes include mouth attributes, eye attributes, whether glasses are worn, whether a mask is worn, and / or whether a necklace is worn. Alternatively, local attributes can be grouped according to their relative position on the face, into three groups: upper, middle, and lower. The upper group includes whether glasses are worn and / or whether bangs are worn; the middle group includes nose attributes, whether a mask is worn, and / or whether earrings are worn; and the lower group includes beard attributes and / or whether a necklace is worn.

[0095] In this embodiment, image features are extracted by using a selected target encoder. That is, multiple tasks use the same feature extractor to extract data features. After obtaining the image features, each task uses a classification head network specific to that task to classify the image. The initial classification model is used to classify the image features extracted by the same encoder simultaneously. This avoids the problem of low task processing efficiency caused by multiple encoders extracting image features and performing multi-task classification, thus improving task processing efficiency.

[0096] S204: Calculate the second loss corresponding to the initial classification model using the predicted classification results and the label values ​​corresponding to the sample images.

[0097] In step S204, the second loss corresponding to the initial classification model is calculated using the predicted classification result and the label value corresponding to the sample image. The second loss is the difference between the predicted classification result and the true label value caused by the non-optimal parameters in the initial classification model.

[0098] In this embodiment, the initial classification model is a multi-task classification model, which includes at least one classification head network. Each classification head network corresponds to one classification task. When each classification task performs classification prediction on the input image features, since the sample image includes label values ​​corresponding to multiple classification tasks, when calculating the second loss corresponding to the initial classification model using the predicted classification result and the label values ​​corresponding to the sample image, it is necessary to obtain the label values ​​corresponding to the task regions in the sample images corresponding to different classification tasks.

[0099] For example, the first classification head network classifies whether a sample image contains glasses. When calculating the difference between the predicted classification result and the corresponding label value of the sample image, it obtains the label value of the eye region in the sample image and compares it with the predicted classification result of the first classification head network to determine the corresponding loss. The second classification head network classifies whether a sample image contains bangs. When calculating the difference between the predicted classification result and the corresponding label value of the sample image, it obtains the label value corresponding to the upper eyebrow region in the sample image and compares it with the predicted classification result of the second classification head network to determine the corresponding loss.

[0100] It should be noted that when using label values ​​from sample images, the number of label types in the sample image can be equal to or unequal to the number of classification head networks in the classification model. When the number of label types in the image is less than the number of classification head networks, when classifying the corresponding sample image, the classification head network corresponding to the task of the corresponding classification label type in the sample image is searched from multiple classification head networks based on the corresponding classification label type in the sample image, and the sample image is classified and predicted.

[0101] For example, when there are 3 corresponding label types in a sample image, and the initial classification model includes a 4-classification head network, when performing classification prediction on the sample image, the classification head network corresponding to the classification task is activated according to the classification task corresponding to the 3 corresponding label types to perform classification prediction on the sample image respectively. Based on the predicted classification result and the label value corresponding to the sample image, the second loss corresponding to the initial classification model is calculated.

[0102] In this embodiment, the category label values ​​of different regions in the sample image and the corresponding predicted classification results are used to calculate the corresponding second loss, that is, the classification loss of the multi-task classification head network using the same sample image. This allows multiple classification head networks to be trained using a small number of sample images, thereby improving the training efficiency of the classification model.

[0103] Optionally, the second loss corresponding to the initial classification model is calculated using the predicted classification results and the label values ​​corresponding to the sample images, including:

[0104] Obtain the label values ​​of the first attribute and the second attribute from the label values ​​corresponding to the sample image;

[0105] The first attribute label value and the second attribute label value are masked to obtain the target first label value and the target second label value;

[0106] Based on the target's first label value, the target's second label value, and the predicted classification result, the second loss corresponding to the initial classification model is calculated.

[0107] In this embodiment, when training the initial classification model using sample images, since the sample images contain only a small amount of labeled information, it is necessary to process the unlabeled sample images to avoid the impact of unlabeled sample images on the classification loss.

[0108] In this embodiment, during sample image annotation, the sample images are annotated according to the attribute information in the face images to obtain label values ​​corresponding to different attributes in the face images. Label values ​​greater than 0 are used to annotate different attributes in the face images. The remaining sample images without annotation information are labeled with the same label value, -1. The label value is used to determine whether a sample image contains annotation information. For example, different categories in the face images are labeled, with the annotation information being the corresponding label value in the face image. Lips can be labeled as 1, eyes as 2, nose as 3, etc., using values ​​greater than 0 to annotate the face images, and the corresponding label value is used as the corresponding label value. Since the sample images used for training the initial classification model include both labeled and unlabeled sample images, corresponding label information is also set for unlabeled sample images, with the corresponding label information set to -1. Therefore, label values ​​of different attributes are used to distinguish between sample images with and without annotation information.

[0109] When training an initial classification model using both labeled and unlabeled sample images, to prevent the unlabeled sample images from affecting the classification loss during training, masking is performed on different attribute label values. Specifically, the first and second attribute label values ​​are masked to obtain target first and second label values. During masking, it's first determined whether any attribute label value is less than 0. If it is, a mask is generated based on that attribute label value. In the mask, a value less than 0 corresponds to 0, and a value less than 0 corresponds to 1. After masking, the target first and second label values ​​for the sample image are obtained. Based on these target first and second label values ​​and the predicted classification result, the second loss corresponding to the initial classification model is calculated.

[0110] In this embodiment, by masking the sample images with labeled information and the sample images without labeled information, the mask value corresponding to the sample images without labeled information after processing is 0. When calculating the sample loss, the value is multiplied by the corresponding value of the mask value. In this way, the data without labels will not affect the calculation of classification loss during the training process.

[0111] Optionally, based on the target's first label value, the target's second label value, and the predicted classification result, a second loss corresponding to the initial classification model is calculated, including:

[0112] Based on the predicted classification results, determine the corresponding predicted classification result for each task in the classification model;

[0113] Based on the target's first label value and second label value, as well as the predicted classification result, the sub-loss in each task of the initial classification model is calculated;

[0114] Based on the sub-loss of each task in the initial classification model, determine the second loss corresponding to the initial classification model.

[0115] In this embodiment, the initial classification model includes at least one classification head network. Each classification head network corresponds to a classification task. The parameters in each classification task are different, and the corresponding classification task is different. For example, one classification head network classifies gender in a face image, and another classification head network classifies glasses in a face image. Each classification head network has a different sub-loss when performing classification. The total classification loss in the classification model is obtained by calculating the corresponding sub-loss in each classification head network.

[0116] When calculating the classification loss in each classifier head network, the prediction result of each network is used as the basis for calculation. The probability value output by each classifier head network is multiplied by the label value corresponding to the sample image to obtain the predicted classification result for that network. The sub-loss of each classifier head network is then calculated based on this predicted result and the label value. The sub-losses of each network are summed to obtain the total classification loss of the model. For example, if the model includes three classifier head networks, the sub-losses of all three networks are summed to obtain the corresponding second loss. The formula for calculating the sub-loss of each classifier head network is as follows:

[0117]

[0118] Where N is the number of sample images, and in the c-th classification head network, y i For the i-th predicted classification result in the c-th classification head network, y j Let L be the j-th predicted classification result in the c-th classifier head network, where C is the number of classifications in the c-th classifier head network, and L is the number of predicted classifications. c Let be the sub-loss in the c-th classification head network.

[0119] The second loss corresponding to the classification model is calculated based on the sub-loss in each classification head network. When calculating the second loss, a corresponding weight value is set for each sub-loss. The formula for calculating the second loss is as follows:

[0120]

[0121] Among them, L m For the second loss, L c For each sub-loss in the classification head network, ω i Let ω be the weight value corresponding to the sub-loss in the i-th classification head network, m be the number of classification head networks, and ω be the weight value. i The sum of is 1.

[0122] In this embodiment, the sub-losses in each classification head network are weighted and summed to obtain the corresponding second loss. When setting different weights for the sub-losses in each classification head network, the weights can be determined based on the classification region of the classification task corresponding to each classification and head network. A larger classification region can include more image features, while a smaller classification region includes fewer image features. Sub-losses based on more image features have higher accuracy, while those based on fewer image features have lower accuracy. For example, when classifying face images, if the classification task is gender, it may be necessary to obtain image features from the entire face image region. If the classification task is whether or not someone wears glasses, only image features from the area around the eyes are needed. A larger weight can be set for the sub-loss in the classification head network corresponding to gender classification, and a smaller weight can be set for the sub-loss in the classification head network corresponding to whether or not someone wears glasses. The sum of the weights of the sub-losses in each classification head network is 1. By setting different weights for the sub-losses in each classification head network according to the size of the classification region that the classification task needs to analyze in the head network, the calculation accuracy of the second loss can be improved.

[0123] S205: Construct a training loss function based on the first loss and the second loss, and train the initial classification model based on the training loss function to obtain a trained classification model.

[0124] In step S205, a training loss function is constructed based on the first loss and the second loss. The initial classification model is trained using the training loss function. When the training loss function converges, training is stopped, and a trained classification model is obtained.

[0125] In this embodiment, the initial classification model is trained using a training loss function constructed from the first loss and the second loss. The initial classification model is a multi-task classification model, which includes at least one classification head network. Each classification head network corresponds to one classification task. During training, multiple classification head networks are trained simultaneously, and the corresponding loss value is applied according to the training loss function. When the training loss function converges, training is stopped, and the trained classification model is obtained.

[0126] In this embodiment, a training loss function is constructed using the first loss and the second loss. This training loss function includes the loss from contrastive learning and the loss from classification. It takes into account both the loss corresponding to the sample images without labeled information and the loss corresponding to the sample images with labeled information. This achieves the goal of training the initial classification model using a small number of sample images with labeled information, thereby improving the training accuracy of the classification model when there are few data labels.

[0127] In another embodiment, all classification head networks can be used as training models, and multiple training models can be trained separately. Since the classification head networks are connected to the backbone networks in the classification models, during the first training, the current classification head network is trained without freezing the parameters of the backbone network, so as to update the parameters of the backbone network and the current classification head network according to the training results. During subsequent training, the current classification head network is trained with the backbone network frozen, so as to update the parameters of the current classification head network according to the training results. After training multiple classification head networks separately, all classification head networks are trained simultaneously without freezing the parameters of the backbone network, so as to update the parameters of the backbone network and multiple classification head networks according to the training results.

[0128] A multi-task classification model requiring training comprises multiple trainable models, which are trained in a specific order. The training results can include information such as the calculated loss function. In this embodiment, a multi-task classification model is considered as multiple trainable models, and multiple training iterations of the multi-task model are viewed as training multiple trainable models separately. During the entire training process of the multiple trainable models: in the first training iteration, the current trainable model is trained without freezing the parameters of the base network; in subsequent training iterations, the current trainable model is trained with the base network frozen. After training multiple trainable models separately, the multi-task classification model is trained without freezing the parameters of the base network. This step is equivalent to training the entire network, used to fine-tune the parameters of the multi-task classification model and improve its training accuracy.

[0129] Optionally, a training loss function is constructed based on the first loss and the second loss, and the initial classification model is trained based on the training loss function to obtain a trained classification model, including:

[0130] Set hyperparameter weights for the first loss and the second loss, calculate the sum of the first loss and the second loss, and obtain the training loss function;

[0131] The initial classification model is trained using a training loss function. When the training loss function converges, the trained classification model is obtained.

[0132] In this embodiment, hyperparameter weights are set for the first loss and the second loss, and the sum of the first loss and the second loss is calculated to obtain the training loss function. The formula for calculating the training loss function is as follows:

[0133]

[0134] Among them, L i As the first loss, L c For each sub-loss in the classification head network, ω i Let ω be the weight value corresponding to the sub-loss in the i-th classification head network, m be the number of classification head networks, and ω be the weight value. i The sum of is 1, and γ is the hyperparameter weight corresponding to the first loss. The initial classification model is trained using the training loss function, and the trained classification model is obtained when the training loss function converges.

[0135] In this embodiment, hyperparameter weights are set for the first loss and the second loss to distinguish the importance of different losses in the training process. Since the first loss is obtained through contrastive learning, which mainly uses unlabeled sample images for calculation, and the second loss is obtained through the classification process, which mainly uses labeled sample images for calculation, the hyperparameter weights can be set according to the number of unlabeled sample images and the number of labeled sample images in the sample images to improve the accuracy of the training loss function, thereby improving the classification accuracy of the trained classification model.

[0136] Please see Figure 4 This is a flowchart illustrating a classification method based on contrastive learning provided in an embodiment of the present invention, as shown below. Figure 4 As shown, this contrastive learning-based classification method may include the following steps:

[0137] S401: Obtain the image to be classified;

[0138] S402: Use the trained classification model to classify the image to be classified, and obtain the classification result corresponding to the image to be classified.

[0139] In this embodiment, the classification method uses the trained classification model to classify the image to be classified. The image to be classified can be a face image captured by different photographic devices. After obtaining the image to be classified, it can be preprocessed to standardize the image and obtain the corresponding standard image. The preprocessing can process the color face image in the image to be classified into grayscale to obtain a grayscale image of the face. Then, the grayscale image histogram is equalized to obtain the processed face image. Grayscale processing reduces redundant information in the original face image, which is more conducive to the classification of face attributes.

[0140] The preprocessed face image is encoded using the corresponding encoder, and the corresponding image features are extracted. The corresponding image features are then input into the trained classification model for classification processing to obtain the classification result corresponding to the image to be classified.

[0141] In this embodiment, a trained classification model is used to classify the image to be classified. Since the classification accuracy of the trained classification model is high, a high-precision classification result can be obtained for the image to be classified.

[0142] The process involves acquiring sample images, extracting corresponding label values ​​from these images, performing comparative learning on the sample images using a first preset encoder and a second preset encoder, determining the first loss corresponding to the comparative learning, selecting a target encoder from the first and second preset encoders, and using the target encoder to encode the sample images to obtain image features corresponding to the sample images. An initial classification model is then used to predict and classify these image features to obtain a predicted classification result. Using the predicted classification result and the corresponding label values ​​of the sample images, a second loss corresponding to the initial classification model is calculated. Based on the first and second losses, a training loss function is constructed, and the initial classification model is trained using this training loss function to obtain a trained classification model. In this invention, the encoder in comparative learning is used to encode the sample images to obtain corresponding image features, and the classification model is trained using the loss from comparative learning and the loss from the classification model. Adding comparative learning to the classification model allows the learning of inherent consistency information between sample images, improving the distinguishability between corresponding image features in different tasks, thereby improving the classification accuracy of the classification model.

[0143] It is understood that in the specific embodiments of this application, data related to facial recognition is involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0144] Please see Figure 5 , Figure 5 This is a schematic diagram of a classification model training device based on contrastive learning provided in an embodiment of the present invention. The units included in this embodiment are used for execution... Figure 2 The steps in the corresponding embodiments. Please refer to the details. Figure 2 The relevant descriptions in the corresponding embodiments are shown below. For ease of explanation, only the parts relevant to this embodiment are shown. See also... Figure 5 The classification model training device 50 includes: an acquisition module 51, a first loss calculation module 52, a classification module 53, a second loss calculation module 54, and a training module 55.

[0145] The acquisition module 51 is used to acquire sample images and extract the label values ​​corresponding to the sample images from the sample images.

[0146] The first loss calculation module 52 is used to compare and learn the sample image using a preset first encoder and a preset second encoder, and determine the first loss corresponding to the comparison and learning.

[0147] The classification module 53 is used to select a target encoder from the preset first encoder and the preset second encoder, use the target encoder to encode the sample image to obtain the image features corresponding to the sample image, and use the initial classification model to predict and classify the image features to obtain the prediction classification result.

[0148] The second loss calculation module 54 is used to calculate the second loss corresponding to the initial classification model using the predicted classification results and the label values ​​corresponding to the sample images.

[0149] Training module 55 is used to construct a training loss function based on the first loss and the second loss, and to train the initial classification model based on the training loss function to obtain a trained classification model.

[0150] Optionally, the first loss calculation module 52 mentioned above includes:

[0151] The image enhancement unit is used to enhance the sample image to obtain a first enhanced image and a second enhanced image corresponding to the sample image;

[0152] The feature encoding unit is used to encode the first enhanced image using a preset first encoder to obtain a first encoded feature, and to encode the second enhanced image using a preset second encoder to obtain the first encoded feature.

[0153] The first loss determination unit is used to calculate the first loss corresponding to the comparative learning based on the first coding feature and the second coding feature.

[0154] Optionally, the aforementioned first loss determination unit includes:

[0155] The projection subunit is used to project the first encoded feature and the second encoded feature into the same space through the multilayer perceptron, so as to obtain the first feature vector corresponding to the first encoded feature and the second feature vector corresponding to the second encoded feature.

[0156] The first computational subunit is used to calculate the similarity difference between the first feature vector and the second feature vector, and to determine the first loss based on the similarity difference.

[0157] Optionally, the second loss calculation module 54 mentioned above includes:

[0158] The label value determination unit is used to obtain the label value of the first attribute and the label value of the second attribute from the label values ​​corresponding to the sample image;

[0159] The masking unit is used to mask the first attribute label value and the second attribute label value to obtain the target first label value and the target second label value.

[0160] The second loss determination unit is used to calculate the second loss corresponding to the initial classification model based on the target's first label value, the target's second label value, and the predicted classification result.

[0161] Optionally, the second loss determination unit mentioned above includes:

[0162] The prediction classification result determination subunit is used to determine the corresponding prediction classification result for each task in the classification model based on the prediction classification result.

[0163] The sub-loss calculation sub-unit is used to calculate the sub-loss for each task in the initial classification model based on the target's first label value, target's second label value, and the predicted classification result.

[0164] The second computational subunit is used to determine the second loss corresponding to the initial classification model based on the sub-loss of each task in the initial classification model.

[0165] Optionally, the training module 55 mentioned above includes:

[0166] The training loss function determination unit is used to set hyperparameter weights for the first loss and the second loss, calculate the sum of the first loss and the second loss, and obtain the training loss function.

[0167] The trained classification model is defined as a unit, which is used to train the initial classification model using the training loss function. When the training loss function converges, the trained classification model is obtained.

[0168] Please see Figure 6 , Figure 6 This is a schematic diagram of a classification device based on contrastive learning provided in an embodiment of the present invention. In this embodiment, the terminal includes units used for execution... Figure 4 The steps in the corresponding embodiments. Please refer to the details. Figure 4 The relevant descriptions in the corresponding embodiments are shown below. For ease of explanation, only the parts relevant to this embodiment are shown. See also... Figure 6 The classification device 60 includes: an acquisition module 61 and a classification module 62.

[0169] The image acquisition module 61 is used to acquire the image to be classified.

[0170] The classification module 62 is used to classify the image to be classified using the trained classification model, and obtain the classification result corresponding to the image to be classified.

[0171] It should be noted that the information interaction and execution process between the above modules, units, and sub-units are based on the same concept as the method embodiments of the present invention. For details on their specific functions and technical effects, please refer to the method embodiments section, which will not be repeated here.

[0172] Figure 7 This is a schematic diagram of the structure of a computer device provided by the present invention. (See diagram below.) Figure 7 As shown, the computer device of this embodiment includes: at least one processor ( Figure 7 Only one is shown in the diagram), a memory, and a computer program stored in the memory and capable of running on at least one processor. When the processor executes the computer program, it implements the steps in any of the above-described classification model training methods and classification method embodiments.

[0173] This computer device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that... Figure 7 The examples of computer devices are merely examples and do not constitute a limitation on computer devices. Computer devices may include more or fewer components than shown in the illustration, or combinations of certain components, or different components, such as network interfaces, displays, and input devices.

[0174] The processor referred to can be a CPU, but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.

[0175] Memory includes readable storage media, internal memory, etc., wherein internal memory can be the RAM of a computer device, providing an environment for the operation of the operating system and computer-readable instructions stored in the readable storage media. The readable storage media can be the hard drive of a computer device, or in other embodiments, it can be an external storage device of the computer device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, memory can include both internal storage units and external storage devices of a computer device. Memory is used to store the operating system, applications, bootloader, data, and other programs, such as program code for computer programs. Memory can also be used to temporarily store data that has been output or will be output.

[0176] Those skilled in the art will understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the functions described above can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this invention. The specific working process of the units and modules in the above device can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here. If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention can implement all or part of the processes in the methods of the above embodiments by instructing related hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the above method embodiments. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. A computer-readable medium can include at least: any entity or device capable of carrying computer program code, a recording medium, a computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.

[0177] The present invention can implement all or part of the processes in the methods of the above embodiments, or it can be accomplished by a computer program product. When the computer program product is run on a computer device, the computer device executes the steps in the above method embodiments.

[0178] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0179] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0180] In the embodiments provided by this invention, it should be understood that the disclosed apparatus / computer devices and methods can be implemented in other ways. For example, the apparatus / computer device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0181] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.

[0182] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A classification model training method based on contrastive learning, characterized in that, The classification model training method includes: Acquire sample images and extract label values ​​corresponding to the sample images from the sample images; the sample images include labeled sample images and unlabeled sample images, and the label values ​​of the unlabeled sample images are labeled with preset identifiers; The sample image is compared and learned by using a preset first encoder and a preset second encoder to determine the first loss corresponding to the comparison and learning. A target encoder is selected from the preset first encoder and the preset second encoder. The target encoder is used to encode the sample image to obtain the image features corresponding to the sample image. The image features are then predicted and classified using an initial classification model to obtain the prediction classification result. Using the predicted classification result and the label value corresponding to the sample image, calculate the second loss corresponding to the initial classification model; The step of using the predicted classification result and the label value corresponding to the sample image to calculate the second loss corresponding to the initial classification model includes: Obtain the label value of the first attribute and the label value of the second attribute from the label values ​​corresponding to the sample image; The first attribute label value and the second attribute label value are masked to obtain the target first label value and the target second label value; wherein, during the masking process, the mask value corresponding to the unlabeled sample image with the label value of the preset identifier is set to 0; Based on the target first label value and the target second label value, as well as the predicted classification result, the second loss corresponding to the initial classification model is calculated; Based on the first loss and the second loss, a training loss function is constructed, and the initial classification model is trained based on the training loss function to obtain a trained classification model.

2. The classification model training method as described in claim 1, characterized in that, The step of using a preset first encoder and a preset second encoder to perform comparative learning on the sample image, and determining the first loss corresponding to the comparative learning, includes: The sample image is enhanced to obtain a first enhanced image and a second enhanced image corresponding to the sample image; The first enhanced image is encoded using a preset first encoder to obtain a first encoded feature, and the second enhanced image is encoded using a preset second encoder to obtain a second encoded feature. The first loss corresponding to the comparative learning is calculated based on the first coding feature and the second coding feature.

3. The classification model training method as described in claim 2, characterized in that, The step of calculating the first loss corresponding to the comparative learning based on the first encoded feature and the second encoded feature includes: projecting the first encoded feature and the second encoded feature into the same space through a multilayer perceptron to obtain a first feature vector corresponding to the first encoded feature and a second feature vector corresponding to the second encoded feature; Calculate the similarity difference between the first feature vector and the second feature vector, and determine the first loss based on the similarity difference.

4. The classification model training method as described in claim 1, characterized in that, The step of calculating the second loss corresponding to the initial classification model based on the target first label value, the target second label value, and the predicted classification result includes: Based on the predicted classification results, determine the corresponding predicted classification results for each task in the initial classification model; Based on the target first label value and target second label value, and the predicted classification result, the sub-loss in each task of the initial classification model is calculated; Based on the sub-loss in each task of the initial classification model, determine the second loss corresponding to the initial classification model.

5. The classification model training method as described in claim 1, characterized in that, The step of constructing a training loss function based on the first loss and the second loss, and training the initial classification model based on the training loss function to obtain a trained classification model includes: Set hyperparameter weights for the first loss and the second loss, calculate the sum of the first loss and the second loss, and obtain the training loss function; The initial classification model is trained using the training loss function, and when the training loss function converges, a trained classification model is obtained.

6. A classification method based on contrastive learning, characterized in that, The classification method includes: Obtain the image to be classified; The classification model trained using the classification model training method according to any one of claims 1 to 5 is used to classify the image to be classified, thereby obtaining the classification result corresponding to the image to be classified.

7. A classification model training device based on contrastive learning, characterized in that, The classification model training device includes: The acquisition module is used to acquire sample images and extract the label values ​​corresponding to the sample images from the sample images; the sample images include labeled sample images and unlabeled sample images, and the label values ​​of the unlabeled sample images are labeled with preset identifiers; The first loss calculation module is used to perform comparative learning on the sample image using a preset first encoder and a preset second encoder, and determine the first loss corresponding to the comparative learning. The classification module is used to select a target encoder from the preset first encoder and the preset second encoder, use the target encoder to encode the sample image to obtain the image features corresponding to the sample image, and use an initial classification model to predict and classify the image features to obtain the predicted classification result. The second loss calculation module is used to calculate the second loss corresponding to the initial classification model using the predicted classification result and the label value corresponding to the sample image. The step of using the predicted classification result and the label value corresponding to the sample image to calculate the second loss corresponding to the initial classification model includes: Obtain the label value of the first attribute and the label value of the second attribute from the label values ​​corresponding to the sample image; The first attribute label value and the second attribute label value are masked to obtain the target first label value and the target second label value; wherein, during the masking process, the mask value corresponding to the unlabeled sample image with the label value of the preset identifier is set to 0; Based on the target first label value and the target second label value, as well as the predicted classification result, the second loss corresponding to the initial classification model is calculated; The training module is used to construct a training loss function based on the first loss and the second loss, and to train the initial classification model based on the training loss function to obtain a trained classification model.

8. A computer device, characterized in that, The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the classification model training method as described in any one of claims 1 to 5 or the classification method as described in claim 6.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the classification model training method as described in any one of claims 1 to 5 or the classification method as described in claim 6.

Citation Information

Patent Citations

  • Training method and device of endoscope image feature learning model and classification model

    CN113706526A

  • Image retrieval model training method and device, equipment and storage medium

    CN114020950A

  • Thermal image reconstruction methods, network training methods, devices, equipment and media

    CN114936969A