Face recognition method, device, electronic device and computer-readable storage medium

By constructing a face recognition model with multiple sets of training samples based on loss function, the problem of poor recognition of abnormal face images is solved, and the robustness and accuracy of face recognition are improved.

CN115188037BActive Publication Date: 2025-08-22ISA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210530918.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-16
Publication Date
2025-08-22
Estimated Expiration
2042-05-16

AI Technical Summary

Technical Problem

In the prior art, the face recognition model has poor recognition effect when processing abnormal face images, resulting in insufficient robustness of the overall algorithm.

Method used

Multiple sets of training samples based on loss function are used to train the initial model. The first loss function term is used to close the spatial distance between normal faces, and the spatial distance between normal faces and abnormal faces. The second loss function term is used to close the spatial distance between abnormal faces, and a face recognition model is built.

Benefits of technology

It improves the robustness of the face recognition model, reduces the unexpected recognition situation caused by abnormal faces, and enhances the accuracy and stability of face recognition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115188037B_ABST
    Figure CN115188037B_ABST
Patent Text Reader

Abstract

The present invention discloses a face recognition method, apparatus, electronic device, and computer-readable storage medium. The method comprises: obtaining a target face image; and using a face recognition model to recognize a target face in the target face image, thereby obtaining a face recognition result for the target face. The face recognition model is a face recognition model obtained by training an initial model using multiple sets of training samples based on a loss function. The present invention addresses the technical problem in related arts of using face recognition models for face recognition, where only normal faces are considered during training, resulting in frequent unexpected face recognition results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a face recognition method, device, electronic device, and computer-readable storage medium. Background Art

[0002] Most face recognition models use deep neural networks. In recent years, deep neural networks have made significant progress, resulting in increasingly higher accuracy in face recognition. Face recognition involves multiple steps: face detection, facial landmark recognition, face alignment, and finally, face recognition. Current face recognition algorithms focus on this last step, assuming that the facial images processed in the first three steps meet the required standard. Current face recognition models perform poorly for abnormal facial images generated in the first three steps, resulting in poor overall algorithm robustness.

[0003] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention

[0004] Embodiments of the present invention provide a face recognition method, device, electronic device, and computer-readable storage medium to at least solve the technical problem in related technologies that, in scenarios where a face recognition model is used for face recognition, only normal faces are considered when training the face model, resulting in frequent unexpected face recognition results.

[0005] According to one aspect of an embodiment of the present invention, a face recognition method is provided, including: obtaining a target face image; using a face recognition model to recognize a target face in the target face image, and obtaining a face recognition result of the target face, wherein the face recognition model is a face recognition model obtained by training an initial model based on a loss function using multiple groups of training samples, and the loss function includes a first loss function term and a second loss function term, the first loss function term is used to shorten the spatial distance between the same face in normal faces in a feature space, and to increase the spatial distance between different faces in normal faces in the feature space, and the second loss function term is used to shorten the spatial distance between abnormal faces in the feature space, and to increase the spatial distance between normal faces and abnormal faces in the feature space.

[0006] Optionally, the method also includes: constructing the first loss function term in the following manner: obtaining the spatial position of the normal face in the feature space; determining the spatial angle between any two spatial positions of the normal face based on the spatial position of the normal face; constructing the first loss function term based on the spatial angle between any two spatial positions of the normal face; constructing the second loss function term in the following manner: obtaining the spatial position of the normal face and the spatial position of the abnormal face in the feature space; determining the spatial angle between any two spatial positions of the abnormal face based on the spatial position of the abnormal face; constructing the second loss function term based on the spatial position of the normal face and the spatial angle between any two spatial positions of the abnormal face.

[0007] Optionally, the face recognition model obtained by training the initial model using multiple groups of training samples includes: obtaining a first training sample, wherein the first training sample includes a first sample image and a face recognition result of the first sample image, and the first sample face in the first sample image is a normal face; training the initial model based on the first training sample to obtain the face recognition model.

[0008] Optionally, the face recognition model obtained by training the initial model using multiple groups of training samples includes: obtaining a second training sample, wherein the second training sample includes a second sample image and a face recognition result in the second sample image, and the second sample face in the second sample image is an abnormal face; training the initial model based on the second training sample to obtain the face recognition model.

