A neural network model training method, device, equipment and storage medium
By adding regularization loss of low rank constraints to neural network model training, the problem of model overfitting is solved, and the generalization performance and prediction accuracy of the model are improved.
Patent Information
- Application Number
- CN202110181147.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-09
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2041-02-09
AI Technical Summary
Existing deep neural network models are prone to overfitting, resulting in low prediction accuracy in test sets or practical applications.
By adding regularization losses of low rank constraints in the neural network model training process, the regularization losses are calculated using the low rank constraints of the feature matrix, and the model parameters are updated in combination with the classification loss, guiding the model to learn compact and discriminant features.
It effectively prevents overfitting of neural network models, improves the generalization performance of the model and the prediction accuracy in practical applications.
Smart Images

Figure CN114943331B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to machine learning technology, and more particularly to a neural network model training method, apparatus, device, and storage medium. Background Art
[0002] With the development of artificial intelligence, deep neural networks have achieved remarkable results in numerous fields with their powerful fitting capabilities. However, to achieve better generalization, existing network structures are becoming increasingly complex, and the number of network parameters is also experiencing explosive growth. Complex neural networks can lead to overfitting. This occurs when a model performs well on a training set but only mediocrely on a test set or in real-world applications, resulting in low prediction accuracy in real-world applications. Summary of the Invention
[0003] The present invention provides a neural network model training method, apparatus, equipment and storage medium, which can effectively prevent the overfitting phenomenon of the neural network model and improve the prediction accuracy of the neural network model in practical applications.
[0004] In a first aspect, an embodiment of the present invention provides a neural network model training method, comprising:
[0005] Obtaining a batch of first training samples and a batch of second training samples for training a neural network model;
[0006] Inputting the first training sample into a neural network model to be trained for processing to obtain a probability vector for predicting that the first training sample belongs to each category;
[0007] Inputting the second training sample into the neural network model to be trained for processing to obtain a feature matrix composed of feature vectors of the second training sample, where the feature vectors of the second training sample are used to characterize properties of the second training sample;
[0008] Calculate the classification loss of a batch of the first training samples based on the probability vector;
[0009] Calculating a regularization loss of a batch of second training samples based on the low rank constraint of the feature matrix;
[0010] Parameters of the neural network model are updated based on the classification loss and the regularization loss.
[0011] In a second aspect, an embodiment of the present invention further provides a neural network model training device, comprising:
[0012] A training sample acquisition module, used to acquire a batch of first training samples and a batch of second training samples for training a neural network model;
[0013] a probability vector acquisition module, configured to input the first training sample into a neural network model to be trained for processing, and obtain a probability vector for predicting that the first training sample belongs to each category;
[0014] a feature matrix acquisition module, configured to input the second training sample into the neural network model to be trained for processing, and obtain a feature matrix composed of feature vectors of the second training sample, wherein the feature vectors of the second training sample are used to characterize the attributes of the second training sample;
[0015] a classification loss calculation module, configured to calculate the classification loss of a batch of the first training samples based on the probability vector;
[0016] A regularization loss calculation module, configured to calculate the regularization loss of a batch of second training samples based on the low-rank constraint of the feature matrix;
[0017] A parameter updating module is used to update the parameters of the neural network model based on the classification loss and the regularization loss.
[0018] In a third aspect, an embodiment of the present invention further provides a computer device, including:
[0019] one or more processors;
[0020] a storage device for storing one or more programs;
[0021] When the one or more programs are executed by the one or more processors, the one or more processors implement the neural network model training method provided in the first aspect of the present invention.
[0022] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the neural network model training method provided in the first aspect of the present invention.
[0023] The neural network model training method provided by an embodiment of the present invention, after obtaining a batch of first training samples and a batch of second training samples, inputs the first training samples and the second training samples into the neural network model to be trained for processing, obtains a probability vector for predicting that the first training sample belongs to each category, and a feature matrix composed of the feature vectors of the second training samples, calculates the classification loss of the batch of first training samples based on the probability vector, and calculates the regularization loss of the batch of second training samples based on the low-rank constraint of the feature matrix, and then updates the parameters of the neural network model based on the classification loss and the regularization loss. By adding the regularization loss based on the low-rank constraint to the classification loss, the human prior knowledge of the neural network model can be integrated into the learning of the model, guiding the model to learn more compact and more discriminative features, while reducing the complexity of the neural network model, and can effectively prevent the neural network model from overfitting, thereby improving the generalization performance of the model, that is, improving the prediction accuracy of the neural network model in practical applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 A flowchart of a neural network model training method provided in Example 1 of the present invention;
[0025] Figure 2 A flowchart of a neural network model training method provided in Example 2 of the present invention;
[0026] Figure 3 A classification prediction method provided in the third embodiment of the present invention;
[0027] Figure 4 A schematic diagram of the structure of a neural network model training device provided in Example 4 of the present invention;
[0028] Figure 5 A schematic diagram of the structure of a classification prediction device provided in Example 5 of the present invention;
[0029] Figure 6 A structural diagram of a computer device provided in Example 6 of the present invention. DETAILED DESCRIPTION
[0030] The present invention will be further described in detail below with reference to the accompanying drawings and examples. It will be understood that the specific embodiments described herein are intended only to illustrate the present invention and are not intended to limit the present invention. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions relevant to the present invention, not all structures.
[0031] Example 1
[0032] Figure 1This is a flowchart of a neural network model training method provided in the first embodiment of the present invention. This embodiment is applicable to the situation where the neural network model has too many parameters, resulting in overfitting. The method can be performed by the neural network model training device provided in the embodiment of the present invention. The device can be implemented in software and / or hardware, and is usually configured in a computer device, such as Figure 1 As shown, the method specifically includes the following steps:
[0033] S101. Obtain a batch of first training samples and a batch of second training samples for training a neural network model.
[0034] In the embodiments of the present invention, the neural network model to be trained is used to implement data classification and recognition tasks. The embodiments of the present invention do not limit the network structure and application scenarios of the neural network model to be trained. For example, in one embodiment of the present invention, the neural network model is used for face recognition, and the person to which the face image belongs is predicted based on the input face image.
[0035] The dataset used to train the neural network model includes training samples from multiple categories, each category having multiple training samples, and a batch of data includes multiple training samples. For training a classification model, the model input unit is a single training sample; for training a metric model, the model input unit is a combined sample, such as a face pair, which is not limited in this embodiment of the present invention. In this embodiment of the present invention, a batch of first training samples and a batch of second training samples can be training samples from the same batch or from different batches, which is not limited in this embodiment of the present invention.
[0036] Exemplarily, in one embodiment of the present invention, taking the neural network model as a classification-based deep face recognition model as an example, the data set used to train the neural network model includes facial images of 100,000 people.
[0037] The training samples (or sample combinations) of the embodiments of the present invention may be labeled with labels indicating the categories to which the training samples (or sample combinations) belong, or may not be labeled with labels indicating the categories to which the training samples (or sample combinations) belong. The embodiments of the present invention are not limited thereto. For example, in some embodiments of the present invention, each training sample (or sample combination) is labeled with a label indicating the category of the training sample (or sample combination). For labeled training samples, supervised learning can be used to train a neural network model. In other embodiments of the present invention, the training samples (or sample combinations) may also not have labeled category labels. In this case, a clustering algorithm (such as K-means, DBSCAN, and spectral clustering, etc.) may be used to cluster the data set first to obtain pseudo-labels for the training samples, and then supervised learning may be used to train the neural network model based on the pseudo-labels.
[0038] S102: Input the first training sample into the neural network model to be trained for processing, and obtain a probability vector for predicting that the first training sample belongs to each category.
[0039] Multiple first training samples from a batch of first training samples are input into the neural network model to be trained for processing. The neural network model can perform operations such as convolution, pooling, and feature fusion on the input first training samples to extract feature vectors used to characterize the attributes of the first training samples. After being transformed by a fully connected layer, the model outputs a logits vector used to predict the category of the first training samples. The logits vector is normalized by a softmax function to obtain a probability vector used to predict that the first training samples belong to each category. Each position in the probability vector corresponds to each category, and the category corresponding to the position with the maximum element value in the probability vector is the category predicted by the neural network model for the first training sample.
[0040] Exemplarily, as described above, the neural network model is a classification-based deep face recognition model. The neural network model processes the input facial image to obtain a feature vector for the facial image. Exemplarily, the feature vector is 512-dimensional, and a 512×100,000 fully connected layer is used to convert the 512-dimensional feature vector into a 100,000-dimensional logits vector. The softmax function normalizes the logits vector to obtain a 100,000-dimensional probability vector. The 100,000 positions in the probability vector correspond to 100,000 people, and the position with the maximum element value in the probability vector corresponds to the person described in the first training sample predicted by the model.
[0041] S103: Input the second training sample into the neural network model to be trained for processing, and obtain a feature matrix composed of feature vectors of the second training sample.
[0042] Similarly, multiple second training samples from a batch of second training samples are input into the neural network model to be trained for processing. The neural network model can perform operations such as convolution, pooling, and feature fusion on the input second training samples to extract feature vectors representing attributes of the second training samples. The feature vectors of the multiple second training samples from the batch of second training samples are arranged in rows or columns to form a feature matrix.
[0043] S104: Calculate the classification loss of a batch of first training samples based on the probability vector.
[0044] In an embodiment of the present invention, the cross entropy loss, negative log-likelihood loss or exponential loss of a batch of first training samples can be calculated based on the probability vector as the classification loss of the batch of training samples, and the present invention is not limited here.
[0045] S105. Calculate the regularization loss of a batch of second training samples based on the low-rank constraint of the feature matrix.
[0046] The low-rank representation of images is a classic research topic in fields such as machine learning. Mathematically, the rank of a matrix refers to the number of the largest linearly independent row (or column) vectors in the matrix; in images, the rank can represent the richness, redundancy, and noise of information. The smaller the rank, the higher the redundancy of the image, the less information rich it is, and the less noise it has. For example, in a picture of a blue sky, most of the images are similar (high redundancy), so the rank of the image is very low. For a picture of random noise, there are almost no similarities in the images. In this case, the rank of the image is very high or reaches full rank, which means that the rank is equal to the number of rows (or columns) of the matrix. Natural images generally have low rank characteristics because there are always local or non-local similarities in images. Therefore, low rank constraints are often used for tasks such as image denoising, super-resolution, and restoration.
[0047] Machine learning problems are nothing more than minimizing error while regularizing parameters. Minimizing error ensures that the model fits the training data, while regularizing the parameters prevents the model from overfitting. Too many parameters increase model complexity and can easily lead to overfitting. Therefore, we need to minimize training error while maintaining a simple model. This ensures good generalization performance (i.e., low test error). This "simple" model is achieved through the regularization function.
[0048] In an embodiment of the present invention, a low-rank constraint is imposed on the rank of the feature matrix, approximating the rank of the feature matrix to the number of classes in the second batch of training samples. A regularization loss for the second batch of training samples is then calculated based on the low-rank constraint of the feature matrix. By incorporating a regularization loss based on the low-rank constraint into the classification loss, prior knowledge of the neural network model can be incorporated into the model's learning process, guiding the model to learn more compact and discriminative features. This also helps reduce the complexity of the neural network model and effectively prevents overfitting, thereby improving the model's generalization performance and, in other words, enhancing the predictive accuracy of the neural network model in practical applications. Compactness can be characterized by the similarity of feature vectors between samples of the same class; the higher the similarity, the better the compactness. Ideally, the rank of a feature matrix composed of feature vectors of samples of the same class is 1. Discriminability can be characterized by the similarity of feature vectors between samples of different classes; the lower the similarity, the better the discriminability. Ideally, the rank of a feature matrix composed of feature vectors of samples of n different classes is n.
[0049] S106. Update the parameters of the neural network model based on the classification loss and the regularization loss.
[0050] In an embodiment of the present invention, a regularization loss based on a low-rank constraint is added on the basis of the classification loss, and the parameters of the neural network model are updated based on the classification loss and the regularization loss. Exemplarily, in one embodiment of the present invention, a hyperparameter is set for the regularization loss, the product of the regularization loss and the hyperparameter is calculated, and then the product is added to the classification loss to obtain the total loss. The hyperparameter is used to balance the classification loss and the regularization loss, and the value can be selected by cross-validation. The parameters of the neural network model are updated based on the total loss. Exemplarily, in some embodiments of the present invention, the total loss is compared with the loss threshold. When the total loss is greater than the loss threshold, the parameters of the neural network model are updated, and the step of obtaining a batch of first training samples and a batch of second training samples for training the neural network model is returned to obtain training samples, and the neural network model is trained again. This cycle is repeated until the total loss is less than or equal to the loss threshold, and the training of the neural network model is determined to be complete.
[0051] The neural network model training method provided by an embodiment of the present invention, after obtaining a batch of first training samples and a batch of second training samples, inputs the first training samples and the second training samples into the neural network model to be trained for processing, obtains a probability vector for predicting that the first training sample belongs to each category, and a feature matrix composed of the feature vectors of the second training samples, calculates the classification loss of the batch of first training samples based on the probability vector, and calculates the regularization loss of the batch of second training samples based on the low-rank constraint of the feature matrix, and then updates the parameters of the neural network model based on the classification loss and the regularization loss. By adding the regularization loss based on the low-rank constraint to the classification loss, the human prior knowledge of the neural network model can be integrated into the learning of the model, guiding the model to learn more compact and more discriminative features, while reducing the complexity of the neural network model, and can effectively prevent the neural network model from overfitting, thereby improving the generalization performance of the model, that is, improving the prediction accuracy of the neural network model in practical applications.
[0052] Example 2
[0053] Figure 2 This is a flowchart of a neural network model training method provided in Example 2 of the present invention. This embodiment is refined based on the above Example 1 and describes in detail the specific process of the neural network model training method, such as Figure 2 As shown, the method specifically includes the following steps:
[0054] S201: Obtain a batch of first training samples and a batch of second training samples for training a neural network model.
[0055] For example, in one embodiment of the present invention, a neural network model is used for face recognition, and based on an input face image, the person to whom the face image belongs is predicted. Given a face dataset X = {x1, x2, ..., x N}={X1,X2,...,X C}, where N is the total number of face images, C is the total number of people, x i Represents the i-th face picture, whose category label is y i , X i Represents a collection of facial images of person i. A batch consists of several facial images, each of which is annotated with a label identifying the person depicted in the image. For example, as described in the previous embodiment, this label can be a real label or a pseudo label derived through a clustering algorithm, which is not limited in this embodiment.
[0056] In some embodiments of the present invention, the first batch of training samples and the second batch of training samples may be different batches of training samples, and the above step S201 may include the following steps:
[0057] 1. Randomly select multiple training samples from the dataset as a batch of first training samples.
[0058] Specifically, a number of training samples are randomly selected from the data set as a batch of first training samples, denoted as {x i} n , where n represents the number of training samples in a batch of first training samples.
[0059] 2. Randomly select k categories from the data set, and randomly select m training samples from each category as a batch of second training samples.
[0060] Specifically, k categories are randomly selected from the data set, and m training samples are randomly selected from each category. A total of k×m training samples are used as a batch of second training samples, denoted as X batch For example, k=32, m=8, that is, a batch of second training samples includes 32 categories, each category has 8 training samples, and a total of 256 samples.
[0061] In other embodiments of the present invention, in order to simplify the process of selecting training samples and improve model training efficiency, the first batch of training samples and the second batch of training samples may be the same batch of training samples, and the above step S201 may include the following steps:
[0062] 1. Randomly select k categories from the dataset, and randomly select m training samples from each category as a batch of first training samples and a batch of second training samples. For example, k = 32 and m = 8, that is, the batch of first training samples and the batch of second training samples are the same batch of training samples, including 32 categories, each category has 8 training samples, a total of 256 samples.
[0063] S202: Input the first training sample into the backbone network for processing to obtain a feature vector of the first training sample.
[0064] For example, in the embodiment of the present invention, taking the classification deep face recognition model as an example, the neural network model can be divided into a backbone network (backbone) and a head network (head). The backbone network processes the input face image (first training sample) and outputs the feature vector of the face image. The head network processes the input feature vector and outputs the probability value used to predict that the face image belongs to each person. In the embodiment of the present invention, the face image (first training sample) is denoted as x i , let the backbone network be f θ (), the head network is where θ and Represent the parameters of the backbone network and the head network respectively, then the first training sample x i The eigenvector of θ (x i ).
[0065] In this embodiment of the present invention, there is no restriction on the structure of the backbone network. Classic models such as GoogleNet, VGGNet, ResNet, or DenseNet can be used. Alternatively, lightweight models for mobile devices such as MobileNet or ShuffleNet, as well as MobileFaceNet, a variant of MobileNet designed for face recognition tasks, can be selected. Models such as ResNet typically output 512-dimensional feature vectors, while models such as MobileFaceNet typically output 128-dimensional feature vectors.
[0066] S203: Input the feature vector of the first training sample into the head network for processing to obtain a probability vector for predicting that the first training sample belongs to each category.
[0067] Specifically, the feature vector of the first training sample is input into the head network for processing, and after being transformed by the fully connected layer in the head network, the logits vector used to predict the category of the first training sample is output. The logits vector is normalized by the softmax function to obtain the probability vector used to predict that the first training sample belongs to each category.
[0068] In the embodiment of the present invention, there is no restriction on the structure of the head network. For example, only one fully connected layer is used, whose input is the feature vector of the first training sample, and the output is the category logits vector of the first training sample. For example, if the face training set contains facial images of 100,000 people, the fully connected layer converts the 512-dimensional or 128-dimensional feature vector into a 100,000-dimensional logits vector. The logits vector is normalized by the softmax function to obtain a probability vector for predicting that the first training sample belongs to each category. Each position in the probability vector corresponds to each category, and the category corresponding to the position with the maximum element value in the probability vector is the category to which the first training sample belongs predicted by the neural network model.
[0069] S204: Input the second training sample into the backbone network for processing to obtain a feature matrix composed of feature vectors of the second training sample.
[0070] Specifically, the second training sample is input into the backbone network for processing to obtain a feature vector for characterizing the attributes of the second training sample. The feature vectors of multiple second training samples in a batch of second training samples are arranged in rows or columns to obtain a feature matrix f θ (X batch ).
[0071] S205 : Calculate the cross entropy loss of the first training sample based on the probability vector.
[0072] In an embodiment of the present invention, the cross entropy loss, negative log-likelihood loss or exponential loss of a batch of first training samples can be calculated based on the probability vector as the classification loss of the batch of training samples, and the present invention is not limited here.
[0073] For example, in a specific embodiment of the present invention, the cross entropy loss of the first training sample is calculated based on the probability vector as the classification loss of the first training sample. For example, the data set used to train the neural network model includes 100,000 human face images, that is, the neural network model in the embodiment of the present invention is applied to a multi-classification problem. For the multi-classification problem, the calculation formula of the cross entropy loss of the first training sample is as follows:
[0074]
[0075] Among them, C is the number of categories, y c is an indicator variable (0 or 1), if the category is the same as the category represented by the label of the training sample, it is 1, otherwise it is 0, p c The probability value of the training sample predicted by the model belongs to category c. The cross entropy loss of the first training sample is recorded as
[0076] S206: Calculate the sum of the cross entropy losses of the first training samples to obtain the classification loss.
[0077] Specifically, the sum of the cross entropy losses of each first training sample in the batch of first training samples is calculated to obtain the classification loss of the batch of training samples. Specifically, the calculation formula for the classification loss of the batch of training samples is as follows:
[0078]
[0079] Among them, n is the number of training samples in a batch, y ic is an indicator variable (0 or 1), if the category is the same as the category represented by the label of the first training sample, it is 1, otherwise it is 0, p ic is the probability value predicted by the model that the i-th training sample belongs to category c, and C is the number of categories. For example, in this embodiment of the present invention, n = 256, C = 100000. The classification loss of the first batch of training samples is
[0080] S207. Calculate the nuclear norm of the feature matrix.
[0081] In an embodiment of the present invention, the nuclear norm of the characteristic matrix is calculated to approximate the rank of the characteristic matrix. The nuclear norm is the sum of the singular values of the matrix and is used to constrain the low rank of the matrix. In other embodiments of the present invention, other improved forms of nuclear norms, such as truncated nuclear norms, can also be used to approximate the rank of the characteristic matrix, which is not limited in this embodiment of the present invention. The characteristic matrix f θ (X batch ) is denoted as ||f θ (X batch )|| * .
[0082] S208 . Calculate the difference between the nuclear norm and the rank of the feature matrix, where the rank of the feature matrix is the number of categories in a batch of second training samples.
[0083] Based on a batch of second training samples X batch The characteristic matrix f θ (X batch ), we can calculate the low-rank regularization loss. The core idea is to constrain the rank of the feature matrix to be approximately k. This idea is simple and natural, because X batch The number of categories included is k, and it is hoped that similar feature expressions can be extracted from similar samples. In an embodiment of the present invention, the nuclear norm of the feature matrix is used to approximate the rank of the feature matrix, and the difference between the nuclear norm and the rank k of the feature matrix is calculated to constrain the rank of the feature matrix.
[0084] S209: Determine a regularization loss of a batch of second training samples based on the difference.
[0085] The regularization loss of a second batch of training samples is determined based on the difference between the nuclear norm of the feature matrix and the rank k of the feature matrix. The regularization loss is recorded as L rank (f θ (X batc )). For example, in some embodiments of the present invention, the absolute value of the difference between the nuclear norm of the feature matrix and the rank k of the feature matrix is used as the regularization loss of a batch of second training samples. Specifically, the regularization loss Lr ank The calculation formula is as follows:
[0086] L rank =|||f θ (X batc )|| * -k|
[0087] In some other embodiments of the present invention, the absolute value of the difference between the nuclear norm of the feature matrix and the rank k of the feature matrix is used as the regularization loss of a batch of second training samples. Specifically, the regularization loss L rank The calculation formula is as follows:
[0088] L rank =(||f θ (X batc )|| * -k) 2
[0089] S210. Calculate the product of the regularization loss and the hyperparameter.
[0090] For example, in one embodiment of the present invention, a hyperparameter is set for the regularization loss, and the product of the regularization loss and the hyperparameter is calculated. The hyperparameter is used to balance the classification loss and the regularization loss. In some embodiments of the present invention, the hyperparameter can be manually assigned a value through cross-validation. In other embodiments of the present invention, the hyperparameter can also be adaptively determined based on the classification loss and the regularization loss. For example, the adaptive formula is as follows:
[0091]
[0092] Among them, λ is a hyperparameter, a is a constant, such as setting it to 0.1, which means that the product of regularization loss and hyperparameter λL is always rank is the classification loss L c 10% of the total cost. Although a constant a is manually specified here, it is different from directly specifying the hyperparameter λ. c and regularization loss L rank are all different, so during the training process the hyperparameter λ can be adjusted based on the classification loss L of the current batch of data. c and regularization loss Lrank Adaptive value, that is, the total loss to the regularization loss L rank The partial derivative of is variable, while the partial derivative corresponding to the latter (i.e. the artificially specified case) is fixed λ.
[0093] S211. Calculate the sum of the product and the classification loss to obtain the total loss.
[0094] Calculate the product of regularization loss and hyperparameter λL rank The sum of the classification loss and the total loss is obtained, and the calculation formula is as follows:
[0095]
[0096] S212: Determine whether the total loss is greater than the loss threshold.
[0097] For example, in some embodiments of the present invention, the total loss L total Compared with the loss threshold, the total loss L total If the loss is greater than the loss threshold, the parameters of the neural network model are updated, and the process returns to step S201 to obtain a batch of first training samples and a batch of second training samples for training the neural network model. The neural network model is trained again after obtaining the training samples. This cycle continues until the total loss is less than or equal to the loss threshold, at which point step S213 is executed to determine that the training of the neural network model is complete.
[0098] The neural network model training method provided by the embodiment of the present invention can incorporate people's prior knowledge of the neural network model into the learning of the model by adding a regularization loss based on low-rank constraints to the classification loss, guiding the model to learn to be more compact and more discriminative, while reducing the complexity of the neural network model, and can effectively prevent the neural network model from overfitting, thereby improving the generalization performance of the model, that is, improving the prediction accuracy of the neural network model in practical applications. In addition, the feature matrix is the deep feature matrix output by the backbone network. By adding a regularization loss based on low-rank constraints to the loss function, the low-rank regularization loss is to impose low-rank constraints on the deep feature matrix of the training sample. Using low-rank constraints for the training of deep neural networks is conducive to improving the prediction accuracy of the deep model.
[0099] Example 3
[0100] Figure 3 A classification prediction method is provided in the third embodiment of the present invention. This embodiment can be used for classification prediction. The method adopts a neural network model trained by the training method of the neural network model provided in any of the previous embodiments of the present invention. The method can be performed by the classification prediction device provided in the embodiment of the present invention. The device can be implemented in software and / or hardware and integrated into the computer device provided in the embodiment of the present invention. Figure 3 As shown, the method specifically includes the following steps:
[0101] S301: Obtain samples to be classified.
[0102] For example, in a specific embodiment of the present invention, the sample to be classified is a face image.
[0103] S302: Input the sample to be classified into the trained neural network model for processing to obtain the category to which the sample to be classified belongs.
[0104] Exemplarily, the neural network model can perform convolution, pooling, feature fusion and other operations on the input face image, extract the feature vector used to characterize the features of the face image, and output the logits vector for predicting the ID to which the face image belongs after conversion through the fully connected network layer. The logits vector is normalized by the softmax function to obtain the probability vector for predicting that the face image belongs to each ID. Each position in the probability vector corresponds to each category, and the category corresponding to the position with the maximum element value in the probability vector is the category predicted by the model to which the sample to be classified belongs. Exemplarily, the 100,000 positions in the probability vector correspond to the IDs of 100,000 people, and the ID corresponding to the position with the maximum element value in the first probability vector is used as the predicted ID of the sample to be classified predicted by the model.
[0105] In a specific embodiment of the present invention, taking the classification deep face recognition model as an example, the neural network model can be divided into a backbone network and a head network. For face recognition tasks, the head network is only used in the training phase. When the model training is completed, the head network is discarded. Only the backbone network is required for deployment and application. For example, taking face recognition in a company park as an example, before the system is activated, a face image library is first constructed, and preprocessing operations such as face alignment are performed. Then, the backbone network is used to extract the feature vectors of the face images to obtain a face feature library (each feature corresponds to an ID). When the system is activated, the face detection algorithm is used to locate the face area to be identified in the image captured by the camera. After the same preprocessing operations, the face image to be identified is sent to the backbone network to extract the feature vector. The pairwise similarity between the feature vector and the feature vectors in the face feature library is then calculated. The feature vector with the largest similarity is found in the face feature library as the target feature vector. If the similarity is greater than a manually set threshold, the match is successful, and the identity of the face to be identified is considered to be the ID corresponding to the target feature vector. Otherwise, the match fails, and the face to be identified is considered not to be a registered person in the park.
[0106] Example 4
[0107] Figure 4 A schematic diagram of the structure of a neural network model training device provided in the fourth embodiment of the present invention is shown in FIG. Figure 4 As shown, the device includes:
[0108] A training sample acquisition module 401 is used to acquire a batch of first training samples and a batch of second training samples for training a neural network model;
[0109] A probability vector acquisition module 402 is configured to input the first training sample into a neural network model to be trained for processing, and obtain a probability vector for predicting that the first training sample belongs to each category;
[0110] A feature matrix acquisition module 403 is configured to input the second training sample into the neural network model to be trained for processing, thereby obtaining a feature matrix composed of feature vectors of the second training sample, wherein the feature vectors of the second training sample are used to characterize properties of the second training sample;
[0111] A classification loss calculation module 404 is configured to calculate the classification loss of a batch of the first training samples based on the probability vector;
[0112] A regularization loss calculation module 405 is used to calculate the regularization loss of a batch of second training samples based on the low rank constraint of the feature matrix;
[0113] The parameter updating module 406 is used to update the parameters of the neural network model based on the classification loss and the regularization loss.
[0114] In some embodiments of the present invention, the training sample acquisition module 401 includes:
[0115] A first acquisition unit is used to randomly select a plurality of training samples from the data set as a batch of first training samples;
[0116] The second acquisition unit is used to randomly select k categories from the data set, and randomly select m training samples from each category as a batch of second training samples.
[0117] In some embodiments of the present invention, a batch of first training samples and a batch of second training samples are the same batch of training samples, and the training sample acquisition module 401 includes:
[0118] The third acquisition unit is used to randomly select k categories from the data set, and randomly select m training samples for each category as a batch of first training samples and a batch of second training samples.
[0119] In some embodiments of the present invention, the neural network model includes a backbone network and a head network, and the probability vector acquisition module 402 includes:
[0120] a feature vector acquisition unit, configured to input the first training sample into the backbone network for processing to obtain a feature vector of the first training sample;
[0121] A probability vector acquisition unit is used to input the feature vector of the first training sample into the head network for processing to obtain a probability vector for predicting that the first training sample belongs to each category.
[0122] In some embodiments of the present invention, the classification loss calculation module 404 includes:
[0123] a cross entropy loss calculation unit, configured to calculate the cross entropy loss of the first training sample based on the probability vector;
[0124] The classification loss calculation unit is used to calculate the sum of the cross entropy losses of each of the first training samples to obtain the classification loss.
[0125] In some embodiments of the present invention, the regularization loss calculation module 405 includes:
[0126] a nuclear norm calculation unit, configured to calculate the nuclear norm of the feature matrix;
[0127] a difference calculation unit, configured to calculate a difference between the nuclear norm and a rank of the feature matrix, where the rank of the feature matrix is the number of categories in a batch of the second training samples;
[0128] A regularization loss calculation unit is used to determine a regularization loss of a batch of second training samples based on the difference.
[0129] In some embodiments of the present invention, the parameter updating module 406 includes:
[0130] A product calculation unit, configured to calculate the product of the regularization loss and a hyperparameter;
[0131] a total loss calculation unit, configured to calculate the sum of the product and the classification loss to obtain a total loss;
[0132] a parameter updating unit, configured to update the parameters of the neural network model when the total loss is greater than a loss threshold, and return to the step of obtaining a batch of first training samples and a batch of second training samples for training the neural network model;
[0133] A training completion determination unit is used to determine that the training of the neural network model is completed when the total loss is less than or equal to a loss threshold.
[0134] The above-mentioned neural network model training device can execute the method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0135] Example 5
[0136] Figure 5 The present invention provides a structural diagram of a classification prediction device. Figure 5 As shown, the device includes:
[0137] The to-be-classified sample acquisition module 501 is used to acquire the to-be-classified samples.
[0138] The category determination module 502 is used to input the sample to be classified into the trained neural network model for processing to obtain the category to which the sample to be classified belongs.
[0139] The above-mentioned classification prediction device can execute the classification prediction method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0140] Example 6
[0141] A sixth embodiment of the present invention provides a computer device, Figure 6 A schematic diagram of the structure of a computer device provided in Example 6 of the present invention is shown in FIG. Figure 6 As shown, the computer device includes a processor 601, a memory 602, a communication module 603, an input device 604 and an output device 605; the number of processors 601 in the computer device can be one or more. Figure 6 In the figure, a processor 601 is used as an example; the processor 601, memory 602, communication module 603, input device 604 and output device 605 in the computer device can be connected by a bus or other means. Figure 6 The processor 601, memory 602, communication module 603, input device 604 and output device 605 can be integrated on a control motherboard of a computer device.
[0142] Memory 602, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as the modules corresponding to the neural network model training method or classification prediction method in the embodiments of the present invention. Processor 601 executes the software programs, instructions, and modules stored in memory 602 to execute various functional applications and data processing of the computer device, thereby implementing the neural network model training method or classification prediction method provided in the above embodiments.
[0143] The memory 602 may primarily include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created based on the use of the computer device, etc. Furthermore, the memory 602 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state memory device. In some instances, the memory 602 may further include memory remotely located relative to the processor 601, and these remote memories may be connected to the computer device via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0144] The communication module 603 is used to establish a connection with an external device (such as a smart terminal) and implement data exchange with the external device. The input device 604 can be used to receive input digital or character information and generate key signal input related to user settings and function control of the computer device.
[0145] This embodiment provides a computer device that can execute the neural network model training method or classification prediction method provided by any of the above embodiments of the present invention, and has specific corresponding functions and beneficial effects.
[0146] Example 7
[0147] Embodiment 7 of the present invention provides a storage medium containing computer-executable instructions, on which a computer program is stored. When the program is executed by a processor, the neural network model training method or classification prediction method provided in any of the above embodiments of the present invention is implemented.
[0148] Neural network model training methods include:
[0149] Obtaining a batch of first training samples and a batch of second training samples for training a neural network model;
[0150] Inputting the first training sample into a neural network model to be trained for processing to obtain a probability vector for predicting that the first training sample belongs to each category;
[0151] Inputting the second training sample into the neural network model to be trained for processing to obtain a feature matrix composed of feature vectors of the second training sample, where the feature vectors of the second training sample are used to characterize properties of the second training sample;
[0152] Calculate the classification loss of a batch of the first training samples based on the probability vector;
[0153] Calculating a regularization loss of a batch of second training samples based on the low rank constraint of the feature matrix;
[0154] Parameters of the neural network model are updated based on the classification loss and the regularization loss.
[0155] The classification prediction method adopts a neural network model trained by the neural network model training method provided in any of the above embodiments of the present invention, including:
[0156] Obtain samples to be classified;
[0157] The samples to be classified are input into the trained neural network model for processing to obtain the category to which the samples to be classified belong.
[0158] Of course, the storage medium containing computer-executable instructions provided by an embodiment of the present invention is not limited to the method operations described above, and can also execute related operations in the neural network model training method or classification prediction method provided by an embodiment of the present invention.
[0159] It should be noted that, for the embodiments of the apparatus, device and storage medium, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0160] Through the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented with the help of software and necessary general-purpose hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for enabling a computer device (which can be a robot, a personal computer, a server, or a network device, etc.) to execute the neural network model training method or classification prediction method described in any embodiment of the present invention.
[0161] It is worth noting that the various modules and units included in the above-mentioned device are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0162] It should be understood that various parts of the present invention can be implemented using hardware, software, firmware, or a combination thereof. In the above-described embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution device. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used to implement the hardware: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application-specific integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0163] Throughout this specification, reference to terms such as "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that a specific feature, structure, material, or characteristic described in conjunction with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
[0164] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the concept of the present invention. The scope of the present invention is determined by the scope of the appended claims.
Claims
1. A face recognition neural network model training method, characterized in that: include: Obtaining a batch of first training samples and a batch of second training samples for training a face recognition neural network model, wherein the first training samples and the second training samples are both face images; Inputting the first training sample into a face recognition neural network model to be trained for processing to obtain a probability vector for predicting that the first training sample belongs to each category; Inputting the second training sample into a face recognition neural network model to be trained for processing to obtain a feature matrix composed of feature vectors of the second training sample, where the feature vectors of the second training sample are used to characterize attributes of the second training sample; Calculate the classification loss of a batch of the first training samples based on the probability vector; Calculating a regularization loss of a batch of second training samples based on the low rank constraint of the feature matrix; Updating parameters of the face recognition neural network model based on the classification loss and the regularization loss; Calculating a regularization loss of a batch of the second training samples based on the low rank constraint of the feature matrix includes: Calculating the nuclear norm of the feature matrix; Calculating a difference between the nuclear norm and a rank of the feature matrix, where the rank of the feature matrix is the number of categories in a batch of the second training samples; A regularization loss for a batch of the second training samples is determined based on the difference.
2. The face recognition neural network model training method according to claim 1, characterized in that: Obtaining a batch of first training samples and a batch of second training samples for training a face recognition neural network model, including: Randomly select multiple training samples from the data set as a batch of first training samples; K categories are randomly selected from the dataset, and m training samples are randomly selected from each category as a batch of second training samples.
3. The face recognition neural network model training method according to claim 1, characterized in that: The first batch of training samples and the second batch of training samples are the same batch of training samples. Obtaining the first batch of training samples and the second batch of training samples for training the face recognition neural network model includes: K categories are randomly selected from the data set, and m training samples are randomly selected from each category as a batch of first training samples and a batch of second training samples.
4. The face recognition neural network model training method according to any one of claims 1 to 3, characterized in that: The face recognition neural network model includes a backbone network and a head network. The first training sample is input into the face recognition neural network model to be trained for processing, and a probability vector for predicting that the first training sample belongs to each category is obtained, including: Inputting the first training sample into the backbone network for processing to obtain a feature vector of the first training sample; The feature vector of the first training sample is input into the head network for processing to obtain a probability vector for predicting that the first training sample belongs to each category.
5. The face recognition neural network model training method according to any one of claims 1 to 3, characterized in that: Calculating the classification loss of a batch of the first training samples based on the probability vector includes: Calculating a cross entropy loss of the first training sample based on the probability vector; The sum of the cross entropy losses of the first training samples is calculated to obtain the classification loss.
6. The face recognition neural network model training method according to any one of claims 1 to 3, characterized in that: Updating parameters of the face recognition neural network model based on the classification loss and the regularization loss includes: Calculate the product of the regularization loss and the hyperparameter; Calculate the sum of the product and the classification loss to obtain a total loss; When the total loss is greater than the loss threshold, updating the parameters of the face recognition neural network model, and returning to the step of obtaining a batch of first training samples and a batch of second training samples for training the face recognition neural network model; When the total loss is less than or equal to a loss threshold, it is determined that the training of the face recognition neural network model is completed.
7. A face recognition neural network model training device, characterized in that: include: A training sample acquisition module is used to acquire a batch of first training samples and a batch of second training samples for training a face recognition neural network model, wherein the first training samples and the second training samples are both face images; a probability vector acquisition module, configured to input the first training sample into a face recognition neural network model to be trained for processing, and obtain a probability vector for predicting that the first training sample belongs to each category; a feature matrix acquisition module, configured to input the second training sample into a face recognition neural network model to be trained for processing, and obtain a feature matrix composed of feature vectors of the second training sample, wherein the feature vectors of the second training sample are used to characterize attributes of the second training sample; a classification loss calculation module, configured to calculate the classification loss of a batch of the first training samples based on the probability vector; A regularization loss calculation module, configured to calculate the regularization loss of a batch of second training samples based on the low-rank constraint of the feature matrix; A parameter updating module is used to update the parameters of the face recognition neural network model based on the classification loss and the regularization loss.
8. A computer device, characterized in that: include: one or more processors; a storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the face recognition neural network model training method as described in any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the face recognition neural network model training method as described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Hash image retrieval method based on deep learning and low-rank matrix optimization
CN110188227A
Transfer learning method and device in machine learning, equipment and readable medium
CN110647920A