Training methods and devices for face recognition models to avoid the long tail problem of data

By constructing a face recognition model that includes feature extraction, normalization, classification, and comparison networks, and by utilizing dynamic sampling and loss calculation methods, the model degradation or overfitting caused by the long tail of data problem is solved, thereby improving model performance.

CN115661891BActive Publication Date: 2026-05-26SHENZHEN XUMI YUNTU SPACE TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN XUMI YUNTU SPACE TECH CO LTD
Filing Date
2022-10-09
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Due to the long tail of data, existing face recognition models suffer from model degradation or overfitting.

Method used

A face recognition model is constructed, including a feature extraction network, a normalization network, a classification network, and a contrastive network. A dynamic sampler is used to sample from the training dataset to obtain a sample set. During multiple rounds of training, the classification loss and contrastive loss are calculated, and the model parameters are updated to avoid the long-tail problem of data.

Benefits of technology

This effectively avoids model degradation or overfitting caused by the long tail of data, thus improving the performance of the face recognition model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115661891B_ABST
    Figure CN115661891B_ABST
Patent Text Reader

Abstract

This disclosure relates to the field of face recognition technology, and provides a training method and apparatus for a face recognition model that avoids the long tail problem of data. The method includes: constructing a face recognition model; obtaining a training dataset, and executing the following loop to train the face recognition model in multiple rounds: sampling the current round of training from the training dataset using a dynamic sampler to obtain a sample set used for the current round of training; inputting the sample set into a feature extraction network to obtain a feature vector set corresponding to the sample set; inputting the feature vector set into a normalization network to normalize the feature vectors in the feature vector set; calculating a classification loss using a classification network and a contrastive loss using a contrastive network based on the feature vector set processed by the normalization network; updating the model parameters of the face recognition model based on the classification loss and contrastive loss; incrementing the training round number corresponding to the current round of training by one; and ending the loop when the training round number equals a preset round number.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of face recognition technology, and in particular to a method and apparatus for training a face recognition model that avoids the long tail problem of data. Background Technology

[0002] In practical applications, facial recognition often suffers from a long-tail effect, also known as the data long-tail problem. This refers to the phenomenon where a small subset of classes (the "head" classes) constitute the vast majority of the samples in the training dataset, while the majority of classes (the "tail" classes) have very few samples. This severe imbalance in data distribution can lead to model degradation or overfitting in the trained facial recognition model.

[0003] In realizing the present invention, the inventors discovered at least the following technical problems in the related technology: due to the long tail of data, the trained face recognition model suffers from model degradation or overfitting. Summary of the Invention

[0004] In view of this, the present disclosure provides a method, apparatus, electronic device and computer-readable storage medium for training a face recognition model to avoid the long tail problem of data, so as to solve the problem of model degradation or overfitting in the trained face recognition model due to the long tail problem of data in the prior art.

[0005] A first aspect of this disclosure provides a method for training a face recognition model to avoid the long-tail problem of data, comprising: constructing a face recognition model, wherein the face recognition model includes: a feature extraction network, a normalization network, a classification network, and a contrastive network; acquiring a training dataset and executing the following loop to train the face recognition model in multiple rounds: sampling the current round of training from the training dataset using a dynamic sampler to obtain a sample set used for the current round of training; inputting the sample set into the feature extraction network to obtain a feature vector set corresponding to the sample set, wherein a sample in the sample set corresponds to a feature vector in the feature vector set; inputting the feature vector set into the normalization network to normalize the feature vectors in the feature vector set; calculating a classification loss using the classification network and a contrastive loss using the contrastive network based on the feature vector set processed by the normalization network; updating the model parameters of the face recognition model based on the classification loss and the contrastive loss; incrementing the training round number corresponding to the current round of training by one; and ending the loop when the training round number equals a preset round number.

[0006] A second aspect of this disclosure provides a training apparatus for a face recognition model that avoids the long tail problem of data, comprising: a construction module configured to construct a face recognition model, wherein the face recognition model includes: a feature extraction network, a normalization network, a classification network, and a contrast network; an acquisition module configured to acquire a training dataset and execute the following loop to perform multiple rounds of training on the face recognition model: a sampling module configured to use a dynamic sampler to sample from the training dataset for the current round of training to obtain a sample set used for the current round of training; and a feature extraction module configured to input the sample set into the feature extraction network to obtain a sample... The feature vector set corresponding to this set, where one sample in the sample set corresponds to one feature vector in the feature vector set; the normalization module is configured to input the feature vector set into the normalization network to normalize the feature vectors in the feature vector set; the loss calculation module is configured to calculate the classification loss using the classification network and the contrastive loss using the contrastive network based on the feature vector set processed by the normalization network; the update module is configured to update the model parameters of the face recognition model based on the classification loss and the contrastive loss, increment the training round number corresponding to the current training round by one, and end the loop when the training round number equals the preset round number.

