Face recognition method and device
Through the cross-attention mechanism and attention pooling, the local features of associated face images are processed, which solves the problem of ignoring similar features in the existing technology and improves the accuracy and recognition effect of face recognition.
Patent Information
- Application Number
- CN202110282834.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-16
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-03-16
AI Technical Summary
Existing face recognition methods ignore the similar features between the compared face image pairs when improving accuracy, and the problem of fixed representation leads to insufficient recognition accuracy.
By obtaining the local features of the face image based on the cross-attention mechanism, using attention pooling processing and the multi-head attention mechanism to associate similar features of the image pairs, the final global features of the image pairs are obtained to improve the recognition accuracy.
Effectively pay attention to the feature correlation between image pairs to improve the accuracy of face recognition. Especially when processing images of the same identity but with different postures, illumination or ages, the same features can be more accurately identified and distinguished between different identities. Facial area characteristics.
Smart Images

Figure CN112966626B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of face recognition technology, and more specifically, to a face recognition method and device. Background Art
[0002] Face recognition technology has a wide range of applications in our daily lives, such as phone unlocking, video surveillance, online payment, access control, photo album management, etc.
[0003] Face recognition technology mainly obtains a trained network to perform face recognition by designing an effective network structure and constructing a discriminant loss function for feature learning. In recent years, due to the rapid development of deep neural network technology and the availability of large-scale face datasets, face recognition accuracy has been significantly improved. Some representative and relatively successful works on face recognition include DeepFace, DeepID, FaceNet, DeepFR, InsightFace, MobileFace, etc.
[0004] Most existing face recognition methods usually extract global features from full face images through a carefully designed CNN network. For example, in order to verify whether a given pair of face images have the same identity, the two face images are fed into a trained CNN classifier to obtain their facial representations, and then the two facial representations are compared to determine whether they are the same person. Since the CNN parameters are fixed after training, the representation of the compared face image obtained by the trained CNN network remains fixed no matter which face image the compared face image is compared with. In order to distinguish the compared face image from all other people's face images, the representation of the face image must be sufficiently discriminative, which is very challenging. In order to make the representation of the face image sufficiently discriminative, the similarity between the paired images can be calculated through a comparator network, however, this method requires facial feature point detection first to perform feature comparison based on feature points, which is a tedious task. In addition, the contrastive convolution mechanism can be used to extract different features between the face image pairs to improve the face recognition accuracy, but this method ignores the role of similar features between the compared face pairs, especially when the two face images are from the same identity. In addition, the accuracy of face recognition can be improved by utilizing the attention mechanism. However, the existing method of improving the accuracy of face recognition through the self-attention mechanism still has the problem of fixed representation of the compared face images, and still ignores the role of similar features between the compared image pairs.
[0005] How to consider the role of similar features between the compared face image pairs in improving face recognition accuracy to further improve face recognition accuracy is an urgent problem to be solved by the present invention. Summary of the invention
[0006] The object of the present invention is to provide a face recognition method and device to at least solve the problems in the above-mentioned related technologies, or not to solve any of the above-mentioned problems.
[0007] According to an exemplary embodiment of the present invention, a face recognition method is provided, the method comprising: obtaining first global features of the first face image and first global features of the second face image respectively based on local features of the first face image and local features of the second face image; obtaining final global features of the first face image based on the first global features and the second global features of the first face image; obtaining final global features of the second face image based on the first global features and the second global features of the second face image; recognizing the first face image and the second face image based on the final global features of the first face image and the final global features of the second face image, wherein the second global features of the first face image are obtained based on the local features of the first face image, and the second global features of the second face image are obtained based on the local features of the second face image.
[0008] Since the final global features of the first face image used for face recognition are related to the second face image, and the final global features of the second image used for recognition are related to the first image, the face recognition method disclosed in the present invention can pay attention to the feature association between image pairs, thereby improving the accuracy of face recognition.
[0009] Optionally, the steps of respectively obtaining the first global features of the first facial image and the first global features of the second facial image based on the local features of the first facial image and the local features of the second facial image include: performing attention pooling processing based on the local features of the first facial image and the local features of the second facial image to respectively obtain the first global features of the first facial image and the first global features of the second facial image.
[0010] Through attention pooling processing, the first global feature of the first face image can be associated with the second face image, and the first global feature of the second face image can be associated with the first face image, so that more attention can be paid to the comparison of similar features between the comparison image pairs, thereby improving the recognition accuracy.
[0011] Optionally, the local features of the first facial image are local features of the first facial image embedded with position information; and the local features of the second facial image are local features of the second facial image embedded with position information.
[0012] By embedding position information into local features of a face image and performing pooling processing based on the local features of the face image embedded with the position information, it is possible to ensure that elements of the face image at corresponding positions correspond to each other, thereby being able to better reflect the association between similar parts of the image.
[0013] Optionally, the steps of performing attention pooling processing based on local features of the first facial image and local features of the second facial image to respectively obtain first global features of the first facial image and first global features of the second facial image include: based on the local features of the first facial image and the local features of the second facial image, using a multi-head attention mechanism to respectively obtain first attention pooling features of the first facial image for the second facial image and second attention pooling features of the second facial image for the first facial image; based on the first attention pooling features, obtaining first global features of the first facial image; based on the second attention pooling features, obtaining first global features of the second facial image.
[0014] Through the cross-attention mechanism, the face recognition method of the present disclosure can pay attention to the association between the most similar features between the image pairs, thereby improving the accuracy of face recognition. For example, when comparing image pairs from the same identity but with different illumination, posture or age, it is easier to find the same features from the image pairs. On the other hand, if the compared images are from different identities, paying attention to the feature comparison between the most similar facial regions will enable more reliable recognition results to be obtained.
[0015] Optionally, based on the local features of the first face image and the local features of the second face image, the steps of using the multi-head attention mechanism to respectively obtain the first attention pooling features of the first face image for the second face image and the second attention pooling features of the second face image for the first face image include: multiplying the local features of the second face image by a first query matrix corresponding to the query (Query) to obtain a first query vector, multiplying the local features of the first face image by a first key matrix corresponding to the key (KEY) to obtain a first key vector, and multiplying the local features of the first face image by a first value matrix corresponding to the value (Value) to obtain a first Value vector, and based on the obtained first query vector, the first key vector and the first value vector, obtain the attention pooling features of the first face image for the second face image; and multiply the local features of the first face image by the second query matrix corresponding to the query to obtain the second query vector, multiply the local features of the second face image by the second key matrix corresponding to the key to obtain the second key vector, multiply the local features of the second face image by the second value matrix corresponding to the value (Value) to obtain the second value vector, and obtain the attention pooling features of the second face image for the first face image based on the obtained second query vector, the second key vector and the second value vector.
[0016] By implementing the cross-attention mechanism through the query vector, it can be ensured that the first global feature of the first face image and the first global feature of the second face image are respectively associated with each other's image local features, so that more attention can be paid to the comparison between similar parts of the face images, thereby improving the recognition success rate.
[0017] Optionally, the step of respectively acquiring the first global feature of the first facial image and the first global feature of the second facial image includes: using the same network or different networks to respectively acquire the first global feature of the first facial image and the first global feature of the second facial image.
[0018] By using the same network, software and hardware expenses can be saved, and by respectively obtaining the first global feature of the first face image and the first global feature of the second face image through different networks, the recognition speed can be improved.
[0019] According to an exemplary embodiment of the present invention, a face recognition device is provided, the device comprising: a first global feature acquisition module: configured to acquire first global features of a first face image and first global features of a second face image respectively based on local features of the first face image and local features of the second face image; a final global feature acquisition module: configured to acquire final global features of the first face image based on the first global features and the second global features of the first face image, and to acquire final global features of the second face image based on the first global features and the second global features of the second face image; a recognition module: configured to recognize the first face image and the second face image based on the final global features of the first face image and the final global features of the second face image, wherein the second global features of the first face image are acquired based on the local features of the first face image, and the second global features of the second face image are acquired based on the local features of the second face image.
[0020] Since the final global features of the first face image used for identification are related to the second face image, and the final global features of the second image used for identification are related to the first image, the face recognition method of the present invention can pay attention to the feature association between image pairs, thereby improving the accuracy of face recognition.
[0021] Optionally, the first global feature acquisition module is configured to: perform attention pooling processing based on local features of the first facial image and local features of the second facial image to obtain first global features of the first facial image and first global features of the second facial image, respectively.
[0022] Through attention pooling processing, the first global feature of the first face image can be associated with the second face image, and the first global feature of the second face image can be associated with the first face image, so that more attention can be paid to the comparison of similar features between the comparison image pairs, thereby improving the recognition accuracy.
[0023] Optionally, the local features of the first facial image are local features of the first facial image embedded with position information; and the local features of the second facial image are local features of the second facial image embedded with position information.
[0024] By embedding position information into local features of a face image and performing pooling processing based on the local features of the face image embedded with the position information, it is possible to ensure that elements of the face image at corresponding positions correspond to each other, thereby being able to better reflect the association between similar parts of the image.
[0025] Optionally, the first global feature acquisition module is configured to: based on local features of the first facial image and local features of the second facial image, use a multi-head attention mechanism to respectively acquire first attention pooling features of the first facial image for the second facial image and second attention pooling features of the second facial image for the first facial image; based on the first attention pooling features, acquire second global features of the first facial image; based on the second attention pooling features, acquire second global features of the second facial image.
[0026] Through the cross-attention mechanism, the face recognition method of the present disclosure can pay attention to the association between the most similar features between the image pairs, thereby improving the accuracy of face recognition. For example, when comparing image pairs from the same identity but with different illumination, posture or age, it is easier to find the same features from the image pairs. On the other hand, if the compared images are from different identities, paying attention to the feature comparison between the most similar facial regions will enable more reliable recognition results to be obtained.
[0027] Optionally, the first global feature acquisition module includes a cross-attention module, which is configured to: multiply the local features of the second facial image by a first query matrix corresponding to the query to obtain a first query (Query) vector, multiply the local features of the first facial image by a first key matrix corresponding to the key (KEY) to obtain a first key vector, multiply the local features of the first facial image by a first value matrix corresponding to the value (Value) to obtain a first value vector, and calculate the attention pooling features of the first facial image for the second facial image based on the obtained first query vector, the first key vector and the first value vector; and multiply the local features of the first facial image by a second query matrix corresponding to the query to obtain a second query vector, multiply the local features of the second facial image by a second key matrix corresponding to the key to obtain a second key vector, multiply the local features of the second facial image by a second value matrix corresponding to the value (Value) to obtain a second value vector, and calculate the attention pooling features of the second facial image for the first facial image based on the obtained second query vector, the second key vector and the second value vector.
[0028] By implementing the cross-attention mechanism through the query vector, it can be ensured that the first global feature of the first face image and the first global feature of the second face image are respectively associated with each other's image local features, so that more attention can be paid to the comparison between similar parts of the face images, thereby improving the recognition success rate.
[0029] Optionally, the first global feature acquisition module includes: a first global feature acquisition module for a first facial image, configured to acquire the first global feature of the first facial image; and a second global feature acquisition module for a second facial image, configured to acquire the first global feature of the second facial image.
[0030] By respectively acquiring the first global feature of the first face image and the first global feature of the second face image through different modules to realize parallel processing of face images, the speed of face recognition can be improved.
[0031] According to an exemplary embodiment of the present invention, there is provided a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the face recognition method as described above is implemented.
[0032] According to an exemplary embodiment of the present invention, there is provided a data storage device, the device comprising: a processor; a memory storing a computer program, and when the computer program is executed by the processor, the face recognition method as described above is implemented.
[0033] The face recognition method and apparatus according to the present disclosure enable more attention to be paid to the association between the most similar features between the image pairs used for recognition, thereby improving the accuracy of face recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The above and other objects and features of the present invention will become more apparent through the following description in conjunction with the accompanying drawings which exemplarily illustrate an example, in which:
[0035] Figure 1 is a flow chart showing a face recognition method according to an embodiment of the present disclosure;
[0036] Figure 2 is a diagram showing an example of performing attention pooling processing on local features of a first face image and local features of a second face image based on a cross attention mechanism according to an embodiment of the present disclosure;
[0037] Figure 3 is a schematic diagram of a face recognition method according to an embodiment of the present disclosure;
[0038] Figure 4 is a diagram showing visualization responses of a face image based on a Baseline face recognition method, a self-attention face recognition method, and a face recognition method according to an embodiment of the present disclosure;
[0039] Figure 5 is a block diagram showing a face recognition apparatus according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0040] Hereinafter, various embodiments of the present disclosure are described with reference to the accompanying drawings, wherein the same reference numerals are used to represent the same or similar elements, features and structures. However, it is not intended that the present disclosure be limited to specific embodiments by the various embodiments described herein, and it is intended that: the present disclosure covers all modifications, equivalents and / or substitutes of the present disclosure, as long as they are within the scope of the attached claims and their equivalents. The terms and words used in the following specification and claims are not limited to their dictionary meanings, but are only used to enable a clear and consistent understanding of the present disclosure. Therefore, it should be apparent to those skilled in the art that the following description of various embodiments of the present disclosure is provided for illustrative purposes only, and not for the purpose of limiting the present disclosure defined by the attached claims and their equivalents.
[0041] It should be understood that the singular includes the plural unless the context clearly indicates otherwise.The terms "include", "comprising" and "having" used herein indicate the presence of disclosed functions, operations or elements, but do not exclude other functions, operations or elements.
[0042] For example, the expression "A or B" or "at least one of A and / or B" may indicate A and B, A or B. For example, the expression "A or B" or "at least one of A and / or B" may indicate (1) A, (2) B, or (3) both A and B.
[0043] In various embodiments of the present disclosure, it is intended that when a component (e.g., a first component) is referred to as being "coupled" or "connected" to another component (e.g., a second component) or being "coupled" or "connected" to another component (e.g., the second component), the component may be directly connected to the other component or may be connected through another component (e.g., a third component). In contrast, when a component (e.g., a first component) is referred to as being "directly coupled" or "directly connected" to another component (e.g., the second component) or being directly coupled to or directly connected to another component (e.g., the second component), there is no other component (e.g., the third component) between the component and the other component.
[0044] The expression "configured to" used in describing various embodiments of the present disclosure may be used interchangeably with expressions such as "suitable for", "having the ability to", "designed to", "suitable for", "manufactured to", and "capable of", for example, depending on the circumstances. The term "configured to" may not necessarily indicate that it is "specially designed to" in terms of hardware. On the contrary, the expression "a device configured to..." in some cases may indicate that the device and another device or part "can..." For example, the expression "a processor configured to perform A, B, and C" may indicate a dedicated processor (e.g., an embedded processor) for performing the corresponding operations or a general-purpose processor (e.g., a central processing unit CPU or an application processor (AP)) for performing the corresponding operations by executing at least one software program stored in a memory device.
[0045] The terms used herein are to describe certain embodiments of the present disclosure, but are not intended to limit the scope of other embodiments. Unless otherwise noted herein, all terms used herein (including technical or scientific terms) may have the same meaning as those generally understood by those skilled in the art. Typically, the terms defined in the dictionary should be considered to have the same meaning as the contextual meaning in the relevant field, and, unless clearly defined herein, should not be understood differently or understood to have an overly formal meaning. In any case, the terms defined in the present disclosure are not intended to be interpreted as excluding embodiments of the present disclosure.
[0046] To facilitate the explanation of the present disclosure, a method for representing local features of a facial image is first described. Those skilled in the art should understand that the local features of the face described herein represent local feature representations or local feature maps of the facial image, which can be represented in the form of a matrix, for example.
[0047] As an example, a convolutional network can be used to obtain local feature representations of facial images.
[0048] As an example, ResNet can be used as the backbone network to extract local features of a face image. For example, for a face image with a size of 112×112, the feature map output from the last layer of the convolutional network can have a size of C×7×7 (C is the channel size, such as C=512), and another convolutional layer can be used to further process the feature map of size C×7×7 into a feature map of size C×5×5.
[0049] As an example, a feature map with a size of C×5×5 can also be directly obtained through a convolutional network. After the convolution process, the face image is divided into 5×5 sub-regions, so a feature map with a size of C×5×5 can be used to describe the face image.
[0050] Furthermore, by inputting the acquired local features into the fully connected layer, the global features or global feature representation of the face image can be obtained.
[0051] Those skilled in the art should understand that the global feature in this article refers to a global feature representation of a face image or a full-image feature map, which can be represented in a matrix form, for example.
[0052] Figure 1 A flow chart of a face recognition method according to an embodiment of the present disclosure is shown.
[0053] Reference Figure 1 In step S101, based on the local features of the first face image and the local features of the second face image, first global features of the first face image and first global features of the second face image are respectively obtained.
[0054] As an example, the same network can be used to obtain the first global features of the first face image and the first global features of the second face image; or the first network can be used to obtain the first global features of the first face image, and the second network can be used to obtain the first global features of the second face image, where the first network and the second network can be the same or different.
[0055] Acquiring the first global feature of a face image through the same network can save software and hardware overhead, and acquiring the first global feature of a first face image and the first global feature of a second face image through two networks respectively can improve the speed of face recognition.
[0056] As an example, the steps of respectively obtaining the first global features of the first facial image and the first global features of the second facial image based on the local features of the first facial image and the local features of the second facial image include: performing attention pooling processing based on the local features of the first facial image and the local features of the second facial image to respectively obtain the first global features of the first facial image and the first global features of the second facial image.
[0057] As an example, the local features of the first face image are the local features of the first face image embedded with position information; the local features of the second face image are the local features of the second face image embedded with position information. For example, the local features of the first face image can be embedded with position information to obtain the local features of the first face image embedded with position information, and the local features of the second face image can be embedded with position information to obtain the local features of the second face image embedded with position information. Figure 2 Describe the attention pooling operation in detail.
[0058] Figure 2 is a diagram showing an example of performing attention pooling processing on local features of a first face image and local features of a second face image based on a cross-attention mechanism according to an embodiment of the present disclosure.
[0059] Reference Figure 2 , the attention pooling features of the first face image for the second face image can be obtained by inputting the local features of face image A embedded with position information (hereinafter may also be referred to as the first face image or image A) and the local features of face image B embedded with position information (hereinafter may also be referred to as the second face image or image B) into the multi-head attention block on the left, and the attention pooling features of the second face image for the first face image can be obtained by inputting the local features of the first face image embedded with position information and the local features of the second face image embedded with position information into the multi-head attention block on the right.
[0060] As an example, the attention pooling features of the first face image for the second face image can be obtained through the multi-head attention layer of the left attention block, and the attention pooling features of the second face image for the first face image can be obtained through the multi-head attention layer of the right attention block.
[0061] As an example, the first global feature of the first face image can be obtained by processing the attention pooling features of the first face image with respect to the second face image through the subsequent layers of the left attention block and inputting the processing results into the first fully connected layer.
[0062] As an example, the pooled features of the second facial image for the first facial image are processed through the subsequent layers of the right attention block, and the processing results are input into the second fully connected layer to obtain the first global features of the second facial image, wherein the first fully connected layer and the second fully connected layer can be the same fully connected layer or two independent fully connected layers.
[0063] The multi-head attention block on the left and the multi-head attention block on the right have the same structure as the multi-head attention block (or standard transformer block) in the prior art. For example, they can be composed of a multi-head attention layer, a residual connection and a layer normalization (Add&Norm) layer, and a feed forward (Feed Forward) layer, and all of them are based on the multi-head attention mechanism to calculate attention.
[0064] For the multi-head attention block based on the self-attention mechanism in the prior art, the Query vector, Key vector, and Value vector input to the multi-head attention layer all correspond to the local features of the image itself, that is, the Query vector, Key vector, and Value vector are obtained by multiplying the local feature representation of the face image by the matrix W q , W k , W vq To obtain the Query vector Q, Key vector K, and Value vector V.
[0065] That is to say, when obtaining the pooling features of a face image based on the self-attention mechanism, the pooling features of the first image obtained are only related to the local features of the first face image embedded with position information, and are not related to the local features of the compared face image. In other words, no matter which face image is compared with, the pooling features of the image obtained are fixed.
[0066] In the present disclosure, the query vector input to the multi-head attention layer does not correspond to the local features of the image itself, but corresponds to the local features of the comparison image, that is, the query vector input to the multi-head attention layer of the multi-head attention block on the left corresponds to the local features of the second face image, and the query vector input to the multi-head attention layer of the multi-head attention block on the right corresponds to the local features of the first face image. In other words, the present disclosure is based on the cross-attention mechanism to obtain the pooled features of the first face image and the pooled features of the second face image.
[0067] Those skilled in the art should understand that, as described above, the difference between the scheme of the present invention for obtaining pooled features of faces based on the cross-attention mechanism and the scheme of obtaining pooled features of facial images based on the attention mechanism in the prior art is that: when the present invention obtains the attention pooled features of the first facial image, the Q vector input to the multi-head attention layer corresponds to the local features of the second facial image embedded with position information, and when obtaining the attention pooled features of the second facial image, the Q vector input to the multi-head attention layer corresponds to the local features of the first facial image embedded with position information; whereas in the prior art, when obtaining the attention pooled features of the first facial image based on the self-attention mechanism, the Q vector input to the multi-head attention layer corresponds to the local features of the first facial image, and when obtaining the attention pooled features of the second facial image based on the self-attention mechanism, the Q vector input to the multi-head attention layer corresponds to the local features of the second facial image.
[0068] That is to say, according to the implementation of the present disclosure, based on the local features of the first facial image with embedded position information and the local features of the second facial image with embedded position information, a multi-head attention mechanism can be used to respectively obtain the first attention pooling features of the first facial image for the second facial image and the second attention pooling features of the second facial image for the first facial image.
[0069] As an example, the local features of the second facial image can be multiplied by a first query matrix corresponding to the query (Query) to obtain a first query vector, the local features of the first facial image can be multiplied by a first key matrix corresponding to the key (Key) to obtain a first key vector, the local features of the first facial image can be multiplied by a first value matrix corresponding to the value (Value) to obtain a first value vector, and the attention pooling features of the first facial image for the second facial image (also referred to as the first attention pooling features in this article) are obtained based on the obtained first query vector, the first key vector and the first value vector; the local features of the first facial image can be multiplied by a second query matrix corresponding to the query to obtain a second query vector, the local features of the second facial image can be multiplied by a second key matrix corresponding to the key to obtain a second key vector, the local features of the second facial image can be multiplied by a second value matrix corresponding to the value (Value) to obtain a second value vector, and the attention pooling features of the second facial image for the first facial image (also referred to as the second attention pooling features in this article) are calculated based on the obtained second query vector, the second key vector and the second value vector.
[0070] Those skilled in the art should understand that if the first attention pooling features and the second attention pooling features are respectively obtained through the same network, the matrix modified with "first" corresponds to the matrix modified with "second", for example, the first query matrix and the second query matrix are the same.
[0071] As an example, if the first attention pooling feature and the second attention pooling feature are obtained respectively through two independent networks, the matrix modified with "first" corresponds to the matrix modified with "second", for example, the first query matrix and the second query matrix are different matrices.
[0072] As another example, if the first attention pooling features and the second attention pooling features are obtained respectively through two independent networks, the matrix modified with "first" and the matrix modified with "second" may also be the same, for example, the first query matrix and the second query matrix are the same matrix.
[0073] For ease of explanation, the local features of the image are processed to have a size of 5×5, and after feature rearrangement, they are represented to have a size of 1×25, and then input into Figure 2 The multi-head attention block in .
[0074] As an example, a local feature map of an image A with a size of 5×5 can be obtained through a convolutional neural network, and then the local feature map of A is subjected to feature rearrangement to obtain {v 1 ,v 2 ,…,v 25},v i ∈R C Represents the local feature map, and then {v 1 ,v 2 ,…,v 25}Embed the position information corresponding to the local feature to obtain the local feature H of A embedded with the position information A,i ={h1A,h2A,…,h25A. The local features HB,i of image B ={h1B,h2B,…,h25B can be obtained in a similar way.
[0075] Reference Figure 2 , the local features of A can be And the local feature representation of B Input the attention block on the left to obtain the attention pooling features of image A for image B. Specifically, by Multiply by the matrix W k , matrix W v Get the Key vector K A and Value vector V A ,Will Multiply by matrix W q Get the Query vector Q B , and the obtained Key vector K A 、Value vector V A and Query vector QB (corresponding to K, V and Q in the left attention block respectively) Input the multi-head attention layer of the left attention block for processing to obtain the attention pooling features of A for B, and then after processing by other layers of the left attention block, the local feature representation of image A based on cross-attention is obtained.
[0076] Those skilled in the art should understand that the local representation of the image input into the left attention block is only based on the local features of the image obtained based on the image itself (hereinafter referred to as the first local features for ease of description). For example, the local features of image A can be obtained through a convolutional network based on image A (i.e., the first local features of image A), or the local features of image B can be obtained through a convolutional network based on image B (i.e., the first local features of image B), and the local features output after processing by the left attention block are local feature representations of image A based on the cross-attention mechanism obtained based on the first local features of image A and the first local features of image B (hereinafter referred to as the second local features of image A for ease of description).
[0077] Similarly, the local feature of B is represented as (the first local feature of image B) And the first local characterization of A Input the attention block on the right to obtain the attention pooling features of image B for image A. Specifically, by Multiply by the matrix W k , W v Get the Key vector K B and Value vector V B ,Will Multiply by matrix W q Get the Query vector Q A , and the obtained Key vector K A 、Value vector V A and Query vector Q B (corresponding to K, V and Q in the right attention block respectively) is input into the multi-head attention layer of the right attention block for processing to obtain the attention pooling features of image B for image A, and then processed by other layers of the right attention block to obtain the local feature representation of image B based on the cross-attention mechanism (which can be called the second local feature of image B).
[0078] As an example, Figure 2 The output of the left multi-head attention layer and the output of one head in the right multi-head attention layer can be expressed as the following equation (1):
[0079]
[0080] Here, d represents the scaling factor.
[0081] As an example, It can represent the first local feature representation of A with embedded position information, The first local feature representation of B in which the position information is embedded can be represented.
[0082] As an example, the local features of the face image may be position-encoded based on a sine function and a cosine function to obtain the local features of the face image embedded with position information.
[0083] The acquisition of local features of a face image in which position information is embedded by embedding position information can be achieved by using any position encoding method in the prior art.
[0084] As an example, the local feature representation of a face image with embedded position information can be expressed as:
[0085] h k =W v v k +W p p k
[0086] Among them, v k p k Respectively represent the local feature elements and position embedding elements of the face image, k = 1, 2, ..., 25, W v , W p They represent the weights corresponding to the local feature elements and the weights corresponding to the position embedding elements respectively.
[0087] As another example, the first local feature of the face image input to the multi-head attention block may also be a local feature of the face that is not position-encoded or position-embedded. That is, the local feature input to the multi-head attention block may be {v 1 ,v 2 ,…,v 25},v i ∈R C As an example, the second local feature of the first face image can be obtained based on the attention pooling feature of the first face image for the second face image (i.e., the output of the left attention block). The second local feature of the second face image can be obtained based on the attention pooling feature of the acquired second face image for the first face image (i.e., the output of the right attention block).
[0088] Specifically, taking the multi-head attention block on the left as an example, after obtaining the attention pooling features of image A for image B through the multi-head attention layer, the second local features of image A are finally output through processing by the subsequent layers of the multi-head attention block.
[0089] As an example, the parameters of the left attention block and the parameters of the right attention block can be the same or different.
[0090] Although Figure 2 Two multi-head attention blocks are shown, but one multi-head attention block can also be used to perform attention pooling on the first face image and the second face image respectively.
[0091] As an example, a multi-head attention block can be used to obtain the attention pooling features of image A and the attention pooling features of image B. For example, the multi-head attention block is used to first obtain the attention pooling features of image A for image B, and then obtain the attention pooling features of image B for image A.
[0092] The above describes a process of using a multi-head attention mechanism to respectively obtain the first attention pooling features of the first face image for the second face image and the second attention pooling features of the second face image for the first face image based on the local features of the first face image and the local features of the second face image.
[0093] After obtaining the attention pooling features of the face image, the first global features of the face image can be further obtained.
[0094] As an example, the first global feature of image A can be obtained by inputting the second local feature of image A into the fully connected layer. Since the second local feature of image A is obtained based on the cross attention mechanism, the first global feature of image A reflects the correlation between image A and image B.
[0095] Similarly, the first global feature of image B is obtained by inputting the second local feature of image B into the fully connected layer. Since the second local feature of image B is obtained based on the cross attention mechanism, the first global feature of image B reflects the correlation between image A and image B.
[0096] return Figure 1 In step S102, a final global feature of the first face image is extracted based on the first global feature and the second global feature of the first face image.
[0097] As an example, the final global feature of the first face image may be obtained by cascading the first global feature and the second global feature of the first face image.
[0098] As an example, the second global feature of the first facial image can be obtained based on the first local feature of the first facial image, that is, the second global feature of the first facial image is obtained based on the first local feature of the first facial image, and is independent of the second facial image. This is different from the first global feature of the first facial image described above, as described above, the first global feature of the first facial image is related to the second facial image.
[0099] In step S103, a final global feature of the second facial image is extracted based on the first global feature and the second global feature of the second facial image.
[0100] As an example, the final global feature of the second facial image may be obtained by concatenating the first global feature and the second global feature of the second facial image.
[0101] As an example, the second global feature of the second facial image can be obtained based on the first local feature of the second facial image, that is, the second global feature of the second facial image is obtained based on the first local feature of the second facial image, and is independent of the first facial image. This is different from the first global feature of the second facial image described above, as described above, the first global feature of the second facial image is related to the second facial image.
[0102] As an example, step S102 and step S103 may be performed sequentially, in parallel or in reverse. In step S104, the first face image and the second face image are recognized based on the final global features of the first face image and the final global features of the second face image.
[0103] As an example, it may be possible to identify whether the first facial image and the second facial image are from the same identity based on the final global features of the first facial image and the final global features of the second facial image according to a preset rule.
[0104] Figure 3 A schematic diagram of a method for performing face recognition according to an embodiment of the present disclosure is shown.
[0105] Reference Figure 3 For the convenience of description, the following Figure 3 The first face image on the upper left side and the second face image on the lower left side are referred to as a first face image (or face image A) and a second face image (or face image B).
[0106] First, the first local features of the first face image and the second image can be extracted by, for example, a convolutional network. Figure 3 Although it is shown that the first local features of the first face image and the first local features of the second face image are respectively obtained through two identical networks, the first local features of the first face and the first local features of the second face may also be respectively obtained through the same network.
[0107] Then, the first local feature of the first face image can be input into the fully connected layer FC to obtain the second global feature g of the first face image. A .
[0108] A feature rearrangement process may be performed on the local features of the first face image and a position embedding operation may be performed to obtain a first local feature representation of the first face image with embedded position information, and then a second local feature representation of the first face image may be obtained based on a cross attention mechanism. The specific process is similar to the above process of obtaining the second local feature, and will not be repeated here.
[0109] The second local feature of the first face image is input into the fully connected layer FC to obtain the first global feature of the first face image.
[0110] The final global feature of the first face image is obtained by performing a cascade operation on the first global feature and the second global feature of the first face image using a cascade layer.
[0111] Reference above Figure 3 The process of obtaining the final global features of the first face image is described.
[0112] Figure 3 The process of obtaining the final global features of the second face image is similar to the process of obtaining the global features of the first face image, and will not be repeated here.
[0113] After the final global features of the first face image and the final global features of the second face are acquired, it can be determined whether the first face image and the second face image are of the same identity based on the final global features.
[0114] The relevant parameters of the network that performs the above-mentioned face recognition method can be jointly trained by utilizing the binary entropy loss function and the additional angular margin loss function.
[0115] Specifically, the elements in the final global features of the image pair used for training can be multiplied element-wise and input into the linear layer to make a binary prediction to determine whether the image pair is from the same identity. The binary entropy loss function can be expressed as the following equation 2:
[0116]
[0117] Among them, j represents the sample pair number, N represents the number of image pairs in the small batch training sample, l j is the true label indicating whether the image pair belongs to the same identity, l j =1 indicates a positive image pair, l j= 0 means negative image pair, s j The output of the linear layer represents the predicted probability.
[0118] The additional angular margin loss function shown in equation (3) below can be used for identity classification:
[0119]
[0120] Where 2N is the number of image pairs in the mini-batch training sample, θ is the angle between the feature and the corresponding weight, s is the size factor, m is the threshold factor, k represents the sample number, and y k Indicates the true value sample number.
[0121] The entire network can be trained end-to-end using the following function:
[0122] min(αL 1 +L 2 )
[0123] Among them, α is the balance between the two L 1 Function and L 2 The coefficient of the function can be, for example, α=10.
[0124] According to the examples disclosed herein, when performing face recognition, there is no need for a complexly designed face alignment module, that is, there is no need to align face pairs, and the local correspondence between face image pairs can be potentially understood based on the cross-attention mechanism.
[0125] Figure 4 is a diagram showing visualization responses of a face image based on a Baseline face recognition method, a self-attention face recognition method, and a face recognition method according to an embodiment of the present disclosure.
[0126] Reference Figure 4 , the first row shows the feature response based on the Baseline, the second row shows the feature response based on self-attention, and the last row is the feature response based on the cross-attention of the present disclosure. Compared with the first and second rows, the method of the present disclosure will have a higher feature response on the most similar face part of the compared face image pairs. Specifically, taking the second pair of face images on the left as an example, there is a higher response around the eyes, which means that the features around the eyes are more similar. By extracting and comparing features from these salient areas, it is possible to determine whether faces with different expressions or postures belong to the same identity. For images of different identities, there are also higher responses in similar facial areas, so different identities can be distinguished, thereby improving the accuracy of face recognition. In contrast, the visualization responses of face images based on other face recognition methods do not show such correspondence.
[0127] In fact, according to an embodiment of the present disclosure, based on the query vector (or the first local feature of the comparison image) of the comparison image (e.g., image B) to calculate the pooled features of the face image (e.g., image A), the query vector of the comparison image (e.g., image B) can guide the calculation of the attention weight to focus on the feature area that is most similar to the comparison image pair. For image pairs of the same person but different postures, illumination or ages, the feature response of the most similar facial parts will be higher. For image pairs of different identities, emphasizing the comparison between similar features allows for more accurate recognition.
[0128] Even for images with small similarity, the features in the facial region of image B will be more similar to the features in the facial region of image A than the features from the background of image A, which will result in a higher response of the features in the entire facial region, that is, more attention can be paid to the comparison between facial regions, excluding the influence of the remaining background information.
[0129] Reference above Figures 1 to 4 The face recognition method according to the embodiment of the present disclosure is described. Figure 5 A face recognition device according to an embodiment of the present disclosure is described.
[0130] Those skilled in the art should understand that the terms used hereinafter have the same or similar meanings as the corresponding terms above.
[0131] Figure 5 is a block diagram showing a face recognition apparatus according to an embodiment of the present disclosure.
[0132] Reference Figure 5 , the face recognition device 500 may include a first global feature acquisition module 501, a final global feature acquisition module 502, and a recognition module 503. Those skilled in the art should understand that the face recognition device 500 may additionally include other components, at least one component of the face recognition device 500 may be combined into one component or one component may be split into multiple components, and the components obtained after splitting or combining can all realize the functions of the components before splitting or combining.
[0133] As an example, the first global feature acquisition module 501 may be configured to respectively acquire first global features of the first facial image and first global features of the second facial image based on local features of the first facial image and local features of the second facial image.
[0134] As an example, the first global feature acquisition module 501 may include: a first global feature acquisition module for a first facial image (not shown), configured to acquire the first global features of the first facial image; and a second global feature acquisition module for a second facial image (not shown), configured to acquire the first global features of the second facial image.
[0135] As an example, the final global feature acquisition module 502 can be configured to: acquire the final global features of the first facial image based on the first global features and the second global features of the first facial image, and acquire the final global features of the second facial image based on the first global features and the second global features of the second facial image, wherein the second global features of the first facial image are acquired based on the local features of the first facial image, and the second global features of the second facial image are acquired based on the local features of the second facial image.
[0136] As an example, the final global feature acquisition module 502 may include a first facial image cascade layer (not shown), configured to obtain the final global features of the first facial image based on the first global features and the second global features of the first facial image; and a second facial image cascade layer (not shown), configured to obtain the final global features of the second facial image based on the first global features and the second global features of the second facial image.
[0137] As an example, the first global feature acquisition module 501 can be configured to: perform attention pooling processing based on local features of the first face image and local features of the second face image to obtain first global features of the first face image and first global features of the second face image, respectively.
[0138] As an example, the first global feature acquisition module 501 may include a first attention pooling module (not shown), which is configured to perform attention pooling processing on local features of the first face image using a cross-attention mechanism to obtain first attention pooling features of the first face image for the second face image; a second attention pooling module (not shown), which is configured to perform attention pooling processing on local features of the second face image based on the cross-attention mechanism to obtain second attention pooling features of the second face image for the first face image.
[0139] As an example, the face recognition device 500 may also include a position information embedding module (not shown), which is configured to: embed position information of local features of the first face image to obtain local features of the first face image with embedded position information; and embed position information of local features of the second face image to obtain local features of the second face image with embedded position information.
[0140] As an example, the face recognition device 500 may further include a feature rearrangement module (not shown) configured to rearrange the first local features of the face image, for example, rearrange the local feature map with a size of 5×5 into a local feature map with a size of 1×25.
[0141] As an example, the first global feature acquisition module 501 may be configured to perform attention pooling processing on the local features of the first face image with embedded position information and the local features of the second face image with embedded position information.
[0142] As an example, the first global feature acquisition module 501 may include a cross-attention module (not shown), which is configured to: multiply the local features of the second facial image by a first query matrix corresponding to the query to obtain a first query (Query) vector, multiply the local features of the first facial image by a first key matrix corresponding to the key (KEY) to obtain a first key vector, multiply the local features of the first facial image by a first value matrix corresponding to the value (Value) to obtain a first value vector, and calculate the attention pooling features of the first facial image for the second facial image based on the obtained first query vector, the first key vector and the first value vector; multiply the local features of the first facial image by a second query matrix corresponding to the query to obtain a second query vector, multiply the local features of the second facial image by a second key matrix corresponding to the key to obtain a second key vector, multiply the local features of the second facial image by a second value matrix corresponding to the value (Value) to obtain a second value vector, and calculate the attention pooling features of the second facial image for the first facial image based on the obtained second query vector, the second key vector and the second value vector.
[0143] As an example, the cross-attention module may include a first cross-attention module, configured to obtain attention pooling features of the first face image for the second face image; and a second cross-attention module, configured to obtain attention pooling features of the second face image for the first face image.
[0144] As an example, the cross-attention module may include a multi-head attention layer, configured to obtain attention pooling features of the first face image for the second face image based on a first local feature of the first face image and a first local feature of the second face image; and to obtain attention pooling features of the second face image for the first face image based on the first local feature of the first face image and the first local feature of the second face image.
[0145] As an example, the cross attention module may also include residual connections and layer normalization (Add&Norm) layers, and feed forward (Feed Forward) layers. Through the residual connections and layer normalization (Add&Norm) layers, and feed forward (Feed Forward) layers, the second local features of the first face image can be obtained from the attention pooling features of the first face image for the second face image, and the second local features of the second face image can be obtained from the attention pooling features of the second face image for the first face image.
[0146] As an example, the first global feature acquisition module may also include a fully connected layer (not shown), which is configured to acquire the first global feature of the first facial image based on the second local feature of the first facial image; and acquire the first global feature of the second facial image based on the second local feature of the second facial image.
[0147] As an example, the face recognition device 500 may also include a first local feature acquisition module (not shown), which is configured to acquire the first local feature of the first face image based on the first face image, and acquire the first local feature of the second face image based on the second face image.
[0148] As an example, the face recognition device 500 may further include a second global feature acquisition module, which is configured to: acquire a second global feature of the first face image based on the first local feature of the first face image, and acquire a second global feature of the second face image based on the first local feature of the second face image. As an example, the second global feature acquisition module may be a fully connected layer.
[0149] According to an embodiment of the present disclosure, a computer-readable storage medium storing a computer program is provided, wherein when the computer program is executed by a processor, the face recognition method as described above is implemented.
[0150] According to an embodiment of the present disclosure, a data storage device is provided, wherein the device comprises: a processor; and a memory storing a computer program, and when the computer program is executed by the processor, the face recognition method as described above is implemented.
[0151] Although the present disclosure includes specific examples, it will be understood by those skilled in the art that various changes in form and detail may be made without departing from the spirit and scope of the claims and their equivalents. The examples disclosed herein are to be considered in a descriptive sense and not for purposes of limitation. The description of features or aspects in each example will be considered applicable to similar features or aspects in other examples. Suitable results may be obtained if the described techniques are performed in a different order, and / or if the described systems, structures, devices, or circuits are combined in a different manner and / or replaced or supplemented by other components or their equivalents. Therefore, the scope of the disclosure is not limited by the detailed description, but by the claims and their equivalents, and all changes within the scope of the claims and their equivalents will be considered to be included in the present disclosure.
Claims
1. A face recognition method, the method include: Based on the local features of the first facial image and the local features of the second facial image, respectively obtain a first global feature of the first facial image and a first global feature of the second facial image; Acquire a final global feature of the first facial image based on the first global feature and the second global feature of the first facial image; Acquire a final global feature of the second facial image based on the first global feature and the second global feature of the second facial image; recognizing the first face image and the second face image based on the final global feature of the first face image and the final global feature of the second face image, The second global feature of the first face image is obtained based on the local feature of the first face image, and the second global feature of the second face image is obtained based on the local feature of the second face image. The step of respectively obtaining the first global feature of the first face image and the first global feature of the second face image based on the local features of the first face image and the local features of the second face image comprises: performing attention pooling processing based on the local features of the first face image and the local features of the second face image to respectively obtain the first global feature of the first face image and the first global feature of the second face image, and The step of performing attention pooling processing based on the local features of the first face image and the local features of the second face image to respectively obtain the first global features of the first face image and the first global features of the second face image includes: Based on the local features of the first face image and the local features of the second face image, a multi-head attention mechanism is used to respectively obtain the first attention pooling features of the first face image for the second face image and the second attention pooling features of the second face image for the first face image. Based on the first attention pooling feature, a first global feature of the first face image is obtained, Based on the second attention pooling feature, a first global feature of the second face image is obtained.
2. The method according to claim 1, in, The local features of the first facial image are local features of the first facial image embedded with position information; The local features of the second facial image are local features of the second facial image embedded with position information.
3. The method according to claim 1, in, Based on the local features of the first face image and the local features of the second face image, the steps of respectively obtaining the first attention pooling features of the first face image for the second face image and the second attention pooling features of the second face image for the first face image by using a multi-head attention mechanism include: Multiplying the local features of the second facial image by a first query matrix corresponding to a query (Query) to obtain a first query vector, multiplying the local features of the first facial image by a first key matrix corresponding to a key (KEY) to obtain a first key vector, multiplying the local features of the first facial image by a first value matrix corresponding to a value (Value) to obtain a first value vector, and obtaining an attention pooling feature of the first facial image for the second facial image based on the obtained first query vector, the first key vector, and the first value vector; and Multiply the local features of the first face image by the second query matrix corresponding to the query to obtain a second query vector, multiply the local features of the second face image by the second key matrix corresponding to the key to obtain a second key vector, multiply the local features of the second face image by the second value matrix corresponding to the value (Value) to obtain a second value vector, and obtain the attention pooling features of the second face image based on the obtained second query vector, the second key vector and the second value vector.
4. The method according to claim 1, in, The step of respectively acquiring the first global feature of the first face image and the first global feature of the second face image comprises: respectively acquiring the first global feature of the first face image and the first global feature of the second face image using the same network or different networks.
5. A face recognition device, the device include: A first global feature acquisition module: configured to acquire first global features of the first face image and first global features of the second face image respectively based on local features of the first face image and local features of the second face image; A final global feature acquisition module: configured to acquire the final global feature of the first face image based on the first global feature and the second global feature of the first face image, and to acquire the final global feature of the second face image based on the first global feature and the second global feature of the second face image; A recognition module: configured to recognize the first face image and the second face image based on the final global features of the first face image and the final global features of the second face image, The second global feature of the first face image is obtained based on the local feature of the first face image, and the second global feature of the second face image is obtained based on the local feature of the second face image. The first global feature acquisition module is configured to: perform attention pooling processing based on the local features of the first face image and the local features of the second face image to obtain the first global feature of the first face image and the first global feature of the second face image respectively, and Wherein, the first global feature acquisition module is configured as follows: Based on the local features of the first face image and the local features of the second face image, a multi-head attention mechanism is used to respectively obtain a first attention pooling feature of the first face image for the second face image and a second attention pooling feature of the second face image for the first face image; Based on the first attention pooling feature, obtaining a first global feature of the first face image; Based on the second attention pooling feature, a first global feature of the second face image is obtained.
6. The device as claimed in claim 5, in, The local features of the first facial image are the local features of the first facial image embedded with position information; the local features of the second facial image are the local features of the second facial image embedded with position information.
7. The device according to claim 5, in, The first global feature acquisition module includes a cross attention module configured as follows: Multiplying the local features of the second face image by a first query matrix corresponding to the query to obtain a first query (Query) vector, multiplying the local features of the first face image by a first key matrix corresponding to the key (KEY) to obtain a first key vector, multiplying the local features of the first face image by a first value matrix corresponding to the value (Value) to obtain a first value vector, and obtaining an attention pooling feature of the first face image for the second face image based on the obtained first query vector, the first key vector, and the first value vector, and Multiply the local features of the first facial image by the second query matrix corresponding to the query to obtain a second query vector, multiply the local features of the second facial image by the second key matrix corresponding to the key to obtain a second key vector, multiply the local features of the second facial image by the second value matrix corresponding to the value (Value) to obtain a second value vector, and obtain the attention pooling features of the second facial image for the first facial image based on the obtained second query vector, the second key vector and the second value vector.
8. The device according to claim 5, in, The first global feature acquisition module includes: A first global feature acquisition module for a first facial image, configured to acquire a first global feature of the first facial image; The second facial image first global feature acquisition module is configured to acquire the first global feature of the second facial image.
9. A computer-readable storage medium storing a computer program, in, When the computer program is executed by a processor, the face recognition method according to any one of claims 1 to 4 is implemented.
10. A data storage device, in, The device comprises: a processor; and a memory storing a computer program. When the computer program is executed by the processor, the face recognition method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Human face similarity degree matching method and device
CN101510257A
Attention-based sequence transduction neural networks
CN110192206A
Target tracking method and related device
CN112037254A