[0009] Optionally, the use of a face recognition model to identify the target face in the target face image to obtain a face recognition result of the target face includes: using the face recognition model to identify the target face image, identifying the probability that the target face in the target face image belongs to multiple faces among normal faces, and the probability that the target face is an abnormal face, and determining the maximum probability between the probabilities of belonging to multiple faces and the probability of belonging to an abnormal face; comparing the maximum probability with a predetermined threshold; when the maximum probability is greater than the predetermined threshold, determining that the face corresponding to the maximum probability is the face to which the target face in the target face image belongs, and obtaining a face recognition result of the target face.

[0010] Optionally, after adopting a face recognition model to recognize a target face in the target face image and obtaining a face recognition result of the target face, the method further includes: displaying the face recognition result of the target face image.

[0011] According to one aspect of an embodiment of the present invention, a face recognition device is provided, including: an acquisition module for acquiring a target face image; a recognition module for using a face recognition model to recognize a target face in the target face image, and obtain a face recognition result of the target face, wherein the face recognition model is a face recognition model obtained by training an initial model based on a loss function using multiple groups of training samples, and the loss function includes a first loss function term and a second loss function term, the first loss function term is used to shorten the spatial distance between the same face in normal faces in a feature space, and to increase the spatial distance between different faces in normal faces in the feature space, and the second loss function term is used to shorten the spatial distance between abnormal faces in the feature space, and to increase the spatial distance between normal faces and abnormal faces in the feature space.

[0012] According to one aspect of an embodiment of the present invention, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement any of the above-mentioned face recognition methods.

[0013] According to one aspect of an embodiment of the present invention, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform any of the above-mentioned face recognition methods.

[0014] According to one aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned face recognition methods.

[0015] In an embodiment of the present invention, a target facial image is acquired and input into a facial recognition model for target face recognition, thereby obtaining a facial recognition result for the target face. This is because the facial recognition model into which the target facial image is input is based on a loss function, obtained by training an initial model using multiple sets of training samples. A loss function is employed, wherein the loss function includes a first loss function term and a second loss function term. The first loss function term is used to reduce the spatial distance between the same face within a normal face in the feature space and to increase the spatial distance between different faces within the normal face in the feature space. The second loss function term is used to reduce the spatial distance between abnormal faces in the feature space and to increase the spatial distance between normal and abnormal faces in the feature space. In other words, the impact of abnormal faces on facial recognition is taken into account, reducing unexpected situations caused by abnormal faces and enhancing the robustness of the facial recognition model. This solves the technical problem in related technologies where, in scenarios where facial recognition models are used for facial recognition, only normal faces are considered during training, resulting in frequent unexpected facial recognition results. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0017] Figure 1 is a flowchart of a face recognition method according to an embodiment of the present invention;

[0018] Figure 2 FIG. 4 is a structural block diagram of a face recognition device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0019] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0020] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0021] Example 1

[0022] According to an embodiment of the present invention, an embodiment of a face recognition method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0023] Figure 1 is a flow chart of a face recognition method according to an embodiment of the present invention. Figure 1 As shown, the method includes the following steps:

[0024] Step S102, obtaining a target face image;

[0025] Step S104: Use a face recognition model to identify the target face in the target face image to obtain a face recognition result of the target face, wherein the face recognition model is a face recognition model obtained by training an initial model based on a loss function using multiple groups of training samples. The loss function includes a first loss function term and a second loss function term. The first loss function term is used to shorten the spatial distance between the same face in normal faces in the feature space, and to increase the spatial distance between different faces in normal faces in the feature space. The second loss function term is used to shorten the spatial distance between abnormal faces in the feature space, and to increase the spatial distance between normal faces and abnormal faces in the feature space.