[0007] A third aspect of this disclosure provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described above.

[0008] A fourth aspect of this disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described method.

[0009] The beneficial effects of this disclosure embodiment compared with the prior art are as follows: This disclosure embodiment constructs a face recognition model, wherein the face recognition model includes: a feature extraction network, a normalization network, a classification network, and a contrast network; obtains a training dataset, and executes the following loop to perform multiple rounds of training on the face recognition model: using a dynamic sampler to sample from the training dataset for the current round of training, obtaining the sample set used for the current round of training; inputting the sample set into the feature extraction network to obtain the feature vector set corresponding to the sample set, wherein one sample in the sample set corresponds to one feature vector in the feature vector set; inputting the feature vector set into... A normalization network is used to normalize the feature vectors in the feature vector set. Based on the feature vector set processed by the normalization network, a classification network is used to calculate the classification loss, and a contrastive network is used to calculate the contrastive loss. The model parameters of the face recognition model are updated based on the classification loss and the contrastive loss. The number of training rounds corresponding to the current round is incremented by one, and the loop ends when the number of training rounds equals the preset number of rounds. Therefore, by adopting the above technical means, the problem of model degradation or overfitting in the face recognition model after training due to the long tail of data in the existing technology can be solved, thereby avoiding model degradation or overfitting caused by the long tail of data. Attached Figure Description

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

[0011] Figure 1 This is a schematic diagram illustrating an application scenario of an embodiment of this disclosure;

[0012] Figure 2 This is a flowchart illustrating a method for training a face recognition model to avoid the long-tail problem of data, provided in an embodiment of this disclosure.

[0013] Figure 3 This is a schematic diagram of the structure of a training device for a face recognition model that avoids the long tail problem of data, provided in an embodiment of this disclosure;

[0014] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

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

[0016] The following describes in detail, with reference to the accompanying drawings, a method and apparatus for training a face recognition model that avoids the long tail problem of data according to an embodiment of the present disclosure.

[0017] Figure 1 This is a schematic diagram illustrating an application scenario of an embodiment of this disclosure. The application scenario may include terminal devices 101, 102, and 103, server 104, and network 105.

[0018] Terminal devices 101, 102, and 103 can be hardware or software. When terminal devices 101, 102, and 103 are hardware, they can be various electronic devices with displays that support communication with server 104, including but not limited to smartphones, tablets, laptops, and desktop computers. When terminal devices 101, 102, and 103 are software, they can be installed in the aforementioned electronic devices. Terminal devices 101, 102, and 103 can be implemented as multiple software programs or software modules, or as a single software program or software module; this disclosure does not impose any limitations on this. Furthermore, various applications can be installed on terminal devices 101, 102, and 103, such as data processing applications, instant messaging tools, social platform software, search applications, shopping applications, etc.

[0019] Server 104 can be a server that provides various services, such as a backend server that receives requests sent by terminal devices with which it has established communication connections. This backend server can receive and analyze the requests sent by the terminal devices and generate processing results. Server 104 can be a single server, a server cluster consisting of several servers, or a cloud computing service center. This embodiment of the disclosure does not impose any limitations on these aspects.

[0020] It should be noted that server 104 can be either hardware or software. When server 104 is hardware, it can be various electronic devices that provide various services to terminal devices 101, 102, and 103. When server 104 is software, it can be multiple software programs or software modules that provide various services to terminal devices 101, 102, and 103, or it can be a single software program or software module that provides various services to terminal devices 101, 102, and 103. This disclosure does not limit the scope of the embodiments.

[0021] Network 105 can be a wired network using coaxial cable, twisted pair, and fiber optic connection, or it can be a wireless network that enables interconnection of various communication devices without wiring, such as Bluetooth, Near Field Communication (NFC), Infrared, etc. This disclosure does not limit the scope of the network.

[0022] Users can establish a communication connection with server 104 via network 105 through terminal devices 101, 102, and 103 to receive or send information, etc. It should be noted that the specific types, quantities, and combinations of terminal devices 101, 102, and 103, server 104, and network 105 can be adjusted according to the actual needs of the application scenario, and this disclosure embodiment does not impose any limitations on this.

