AI face-changing method and intelligent face-changing device
Through dense facial key point detection and feature fusion models, mixed facial features are generated and texture mapped, which solves the problem of high computing resources of existing AI face-changing technology and enables fast face-changing operations on low-configuration devices. It is suitable for in various scenarios.
Patent Information
- Application Number
- CN202410627740.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-05-21
AI Technical Summary
Existing AI face-changing technology requires high computing resources and is difficult to integrate into dedicated chips, limiting its use scenarios on mobile or low-configuration devices.
Use the face dense key point detection model to obtain multiple dense key points for three-dimensional face reconstruction, combine it with the feature fusion model to generate mixed facial features, and use the face-swap model for texture mapping to achieve pixel-level fusion and generate a face-swap image, which is applicable for devices with low computing resources.
It enables fast face-changing operations on mobile or low-configuration devices, improves the operability and applicability of the algorithm, and is suitable for a variety of usage scenarios.
Smart Images

Figure CN118212677B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an AI face-changing method and an intelligent face-changing device. Background Art
[0002] With the rapid development of deep learning and computer vision technology, especially the widespread application of Generative Adversarial Networks (GANs), AI face-changing technology has moved from the laboratory to the public, achieving accurate replacement of faces in facial images or videos. Existing AI face-changing technology usually relies on powerful computing platforms and complex post-production processes, and users often need to have certain technical knowledge and professional software operation capabilities.
[0003] Although some existing smart devices have face recognition and tracking functions, they do not have the ability to change faces in real time. Users need to import the collected video or image data into professional software running on the computer to complete the face-changing process. Since the face-changing calculation process of existing face-changing algorithms requires high computing resources, existing non-integrated solutions often cannot achieve real-time face-changing processing, especially on mobile or low-configuration devices.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0005] Existing face-changing algorithms require high computing resources and are difficult to integrate into dedicated chips, making them inconvenient to use on mobile or low-configuration devices, which limits their usage scenarios. Summary of the invention
[0006] The purpose of the present invention is to provide an AI face-changing method and an intelligent face-changing device to solve the technical problem that the face-changing algorithm in the prior art requires high computing resources and is difficult to integrate into a dedicated chip, which is not convenient for use on mobile or low-configuration devices and limits the use scenarios. The preferred technical solutions among the many technical solutions provided by the present invention can produce many technical effects as described below.
[0007] To achieve the above object, the present invention provides the following technical solutions:
[0008] The present invention provides an AI face-changing method, comprising the following steps: S10: obtaining an original face image, locating and extracting a face region in the original face image through a face detection model, and extracting features of the face region using a face feature model to obtain original face features; S20: based on the original face features, using a face dense key point detection model to obtain multiple dense key points in the face region; S30: inputting the multiple dense key points into a three-dimensional face model to perform three-dimensional face reconstruction to obtain target face features, and recombining the target face features and the original face features through a feature fusion model to generate mixed face features; S40: using a face-changing model to perform texture mapping on the mixed face features and the three-dimensional face model to obtain a three-dimensional face model after face-changing with color texture. The two-dimensional face image is fused into the original face image through pixel-level fusion to obtain a face-changing image; in the step S20, the face areas corresponding to the several dense key points are lips, nose, and eyes; a lip correction and repair operation is also performed, and the lip abnormality is corrected and repaired by calculating the lip shape difference loss value, specifically including: the original face image is subjected to 4 convolutions and LeakyRelu function operations for facial feature encoding, and then the features of the target face image after slicing are reorganized by 12 residual modules; the upper branches of the 12 residual modules extract the features of the first 6 low-level blocks to retain the features of the facial features, and after 2 convolutions and LeakyRelu function operations, multi-dimensional features and lip heat maps are obtained; by formula Calculate the loss of the predicted lip heat map and the sample lip heat map, where n represents the batch size during training, k is the number of each training sample in the batch, and t represents the number of steps in the current training process. represents the sample lip heat map, represents the predicted lip heat map obtained by the feature fusion model; the total loss is ,in Cosine loss of the feature vector representing the swapped face image and the target face image.
[0009] An intelligent face-changing device performs face-changing operations through the above-mentioned AI face-changing method, including an image and video acquisition module, an embedded AI processor and a deep learning module; the image and video acquisition module uses infrared and visible light dual-mode shooting to collect facial image information and / or facial video information; the deep learning module is used to store face-changing models; the embedded AI processor pre-loads the face-changing model, and when the image acquisition module obtains the face image, the AI processor will run the face detection model, the face feature model, the face dense key point detection model and the three-dimensional face model to construct the three-dimensional structural information of the face.
[0010] Preferably, it also includes an interface module and an interaction and control module; the interface module is a USB interface, which transmits facial image information and / or facial video information to the host machine through the USB protocol; the interaction and control module is used to preset face-changing targets, upload customized face-changing template photos, adjust face-changing parameters, and preview real-time face-changing effects.
[0011] Preferably, it also includes a memory module, a storage module, a power management module, and a heat dissipation module; the memory module is used to temporarily store image data and model parameters, and cache temporary data in face-changing calculations; the storage module is used to save user configurations, face template materials and system files; the power management module is used to perform power management of the intelligent face-changing device; the heat dissipation module is used to dissipate heat from the intelligent face-changing device.
[0012] Implementing one of the above technical solutions of the present invention has the following advantages or beneficial effects:
[0013] The present invention obtains multiple dense key points in the face area through a dense key point detection model of the face, thereby performing three-dimensional reconstruction of the face, and generates mixed face features through a feature fusion model. After processing, a face-changing image is obtained. The algorithm has strong operability, requires fewer hardware resources, and is easy to implement through a dedicated chip, so it can be integrated in various hardware devices to realize fast face-changing operations and is suitable for a variety of usage scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. It is obvious that the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0015] Figure 1 This is a flow chart of an AI face-changing method according to Embodiment 1 of the present invention;
[0016] Figure 2 2 is a schematic diagram of a neural network structure for performing lip correction and repair operations in the AI face-changing method according to the first embodiment of the present invention;
[0017] Figure 3 It is a structural diagram of the intelligent face-changing device according to the second embodiment of the present invention. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solutions and advantages of the present invention clearer, the various exemplary embodiments to be described below will refer to the corresponding drawings, which constitute a part of the exemplary embodiments, wherein various exemplary embodiments that may be used to implement the present invention are described. Unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation methods described in the following exemplary embodiments do not represent all implementation methods consistent with the present disclosure. It should be understood that they are only examples of processes, methods, devices, etc. that are consistent with some aspects of the present disclosure as detailed in the attached claims, and other embodiments may also be used, or the embodiments listed herein may be modified in structure and function without departing from the scope and essence of the present invention.
[0019] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", etc. indicate the orientation or positional relationship based on the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the elements referred to must have a specific orientation, be constructed and operated in a specific orientation. The terms "first", "second", etc. are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. The term "multiple" means two or more. The terms "connected" and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, an integral connection, a mechanical connection, an electrical connection, a communication connection, a direct connection, an indirect connection through an intermediate medium, and can be the internal connection of two elements or the interaction relationship between two elements. The term "and / or" includes any and all combinations of one or more related listed items. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to the specific circumstances.
[0020] In order to illustrate the technical solution of the present invention, a specific embodiment is used below for description, and only the parts related to the embodiment of the present invention are shown.
[0021] Embodiment 1:
[0022] like Figure 1As shown, the present invention provides an AI face-changing method, comprising the following steps: S10: obtaining an original face image, locating and extracting a face area in the original face image through a face detection model, and using a face feature model to perform feature extraction on the face area to obtain original face features; S20: based on the original face features, using a face dense key point detection model to obtain multiple dense key points in the face area, and facilitating obtaining main features of the face through the dense key points; S30: inputting multiple dense key points into a three-dimensional face model to perform three-dimensional reconstruction of the face to obtain target face features, and recombining the target face features and the original face features through a feature fusion model to generate mixed face features, wherein the mixed face features are obtained by recombining the target face features with the original face features, and the features retain the facial features information of the target face as well as the expression information of the original face, and therefore are mixed face features. S40: Use the face-changing model to perform texture mapping on the mixed face features and the three-dimensional face model, obtain a three-dimensional face model and a two-dimensional face image with color texture after face-changing, and fuse the two-dimensional face image into the original face image through pixel-level fusion to obtain a face-changing image. The present invention obtains multiple dense key points of the face area through a face dense key point detection model, and uses them to perform three-dimensional face reconstruction, generates mixed face features through a feature fusion model, and obtains a face-changing image after processing. The algorithm is highly operable and easy to implement through a dedicated chip, so that it can be integrated in various hardware devices to realize fast face-changing operations and is suitable for a variety of usage scenarios.
[0023] As an optional implementation, in step S20, the facial areas corresponding to the several dense key points are at least one of the lips, nose, and eyes. These areas are the most important feature areas in the face and are the main parts for distinguishing different faces. The dense key points of these areas are extracted.
[0024] As an optional implementation, when the face area corresponding to the dense key points includes lips, a lip correction and repair operation is also performed to solve the problem of occlusion and the large difference between the lips and the original image after face replacement. Figure 2As shown in the figure, this operation extracts features by branch coding based on the feature map of the original face image. The purpose of extracting features by branch coding is to obtain the lip feature map of the original face. Different from the original face feature extracted by the face feature model, the lip heat map is output, and the lip abnormality is corrected and repaired by calculating the lip shape difference loss value. Through layer-by-layer analysis, it is found that the details of the facial features are lost very seriously in the middle and high layers, resulting in excessive reliance on the facial features of the target image in the process of reorganizing the target face shape features. Therefore, a middle and low-level branch is redesigned on the network, and the low-level features of the original face image are introduced, which is conducive to preserving more facial features. The optimal model inputs the original face image of 1×3×128×128, which is a three-channel face cutout, and the target face feature map of 1×512 is input at the same time, which is the face feature map extracted by the face recognition network. The ultimate goal is to encode the original face features while fusing the features of the target face layer by layer, so as to construct a new face after face replacement.
[0025] As an optional implementation, by formula Calculate the loss of the predicted lip heat map and the sample lip heat map, where n represents the batch size during training, that is, batchsize, and k is the number of each training sample in a batch. For example, when the batch size is 4, the value of k will gradually increase from 1 to 4, which is used to calculate the loss for each training sample and the label corresponding to the sample. t represents the number of steps in the current training. represents the sample lip heat map, Represents the predicted lip heat map. This formula is to calculate the lip heat map of the original face label and the lip heat map after the upper branch feature extraction, calculate the sample true value and the network's predicted value, compare the difference between the two heat maps, that is, the difference in lip shape, to feedback the network's degree of restoration of lip details, adjust the network parameters according to the loss, let the lips before and after the face swap participate in the network adjustment, and feedback the lip shape difference after the face swap. The total loss is ,in The cosine loss of the feature vector representing the face-swapped image and the target face image represents the loss of the face and is used to determine the quality of the face-swapped image for each data sample.
[0026] As an optional implementation, Figure 2As shown in the figure, the original face image is padded (Padding, adding extra borders around the input image to better process the information of the image edge in the convolution operation, usually with zero values), 4 convolutions and LeakyRelu function operations are performed to encode facial features, and then the features of the sliced target face image (1×512 target face feature map is processed by Linear linear function and Unsqueeze function, and then Slice slicing process) are used to perform feature reorganization of 12 residual modules (specifically, feature reorganization is performed through residual module ResBlock and feature pyramid network FPN, among which the residual module ResBlock is used to solve the problem that deep models are difficult to optimize and to realize network training at deeper levels. Feature pyramid network FPN (Feature Pyramid Network) is a neural network structure commonly used in target detection and semantic segmentation tasks). Convolution can extract features from face pixels, and the deep convolution network formed by multiple layers of convolution can effectively extract facial feature information. The Leaky ReLU function is a variant of the Rectified Linear Unit. It introduces a small slope when the input is less than 0, so that some negative inputs can also get non-zero outputs. It is widely used in image processing, natural language processing, reinforcement learning, and audio processing, and has high computational efficiency and generalization capabilities. Among them, convolution can extract features from face pixels, and the deep convolution network formed by multiple layers of convolution can effectively extract facial feature information. At the same time, the activation function uses LeakyRelu to reduce the gradient vanishing and gradient exploding phenomena of the network.
[0027] As an optional implementation, the upper branch of the 12 residual modules extracts the features of the first 6 low-level blocks to retain the features of the facial features, and obtains multi-dimensional features after two convolutions and LeakyRelu function operations. The output dimensions of the three times in the figure are 1×1×128×128. In order to merge the features of the upper branch into the lower branch, the second output result is taken, and the dimension is 1×128×128×128. In the 12-layer residual module structure, each layer will perform a feature operation of merging the target features into the original face to achieve the effect of face-changing. As the network deepens, the lip feature information of the original face will gradually be replaced by the lip information of the target face, resulting in a face-changing effect with inconsistent lip shapes. In a deep neural network, the receptive field of the middle and lower layers is relatively small, and some original image semantic features are still retained. The facial features of the original face are relatively richer than those of the high (deep) layers. In the 12-layer residual module structure, the upper branch network mainly extracts the lip features of the original face, and the lower branch network fuses the global features of the target face and the original face to achieve the effect of face swapping. Therefore, the first 6 layers are taken as the input of the upper branch to retain some features of the original face in the middle and lower layers. The lower branch of the 12 residual modules uses the reorganized features output by the high-level blocks, and after 3 convolutions and the LeakyRelu function, the lip heat map is also obtained. The output features of the third convolution are taken for fusion, and the dimension is also 1×128×128×128. Then, the final lip heat map is obtained by connecting (Concat) with the features of the upper branch. Concat is to connect two features. Specifically, the 1×128×128×128 shape features of the upper branch are spliced with the 1×128×128×128 shape features of the lower branch to obtain a 1×256×128×128 feature map.
[0028] As an optional implementation, the upper branch obtains a lip heat map through convolution and LeakyRelu function calculation, which is used to calculate the lip loss, and the lower branch obtains a face-changing image through convolution and LeakyRelu function calculation.
[0029] As an optional implementation, in order to make the data more accurate, the dense key point detection model of the face is used to pre-label the lip key points, and then the individual samples with problems are manually corrected, and the extracted lip heat map is used as an additional label. At the same time, the data of the samples is enhanced during the training process, which can effectively speed up the convergence of the network.
[0030] The embodiment is only a specific example and does not represent only one implementation mode of the present invention.
[0031] Embodiment 2:
[0032] An intelligent face-changing device performs a face-changing operation through the AI face-changing method in the first embodiment. The intelligent face-changing device can be an intelligent camera, etc. Figure 3 As shown, it includes an image and video acquisition module, an embedded AI processor and a deep learning module. The image and video acquisition module uses infrared and visible light dual-mode shooting to collect facial image information and / or facial video information. If the image and video acquisition module is a high-quality CMOS image sensor, it converts the image signal into an electrical signal and transmits it to the subsequent processing unit to achieve high-quality facial image capture in all-weather and multi-environment conditions. The deep learning module is used to store feature fusion models and face-changing models, so that the embedded AI processor can quickly retrieve feature fusion models and face-changing models for face-changing calculations. The embedded AI processor pre-loads the face-changing model, and the embedded AI processor integrates multiple functional modules required for face-changing algorithms. When the image acquisition module obtains the face image, the AI processor will run the face detection model, face feature model, face dense key point detection model and three-dimensional face model to construct the three-dimensional structural information of the face, so as to cooperate with the deep learning module for fast and accurate face-changing. The preferred smart device also includes a face tracking module, which is used to associate the face with a unique identity ID in each frame of the original face image to ensure that the selected target face for face-changing can be matched indiscriminately in the previous and next frames for face-changing operations. The smart face-changing device uses an AI processor and a deep learning module to run the AI face-changing method in Example 1, ensuring that real-time face replacement can be achieved under low computing resource conditions, meeting the needs of real-time application scenarios such as video chat, conferencing, and live interaction. At the same time, the high-performance AI processor chip is integrated with the high-definition camera module to achieve the effect of an integrated design, realizing the convenience of plug-and-play, and users do not need additional complex operations or powerful computing platform support.
[0033] As an optional implementation, it also includes an interface module and an interaction and control module; the interface module is a USB interface, which is widely used and easy to be compatible with various devices. At the same time, the USB interface also supports data transmission and power supply. It transmits face image information and / or face video information with the host machine (such as a computer, tablet, mobile phone, etc.) through the USB protocol, and can also realize the type identification of the image video acquisition module. The USB protocol specification ensures the real-time transmission of face video information and / or face image information and the synchronous update of the device status. The interaction and control module is used to preset the face-changing target, upload a custom face-changing template photo, adjust the face-changing parameters, and preview the real-time face-changing effect. The interaction and control module can be a simple and easy-to-use software application that runs on the host device through a USB connection, which reduces the technical threshold, so that ordinary users can also easily master and apply it to different scenarios, and improve the universality and user experience of the product. Users can select a preset face-changing target or upload a custom face-changing template photo, adjust the face-changing parameters, and preview the real-time face-changing effect through the application. At the same time, the interaction and control module can also include data encryption and privacy protection mechanisms to ensure the security of face data and facilitate use by different users.
[0034] As an optional implementation, it also includes a memory module, a storage module, a power management module, and a heat dissipation module. The memory module is RAM, which is used to temporarily store image data and model parameters, and cache temporary data in the face-changing calculation. The storage module is ROM, which is used to save user configurations, face template materials and system files. The normal execution of the face-changing algorithm is ensured through the cooperation of the memory module and the storage module. The power management module is used to perform power management of the intelligent face-changing device. The power management facilitates the normal and safe use of the device and saves electricity. The heat dissipation module is used to dissipate heat for the intelligent face-changing device. The heat dissipation module can be active heat dissipation and / or passive heat dissipation. It can be selected according to the power consumption, space size, etc. of the intelligent face-changing device to achieve efficient heat dissipation in a compact space and extend the service life of the device.
[0035] The above description is only the preferred embodiment of the present invention. It is known to those skilled in the art that various changes or equivalent substitutions may be made to these features and embodiments without departing from the spirit and scope of the present invention. In addition, under the teachings of the present invention, these features and embodiments may be modified to adapt to specific circumstances and materials without departing from the spirit and scope of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application belong to the protection scope of the present invention.
Claims
1. An AI face-changing method, characterized in that: The following steps are involved: S10: obtaining an original face image, locating and extracting the face area in the original face image through a face detection model, and extracting features of the face area using a face feature model to obtain original face features; S20: obtaining multiple dense key points of the face area using a face dense key point detection model based on the original face features; S30: inputting multiple dense key points into a three-dimensional face model for three-dimensional face reconstruction to obtain target face features, and recombining the target face features with the original face features through a feature fusion model to generate mixed face features; S40: using a face-changing model to perform texture mapping on the mixed face features and the three-dimensional face model to obtain a three-dimensional face model and a two-dimensional face image after face-changing with color texture, and fusing the two-dimensional face image into the original face image through pixel-level fusion to obtain a face-changing image; In the step S20, the facial regions corresponding to the plurality of dense key points are lips, nose, and eyes; The lip correction and repair operation is also performed. This operation corrects and repairs lip abnormalities by calculating the lip shape difference loss value. Specifically, the original face image is subjected to 4 convolutions and LeakyRelu function operations to encode facial features, and then the features of the target face image after slicing are reorganized by 12 residual modules; the upper branches of the 12 residual modules extract the features of the first 6 low-level blocks to retain the features of the facial features, and after 2 convolutions and LeakyRelu function operations, multi-dimensional features and lip heat maps are obtained; By formula Calculate the loss of the predicted lip heat map and the sample lip heat map, where n represents the batch size during training, k is the number of each training sample in the batch, and t represents the number of steps in the current training process. represents the sample lip heat map, represents the predicted lip heat map obtained by the feature fusion model; the total loss is ,in Cosine loss of the feature vector representing the swapped face image and the target face image.
2. An intelligent face-changing device, characterized in that: The face-changing operation is performed by the AI face-changing method described in claim 1, including an image and video acquisition module, an embedded AI processor and a deep learning module; the image and video acquisition module uses infrared and visible light dual-mode shooting to collect facial image information and / or facial video information; the deep learning module is used to store feature fusion models and face-changing models; the embedded AI processor pre-loads the face-changing model, and when the image acquisition module obtains the face image, the AI processor will run the face detection model, the face feature model, the face dense key point detection model and the three-dimensional face model to construct the three-dimensional structural information of the face.
3. The intelligent face-changing device according to claim 2, characterized in that: It also includes an interface module and an interaction and control module; the interface module is a USB interface, which transmits facial image information and / or facial video information to the host machine through the USB protocol; the interaction and control module is used to preset face-changing targets, upload customized face-changing template photos, adjust face-changing parameters, and preview real-time face-changing effects.
4. The intelligent face-changing device according to claim 2, characterized in that: It also includes a memory module, a storage module, a power management module, and a heat dissipation module; the memory module is used to temporarily store image data and model parameters, and cache temporary data in face-changing calculations; the storage module is used to save user configurations, face template materials and system files; the power management module is used to perform power management of the intelligent face-changing device; the heat dissipation module is used to perform heat dissipation of the intelligent face-changing device.
Citation Information
Patent Citations
Three-dimensional expression face restoration method, system and device based on XR device in live scene
CN116563506A
Method for detecting face key points in complex environment by combining real and synthetic data
CN117253277A