[0026] Through the above steps, a target facial image is obtained and input into a facial recognition model for target face recognition, thereby obtaining a facial recognition result for the target face. This is because the facial recognition model into which the target facial image is input is based on a loss function, obtained by training an initial model using multiple sets of training samples. A loss function is employed, wherein the loss function includes a first loss function term and a second loss function term. The first loss function term is used to reduce the spatial distance between the same face within a normal face in the feature space and to increase the spatial distance between different faces within the normal face in the feature space. The second loss function term is used to reduce the spatial distance between abnormal faces in the feature space and to increase the spatial distance between normal and abnormal faces in the feature space. In other words, the impact of abnormal faces on facial recognition is taken into account, reducing unexpected situations caused by abnormal faces and enhancing the robustness of the facial recognition model. This solves the technical problem in related technologies where, when training a facial recognition model for facial recognition, only normal faces are considered, resulting in frequent unexpected facial recognition results.

[0027] It should be noted that the target facial image can be of multiple types and can be configured accordingly based on different scenarios. For example, in the security field, the target facial image can be a facial image captured by a camera; in the payment field, the target facial image can be a frontal facial image of a person captured by a terminal, and so on, without limitation. The target facial image can also contain multiple target faces. In such cases, each of the multiple target faces is recognized separately.

[0028] It should also be noted that the face recognition model is used to identify the target face in the target face image. The facial recognition result of the target face can be a specific face among normal faces, an abnormal face, or an unknown face. An abnormal face can be a blurred face with low facial clarity; a face from the side or back; or a face with key facial features blocked, etc. An unknown face means that the target face does not exist in the database. If it is recognized for the first time, the face can be recorded.

[0029] The face recognition model used in the present invention is a face recognition model obtained by training the initial model based on a loss function using multiple sets of training samples. The loss function includes a first loss function term and a second loss function term. The first loss function term is used to shorten the spatial distance between the same face in the normal face in the feature space, that is, shorten the distance between the face vectors corresponding to the same face in the feature space; and shorten the spatial distance between different faces in the normal face in the feature space, that is, shorten the distance between the face vectors corresponding to different faces in the feature space. The second loss function term is used to shorten the spatial distance between abnormal faces in the feature space, that is, shorten the distance between the face vectors corresponding to abnormal faces in the feature space; and shorten the spatial distance between normal faces and abnormal faces in the feature space, that is, shorten the distance between the face vectors corresponding to normal faces and the face vectors corresponding to abnormal faces in the feature space. This allows for better identification of the distinguishing features between normal faces and abnormal faces, improves model robustness, and reduces the occurrence of emergencies during face recognition. Among them, the face recognition model can adopt a variety of deep neural network models. For example, it can be a model obtained by adopting the resnet101 (101-layer residual network) network structure and training with the ArcFace loss function, or it can be a model obtained by adopting the resnet101 network structure and training with the Triplet loss function, or it can be a model obtained by adopting the resnet101 network structure and training with the ArcFace loss function and the Triplet loss function.

[0030] As an optional embodiment, if the above-mentioned face recognition model adopts the resnet101 network structure and is trained by the ArcFace loss function. The ArcFace loss function includes a first function term and a second function term. Optionally, the first loss function term is constructed in the following manner: obtaining the spatial position of a normal face in the feature space; determining the spatial angle between any two spatial positions in the spatial position of the normal face based on the spatial position of the normal face; constructing the first loss function term based on the spatial angle between any two spatial positions in the spatial position of the normal face; constructing the second loss function term in the following manner: obtaining the spatial position of the normal face and the spatial position of the abnormal face in the feature space; determining the spatial angle between any two spatial positions in the spatial position of the abnormal face based on the spatial position of the abnormal face; constructing the second loss function term based on the spatial position of the normal face and the spatial angle between any two spatial positions in the spatial position of the abnormal face. This will shorten the spatial distance between the same face in the normal face space in the feature space, increase the spatial distance between different faces in the normal face space in the feature space, shorten the spatial distance between abnormal faces in the feature space, and increase the spatial distance between normal faces and abnormal faces in the feature space.

[0031] As an optional embodiment, if the above-mentioned face recognition model adopts the resnet101 network structure and is trained by the triplet loss function. The triplet loss function includes a first function term and a second function term. Optionally, when using the triplet loss process, the loss function formula is modified as follows:

[0032]