[0023] Figure 2 This is a flowchart illustrating a method for training a face recognition model to avoid the long tail problem of data, provided in an embodiment of this disclosure. Figure 2 Training methods for face recognition models that avoid the long tail problem can be developed by... Figure 1 The computer or server, or the software on the computer or server, executes the command. For example... Figure 2 As shown, the training method for this face recognition model that avoids the long-tail problem of data includes:

[0024] S201, Construct a face recognition model, which includes: a feature extraction network, a normalization network, a classification network, and a contrast network;

[0025] S202, Obtain the training dataset and execute the following loop to train the face recognition model in multiple rounds:

[0026] S203, use a dynamic sampler to sample from the training dataset for the current round of training to obtain the sample set used for the current round of training;

[0027] S204, Input the sample set into the feature extraction network to obtain the feature vector set corresponding to the sample set, wherein one sample in the sample set corresponds to one feature vector in the feature vector set;

[0028] S205, input the feature vector set into the normalization network to normalize the feature vectors in the feature vector set;

[0029] S206. Based on the feature vector set processed by the normalized network, the classification loss is calculated using the classification network, and the contrast loss is calculated using the contrast network.

[0030] S207: Update the model parameters of the face recognition model based on the classification loss and contrast loss, increment the training round number corresponding to the current training round by one, and end the loop when the training round number equals the preset round number.

[0031] The feature extraction network can be ResNet50, the classification network can be a fully connected layer network, and the contrastive network is a network that was constructed based on the principle of contrastive learning in this disclosure.

[0032] According to the technical solution provided in this disclosure, a face recognition model is constructed, comprising: a feature extraction network, a normalization network, a classification network, and a contrast network. A training dataset is obtained, and the following loop is executed to train the face recognition model in multiple rounds: a dynamic sampler is used to sample the current round of training data from the training dataset to obtain the sample set used for the current round of training; the sample set is input into the feature extraction network to obtain the feature vector set corresponding to the sample set, wherein one sample in the sample set corresponds to one feature vector in the feature vector set; the feature vector set is input into the normalization network to normalize the feature vectors in the feature vector set; based on the feature vector set processed by the normalization network, the classification network is used to calculate the classification loss, and the contrast network is used to calculate the contrast loss; the model parameters of the face recognition model are updated based on the classification loss and the contrast loss; the number of training rounds corresponding to the current round of training is incremented by one, and the loop ends when the number of training rounds equals a preset number of rounds. Therefore, by adopting the above technical means, the problem of model degradation or overfitting in the trained face recognition model due to the long tail of data in the prior art can be solved, thereby avoiding model degradation or overfitting caused by the long tail of data.

[0033] Currently, the most effective method to address the long-tail effect is the class rebalancing strategy, which aims to alleviate extreme imbalance in training data. Generally, class rebalancing can be divided into two main categories: re-sampling and re-weighting. These methods resample samples in a batch, reweighting the loss function to adjust the network training, making the training sample distribution closer to the testing sample distribution. Although rebalancing strategies improve accuracy, the side effects cannot be ignored. These methods will, to some extent, impair the representational power of the learned deep features. Specifically, when the data imbalance is very severe, resampling risks overfitting the tail data (oversampling) and underfitting the entire data distribution. Re-weighting distorts the original distribution by directly changing or even reversing the frequency of data presentation. All of these impair feature representation. The embodiments disclosed in this disclosure effectively avoid the long-tail problem by using dynamic sampling and comprehensively utilizing classification and contrastive losses to train the model.

[0034] The current training round sample is obtained by sampling from the training dataset using a dynamic sampler, including: calculating the function value of the dynamic adjustment function based on the training round number and the preset round number; calculating the sampling probability of each category of samples in the training dataset based on the function value; and completing the sampling for the current training round based on the sampling probability of each category of samples, thus obtaining the sample set used for the current training round.

[0035] Because the number of training rounds is different for each round, the function value is different for each round. Therefore, the sampling probability of each category of samples in the training dataset is different for each round, thus achieving dynamic sampling and avoiding the problem of some tail data being used less often in the long tail problem.

[0036] Dynamic samplers, including:

[0037]

[0038]

[0039] Where j and i are the classes of the samples, C is the number of all classes of the samples in the training dataset, l is the training round number corresponding to the current round, L is the preset number of rounds, π is pi, g(l) is the function value, and n j n is the number of all samples in the j-th class. i p is the number of all samples in the i-th category. j Let be the sampling probability of the sample of the j-th class.

