Face recognition method, device, electronic device and storage medium
By slicing the face image and extracting feature information using the coding layer and multi-head context attention mechanism of the pre-trained model, the problem of large amount of parameters and high computational complexity of convolutional neural network is solved, and the efficiency and accuracy of face recognition are improved sex.
Patent Information
- Application Number
- CN202111587227.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-23
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2041-12-23
AI Technical Summary
In the existing face recognition technology, the large number of parameters and high computational complexity of the convolutional neural network affect the efficiency of face recognition.
By slicing face images, using the encoding layer and multi-head context attention mechanism in the pre-trained face recognition model, the internal and external correlation information of the sliced image is extracted, the image feature information is generated, and the classification network is recognized and reduced. The vector dimension of the model.
It improves the accuracy and efficiency of face recognition, avoids the local perception and dependence defects of convolutional neural networks, and reduces the complexity and parameter amount of face feature extraction.
Smart Images

Figure CN114267064B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence, and in particular to a face recognition method, device, electronic device and computer-readable storage medium. Background Art
[0002] Face recognition, also known as face identification system, refers to computer technology that uses analysis and comparison of facial visual feature information to authenticate identity. With the development of face recognition technology, it has been widely used in various scenarios in people's lives, such as community security, convenient payment and other scenarios.
[0003] At present, face recognition is usually implemented based on neural network learning methods, that is, the performance and speed of face recognition are enhanced by optimizing the way of extracting facial features. Convolutional neural networks are the main means of extracting facial features. Since the receptive field of convolutional neural networks is determined by the size of the convolution kernel and the number of filter channels, it is necessary to increase the size of the convolution kernel or the number of filter channels to ensure the accuracy of facial feature extraction. However, this will greatly increase the number of model parameters and the complexity of model calculation, which will affect the efficiency of face recognition. Summary of the invention
[0004] In order to solve the above technical problems, the present invention provides a face recognition method, device, electronic device and computer-readable storage medium, which can improve the efficiency of face recognition.
[0005] In a first aspect, the present invention provides a face recognition method, comprising:
[0006] Acquire a face image to be recognized, and slice the face image to obtain a plurality of slice images;
[0007] Encoding each of the slice images using an encoding layer in a pre-trained face recognition model to obtain a plurality of encoding vectors;
[0008] Using the multi-head context attention mechanism in the face recognition model to identify the internal correlation information and the external correlation information of each of the encoding vectors, and generating image feature information of each of the slice images according to the internal correlation information and the external correlation information;
[0009] According to the image feature information, the facial image is recognized using a classification network in the facial recognition model to obtain a recognition result of the facial image.
[0010] In a possible implementation manner of the first aspect, slicing the face image to obtain a plurality of slice images includes:
[0011] The face region in the face image is detected, and the face region is segmented according to a preset slice size to obtain a plurality of slice images.
[0012] In a possible implementation of the first aspect, the encoding layer in the pre-trained face recognition model is used to encode the position vector of each slice image to obtain multiple encoding vectors, including:
[0013] Using the vector conversion algorithm in the coding layer to encode vector information of each slice image, to obtain a plurality of coded image vectors;
[0014] Each of the coded image vectors is position-coded using a position coding algorithm in the coding layer to obtain a plurality of coding vectors.
[0015] In a possible implementation manner of the first aspect, the identifying the internal association information and the external association information of each of the encoding vectors by using the multi-head context attention mechanism in the face recognition model includes:
[0016] Mapping each of the encoding vectors using preset branch matrix parameters to obtain a mapping matrix;
[0017] Splicing each of the mapping matrices with its corresponding encoding vector to obtain a spliced mapping graph, and extracting internal correlation information of each of the encoding vectors according to the spliced mapping graph;
[0018] An inner product operation is performed on the concatenated mapping graph and the mapping matrix to obtain the mapping matrix graph, and external correlation information of each of the encoding vectors is extracted based on the mapping matrix graph.
[0019] In a possible implementation manner of the first aspect, recognizing the face image by using a classification network in the face recognition model according to the image feature information includes:
[0020] Standardizing the image feature information using a standard layer in the classification network to obtain standard feature information;
[0021] Activating the standard feature information using an activation function in the classification network to obtain activated feature information;
[0022] According to the activated feature information, the image category of the face image is calculated using the fully connected layer in the classification network, and according to the image category, the recognition result of the face image is output using the output layer in the classification network.
[0023] In a possible implementation manner of the first aspect, the using a standard layer in the classification network to standardize the image feature information to obtain standard feature information includes:
[0024] The image feature information is standardized using the following formula:
[0025]
[0026] Among them, P′ i Indicates standard feature information, P i represents the image feature information, μ represents the mean of the image feature information, σ 2 Represents the variance of image feature information, and ε is a bias term set to prevent the denominator from being zero.
[0027] In a possible implementation manner of the first aspect, the method further includes: using a preset loss function to supervise the learning ability of the face recognition model during the pre-training process, wherein the preset loss function includes:
[0028]
[0029] Among them, L represents the training loss value of the face recognition model, S n represents negative samples, S p represents positive samples, L represents the number of negative samples, K represents the number of positive samples, γ represents the learning rate, and m represents the sample distance parameter.
[0030] In a second aspect, the present invention provides a face recognition device, the device comprising:
[0031] A face image slicing module is used to obtain a face image to be identified, and slice the face image to obtain a plurality of slice images;
[0032] An image encoding module, used for encoding each of the slice images using an encoding layer in a pre-trained face recognition model to obtain a plurality of encoding vectors;
[0033] A feature information generation module, used to identify internal correlation information and external correlation information of each of the encoding vectors by using the multi-head context attention mechanism in the face recognition model, and generate image feature information of each of the slice images according to the internal correlation information and the external correlation information;
[0034] The face image recognition module is used to recognize the face image according to the image feature information and utilize the classification network in the face recognition model to obtain the recognition result of the face image.
[0035] In a third aspect, the present invention provides an electronic device, comprising:
[0036] at least one processor; and a memory communicatively coupled to the at least one processor;
[0037] The memory stores a computer program executable by the at least one processor, so that the at least one processor can execute the face recognition method as described in any one of the first aspects above.
[0038] In a fourth aspect, the present invention provides 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 in any one of the first aspects above is implemented.
[0039] Compared with the prior art, the technical principle and beneficial effects of this solution are:
[0040] This solution obtains multiple slice images by slicing a face image to achieve face segmentation of the face image, identify the information features of each face area, and ensure the accuracy of face recognition; secondly, the embodiment of the present invention uses the encoding layer in the pre-trained face recognition model to encode each of the slice images to obtain multiple encoding vectors to achieve long-distance feature dependency attention on each face area in the face image, enhance the face feature receptive field of the face image, and use the multi-head context attention mechanism in the face recognition model to identify the internal correlation information and external correlation information of each encoding vector to generate image feature information of each slice image, which can avoid the defects of local perception and dependence through convolutional neural networks in the prior art, greatly reduce the complexity and parameter amount of face feature extraction, and improve the performance and efficiency of face recognition; further, the embodiment of the present invention uses the classification network in the face recognition model to identify the face image according to the image feature information, so as to summarize the information of the face image into the head of the model classification network for recognition, reduce the vector dimension of the model, and further improve the efficiency of face recognition. Therefore, the face recognition method, device, electronic device and storage medium proposed in the embodiments of the present invention can improve the efficiency of face recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0043] Figure 1 A schematic diagram of a flow chart of a face recognition method provided by an embodiment of the present invention;
[0044] Figure 2 In one embodiment of the present invention Figure 1 A flowchart of one step of a face recognition method is provided;
[0045] Figure 3 A schematic diagram of a network structure of a multi-head attention mechanism in a face recognition method provided by an embodiment of the present invention;
[0046] Figure 4 A schematic diagram of a module of a face recognition device provided by an embodiment of the present invention;
[0047] Figure 5 A schematic diagram of the internal structure of an electronic device for implementing a face recognition method provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0049] The embodiment of the present invention provides a face recognition method, and the execution subject of the face recognition method includes but is not limited to at least one of the electronic devices such as a server and a terminal that can be configured to execute the method provided by the embodiment of the present invention. In other words, the face recognition method can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0050] See also Figure 1 FIG. 1 is a flow chart of a face recognition method provided by an embodiment of the present invention. Figure 1 The face recognition methods described in include:
[0051] S1. Acquire a face image to be recognized, and slice the face image to obtain a plurality of slice images.
[0052] In an embodiment of the present invention, the facial image to be identified refers to a picture that requires facial identity verification, which is generated based on different business scenarios. For example, in a community security scenario, the facial image to be identified includes a facial picture of a person entering the community gate; in an airport security scenario, the facial image to be identified includes a facial picture of a security check. Optionally, in an embodiment of the present invention, the facial image to be identified is acquired through a high-definition camera.
[0053] It should be understood that there may be different facial regions in the facial image, and different facial regions may contain different facial information. Therefore, the embodiment of the present invention slices the facial image to divide the facial image into multiple different facial regions, thereby identifying the information features of each facial region and ensuring the accuracy of facial recognition.
[0054] As an embodiment of the present invention, slicing the face image to obtain a plurality of slice images includes: detecting a face region in the face image, segmenting the face region according to a preset slice size, and obtaining a plurality of slice images. The face region refers to a face image that does not contain a background region in the face image, which is detected by a target detection network, such as a YOLO3 network, and the preset slice size is set based on the size of different face regions. For example, if the size of the face region is 16*16, the preset slice size can be set to 4*4, that is, the face region is divided into 16 4*4 slice images.
[0055] S2. Encode each of the slice images using the encoding layer in the pre-trained face recognition model to obtain multiple encoding vectors.
[0056] In an embodiment of the present invention, the face recognition model is constructed through a VIT network structure for face recognition, which includes a coding layer, a multi-head context attention mechanism and a classification network, wherein the coding layer is used to perform position vector encoding on the slice image to realize the vectorized form and position information of the slice image, and ensure the context information recognition premise of the slice image; the multi-head context attention mechanism is used to extract internal correlation information and external correlation information of the slice image to improve the image feature recognition accuracy of the slice image; the classification network is used to detect the image category of the face image and obtain the recognition result of the face image.
[0057] It should be noted that, in the embodiment of the present invention, when training the face recognition model, a preset loss function is used to supervise the learning ability of the face recognition model to ensure the recognition ability of the pre-trained face recognition model. The preset loss function includes:
[0058]
[0059] Among them, L represents the training loss value of the face recognition model, S n represents negative samples, S p represents positive samples, L represents the number of negative samples, K represents the number of positive samples, γ represents the learning rate, and m represents the sample distance parameter, which is used to limit the minimum distance between samples.
[0060] Furthermore, the embodiment of the present invention utilizes the encoding layer in the pre-trained face recognition model to encode each of the slice images, so as to achieve long-distance feature-dependent attention to each face region in the face image, enhance the face feature receptive field of the face image, and ensure the accuracy of face recognition.
[0061] As an embodiment of the present invention, the encoding layer in the pre-trained face recognition model is used to encode each of the slice images to obtain multiple encoding vectors, including: using the vector conversion algorithm in the encoding layer to encode the vector information of each of the slice images to obtain multiple encoding image vectors, and using the position encoding algorithm in the encoding layer to position encode each of the encoding image vectors to obtain multiple encoding vectors.
[0062] The vector conversion algorithm includes a matlab algorithm, which is used to pull each of the slice images into a one-dimensional vector, and then obtain a coded image vector of the image content information through full connection to realize image information recognition and extraction of subsequent slice images. The position encoding of the coded image vector is used to mark the position sequence information of each coded image vector to make up for the lack of position information of subsequent slice images in the feature extraction process, and ensure the accuracy of feature extraction of slice images.
[0063] In the present invention, the position encoding algorithm is different from the encoding method using the PE algorithm in natural language processing. Instead, at the initial stage, learnable initialization encoding parameters are set during pre-training of the encoding layer. As the training is iterated, the initialization encoding parameters are continuously updated to reach stable target encoding parameters, so as to realize the position encoding of the encoded image vector through the target encoding parameters.
[0064] S3. Utilize the multi-head contextual attention mechanism in the face recognition model to identify the internal correlation information and external correlation information of each of the encoding vectors, and generate image feature information of each of the slice images based on the internal correlation information and the external correlation information.
[0065] In an embodiment of the present invention, the multi-head contextual attention mechanism compresses the encoding vector into a latent space representation to identify the association information of the encoding vector and obtain the image feature information of the slice image. The internal association information refers to the contextual semantic information contained in the encoding vector, and the external association information refers to the interactive semantic information between the encoding vectors.
[0066] Furthermore, the embodiment of the present invention utilizes the multi-head contextual attention mechanism in the face recognition model to identify the internal correlation information and external correlation information of each of the encoding vectors to generate image feature information of each of the slice images, thereby greatly reducing the complexity and parameter amount of face feature extraction and improving the performance and efficiency of face recognition.
[0067] As an embodiment of the present invention, see Figure 2 As shown, the method of using the multi-head context attention mechanism in the face recognition model to identify the internal correlation information and external correlation information of each encoding vector includes:
[0068] S201, mapping each of the encoding vectors using preset branch matrix parameters to obtain a mapping matrix;
[0069] S202, concatenating each of the mapping matrices and its corresponding encoding vector to obtain a concatenated mapping graph, and extracting internal correlation information of each of the encoding vectors according to the concatenated mapping graph;
[0070] S203, performing an inner product operation on the concatenated mapping graph and the mapping matrix to obtain the mapping matrix graph, and extracting external correlation information of each of the encoding vectors according to the mapping matrix graph.
[0071] The preset branch matrix parameters include at least two dimensional parameters, such as W k and W v dimensional parameters, the mapping of the encoding vector is realized by the encoder of the multi-head context attention mechanism, that is, the encoder is used to transform the dimensional parameters of the encoding vector according to the branch matrix parameters respectively, and the splicing of the feature mapping vector and its corresponding encoding vector is realized by the splicing channel in the multi-head context attention mechanism, which is used to realize the information feature fusion of the feature mapping vector and the original image, and ensure the recognition accuracy of the internal contextual association information of the feature mapping vector. The internal association information is realized by convolution, and the extraction of the external association information is realized by matrix inner product association.
[0072] Furthermore, an embodiment of the present invention generates image feature information of each of the slice images based on the internal correlation information and the external correlation information, that is, the internal correlation information and the external correlation information are inner-product fused through the fully connected layer in the multi-head contextual attention mechanism as the image feature information of each of the slice images, so as to ensure the comprehensiveness of the semantic information acquisition of the encoding vector, thereby improving the accuracy of image feature extraction.
[0073] For more information on how the multi-head contextual attention mechanism works, see Figure 3 , which is a schematic diagram of the network structure of the multi-head contextual attention mechanism provided by an embodiment of the present invention, Figure 3 In the above example, X represents the encoding vector, Query represents the encoding vector, and W k and W v represents the preset branch matrix parameters, the key map and value map represent the k and W v The mapping matrix of the mapping, the KQ map represents the concatenated mapping map, the W θ and W δ represents the extraction parameter of the internal correlation information, A represents the extracted internal correlation information, the KQ map and the value map are connected to obtain the mapping matrix diagram, and Y represents the image feature information.
[0074] S4. According to the image feature information, the facial image is recognized using a classification network in the facial recognition model to obtain a recognition result of the facial image.
[0075] As an embodiment of the present invention, the step of recognizing the face image using a classification network in the face recognition model according to the image feature information includes:
[0076] Standardizing the image feature information using a standard layer in the classification network to obtain standard feature information;
[0077] Activating the standard feature information using an activation function in the classification network to obtain activated feature information;
[0078] According to the activated feature information, the image category of the face image is calculated using the fully connected layer in the classification network, and according to the image category, the recognition result of the face image is output using the output layer in the classification network.
[0079] Among them, the standardization of the image feature information is used to standardize the image feature information to obtain the head information in the image feature information, accelerate the convergence of the classification network, and improve the speed of subsequent information processing. The activation of the standard feature information is used to activate the standard feature information to ensure the premise of subsequent image category recognition and further improve the speed of subsequent information processing. The image category is used to characterize whether the face image is a correct face image, including 0 and 1, that is, when the image category is 0, it means that the face image is not a correct face image, and the face image recognition fails. When the image category is 1, it means that the face image is a correct face image, and the face image recognition is successful.
[0080] Furthermore, in an optional embodiment of the present invention, the image feature information is standardized using the following formula:
[0081]
[0082] Among them, P′ i Indicates standard feature information, P i represents the image feature information, μ represents the mean of the image feature information, σ 2 represents the variance of image feature information, and ε is a bias term set to prevent the denominator from being zero.
[0083] Furthermore, in an optional embodiment of the present invention, the activation function includes a relu function, and the image category of the face image is realized by an activation function in the fully connected layer, such as a softmax function.
[0084] It can be seen that the present solution obtains a plurality of slice images by slicing a face image to achieve face segmentation of the face image, identify the information features of each face region, and ensure the accuracy of face recognition; secondly, the embodiment of the present invention uses the encoding layer in the pre-trained face recognition model to encode each of the slice images to obtain a plurality of encoding vectors to achieve long-distance feature dependency attention on each face region in the face image, enhance the face feature receptive field of the face image, and use the multi-head context attention mechanism in the face recognition model to identify the internal correlation information and external correlation information of each encoding vector to generate image feature information of each slice image, which can avoid the defects of local perception and dependence of convolutional neural networks in the prior art, greatly reduce the complexity and parameter amount of face feature extraction, and improve the performance and efficiency of face recognition; further, the embodiment of the present invention uses the classification network in the face recognition model to identify the face image according to the image feature information, so as to summarize the information of the face image into the head of the model classification network for recognition, reduce the vector dimension of the model, and further improve the efficiency of face recognition. Therefore, a face recognition method proposed in an embodiment of the present invention can improve the efficiency of face recognition.
[0085] like Figure 4 , which is a functional module diagram of the face recognition device of the present invention.
[0086] The face recognition device 400 of the present invention can be installed in an electronic device. According to the functions to be implemented, the face recognition device can include a face image slicing module 401, an image encoding module 402, a feature information generation module 403 and a face image recognition model 404. The module of the present invention can also be called a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.
[0087] In the embodiment of the present invention, the functions of each module / unit are as follows:
[0088] The face image slicing module 401 is used to obtain a face image to be identified, and slice the face image to obtain a plurality of slice images;
[0089] The image encoding module 402 is used to encode each of the slice images using the encoding layer in the pre-trained face recognition model to obtain multiple encoding vectors;
[0090] The feature information generating module 403 is used to identify the internal correlation information and the external correlation information of each of the encoding vectors by using the multi-head context attention mechanism in the face recognition model, and generate the image feature information of each of the slice images according to the internal correlation information and the external correlation information;
[0091] The face image recognition module 404 is used to recognize the face image according to the image feature information using the classification network in the face recognition model to obtain the recognition result of the face image.
[0092] In detail, each module in the face recognition device 400 in the embodiment of the present invention is used in the same manner as described above. Figures 1 to 3 The face recognition method described in the invention has the same technical means and can produce the same technical effects, so I will not go into details here.
[0093] like Figure 5 FIG. 1 is a schematic diagram of the structure of an electronic device for implementing the face recognition method of the present invention.
[0094] The electronic device may include a processor 50 , a memory 51 , a communication bus 52 , and a communication interface 53 , and may also include a computer program stored in the memory 51 and executable on the processor 50 , such as a face recognition program.
[0095] In some embodiments, the processor 50 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 50 is the control core (ControlUnit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 51 (for example, executing a face recognition program, etc.), and calls data stored in the memory 51 to execute various functions of the electronic device and process data.
[0096] The memory 51 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, mobile hard disk, multimedia card, card-type memory (for example: SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 51 can be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 51 can also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Further, the memory 51 can also include both an internal storage unit of the electronic device and an external storage device. The memory 51 can not only be used to store application software and various types of data installed in the electronic device, such as the code of the face recognition program, etc., but also can be used to temporarily store data that has been output or is to be output.
[0097] The communication bus 52 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 51 and at least one processor 50, etc.
[0098] The communication interface 53 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), and optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.
[0099] Figure 5 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 5The structure shown does not constitute a limitation on the electronic device, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0100] For example, although not shown, the electronic device may also include a power source (such as a battery) for supplying power to various components. Preferably, the power source may be logically connected to the at least one processor 50 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include any components such as one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, etc. The electronic device may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0101] It should be understood that the embodiment is for illustrative purposes only and the scope of the patent invention is not limited to this structure.
[0102] The face recognition program stored in the memory 51 in the electronic device is a combination of multiple computer programs. When running in the processor 50, it can achieve:
[0103] Acquire a face image to be recognized, and slice the face image to obtain a plurality of slice images;
[0104] Encoding each of the slice images using an encoding layer in a pre-trained face recognition model to obtain a plurality of encoding vectors;
[0105] Using the multi-head context attention mechanism in the face recognition model to identify the internal correlation information and the external correlation information of each of the encoding vectors, and generating image feature information of each of the slice images according to the internal correlation information and the external correlation information;
[0106] According to the image feature information, the facial image is recognized using a classification network in the facial recognition model to obtain a recognition result of the facial image.
[0107] Specifically, the specific implementation method of the processor 50 for the above computer program can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.
[0108] Furthermore, if the module / unit integrated in the electronic device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).
[0109] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program can implement:
[0110] Acquire a face image to be recognized, and slice the face image to obtain a plurality of slice images;
[0111] Encoding each of the slice images using an encoding layer in a pre-trained face recognition model to obtain a plurality of encoding vectors;
[0112] Using the multi-head context attention mechanism in the face recognition model to identify the internal correlation information and the external correlation information of each of the encoding vectors, and generating image feature information of each of the slice images according to the internal correlation information and the external correlation information;
[0113] According to the image feature information, the facial image is recognized using a classification network in the facial recognition model to obtain a recognition result of the facial image.
[0114] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0115] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0116] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0117] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0118] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.
[0119] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0120] The above description is only a specific embodiment of the present invention, so that those skilled in the art can understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but should conform to the widest scope consistent with the principles and novel features invented herein.
Claims
1. A face recognition method, characterized in that: The method comprises: Acquire a face image to be recognized, and slice the face image to obtain a plurality of slice images; Encoding each of the slice images using an encoding layer in a pre-trained face recognition model to obtain a plurality of encoding vectors; The multi-head contextual attention mechanism in the face recognition model is used to identify the internal correlation information and external correlation information of each of the coding vectors, and generate the image feature information of each of the slice images according to the internal correlation information and the external correlation information; wherein the multi-head contextual attention mechanism is used to compress the coding vectors into a latent space representation to identify the correlation information of the coding vectors and obtain the image feature information of the slice images; the internal correlation information refers to the contextual semantic information contained in the coding vectors; the external correlation information refers to the interactive semantic information between the coding vectors; Standardizing the image feature information using a standard layer in a classification network in the face recognition model to obtain standard feature information; Activating the standard feature information using an activation function in the classification network to obtain activated feature information; According to the activated feature information, the image category of the face image is calculated using the fully connected layer in the classification network, and according to the image category, the recognition result of the face image is output using the output layer in the classification network.
2. The method according to claim 1, characterized in that: The step of slicing the face image to obtain a plurality of slice images includes: The face region in the face image is detected, and the face region is segmented according to a preset slice size to obtain a plurality of slice images.
3. The method according to claim 1, characterized in that The encoding layer in the pre-trained face recognition model is used to encode each slice image to obtain multiple encoding vectors, including: Using the vector conversion algorithm in the coding layer to encode vector information of each slice image, to obtain a plurality of coded image vectors; Each of the coded image vectors is position-coded using a position coding algorithm in the coding layer to obtain a plurality of coding vectors.
4. The method according to claim 1, characterized in that: The method of using the multi-head context attention mechanism in the face recognition model to identify the internal correlation information and the external correlation information of each of the encoding vectors includes: Mapping each of the encoding vectors using preset branch matrix parameters to obtain a mapping matrix; Splicing each of the mapping matrices with its corresponding encoding vector to obtain a spliced mapping graph, and extracting internal correlation information of each of the encoding vectors according to the spliced mapping graph; An inner product operation is performed on the concatenated mapping graph and the mapping matrix to obtain a mapping matrix graph, and external correlation information of each of the encoding vectors is extracted based on the mapping matrix graph.
5. The method according to claim 1, characterized in that The step of standardizing the image feature information by using a standard layer in a classification network in the face recognition model to obtain standard feature information includes: The image feature information is standardized using the following formula: in, Indicates standard feature information, Represents image feature information, Represents the mean of image feature information, Represents the variance of image feature information, Represents a random number.
6. The method according to claim 1, characterized in that The method further includes: using a preset loss function to supervise the learning ability of the face recognition model during the pre-training process, wherein the preset loss function includes: Among them, L represents the training loss value of the face recognition model, Sn represents the negative sample, Sp represents the positive sample, L represents the number of negative samples, and K represents the number of positive samples. represents the learning rate, and m represents the sample distance parameter.
7. A face recognition device, characterized in that: The device comprises: A face image slicing module is used to obtain a face image to be identified, and slice the face image to obtain a plurality of slice images; An image encoding module, used for encoding each of the slice images using an encoding layer in a pre-trained face recognition model to obtain a plurality of encoding vectors; A feature information generation module, used to identify the internal correlation information and external correlation information of each of the coding vectors by using the multi-head contextual attention mechanism in the face recognition model, and generate the image feature information of each of the slice images according to the internal correlation information and the external correlation information; wherein the multi-head contextual attention mechanism is used to compress the coding vectors into a latent space representation to identify the correlation information of the coding vectors and obtain the image feature information of the slice images; the internal correlation information refers to the contextual semantic information contained in the coding vectors; the external correlation information refers to the interactive semantic information between the coding vectors; The face image recognition module is used to standardize the image feature information using the standard layer in the classification network in the face recognition model to obtain standard feature information; activate the standard feature information using the activation function in the classification network to obtain activated feature information; calculate the image category of the face image using the fully connected layer in the classification network based on the activated feature information, and output the recognition result of the face image using the output layer in the classification network based on the image category.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the face recognition method as described in any one of claims 1 to 6.
9. A computer-readable storage medium storing 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.
