Training method, recognition method, device, equipment and medium for face recognition model
By adding a fully connected layer after the encoding network of the face recognition model, and using face image training from different angles, the problem of lack of alignment in feature extraction from angled face images is solved, and the efficiency and accuracy of face recognition are improved.
Patent Information
- Application Number
- CN202111384881.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-22
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-11-22
AI Technical Summary
When existing face recognition models process angled face images, the extracted facial features do not have alignment characteristics, resulting in low face recognition efficiency.
By adding a first fully connected layer after the coding network of the recognition model to be trained, and using face images from different angles to iteratively train the model, the model loss value is within a certain range, forming a coding network and a second fully connected layer. and the first fully connected layer to extract facial features with alignment and facial identity information.
The efficiency of face recognition is improved, so that facial features with alignment and facial identity information can be obtained without face alignment, and the accuracy of recognition is improved.
Smart Images

Figure CN114187626B
Abstract
Description
Technical Field
[0001] The present application belongs to the field of image recognition technology, and in particular relates to a training method, recognition method, device, equipment and medium for a face recognition model. Background Art
[0002] Existing face recognition models are divided into two steps. First, face correction and alignment are performed, and then the face is sent to the recognition network for recognition. In general, the alignment and recognition are two independent tasks. The quality of alignment has a great impact on recognition, but the recognition result cannot directly give feedback to the alignment task. When recognizing angled face images (i.e., images with angle deviations relative to the frontal face image), if the angled face is directly used for feature extraction and identity (ID) recognition, the extracted face features do not have alignment characteristics, resulting in low face recognition efficiency. Summary of the invention
[0003] The embodiments of the present application provide a training method, recognition method, device, equipment and medium for a face recognition model, which can solve the technical problem of low face recognition efficiency.
[0004] In a first aspect, an embodiment of the present application provides a method for training a face recognition model, comprising:
[0005] Extracting a preset number of face images from a plurality of face images at different angles;
[0006] Inputting the preset number of face images into the recognition model to be trained for training, obtaining a first aligned face image of all the extracted face images from the decoding network of the recognition model to be trained, and obtaining first face features of all the extracted face images from the first fully connected layer of the recognition model to be trained; the recognition model to be trained includes the first fully connected layer, and a sequentially connected encoding network, a second fully connected layer and the decoding network, and the input end of the first fully connected layer is connected to the output end of the second fully connected layer;
[0007] Obtaining a model loss value of the recognition model to be trained according to all extracted face images, first aligned face images of all extracted face images, and first face features of all extracted face images;
[0008] Determine whether the model loss value meets the preset training end condition;
[0009] When the model loss value meets the preset training end condition, the encoding network, the second fully connected layer and the first fully connected layer connected in sequence are used as a face recognition model.
[0010] In a second aspect, an embodiment of the present application provides a face recognition method, including:
[0011] Obtain a face image to be recognized;
[0012] Inputting the face image to be identified into a face recognition model to obtain a third face feature of the face image to be identified; the face recognition model is obtained according to the above training method;
[0013] The third facial feature is compared with the facial features in the facial image database to obtain a recognition result of the facial image to be recognized.
[0014] In a third aspect, an embodiment of the present application provides a training device for a face recognition model, comprising:
[0015] An extraction module, used for extracting a preset number of face images from a plurality of face images at different angles;
[0016] A training module, used for inputting the preset number of face images into a recognition model to be trained for training, obtaining a first aligned face image of all face images extracted from a decoding network of the recognition model to be trained, and obtaining first face features of all face images extracted from a first fully connected layer of the recognition model to be trained; the recognition model to be trained includes the first fully connected layer, and a sequentially connected encoding network, a second fully connected layer and the decoding network, wherein an input end of the first fully connected layer is connected to an output end of the second fully connected layer;
[0017] An acquisition module, used for obtaining a model loss value of the recognition model to be trained according to all extracted face images, first aligned face images of all extracted face images, and first face features of all extracted face images;
[0018] A judgment module, used to judge whether the model loss value meets the preset training end condition, and trigger the determination module when the model loss value meets the preset training end condition, and trigger the adjustment module when the model loss value does not meet the preset training end condition;
[0019] A determination module is used to use the sequentially connected encoding network, the second fully connected layer and the first fully connected layer as a face recognition model according to the triggering of the judgment module.
[0020] In a fourth aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned training method when executing the computer program, or implements the above-mentioned face recognition method when executing the computer program.
[0021] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned training method is implemented, or when the computer program is executed by a processor, the above-mentioned face recognition method is implemented.
[0022] In a sixth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on a terminal device, the terminal device executes the steps of the training method described in the first aspect, or the terminal device executes the steps of the face recognition method described in the second aspect.
[0023] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0024] In an embodiment of the present application, a first fully-connected layer is added after the encoding network and the second fully-connected layer of the recognition model to be trained, so that when the face image is input into the recognition model to be trained for training, the face features for characterizing the identity information of the face image can be obtained from the first fully-connected layer, and the face features output by the first fully-connected layer constrain the encoding network and the second fully-connected layer, so that the face recognition model composed of the encoding network, the second fully-connected layer and the first fully-connected layer can extract the face identity information when performing recognition processing on the face image to be recognized. At the same time, because the encoding network and the second fully-connected layer themselves have the ability to implicitly learn face alignment, it is ensured that when the face image to be recognized is recognized, the face recognition model can obtain face features with alignment and face identity information without performing face alignment, thereby achieving the effect of improving face recognition efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0026] Figure 1 is a flow chart of a method for training a face recognition model provided in Example 1 of the present application;
[0027] Figure 2 is a schematic diagram of the structure of the recognition model to be trained provided in Example 1 of the present application;
[0028] Figure 3 This is a flowchart of step S13 of the face recognition model training method provided in Example 2 of the present application;
[0029] Figure 4This is a flow chart of obtaining a training loss value corresponding to a face image provided in Example 2 of the present application;
[0030] Figure 5 is a flow chart of the face recognition method provided in Example 3 of the present application;
[0031] Figure 6 It is a structural schematic diagram of a training device for a face recognition model provided in Embodiment 4 of the present application;
[0032] Figure 7 It is a structural diagram of the terminal device provided in Example 5 of the present application. DETAILED DESCRIPTION
[0033] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0034] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0035] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0036] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0037] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0038] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0039] The training method of the face recognition model provided in the embodiment of the present application can be applied to a terminal device, which can be based on the recognition model to be trained, and the recognition model to be trained can be a deep convolutional generative adversarial network (DCGAN, Deep Convolutional Generative Adversarial Networks) model. Specifically, by adding a first fully connected layer after the encoding network and the second fully connected layer of the DCGAN model, and then iteratively training the DCGAN model using face images from different angles, the model loss value of the DCGAN model is within a certain range (such as the model loss value is less than 0.4), and the encoding network, the second fully connected layer and the first fully connected layer in the DCGAN model at this time are used as the face recognition model.
[0040] It should be noted that since the first fully connected layer can constrain the encoding network and the second fully connected layer, the face recognition model can extract face identity information (such as eyes, nose, etc.) when processing the face image to be identified. At the same time, since the encoding network and the second fully connected layer themselves have the ability to implicitly learn face alignment, it ensures that when the terminal device identifies the face image to be identified, the face recognition model can obtain face features with alignment and face identity information without performing face alignment, thereby greatly improving the efficiency of face recognition.
[0041] In the embodiments of the present application, the terminal device may be a mobile phone, a tablet computer, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), and the like. For example, the terminal device may be a station (ST, STAION) in a WLAN, a cellular phone, a cordless phone, a Session Initiation Protocol (SIP) phone, a Wireless Local Loop (WLL) station, a Personal Digital Assistant (PDA) device, a handheld device with wireless communication function, a computing device or other processing devices connected to a wireless modem, a computer, a laptop computer, a handheld communication device, a handheld computing device, a satellite wireless device, etc. The embodiments of the present application do not impose any restrictions on the specific types of the terminal devices.
[0042] The following is an exemplary description of the training method of the face recognition model provided by the present application in conjunction with specific embodiments.
[0043] Embodiment 1
[0044] like Figure 1 As shown, an embodiment of the present application provides a training method for a face recognition model, and the training method comprises the following steps:
[0045] Step 11, extracting a preset number of face images from a plurality of face images at different angles.
[0046] In some embodiments of the present application, the facial images at different angles may include frontal facial images and facial images with angle deviations relative to the frontal facial images; the preset number is less than the total number of facial images at different angles. For example, if the facial images at different angles include 1,000 facial images, the preset number may be 100.
[0047] Step 12: input the preset number of face images into the recognition model to be trained for training, obtain the first aligned face image of all the extracted face images from the decoding network of the recognition model to be trained, and obtain the first face features of all the extracted face images from the first fully connected layer of the recognition model to be trained.
[0048] In some embodiments of the present application, Figure 2As shown, the above-mentioned recognition model 200 to be trained includes an encoding network 201, a second fully connected layer 202, a decoding network 203 and a first fully connected layer 204, the encoding network (Encoding), the second fully connected layer 202 and the decoding network (Decoding) are connected in sequence, and the input end of the first fully connected layer 204 is connected to the output end of the second fully connected layer 202. It should be noted that the specific structures of the above-mentioned second fully connected layer 202 and the first fully connected layer 204 can both be commonly used fully connected layer (fc, fully connected layers) structures. And in some embodiments of the present application, the above-mentioned recognition model to be trained can be a DCGAN model.
[0049] Step 13, obtaining the model loss value of the recognition model to be trained according to all the extracted face images, the first aligned face images of all the extracted face images, and the first face features of all the extracted face images.
[0050] Among them, in some embodiments of the present application, the encoding network is mainly used to perform convolution processing, pooling processing, activation function (relu) activation processing and normalization processing on the face image input to the recognition model to be trained in sequence, to obtain the first intermediate layer face features of the face image, and output the first intermediate layer face features to the second fully connected layer; the second fully connected layer is mainly used to calculate the product of the matrix vector and the first intermediate layer face features, to obtain the second intermediate layer face features, and output the second intermediate layer face features to the first fully connected layer and the decoding network respectively; the first fully connected layer is mainly used to calculate the product of the matrix vector and the second intermediate layer face features, to obtain the face features of the face image (that is, the above-mentioned first face features); the decoding network is mainly used to perform deconvolution processing, upsampling processing, relu activation processing and normalization processing on the second intermediate layer face features in sequence, to obtain an aligned face image of the face image (that is, the above-mentioned first aligned face image). Therefore, in some embodiments of the present application, after a facial image is input into the recognition model to be trained, the facial features of the facial image (i.e., the above-mentioned first facial features) can be obtained from the first fully connected layer, and the aligned facial image of the facial image (i.e., the above-mentioned first aligned facial image) can be obtained from the decoding network, and the model loss value of the recognition model to be trained can be calculated based on the obtained facial features and the aligned facial image, so that the model loss value can be used to subsequently adjust the network parameters of the recognition model to be trained, so that the final facial recognition model can obtain facial features with alignment and facial identity information when performing recognition processing on the facial image to be recognized, thereby improving the efficiency of facial recognition.
[0051] Step 14, determine whether the model loss value meets the preset training end condition, and when the model loss value meets the preset training end condition, execute step 15, when the model loss value does not meet the preset training end condition, execute step 16.
[0052] Step 15: Use the encoding network, the second fully connected layer and the first fully connected layer connected in sequence as a face recognition model.
[0053] Step 16, adjust the network parameters of the recognition model to be trained, and return to step 11.
[0054] In some embodiments of the present application, the above step 14 can determine whether the model loss value meets the preset training end condition by judging whether the model loss value is within the preset loss range (such as judging whether the model loss value is less than 0.4). Specifically, when the model loss value is within the preset loss range, it is determined that the model loss value meets the preset training end condition; when the model loss value is not within the preset loss range, it is determined that the model loss value does not meet the preset training end condition.
[0055] The above network parameters may be parameters such as convolution kernel weight, convolution kernel bias, normalization layer coefficient, full connection layer weight, full connection layer bias, etc. in the recognition model to be trained. When the model loss value is not within the preset loss range, the Stochastic Gradient Descent (SGD) strategy may be used to adjust the network parameters of the recognition model to be trained.
[0056] It should be noted that, in order to make the recognition model to be trained meet the requirements (i.e., the model loss value of the recognition model to be trained is within a certain range and meets the preset training end condition), the face images extracted from the multiple face images at different angles are different each time. That is, when the network parameters of the recognition model to be trained are adjusted and the preset number of face images extracted when returning to step 11 are different from the preset number of face images extracted when step 11 is executed any time before.
[0057] For example, assuming that there are 1000 face images at multiple different angles, the preset number is 100, and the recognition model to be trained is a DCGAN model. Then, when 100 face images are extracted for the first time and input into the DCGAN model to train the DCGAN model, if it is found that the model loss value does not meet the preset training end condition, the network parameters of the DCGAN model are adjusted, and then 100 face images are extracted from the remaining 900 face images of the 1000 face images to continue training the DCGAN model, and it is determined whether the model loss value of the DCGAN model at this time meets the preset training end condition. When the preset training end condition is not met, the network parameters of the DCGAN model are continued to be adjusted, and 100 face images are extracted from the remaining 800 face images of the 1000 face images to continue training the DCGAN model. The training is iterated in this way until the model loss value of the DCGAN model meets the preset training end condition.
[0058] It is worth mentioning that in some embodiments of the present application, by adding a first fully connected layer after the encoding network and the second fully connected layer of the DCGAN model, when the face image is input into the DCGAN model for training, the face features used to characterize the identity information of the face image can be obtained from the first fully connected layer, and the face features output by the first fully connected layer constrain the encoding network and the second fully connected layer, so that the face recognition model composed of the encoding network, the second fully connected layer and the first fully connected layer can extract the face identity information when performing recognition processing on the face image to be recognized. At the same time, because the encoding network and the second fully connected layer themselves have the ability to implicitly learn face alignment, it is ensured that when the face image to be recognized is recognized, the face recognition model can obtain face features with alignment and face identity information without performing face alignment, thereby achieving the effect of improving face recognition efficiency.
[0059] Embodiment 2
[0060] This embodiment is a further explanation of the first embodiment. For details of the same or similar parts as the first embodiment, please refer to the relevant description of the first embodiment, which will not be repeated here.
[0061] like Figure 3 As shown, in some embodiments of the present application, the above step 13, based on all the extracted face images, the first aligned face images of all the extracted face images, and the first face features of all the extracted face images, a specific implementation method of obtaining the model loss value of the recognition model to be trained includes the following steps:
[0062] Step 31, for each extracted face image, obtain a training loss value corresponding to the face image according to the face image, the first aligned face image of the face image and the first face feature of the face image.
[0063] Among them, in some embodiments of the present application, after the face image is input into the encoding network of the recognition model to be trained, the first face feature of the face image can be obtained from the first fully connected layer of the recognition model to be trained (the first face feature can represent the identity information of the face image), and at the same time, the face image can generate an aligned face image of the face image after passing through the second fully connected layer and the decoding network, that is, the above-mentioned first aligned face image.
[0064] It is understandable that, in order to facilitate data processing, the facial image may be normalized before being input into the encoding network of the recognition model to be trained.
[0065] Step 32, calculating the average of the training loss values corresponding to all the extracted face images.
[0066] Step 33: Use the average value as the model loss value of the recognition model to be trained.
[0067] Among them, in some embodiments of the present application, such as Figure 4 As shown, in the above step 31, the specific implementation method of obtaining the training loss value corresponding to the face image according to the face image, the first aligned face image of the face image and the first face feature of the face image can be:
[0068] Step 41, obtaining a real second aligned face image of the face image.
[0069] Among them, in some embodiments of the present application, a key point algorithm (landmark) can be used to obtain a true aligned face image of the face image, that is, the above-mentioned second aligned face image. For example, through 5 or 68 key points of the face image, a true second aligned face image of the face image is obtained. Specifically, a plurality of key points (such as 5 or 68 key points) of the face image can be obtained, and then a face affine transformation matrix can be obtained based on the image features of the plurality of key points; and then the face affine transformation matrix can be used to perform an affine transformation on the face image to obtain a true aligned face image of the face image.
[0070] Step 42: Obtain a training loss value corresponding to the facial image according to the first aligned facial image of the facial image, the first facial feature of the facial image, and the second aligned facial image.
[0071] Among them, in some embodiments of the present application, the second aligned face image obtained by using the first facial features output by the first fully connected layer and the landmark is used to constrain the encoding network and the second fully connected layer, which can increase the implicit learning of the alignment ability of the encoding network and the second fully connected layer, ensure that the training can be carried out stably, and avoid the generation and discrimination network model of the recognition model to be trained from falling into the local minimum.
[0072] In some embodiments of the present application, the specific implementation of step 42 includes the following steps:
[0073] The second aligned face image is input into the encoding network, and the second face feature of the second aligned face image is obtained from the first fully connected layer; then, the training loss value corresponding to the face image is obtained according to the first face feature of the face image, the second face feature, the first aligned face image of the face image, and the second aligned face image.
[0074] In some embodiments of the present application, the processing process of the second aligned face image by the recognition model to be trained is as follows: after the second aligned face image is input into the recognition model to be trained (i.e., input into the encoding network of the recognition model to be trained), the encoding network performs convolution processing, pooling processing, relu activation processing and normalization processing on the second aligned face image in sequence, outputs the first intermediate face feature, and outputs the first intermediate face feature to the second fully connected layer. After receiving the first intermediate face feature, the second fully connected layer calculates the product of the matrix vector and the first intermediate face feature to obtain the second intermediate layer face feature, and outputs the second intermediate layer face feature to the first fully connected layer. After receiving the second intermediate layer face feature, the first fully connected layer calculates the product of the matrix vector and the second intermediate layer face feature to obtain the face feature of the second aligned face image (i.e., the above-mentioned second face feature). Therefore, by inputting the second aligned face image into the encoding network of the recognition model to be trained, the second facial features of the second aligned face image can be obtained from the first fully connected layer of the recognition model to be trained, and the second facial features can represent the identity information of the second aligned face image.
[0075] In some embodiments of the present application, a specific implementation method of obtaining a training loss value corresponding to the facial image according to the first facial feature of the facial image, the second facial feature, the first aligned facial image of the facial image, and the second aligned facial image may include the following steps:
[0076] The first step is to obtain a face identity information loss value of the face image based on the first face feature and the second face feature of the face image.
[0077] Wherein, in some embodiments of the present application, the DCGAN model further includes a prototype, the input end of the prototype is connected to the output end of the first fully connected layer. The specific structure of the Prototypes is consistent with the fully connected layer, and is also a matrix vector. Prototypes is mainly used to perform a matrix product operation on the first facial feature output by the first fully connected layer to obtain the confidence of the facial image corresponding to the first facial feature. Accordingly, the specific implementation method of the first step, according to the first facial feature and the second facial feature of the facial image, to obtain the facial identity information loss value of the facial image is:
[0078] Step 1: Input the first facial feature and the second facial feature of the facial image into a cosine loss function to obtain a cosine loss value of the facial image.
[0079] Among them, the above cosine loss function can be specifically In this formula, N represents the batch size of images. represents the first facial feature, represents the second facial feature, express and The inner product, L cosine Represents the cosine loss value. It is worth mentioning that the cosine loss function can constrain the facial features of the facial image so that the facial image is consistent with the second facial features. It should be noted that the above cosine loss function is a commonly used cosine loss function, so its principle will not be elaborated here.
[0080] It is worth mentioning that in the iterative training process of the DCGAN model, using the above cosine loss value to adjust the network parameters of the DCGAN model can make the final face recognition model output facial features with an alignment effect when recognizing face images.
[0081] Step 2: Input the data output by the prototype into a face recognition loss function to obtain a face recognition loss value of the face image; the data output by the prototype is the confidence level of the face image.
[0082] Among them, the above face recognition loss function can be a flexible maximum activation function loss function with increased interval (Amsoftmax loss), and the specific formula of this function is: In this formula, L id represents the above face recognition loss value, cos(θ yi ) represents the data output by the prototype, that is, the confidence of the face image corresponding to the first face feature, cos(θ yi -m) is cos(θyi ) is obtained through mathematical transformation. It should be noted that the above-mentioned Amsoftmaxloss is a commonly used loss function, so its principle will not be elaborated in detail here.
[0083] It is worth mentioning that during the iterative training process of the DCGAN model, using the above-mentioned face recognition loss value to adjust the network parameters of the DCGAN model can enable the final face recognition model to output facial features with facial identity information when recognizing face images, thereby ensuring the accuracy of recognition.
[0084] Step 3: The sum of the cosine loss value and the face recognition loss value is used as the face identity information loss value of the face image. That is, the cosine loss value and the face recognition loss value are cumulatively added and the sum is used as the face identity information loss value of the face image.
[0085] In the second step, based on the first aligned face image and the second aligned face image, a face appearance information loss value of the face image and a generation discrimination loss value of the face image are obtained.
[0086] In an embodiment of the present application, the facial appearance information loss value of the facial image can be obtained by inputting the first aligned facial image and the second aligned facial image into a facial appearance information loss function.
[0087] Among them, the above face appearance information loss function can be In this formula represents the pixel value at the coordinate (x, y) position in the first aligned face image, represents the pixel value at the coordinate (x, y) position in the second aligned face image, W represents the image width, H represents the image height, and L p It should be noted that the above-mentioned face appearance information loss function is a commonly used face appearance information loss function, so its principle will not be elaborated here.
[0088] In some embodiments of the present application, the generation discrimination loss value of the face image can be obtained by inputting the first aligned face image and the second aligned face image into the discrimination module of the DCGAN model.
[0089] Among them, the above generated discriminant loss value can be obtained by the formula Calculated, in this formula, D represents the discriminant module of the DCGAN model, G represents the generation module of the DCGAN model (that is, the encoding network, the second fully connected layer and the decoding network connected in sequence above), P data represents the second aligned face image, P Zrepresents the first aligned face image, E represents the expectation, It should be noted that the calculation formula for generating the above-mentioned discrimination loss value is a commonly used calculation formula at present, so its principle will not be described in detail here.
[0090] It is understandable that, for the convenience of data processing, the first aligned face image and the second aligned face image may be normalized before being input into the discriminant module of the DCGAN model. The above-mentioned discriminant module can determine whether the first aligned face image is a real aligned face image, and the output is 0 or 1, and the discriminant loss is obtained, thereby supervising the encoding branch of the generation module to implicitly extract the alignment information. Specifically, when the discriminant module determines that the first aligned face image is a real aligned face image, it is considered that the generated first aligned face image is qualified, and the generated discriminant loss value is relatively small.
[0091] In the third step, the sum of the face identity information loss value, the face appearance information loss value and the generated discrimination loss value is used as the training loss value corresponding to the face image.
[0092] That is, by accumulating the face identity information loss value, the face appearance information loss value and the generation discrimination loss value, the obtained sum is used as the training loss value corresponding to the face image.
[0093] It is worth mentioning that during the training process, for each face image, the training loss value of the face image is determined by the sum of the face identity information loss value, the face appearance information loss value and the generated discrimination loss value of the face image, and then the model loss value of the recognition model to be trained is determined, and the network parameters of the recognition model to be trained are adjusted according to the model loss value. When the model loss value of the recognition model to be trained meets the preset training end condition, the encoding network, the second fully connected layer and the first fully connected layer connected in sequence are used as the face recognition model, so that when the face recognition model recognizes the face image to be recognized, it can obtain face features with alignment and face identity information without face alignment (that is, the face feature extraction is coupled with the face alignment, so that the feedback of the alignment effect can directly act on the feature extraction, ensuring the recognition accuracy), so as to improve the efficiency of face recognition.
[0094] Embodiment 3
[0095] Corresponding to the training method of the face recognition model described in the above embodiment, Figure 5 As shown, an embodiment of the present application provides a face recognition method, which includes the following steps:
[0096] Step 51, obtaining a face image to be recognized.
[0097] The above-mentioned face image to be recognized may be an angled face image (ie, an image having an angle deviation relative to a frontal face image) or a frontal face image.
[0098] Step 52: input the face image to be identified into a face recognition model to obtain a third face feature of the face image to be identified.
[0099] Among them, the above-mentioned face recognition model is obtained according to the above-mentioned training method. The face recognition model can obtain face features with alignment and face identity information without face alignment, that is, the above-mentioned third face feature has alignment and face identity information.
[0100] It should be noted that all embodiments regarding the face recognition model in the above embodiments use the face recognition model in this embodiment, so the face recognition model will not be described in detail here.
[0101] It is understandable that, in order to facilitate image processing and recognition, the facial image to be recognized may be normalized before being input into the facial recognition model.
[0102] Step 53: compare the third facial feature with the facial features in the facial image database to obtain a recognition result of the facial image to be recognized.
[0103] Specifically, in some embodiments of the present application, the specific implementation method of the above step 53 can be: calculating the cosine similarity between the third facial feature and each facial feature in the facial image database, and then determining whether the cosine similarity with the largest value among all the cosine similarities obtained is greater than a preset similarity threshold; when the cosine similarity with the largest value among all the cosine similarities is greater than the preset similarity threshold, determining that the facial image to be identified and the facial image corresponding to the facial feature with the largest value are facial images of the same person; otherwise, determining that there is no facial image in the facial image database that is the same person as the facial image to be identified.
[0104] It is worth mentioning that since the face recognition model can obtain facial features with alignment and face identity information without face alignment, recognizing the face image to be recognized by the above-mentioned face recognition method can greatly improve the recognition efficiency while ensuring the recognition accuracy.
[0105] Embodiment 4
[0106] Corresponding to the training method of the face recognition model described in the above embodiment, Figure 6 As shown, an embodiment of the present application provides a training device 600 for a face recognition model, comprising:
[0107] The extraction module 601 is used to extract a preset number of face images from a plurality of face images at different angles.
[0108] The training module 602 is used to input the preset number of facial images into the recognition model to be trained for training, obtain the first aligned facial image of all the extracted facial images from the decoding network of the recognition model to be trained, and obtain the first facial features of all the extracted facial images from the first fully connected layer of the recognition model to be trained.
[0109] The above-mentioned recognition model to be trained includes the first fully connected layer, and the encoding network, the second fully connected layer and the decoding network connected in sequence, and the input end of the first fully connected layer is connected to the output end of the second fully connected layer.
[0110] The acquisition module 603 is used to obtain the model loss value of the recognition model to be trained based on all the extracted face images, the first aligned face images of all the extracted face images, and the first face features of all the extracted face images.
[0111] The judgment module 604 is used to judge whether the model loss value meets the preset training end condition, and when the model loss value meets the preset training end condition, trigger the determination module 605, when the model loss value does not meet the preset training end condition, trigger the adjustment module 606.
[0112] The determination module 605 is used to use the encoding network, the second fully connected layer and the first fully connected layer connected in sequence as a face recognition model according to the triggering of the judgment module 604.
[0113] The adjustment module 606 is used to adjust the network parameters of the recognition model to be trained according to the triggering of the judgment module 604, and trigger the extraction module 601 to extract a preset number of face images from multiple face images at different angles.
[0114] The facial images extracted from the multiple facial images at different angles are different each time.
[0115] The acquisition module 603 includes:
[0116] The first acquisition submodule is used to obtain, for each extracted face image, a training loss value corresponding to the face image according to the face image, the first aligned face image of the face image and the first face feature of the face image.
[0117] The calculation submodule is used to calculate the average of the training loss values corresponding to all the extracted face images.
[0118] A determination submodule is used to use the average value as a model loss value of the recognition model to be trained.
[0119] The first acquisition submodule includes:
[0120] A first acquisition unit, used to acquire a real second aligned face image of the face image;
[0121] The second acquisition unit is used to obtain a training loss value corresponding to the face image according to the first aligned face image of the face image, the first face feature of the face image and the second aligned face image.
[0122] Among them, the above-mentioned second acquisition unit is specifically used to input the second aligned face image into the encoding network, obtain the second face feature of the second aligned face image from the first fully connected layer; and obtain the training loss value corresponding to the face image according to the first face feature of the face image, the second face feature, the first aligned face image of the face image and the second aligned face image.
[0123] Wherein, the second acquisition unit comprises:
[0124] A first acquisition subunit, configured to obtain a face identity information loss value of the face image according to the first face feature and the second face feature of the face image;
[0125] A second acquisition subunit is used to obtain a face appearance information loss value of the face image and a generation discrimination loss value of the face image according to the first aligned face image and the second aligned face image of the face image;
[0126] A determination subunit is used to use the sum of the face identity information loss value, the face appearance information loss value and the generated discrimination loss value as the training loss value corresponding to the face image.
[0127] Among them, the above-mentioned recognition model to be trained also includes a prototype, and the input end of the prototype is connected to the output end of the first fully connected layer; the above-mentioned first acquisition subunit is specifically used to input the first facial feature and the second facial feature of the facial image into the cosine loss function to obtain the cosine loss value of the facial image; input the data output by the prototype into the face recognition loss function to obtain the face recognition loss value of the face image; use the sum of the cosine loss value and the face recognition loss value as the face identity information loss value of the facial image; the data output by the prototype is the confidence of the facial image.
[0128] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0129] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by 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 embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0130] Embodiment 5
[0131] like Figure 7 As shown, an embodiment of the present application provides a terminal device, such as Figure 7 As shown, the terminal device D10 of this embodiment includes: at least one processor D100 ( Figure 7 Only one processor is shown in the figure), a memory D101, and a computer program D102 stored in the memory D101 and executable on the at least one processor D100, wherein the processor D100 implements the steps in any of the above-mentioned method embodiments when executing the computer program D102. Alternatively, the processor D100 implements the functions of each module / unit in the above-mentioned device embodiments when executing the computer program D102.
[0132] In some embodiments, the processor D100 implements the following steps when executing the computer program D102: extracting a preset number of face images from multiple face images at different angles; inputting the preset number of face images into a recognition model to be trained for training, obtaining a first aligned face image of all the extracted face images from a decoding network of the recognition model to be trained, and obtaining a first face feature of all the extracted face images from a first fully connected layer of the recognition model to be trained; the recognition model to be trained includes the first fully connected layer, and a coding network, a second fully connected layer and the decoding network connected in sequence, the input end of the first fully connected layer is connected to the output end of the second fully connected layer; according to all the extracted face images, The invention relates to a method for extracting a face image, a first aligned face image of all extracted face images and a first face feature of all extracted face images to obtain a model loss value of the recognition model to be trained; judging whether the model loss value meets the preset training end condition; when the model loss value meets the preset training end condition, using the encoding network, the second fully connected layer and the first fully connected layer connected in sequence as the face recognition model; when the model loss value does not meet the preset training end condition, adjusting the network parameters of the recognition model to be trained, and returning to the step of extracting a preset number of face images from face images at multiple different angles; wherein the face images extracted from the multiple face images at different angles are different each time.
[0133] Optionally, the processor D100 may further implement the following steps when executing the computer program D102: for each extracted facial image, obtaining a training loss value corresponding to the facial image based on the facial image, the first aligned facial image of the facial image, and the first facial feature of the facial image; calculating the average of the training loss values corresponding to all the extracted facial images; and using the average as the model loss value of the recognition model to be trained.
[0134] Optionally, when the processor D100 executes the computer program D102, the following steps may be further implemented: obtaining a true second aligned face image of the face image; and obtaining a training loss value corresponding to the face image based on the first aligned face image of the face image, the first face feature of the face image and the second aligned face image.
[0135] Optionally, when the processor D100 executes the computer program D102, the following steps may be further implemented: inputting the second aligned face image into the encoding network, obtaining the second face feature of the second aligned face image from the first fully connected layer; and obtaining the training loss value corresponding to the face image based on the first face feature of the face image, the second face feature, the first aligned face image of the face image, and the second aligned face image.
[0136] Optionally, when the processor D100 executes the computer program D102, the following steps may be further implemented: obtaining a face identity information loss value of the face image based on the first face feature and the second face feature of the face image; obtaining a face appearance information loss value of the face image and a generation discrimination loss value of the face image based on the first aligned face image and the second aligned face image of the face image; and using the sum of the face identity information loss value, the face appearance information loss value and the generation discrimination loss value as the training loss value corresponding to the face image.
[0137] Optionally, the above-mentioned recognition model to be trained also includes a prototype, and the input end of the prototype is connected to the output end of the first fully connected layer; when the processor D100 executes the computer program D102, it can also implement the following steps: input the first facial feature and the second facial feature of the facial image into the cosine loss function to obtain the cosine loss value of the facial image; input the data output by the prototype into the face recognition loss function to obtain the face recognition loss value of the facial image; use the sum of the cosine loss value and the face recognition loss value as the face identity information loss value of the facial image; the data output by the prototype is the confidence of the facial image.
[0138] In some embodiments, the processor D100 implements the following steps when executing the computer program D102: obtaining a facial image to be identified; inputting the facial image to be identified into a facial recognition model to obtain a third facial feature of the facial image to be identified; the facial recognition model is obtained according to the above-mentioned training method; comparing the third facial feature with the facial features in the facial image database to obtain a recognition result of the facial image to be identified.
[0139] The terminal device D10 may be a computing device such as a desktop computer, a notebook, a PDA, a server, a server cluster, a cloud server, etc. The terminal device may include, but is not limited to, a processor D100 and a memory D101. Those skilled in the art will appreciate that Figure 7 This is only an example of the terminal device D10 and does not constitute a limitation on the terminal device D10. The terminal device D10 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.
[0140] The processor D100 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0141] In some embodiments, the memory D101 may be an internal storage unit of the terminal device D10, such as a hard disk or memory of the terminal device D10. In other embodiments, the memory D101 may also be an external storage device of the terminal device D10, such as a plug-in hard disk, a smart memory card (SMC, SmartMedia Card), a secure digital (SD, Secure Digital) card, a flash card (Flash Card), etc. equipped on the terminal device D10. Further, the memory D101 may also include both an internal storage unit of the terminal device D10 and an external storage device. The memory D101 is used to store an operating system, an application program, a boot loader (BootLoader), data and other programs, such as the program code of the computer program, etc. The memory D101 may also be used to temporarily store data that has been output or is to be output.
[0142] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0143] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by 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 embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0144] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it can implement the steps in the embodiments of the above-mentioned methods (including the above-mentioned training method and the above-mentioned face recognition method).
[0145] An embodiment of the present application provides a computer program product. When the computer program product runs on a mobile terminal, the mobile terminal implements the steps in the embodiments of the above-mentioned methods (including the above-mentioned training method and the above-mentioned face recognition method) when executing the computer program product.
[0146] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the training device / terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, RandomAccess Memory), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0147] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0148] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0149] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0150] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0151] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A training method for a face recognition model, characterized in that: include: Extracting a preset number of face images from a plurality of face images at different angles; Inputting the preset number of face images into the recognition model to be trained for training, obtaining a first aligned face image of all the extracted face images from the decoding network of the recognition model to be trained, and obtaining first face features of all the extracted face images from the first fully connected layer of the recognition model to be trained; the recognition model to be trained includes the first fully connected layer, and a sequentially connected encoding network, a second fully connected layer and the decoding network, and the input end of the first fully connected layer is connected to the output end of the second fully connected layer; Obtaining a model loss value of the recognition model to be trained according to all extracted face images, first aligned face images of all extracted face images, and first face features of all extracted face images; Determine whether the model loss value meets the preset training end condition; When the model loss value meets the preset training end condition, the encoding network, the second fully connected layer and the first fully connected layer connected in sequence are used as a face recognition model.
2. The training method according to claim 1, characterized in that: The step of obtaining the model loss value of the recognition model to be trained according to all the extracted face images, the first aligned face images of all the extracted face images, and the first face features of all the extracted face images comprises: For each extracted face image, respectively, obtaining a training loss value corresponding to the face image according to the face image, the first aligned face image of the face image, and the first face feature of the face image; Calculate the average of the training loss values corresponding to all the extracted face images; The average value is used as the model loss value of the recognition model to be trained.
3. The training method according to claim 2, characterized in that: The step of obtaining a training loss value corresponding to the face image according to the face image, the first aligned face image of the face image and the first face feature of the face image comprises: Acquire a real second aligned face image of the face image; A training loss value corresponding to the facial image is obtained according to the first aligned facial image of the facial image, the first facial feature of the facial image and the second aligned facial image.
4. The training method according to claim 3, characterized in that: The step of obtaining a training loss value corresponding to the face image according to the first aligned face image of the face image, the first face feature of the face image and the second aligned face image comprises: Inputting the second aligned face image into the encoding network, and obtaining a second face feature of the second aligned face image from the first fully connected layer; A training loss value corresponding to the facial image is obtained according to the first facial feature of the facial image, the second facial feature, the first aligned facial image of the facial image, and the second aligned facial image.
5. The training method according to claim 4, characterized in that: The step of obtaining a training loss value corresponding to the facial image according to the first facial feature of the facial image, the second facial feature, the first aligned facial image of the facial image, and the second aligned facial image comprises: Obtaining a face identity information loss value of the face image according to the first face feature and the second face feature of the face image; Obtaining a facial appearance information loss value of the facial image and a generation discrimination loss value of the facial image according to the first aligned facial image and the second aligned facial image of the facial image; The sum of the face identity information loss value, the face appearance information loss value and the generation discrimination loss value is used as the training loss value corresponding to the face image.
6. The training method according to claim 5, characterized in that: The recognition model to be trained also includes a prototype, and an input end of the prototype is connected to an output end of the first fully connected layer; The step of obtaining the face identity information loss value of the face image according to the first face feature and the second face feature of the face image comprises: Inputting the first facial feature and the second facial feature of the facial image into a cosine loss function to obtain a cosine loss value of the facial image; Inputting the data output by the prototype into a face recognition loss function to obtain a face recognition loss value of the face image; the data output by the prototype is the confidence of the face image; The sum of the cosine loss value and the face recognition loss value is used as the face identity information loss value of the face image.
7. A face recognition method, characterized in that: include: Obtaining a face image to be recognized; Inputting the face image to be identified into a face recognition model to obtain a third face feature of the face image to be identified; the face recognition model is obtained by the training method according to any one of claims 1 to 6; The third facial feature is compared with the facial features in the facial image database to obtain a recognition result of the facial image to be recognized.
8. A training device for a face recognition model, characterized in that: include: An extraction module, used for extracting a preset number of face images from a plurality of face images at different angles; A training module, used for inputting the preset number of face images into a recognition model to be trained for training, obtaining a first aligned face image of all face images extracted from a decoding network of the recognition model to be trained, and obtaining first face features of all face images extracted from a first fully connected layer of the recognition model to be trained; the recognition model to be trained includes the first fully connected layer, and a sequentially connected encoding network, a second fully connected layer and the decoding network, wherein an input end of the first fully connected layer is connected to an output end of the second fully connected layer; An acquisition module, used for obtaining a model loss value of the recognition model to be trained according to all extracted face images, first aligned face images of all extracted face images, and first face features of all extracted face images; A judgment module, used to judge whether the model loss value meets the preset training end condition, and trigger the determination module when the model loss value meets the preset training end condition, and trigger the adjustment module when the model loss value does not meet the preset training end condition; A determination module is used to use the sequentially connected encoding network, the second fully connected layer and the first fully connected layer as a face recognition model according to the triggering of the judgment module.
9. A terminal 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 training method as described in any one of claims 1 to 6, or when the processor executes the computer program, it implements the face recognition method as described in claim 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, it implements the training method as described in any one of claims 1 to 6, or when the computer program is executed by a processor, it implements the face recognition method as described in claim 7.