[0040] This disclosure provides a training dataset in the field of face recognition. Each face image is a sample, and samples whose feature vectors are less than a preset distance belong to the same category (the nearest neighbor rule can be used to determine whether two or more samples belong to the same category). sin() is a sine function. For all and.

[0041] Based on the feature vector set processed by the normalized network, a classification network is used to calculate the classification loss. This includes: a feature vector set comprising a first vector set and a second vector set, wherein each feature vector in the first vector set has a corresponding feature vector in the second vector set; and two corresponding feature vectors in the first and second vector sets are feature vectors corresponding to two different samples under the same identifier. Based on the first vector set processed by the normalized network, a first classification loss is calculated using the classification network; and based on the second vector set processed by the normalized network, a second classification loss is calculated using the classification network. The classification loss includes both the first and second classification losses.

[0042] Similarly, the sample set includes: a first sample set and a second sample set; one sample in the first sample set corresponds to one feature vector in the first vector set, and one sample in the second sample set corresponds to one feature vector in the second vector set. In practice, during the current round of training, the first sample set is obtained, and then the second sample set is obtained based on the identifiers of the samples in the first sample set; face images of the same person have the same identifier. This embodiment differs from existing technologies in that it actually calculates two classification losses: a first classification loss and a second classification loss. This is also to avoid the problem of some tail data being used less frequently in the long-tail data problem.

[0043] Classification networks, including:

[0044]

[0045]

[0046] Among them, L cls Let N be the classification loss for the current batch, N be the number of samples in the current batch, the current training round includes multiple batches, h be the sample index, and y be the classification loss for the current batch. h Let be the category of the h-th sample, j be any category in the current batch other than the category of the h-th sample, and n be the number of all categories of samples in the current batch. Let θ be the angle between the h-th sample and the center of the positive sample class. j Let be the angle between the h-th sample and the negative sample class center, s and M are preset hyperparameters, c is the adjustment coefficient, Ki is the number of all samples of class i, and min() is the minimum value function.

[0047] The training of multiple batches in the current round of training is similar to multi-round training. The inventive aspect of this disclosure is that the hyperparameter *m*, which is a preset parameter in the prior art, is adjusted to a dynamically changing function. Of course, the classification loss, including both the first classification loss and the second classification loss, is also an inventive aspect of this disclosure. In fact, both the classification loss and the contrast loss are calculated batch by batch; after training multiple batches in the current round, training multiple batches in the next round is then performed.

[0048] The first classification loss is calculated using a classification network based on the first vector set processed by the normalized network; the second classification loss is calculated using a classification network based on the second vector set processed by the normalized network.

[0049] Comparison networks include:

[0050]

[0051] Among them, Lcon Let be the contrastive loss for the current batch, N be the number of samples in the current batch of any set in the first and second vector sets, 2N be the number of samples in the current batch of both sets in the first and second vector sets, i be the index of the sample in the current batch, the current training round includes multiple batches, P(i) be all positive samples corresponding to the i-th sample in the current batch, A(i) be all negative samples corresponding to the i-th sample in the current batch, τ be the adjustment coefficient, and z be the contrastive loss for the current batch. i z is the feature vector of the i-th sample. p Z represents all the eigenvectors corresponding to P(i). a is all the feature vectors corresponding to A(i), p is the index of the sample in P(i), a is the index of the sample in A(i), and the feature vector set includes: a first vector set and a second vector set. Each feature vector in the first vector set has a corresponding feature vector in the second vector set. The two corresponding feature vectors in the first vector set and the second vector set are the feature vectors corresponding to two different samples under the same identifier.

[0052] exp is an exponential function with the natural constant e as its base.

[0053] The face recognition model parameters are updated based on classification loss and contrastive loss, including: determining the total loss using the following formula, and then updating the face recognition model parameters using the total loss:

[0054] L zon =f(l)*(L) cls1 +L cls2 )+L con

[0055]

[0056] Where l is the training round number corresponding to the current training round, and L is the preset number of rounds. zon L represents the total loss for the current batch. con L represents the classification loss for the current batch. cls1 L represents the first classification loss of the current batch. cls2 The second classification loss is for the current batch, and the current training round includes multiple batches. As shown in the formula above, this embodiment of the disclosure combines the classification loss, the first classification loss, and the second classification loss to obtain the total loss.