[0033] in the formula A face vector in the training sample, Represents Face vectors of different images of the same person, Represents Face vectors of images where faces belong to different people. A vector representing an abnormal face. α1 represents the spatial distance between faces of the same person being brought closer together and between faces of different people being further apart. α2 represents the spatial distance between faces of the same person being brought closer together and between normal and abnormal faces being further apart. The upper portion of the loss function term is the same as the first loss function term described above, while the lower portion is the same as the second loss function term described above. This results in the spatial distance between faces within the normal face set in the feature space being brought closer together, while the spatial distance between different faces within the normal face set in the feature space being further apart. The spatial distance between abnormal faces in the feature space being brought closer together, while the spatial distance between normal and abnormal faces in the feature space being further apart.

[0034] It should be noted that the ArcFace loss function and the Triplet loss function can also be used to jointly construct a loss function including the first loss function term and the second loss function term, which can greatly improve the robustness.

[0035] As an optional embodiment, when using multiple sets of training samples to train an initial model to obtain a face recognition model, multiple sets of training samples are first obtained, wherein the multiple sets of training samples include a first training sample and a second training sample. The first training sample includes a first sample image and a face recognition result of the first sample image, wherein the first sample face in the first sample image is a normal face. The second training sample includes a second sample image and a face recognition result of the second sample image, wherein the second sample face in the second sample image is an abnormal face. The initial model can be trained based on the first training sample to obtain a face recognition model that is improved in recognizing normal faces. The initial model can also be trained based on the second training sample to obtain a face recognition model that is improved in recognizing abnormal faces. Optionally, the initial model can be trained based on both the first training sample and the second training sample to obtain a face recognition model that is improved in recognizing both normal and abnormal faces, thereby improving not only the accuracy of the model in recognizing faces but also the robustness of the model in recognizing faces.

[0036] As an optional embodiment, the process of using a face recognition model to identify a target face in a target face image and obtaining a face recognition result for the target face may further include: using the face recognition model to identify the target face image, identifying the probability that the target face in the target face image belongs to multiple types of normal faces, and the probability that the target face is an abnormal face, and determining the maximum probability among the probabilities of belonging to the multiple types of faces and the probabilities of belonging to the abnormal face; comparing the maximum probability with a predetermined threshold; and when the maximum probability is greater than the predetermined threshold, determining the face corresponding to the maximum probability as the face to which the target face in the target face image belongs, and obtaining a face recognition result for the target face. The maximum probability result and the predetermined threshold can ensure the validity of the face recognition result.

[0037] Based on the above embodiment and optional embodiment, an optional implementation manner is provided, which is described in detail below.

[0038] In related technologies, facial recognition involves multiple steps: first, face detection; second, facial keypoint recognition; third, face alignment; and finally, face recognition. In applications like mobile payments, facial recognition accuracy is primarily affected by this final step. This requirement allows users to face the screen directly, revealing their entire face. This eliminates errors introduced by the first three steps. However, in security, faces are captured by cameras, making the faces fed into the facial recognition model unpredictable. First, the facial detection model may contain errors, such as misidentifying an animal face as a human face; detecting a profile or back face due to the angle of the face; or detecting multiple exposed or blurred faces due to factors like lighting and distance. These errors can affect the accuracy of the facial recognition model. Second, the facial keypoint detection model may contain errors. For example, detecting facial keypoints on a pedestrian wearing a mask can cause keypoints to deviate from their correct positions. Furthermore, when facial keypoint detection fails, face alignment also fails, directly impacting facial recognition accuracy. Current facial recognition algorithms are often targeted at mobile payment applications. They assume the accuracy of the first three steps of facial recognition, meaning the facial image fed into the facial recognition model is complete and aligned. However, these facial recognition algorithms have significant drawbacks when applied to security applications.

[0039] In view of this, an optional embodiment of the present invention provides a face recognition model, which can improve the robustness of face recognition and enable the face recognition model to better adapt to abnormal face images.

[0040] S1, obtaining training samples, wherein the training samples include a first training sample and a second training sample, the first training sample includes a first sample image and a face recognition result of the first sample image, and the first sample face in the first sample image is a normal face; the second training sample includes a second sample image and a face recognition result of the second sample image, and the second sample face in the second sample image is an abnormal face;

[0041] S2, use the training samples to train the initial model to obtain the face recognition model;

[0042] In the process of training the initial model, the Arcface loss function and the Triplet loss function are used to train the initial model.