[0057] In an optional embodiment, the following loop is executed to train multiple batches in the current training round, including: determining a third vector set for the current batch training from the first vector set processed by the normalized network based on the batch number; determining a fourth vector set for the current batch training from the second vector set processed by the normalized network based on the batch number; calculating a first classification loss corresponding to the third vector set using a classification network; calculating a second classification loss corresponding to the fourth vector set using a classification network; calculating a contrast loss corresponding to the third and fourth vector sets using a contrast network; determining a total loss based on the classification loss, the first classification loss, and the second classification loss; updating the model parameters of the face recognition model based on the total loss; incrementing the training batch corresponding to the current batch training by one; and ending the loop when the training batch equals a preset number of training iterations.

[0058] Furthermore, the sum of the first classification losses in all batches of training in the current round can be used as the first classification loss calculated by the classification network based on the first vector set processed by the normalized network; the sum of the second classification losses in all batches of training in the current round can be used as the second classification loss calculated by the classification network based on the second vector set processed by the normalized network; and the sum of the contrastive losses in all batches of training in the current round can be used as the contrastive loss calculated by the classification network based on the feature vector set processed by the normalized network.

[0059] All of the above-mentioned optional technical solutions can be combined in any way to form the optional embodiments of this application, and will not be described in detail here.

[0060] The following are embodiments of the apparatus disclosed herein, which can be used to execute embodiments of the method disclosed herein. For details not disclosed in the apparatus embodiments of this disclosure, please refer to the embodiments of the method disclosed herein.

[0061] Figure 3 This is a schematic diagram of a training device for a face recognition model that avoids the long-tail problem of data, provided in an embodiment of this disclosure. Figure 3 As shown, the training device for this face recognition model that avoids the long tail problem of data includes:

[0062] Module 301 is configured to build a face recognition model, wherein the face recognition model includes: a feature extraction network, a normalization network, a classification network, and a contrast network;

[0063] Module 302 is configured to acquire the training dataset and execute the following loop to train the face recognition model in multiple rounds:

[0064] The sampling module 303 is configured to use a dynamic sampler to sample from the training dataset for the current round of training to obtain the sample set used for the current round of training;

[0065] The feature extraction module 304 is configured to input the sample set into the feature extraction network to obtain the feature vector set corresponding to the sample set, wherein one sample in the sample set corresponds to one feature vector in the feature vector set.

[0066] Normalization module 305 is configured to input a feature vector set into a normalization network to normalize the feature vectors in the feature vector set.

[0067] The loss calculation module 306 is configured to calculate the classification loss using a classification network and the contrast loss using a contrast network based on the feature vector set processed by the normalized network.

[0068] The update module 307 is configured to update the model parameters of the face recognition model based on the classification loss and the contrast loss, increment the training round number corresponding to the current training round by one, and end the loop when the training round number equals the preset round number.

[0069] The feature extraction network can be ResNet50, the classification network can be a fully connected layer network, and the contrastive network is a network that was constructed based on the principle of contrastive learning in this disclosure.

[0070] According to the technical solution provided in this disclosure, a face recognition model is constructed, comprising: a feature extraction network, a normalization network, a classification network, and a contrast network. A training dataset is obtained, and the following loop is executed to train the face recognition model in multiple rounds: a dynamic sampler is used to sample the current round of training data from the training dataset to obtain the sample set used for the current round of training; the sample set is input into the feature extraction network to obtain the feature vector set corresponding to the sample set, wherein one sample in the sample set corresponds to one feature vector in the feature vector set; the feature vector set is input into the normalization network to normalize the feature vectors in the feature vector set; based on the feature vector set processed by the normalization network, the classification network is used to calculate the classification loss, and the contrast network is used to calculate the contrast loss; the model parameters of the face recognition model are updated based on the classification loss and the contrast loss; the number of training rounds corresponding to the current round of training is incremented by one, and the loop ends when the number of training rounds equals a preset number of rounds. Therefore, by adopting the above technical means, the problem of model degradation or overfitting in the trained face recognition model due to the long tail of data in the prior art can be solved, thereby avoiding model degradation or overfitting caused by the long tail of data.

[0071] Currently, the most effective method to address the long-tail effect is the class rebalancing strategy, which aims to alleviate extreme imbalance in training data. Generally, class rebalancing can be divided into two main categories: re-sampling and re-weighting. These methods resample samples in a batch, reweighting the loss function to adjust the network training, making the training sample distribution closer to the testing sample distribution. Although rebalancing strategies improve accuracy, the side effects cannot be ignored. These methods will, to some extent, impair the representational power of the learned deep features. Specifically, when the data imbalance is very severe, resampling risks overfitting the tail data (oversampling) and underfitting the entire data distribution. Re-weighting distorts the original distribution by directly changing or even reversing the frequency of data presentation. All of these impair feature representation. The embodiments disclosed in this disclosure effectively avoid the long-tail problem by using dynamic sampling and comprehensively utilizing classification and contrastive losses to train the model.

[0072] Optionally, the sampling module 303 is further configured to calculate the function value of the dynamic adjustment function based on the number of training rounds corresponding to the current round of training and the preset number of rounds; calculate the sampling probability of each category of samples in the training dataset based on the function value; and complete the sampling of the current round of training based on the sampling probability of each category of samples to obtain the sample set used for the current round of training.

[0073] Because the number of training rounds is different for each round, the function value is different for each round. Therefore, the sampling probability of each category of samples in the training dataset is different for each round, thus achieving dynamic sampling and avoiding the problem of some tail data being used less often in the long tail problem.

[0074] Dynamic samplers, including:

[0075]

[0076]

[0077] Where j and i are the classes of the samples, C is the number of all classes of the samples in the training dataset, l is the training round number corresponding to the current round, L is the preset number of rounds, π is pi, g(l) is the function value, and n j n is the number of all samples in the j-th class. i p is the number of all samples in the i-th category. j Let be the sampling probability of the sample of the j-th class.

[0078] This disclosure provides a training dataset in the field of face recognition. Each face image is a sample, and samples whose feature vectors are less than a preset distance belong to the same category (the nearest neighbor rule can be used to determine whether two or more samples belong to the same category). sin() is a sine function. For all and.

[0079] Optionally, the loss calculation module 306 is further configured as a feature vector set, including: a first vector set and a second vector set, wherein each feature vector in the first vector set has a corresponding feature vector in the second vector set, and the two corresponding feature vectors in the first vector set and the second vector set are feature vectors corresponding to two different samples under the same identifier; based on the first vector set after normalization network processing, a first classification loss is calculated using a classification network, and based on the second vector set after normalization network processing, a second classification loss is calculated using a classification network, wherein the classification loss includes: the first classification loss and the second classification loss.

[0080] Similarly, the sample set includes: a first sample set and a second sample set; one sample in the first sample set corresponds to one feature vector in the first vector set, and one sample in the second sample set corresponds to one feature vector in the second vector set. In practice, during the current round of training, the first sample set is obtained, and then the second sample set is obtained based on the identifiers of the samples in the first sample set; face images of the same person have the same identifier. This embodiment differs from existing technologies in that it actually calculates two classification losses: a first classification loss and a second classification loss. This is also to avoid the problem of some tail data being used less frequently in the long-tail data problem.

[0081] Classification networks, including:

[0082]

[0083]

[0084] Among them, L cls Let N be the classification loss for the current batch, N be the number of samples in the current batch, the current training round includes multiple batches, h be the sample index, and y be the classification loss for the current batch. h Let be the category of the h-th sample, j be any category in the current batch other than the category of the h-th sample, and n be the number of all categories of samples in the current batch. Let θ be the angle between the h-th sample and the center of the positive sample class. j Let be the angle between the h-th sample and the negative sample class center, s and M are preset hyperparameters, c is the adjustment coefficient, Ki is the number of all samples of class i, and min() is the minimum value function.

[0085] The training of multiple batches in the current round of training is similar to multi-round training, which is the same as in existing technology and will not be elaborated here. The inventive point of this disclosure is that the hyperparameter m, which is set as a preset parameter in the prior art, is adjusted to a dynamically changing function. Of course, the classification loss, including the first classification loss and the second classification loss, is also an inventive point of this disclosure. In fact, both the classification loss and the contrast loss are calculated on a batch basis. After training multiple batches in the current round of training, training multiple batches in the next round of training is performed.

[0086] Comparison networks include:

[0087]

[0088] Among them, L con Let be the contrastive loss for the current batch, N be the number of samples in the current batch of any set in the first and second vector sets, 2N be the number of samples in the current batch of both sets in the first and second vector sets, i be the index of the sample in the current batch, the current training round includes multiple batches, P(i) be all positive samples corresponding to the i-th sample in the current batch, A(i) be all negative samples corresponding to the i-th sample in the current batch, τ be the adjustment coefficient, and z be the contrastive loss for the current batch. i z is the feature vector of the i-th sample. p Z represents all the eigenvectors corresponding to P(i). a is all the feature vectors corresponding to A(i), p is the index of the sample in P(i), a is the index of the sample in A(i), and the feature vector set includes: a first vector set and a second vector set. Each feature vector in the first vector set has a corresponding feature vector in the second vector set. The two corresponding feature vectors in the first vector set and the second vector set are the feature vectors corresponding to two different samples under the same identifier.