[0043] 1) In the process of using the Arcface loss function, based on the aggregation of normal face categories (same as the first training samples mentioned above) in related technologies, an abnormal face category (same as the second training samples mentioned above) is added. That is, the collected abnormal face images are added to the training as a separate category. The purpose is to aggregate these abnormal face vectors in the feature space to avoid the random distribution of abnormal face vectors in the feature space. The formula of the Arcface loss function is as follows:

[0044]

[0045] It should be noted that the purpose of this formula is to make the face vectors of the same person as close as possible in the high-dimensional feature space, and to make the cosine distances of the face vectors of different people as far as possible in the high-dimensional space. y The angle between two faces in feature space. m is a constant representing the angle between the two face vectors, which is the value obtained by multiplying the angle between them. s is a constant used to prevent vanishing gradients.

[0046] 2) When using the Triplet loss function, the abnormal face part was added and the loss function was improved. The modified loss function formula is as follows:

[0047]

[0048] It should be noted that in the formula A face vector in the training set, Represents Face vectors of different images of the same person, Represents Face vectors of images where faces belong to different people. The vector of an abnormal face. α1 means that the faces of the same person are brought closer together and the faces of different people are further apart. α2 means that the faces of the same person are brought closer together and the distance between normal and abnormal faces is further apart.

[0049] This loss function builds on the Triplet loss function used in related techniques to train normal faces by adding a component for abnormal faces. The Triplet loss function consists of a training face image A, a face B belonging to the same person as face A, and a face C belonging to a different person. The Triplet loss function minimizes the spatial distance between A and B and increases the spatial distance between A and C. This new loss function builds on the Triplet loss function by selecting an additional abnormal face image D and another abnormal face image E. This approach minimizes the distance between A and E and increases the distance between A and D. The goal is to keep the abnormal face vector as far away from the normal face vector as possible in feature space.

[0050] It should also be noted that after the model training is completed, the abnormal face vectors in all training samples are obtained, and the center points of these vectors are calculated as abnormal vectors, which can be used for model inference. This abnormal vector center point can also be used to filter out all possible abnormal face images.

[0051] S3, using the face recognition model, inputs the target face image into the face recognition model to obtain the face recognition result.

[0052] Get the target face image vector and calculate the cosine similarity between the vector and the abnormal vector. If the similarity is greater than 0.5, mark the face image as abnormal. Otherwise, it is a normal face vector and identify a face among the normal faces.

[0053] The above optional implementation can achieve at least the following beneficial effects: The model provided in this optional implementation specifically processes abnormal facial images. Using two loss functions, it aggregates all abnormal facial vectors predicted by the model in feature space and calculates the center point of the model's abnormal vectors. This center point is then used to filter out all possible abnormal facial images. This prevents other facial recognition models from ignoring abnormal facial images, causing these vectors to be randomly distributed in feature space, ultimately resulting in unexpected erroneous results during face comparison.

[0054] It should be noted that for the aforementioned method embodiments, for simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should be aware that the present invention is not limited by the order of the actions described, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.

[0055] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, 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, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of various embodiments of the present invention.

[0056] Example 2

[0057] According to an embodiment of the present invention, a device for implementing the above-mentioned face recognition method is also provided. Figure 2 : is a structural block diagram of a face recognition device according to an embodiment of the present invention. Figure 2 As shown, the device includes: an acquisition module 202 and an identification module 204. The device will be described in detail below.

[0058] The acquisition module 202 is used to acquire a target face image; the recognition module 204 is connected to the above-mentioned acquisition module 202, and is used to use a face recognition model to recognize the target face in the target face image to obtain a face recognition result of the target face, wherein the face recognition model is a face recognition model obtained by training an initial model based on a loss function using multiple groups of training samples. The loss function includes a first loss function term and a second loss function term. The first loss function term is used to shorten the spatial distance between the same face in normal faces in the feature space, and to increase the spatial distance between different faces in normal faces in the feature space. The second loss function term is used to shorten the spatial distance between abnormal faces in the feature space, and to increase the spatial distance between normal faces and abnormal faces in the feature space.

[0059] It should be noted here that the above-mentioned acquisition module 202 and recognition module 204 correspond to steps S102 to S104 in implementing the face recognition method. The instances and application scenarios implemented by multiple modules and corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned embodiment 1.