[0089] Optionally, the update module 307 is also configured to determine the total loss using the following formula, and then update the model parameters of the face recognition model using the total loss:

[0090] L zon =f(l)*(L) cls1 +L cls2 )+L con

[0091]

[0092] Where l is the training round number corresponding to the current training round, and L is the preset number of rounds. zon L represents the total loss for the current batch. con L represents the classification loss for the current batch.cls1 L represents the first classification loss of the current batch. cls2 The second classification loss is for the current batch, and the current training round includes multiple batches. As shown in the formula above, this embodiment of the disclosure combines the classification loss, the first classification loss, and the second classification loss to obtain the total loss.

[0093] Optionally, the update module 307 is further configured to: determine the third vector set used for training the current batch from the first vector set processed by the normalization network based on the batch number; determine the fourth vector set used for training the current batch from the second vector set processed by the normalization network based on the batch number; calculate the first classification loss corresponding to the third vector set using a classification network; calculate the second classification loss corresponding to the fourth vector set using a classification network; calculate the contrast loss corresponding to the third and fourth vector sets using a contrast network; determine the total loss based on the classification loss, the first classification loss, and the second classification loss; update the model parameters of the face recognition model based on the total loss; increment the training batch corresponding to the current batch training by one; and end the loop when the training batch equals a preset number of times.

[0094] Furthermore, the sum of the first classification losses in all batches of training in the current round can be used as the first classification loss calculated by the classification network based on the first vector set processed by the normalized network; the sum of the second classification losses in all batches of training in the current round can be used as the second classification loss calculated by the classification network based on the second vector set processed by the normalized network; and the sum of the contrastive losses in all batches of training in the current round can be used as the contrastive loss calculated by the classification network based on the feature vector set processed by the normalized network.

[0095] It should be understood that the sequence number of each step in the above 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 this disclosure.

[0096] Figure 4 This is a schematic diagram of the electronic device 4 provided in an embodiment of this disclosure. Figure 4 As shown, the electronic device 4 of this embodiment includes: a processor 401, a memory 402, and a computer program 403 stored in the memory 402 and executable on the processor 401. When the processor 401 executes the computer program 403, it implements the steps in the various method embodiments described above. Alternatively, when the processor 401 executes the computer program 403, it implements the functions of each module / unit in the various device embodiments described above.

[0097] Electronic device 4 can be a desktop computer, laptop, handheld computer, cloud server, or other electronic device. Electronic device 4 may include, but is not limited to, processor 401 and memory 402. Those skilled in the art will understand that... Figure 4 This is merely an example of electronic device 4 and does not constitute a limitation on electronic device 4. It may include more or fewer components than shown, or different components.

[0098] The processor 401 may be a central processing unit (CPU), or 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.

[0099] The memory 402 can be an internal storage unit of the electronic device 4, such as a hard disk or RAM of the electronic device 4. The memory 402 can also be an external storage device of the electronic device 4, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc., equipped on the electronic device 4. The memory 402 can also include both internal and external storage units of the electronic device 4. The memory 402 is used to store computer programs and other programs and data required by the electronic device.

[0100] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions 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.

[0101] If an integrated module / 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, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. 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 various method embodiments described above. The computer program may include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. A computer-readable medium may include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in a computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in a jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media may not include electrical carrier signals and telecommunication signals.

[0102] The above embodiments are only used to illustrate the technical solutions of this disclosure, and are not intended to limit it. Although this disclosure 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 this disclosure, and should all be included within the protection scope of this disclosure.

Claims

1. A method for training a face recognition model to avoid the long-tail problem of data, characterized in that, include: Construct a face recognition model, wherein the face recognition model includes: a feature extraction network, a normalization network, a classification network, and a comparison network; Obtain the training dataset and execute the following loop to train the face recognition model in multiple rounds: The current training round sample set is obtained by sampling from the training dataset using a dynamic sampler. The sample set is input into the feature extraction network to obtain the feature vector set corresponding to the sample set, wherein one sample in the sample set corresponds to one feature vector in the feature vector set; The feature vector set is input into the normalization network to normalize the feature vectors in the feature vector set; Based on the feature vector set processed by the normalized network, the classification network is used to calculate the classification loss, and the contrast network is used to calculate the contrast loss. The model parameters of the face recognition model are updated according to the classification loss and the contrast loss, the training round number corresponding to the current training round is incremented by one, and the loop ends when the training round number is equal to the preset round number. The step of sampling from the training dataset using a dynamic sampler to obtain the sample set used for the current training round includes: Based on the number of training rounds corresponding to the current training round and the preset number of rounds, calculate the function value of the dynamic adjustment function; Based on the function value, the sampling probability of each category of samples in the training dataset is calculated respectively; Based on the sampling probability of samples of each category, the sampling for the current round of training is completed, and the sample set used for the current round of training is obtained; The dynamic sampler includes: Where j and i are the categories of the samples, C is the number of all categories of samples in the training dataset, l is the training round number corresponding to the current training round, and L is the preset number of rounds. Pi The function value is... It is the number of all samples in the j-th category. It is the number of all samples in the i-th category. Let be the sampling probability of the sample of the j-th class.

2. The method according to claim 1, characterized in that, The step of calculating the classification loss using the classification network based on the feature vector set processed by the normalized network includes: The feature vector set includes: a first vector set and a second vector set, wherein each feature vector in the first vector set has a corresponding feature vector in the second vector set, and the two corresponding feature vectors in the first vector set and the second vector set are feature vectors corresponding to two different samples under the same identifier. Based on the first vector set processed by the normalized network, a first classification loss is calculated using the classification network; based on the second vector set processed by the normalized network, a second classification loss is calculated using the classification network, wherein the classification loss includes: the first classification loss and the second classification loss.

3. The method according to claim 1, characterized in that, The classification network includes: Among them, L cls Let N be the classification loss for the current batch, N be the number of samples in the current batch, the current training round includes multiple batches, h be the sample index, and y be the classification loss for the current batch. h Let be the category of the h-th sample, j be any category in the current batch other than the category of the h-th sample, and n be the number of all categories of samples in the current batch. Let h be the angle between the h-th sample and the center of the positive sample class. Let be the angle between the h-th sample and the class center of the negative sample, s and M are preset hyperparameters, c is the adjustment coefficient, Ki is the number of all samples of class i, and min() is the minimum value function.

4. The method according to claim 1, characterized in that, The comparison network includes: Among them, L con Let be the contrastive loss for the current batch, N be the number of samples in the current batch of either the first or second vector set, 2N be the number of samples in the current batch of both the first and second vector sets, d be the index of the sample in the current batch (the current training round includes multiple batches), P(d) be all positive samples corresponding to the d-th sample in the current batch, and A(d) be all negative samples corresponding to the d-th sample in the current batch. It is the adjustment coefficient, z d z is the feature vector of the d-th sample. p These are all the eigenvectors corresponding to P(d), z a It is all the feature vectors corresponding to A(d), p is the index of the sample in P(d), a is the index of the sample in A(d), the feature vector set includes: the first vector set and the second vector set, each feature vector in the first vector set has a corresponding feature vector in the second vector set, and the two corresponding feature vectors in the first vector set and the second vector set are the feature vectors corresponding to two different samples under the same identifier.

5. The method according to claim 1, characterized in that, The step of updating the model parameters of the face recognition model based on the classification loss and the contrast loss includes: The total loss is determined using the following formula, and the model parameters of the face recognition model are updated using the total loss: Where l is the training round number corresponding to the current training round, and L is the preset number of rounds. zon L represents the total loss for the current batch. con L represents the comparison loss for the current batch. cls1 L represents the first classification loss of the current batch. cls2 The second classification loss is used for the current batch, and the current training round includes multiple batches.

6. A training apparatus for a face recognition model that avoids the long-tail problem of data, used to implement the method according to any one of claims 1-5, characterized in that, include: The construction module is configured to build a face recognition model, wherein the face recognition model includes: a feature extraction network, a normalization network, a classification network, and a comparison network; The acquisition module is configured to acquire a training dataset and execute the following loop to train the face recognition model in multiple rounds: The sampling module is configured to use a dynamic sampler to sample from the training dataset for the current round of training to obtain the sample set used for the current round of training; The feature extraction module is configured to input the sample set into the feature extraction network to obtain a feature vector set corresponding to the sample set, wherein one sample in the sample set corresponds to one feature vector in the feature vector set; A normalization module is configured to input the feature vector set into the normalization network to normalize the feature vectors in the feature vector set. The loss calculation module is configured to calculate the classification loss using the classification network and the contrast loss using the contrast network based on the feature vector set processed by the normalization network. The update module is configured to update the model parameters of the face recognition model based on the classification loss and the contrast loss, increment the training round number corresponding to the current training round by one, and end the loop when the training round number equals the preset round number.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 5.