[0060] Example 3

[0061] According to another aspect of an embodiment of the present invention, an electronic device is provided, including: a processor; and a memory for storing processor-executable instructions, wherein the processor is configured to execute the instructions to implement any of the above-mentioned face recognition methods.

[0062] Example 4

[0063] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided. When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device can perform any of the above-mentioned face recognition methods.

[0064] Example 5

[0065] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned face recognition methods.

[0066] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.

[0067] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0068] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, 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 units or modules, which can be electrical or other forms.

[0069] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0070] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0071] 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 technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk, etc. Various media that can store program codes.

[0072] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.

Claims

1. A face recognition method, characterized in that: include: Get the target face image; A face recognition model is used to identify the target face in the target face image to obtain a face recognition result of the target face, wherein the face recognition model is a face recognition model obtained by training an initial model based on a loss function using multiple groups of training samples, and the loss function includes a first loss function term and a second loss function term. The first loss function term is used to shorten the spatial distance between the same face in normal faces in the feature space, and to increase the spatial distance between different faces in the normal faces in the feature space. The second loss function term is used to shorten the spatial distance between abnormal faces in the feature space, and to increase the spatial distance between normal faces and abnormal faces in the feature space.

2. The method according to claim 1, characterized in that The method further comprises: The first loss function term is constructed by: obtaining the spatial position of the normal face in the feature space; determining the spatial angle between any two spatial positions of the normal face based on the spatial position of the normal face; and constructing the first loss function term based on the spatial angle between any two spatial positions of the normal face; The second loss function term is constructed in the following manner: obtaining the spatial position of a normal face and the spatial position of the abnormal face in the feature space; determining the spatial angle between any two spatial positions of the abnormal face based on the spatial position of the abnormal face; constructing the second loss function term based on the spatial position of the normal face and the spatial angle between any two spatial positions of the abnormal face.

3. The method according to claim 1, characterized in that The face recognition model obtained by training the initial model using multiple sets of training samples includes: Obtaining a first training sample, wherein the first training sample includes a first sample image and a face recognition result of the first sample image, and the first sample face in the first sample image is a normal face; The initial model is trained based on the first training sample to obtain the face recognition model.

4. The method according to claim 1, wherein The face recognition model obtained by training the initial model using multiple sets of training samples includes: Obtaining a second training sample, wherein the second training sample includes a second sample image and a face recognition result in the second sample image, and the second sample face in the second sample image is an abnormal face; The initial model is trained based on the second training sample to obtain the face recognition model.

5. The method according to claim 1, wherein The face recognition model is used to recognize the target face in the target face image to obtain a face recognition result of the target face, including: Using the face recognition model, identifying the target face image, identifying the probability that the target face in the target face image belongs to multiple types of normal faces, and the probability that the target face belongs to the abnormal face, and determining the maximum probability between the probabilities of belonging to the multiple types of faces and the probabilities of belonging to the abnormal face; comparing the maximum probability with a predetermined threshold; When the maximum probability is greater than the predetermined threshold, the face corresponding to the maximum probability is determined to be the face to which the target face in the target face image belongs, and a face recognition result of the target face is obtained.

6. The method according to any one of claims 1 to 5, characterized in that After the face recognition model is used to recognize the target face in the target face image and a face recognition result of the target face is obtained, the method further includes: Display the face recognition result of the target face image.

7. A face recognition device, characterized in that: include: An acquisition module is used to acquire a target face image; A recognition module is used to use a face recognition model to identify the target face in the target face image and obtain a face recognition result of the target face, wherein the face recognition model is a face recognition model obtained by training an initial model based on a loss function using multiple groups of training samples, and the loss function includes a first loss function term and a second loss function term. The first loss function term is used to shorten the spatial distance between the same face in normal faces in the feature space, and to increase the spatial distance between different faces in normal faces in the feature space. The second loss function term is used to shorten the spatial distance between abnormal faces in the feature space, and to increase the spatial distance between normal faces and abnormal faces in the feature space.

8. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the face recognition method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the face recognition method according to any one of claims 1 to 6.

10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the face recognition method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Pedestrian re-identification method and device based on deep metric learning

    CN110968734A

  • Face recognition method

    CN111209839A