Video face-changing method, device, equipment and storage medium based on deep learning
Through the video face-changing method based on deep learning, the pre-stored face-changing model is used to quickly process the video frames to be changed, which solves the problems of long training time and high resource consumption in the existing technology, and achieves efficient video face-changing processing.
Patent Information
- Application Number
- CN202110754216.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-01
- Publication Date
- 2024-08-13
- Estimated Expiration
- 2041-07-01
AI Technical Summary
Existing face-changing technology takes a long time to train, has many training times, and consumes a lot of resources during the video replacement process.
The video face-changing method based on deep learning is used to obtain the pre-stored face-changing model, extract the face information in the video frame to be swapped, and use the pre-stored face-changing model to determine the face-changing image, and finally update the face-to-be-swapped image based on the face-changing image. Video to achieve quick face-changing processing.
It reduces the number of training times for video face-changing, shortens the time-consuming steps, reduces resource consumption, and improves the efficiency of face-changing.
Smart Images

Figure CN113486785B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of face-changing technology, and in particular to a video face-changing method, device, equipment and storage medium based on deep learning. Background Art
[0002] Face-swapping technology has emerged in recent years, and many scholars in both industry and academia are researching it. Face-swapping technology can automatically replace a person's face in a video or image with another person's face, and is widely used in various fields. However, existing face-swapping technology requires a long period of time and multiple trainings each time a video is replaced, which consumes too many resources.
[0003] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0004] The main purpose of the present invention is to provide a video face-changing method, device, equipment and storage medium based on deep learning, aiming to solve the technical problems of the prior art of replacing video with long training time, large number of training times and high resource consumption.
[0005] To achieve the above object, the present invention provides a video face-swapping method based on deep learning, the method comprising the following steps:
[0006] When receiving a face-swapping instruction of a video to be face-swapped, obtaining a pre-stored face-swapping model according to the face-swapping instruction;
[0007] Extracting a video frame to be replaced with a face in the video to be replaced with a face;
[0008] When there is face information in the video frame to be replaced, the face information in the video frame to be replaced is used to determine the face replacement image through the pre-stored face replacement model to obtain the face replacement image;
[0009] The video to be face-swapped is updated according to the face-swapped image to obtain a target video.
[0010] Optionally, when receiving a face-swapping instruction of a video to be face-swapped, before acquiring a pre-stored face-swapping model according to the face-swapping instruction, the method further includes:
[0011] Obtain historical face-swap images, historical replacement images, and historical target video frames;
[0012] Training the original model according to the historical face-swapped image, the historical replacement image and the historical target video frame to obtain a trained model;
[0013] The trained model is adjusted through a preset format to obtain a pre-stored face-changing model.
[0014] Optionally, before the original model is trained according to the historical face-swapped image, the historical replacement image and the historical target video frame to obtain the trained model, the method further includes:
[0015] Get several preset loss functions;
[0016] Obtaining a preset total loss function according to the preset loss function;
[0017] The original model is updated according to the preset total loss function to obtain a target model;
[0018] The training of the original model according to the historical face-swapped image, the historical image to be replaced and the historical target video frame to obtain the trained model includes:
[0019] The target model is trained according to the historical face-swapped images, the historical images to be replaced and the historical target video frames to obtain a trained model.
[0020] Optionally, when there is face information in the video frame to be face-swapped, determining the face-swapped image by using the pre-stored face-swapped model to obtain the face-swapped image includes:
[0021] When there is face information in the video frame to be replaced, obtaining an aligned face image according to the video frame to be replaced;
[0022] The aligned face image is subjected to face-changing image determination through the pre-stored face-changing model to obtain a face-changing image.
[0023] Optionally, when a face is recognized in the video frame to be replaced, obtaining an aligned face image according to the video frame to be replaced includes:
[0024] When a human face is recognized in the video frame to be replaced, the video frame to be replaced is detected to obtain a number of human face key points;
[0025] Cutting out a face region image of a preset size in the video frame to be face-swapped according to the face key points;
[0026] The face is aligned according to the face region image to obtain an aligned face image.
[0027] Optionally, after extracting the video frame to be replaced in the video to be replaced, the method further includes:
[0028] When no human face is recognized in the to-be-face-swapped video frame, taking the to-be-face-swapped video frame as the first target video frame;
[0029] Querying the video frame position information of the first target video frame in the video to be face-swapped;
[0030] The first target video frame is written back to the video to be face-swapped according to the video frame position information.
[0031] Optionally, updating the to-be-face-swapped video according to the face-swapped image to obtain a target video includes:
[0032] Querying the corresponding position of the face-swapped image in the to-be-swapped video frame;
[0033] determining a replacement image according to the corresponding position;
[0034] Replacing the face-swapped image in the to-be-swapped video frame with the replacement image to obtain a second target video frame;
[0035] The video to be face-swapped is updated according to the second target video frame to obtain a target video.
[0036] In addition, to achieve the above-mentioned purpose, the present invention also proposes a video face-changing device based on deep learning, and the video face-changing device based on deep learning comprises:
[0037] A calling module, configured to obtain a pre-stored face-changing model according to a face-changing instruction of a video to be face-changed when a face-changing instruction is received;
[0038] An extraction module, used for extracting the video frame to be replaced in the video to be replaced;
[0039] A determination module, for determining the face-changing image by using the pre-stored face-changing model to obtain the face-changing image when there is face information in the video frame to be face-changed;
[0040] An updating module is used to update the face-changing video according to the face-changing image to obtain a target video.
[0041] In addition, to achieve the above-mentioned objectives, the present invention also proposes a deep learning-based video face-changing device, the deep learning-based video face-changing device comprising: a memory, a processor, and a deep learning-based video face-changing program stored in the memory and executable on the processor, the deep learning-based video face-changing program being configured to implement the deep learning-based video face-changing method as described above.
[0042] In addition, to achieve the above-mentioned purpose, the present invention also proposes a storage medium, on which a deep learning-based video face-changing program is stored. When the deep learning-based video face-changing program is executed by a processor, the deep learning-based video face-changing method described above is implemented.
[0043] When the present invention receives a face-changing instruction of a video to be replaced, the pre-stored face-changing model is obtained according to the face-changing instruction; the video frame to be replaced in the video to be replaced is extracted; when there is face information in the video frame to be replaced, the face information in the video frame to be replaced is determined by the pre-stored face-changing model to obtain a face-changing image; the video to be replaced is updated according to the face-changing image to obtain a target video. In this way, the pre-stored face-changing model can be obtained when the face-changing instruction is received, and then the video frame to be replaced that needs to be replaced is extracted, and when there is face information in the video frame to be replaced, the face-changing image is determined by the pre-stored face-changing model, and finally the video to be replaced is updated according to the face-changing image to obtain a target video, so that only one pre-stored face-changing model is called to process the video frame and finally obtain the face-changing image, so that the number of video face-changing training times is small, the steps are short in time and the resource consumption is small. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is a structural diagram of a deep learning-based video face-changing device in a hardware operating environment involved in an embodiment of the present invention;
[0045] Figure 2 This is a flowchart of a first embodiment of a video face-swapping method based on deep learning according to the present invention;
[0046] Figure 3 This is a flow chart of a second embodiment of the video face swapping method based on deep learning of the present invention;
[0047] Figure 4 This is a schematic diagram of key points of a face in an embodiment of a video face swapping method based on deep learning of the present invention;
[0048] Figure 5 This is a structural block diagram of the first embodiment of the video face-changing device based on deep learning of the present invention.
[0049] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0050] 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.
[0051] Reference Figure 1 , Figure 1 This is a schematic diagram of the structure of a deep learning-based video face-changing device in the hardware operating environment involved in an embodiment of the present invention.
[0052] like Figure 1As shown, the deep learning-based video face-changing device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) memory, or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0053] Those skilled in the art will understand that Figure 1 The structure shown in does not constitute a limitation of the deep learning-based video face-changing device, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0054] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a video face-changing program based on deep learning.
[0055] exist Figure 1 In the deep learning-based video face-changing device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the deep learning-based video face-changing device of the present invention can be set in the deep learning-based video face-changing device, and the deep learning-based video face-changing device calls the deep learning-based video face-changing program stored in the memory 1005 through the processor 1001, and executes the deep learning-based video face-changing method provided by an embodiment of the present invention.
[0056] The embodiment of the present invention provides a video face swapping method based on deep learning, referring to Figure 2 , Figure 2 This is a flow chart of a first embodiment of a deep learning-based video face-swapping method according to the present invention.
[0057] In this embodiment, the video face-swapping method based on deep learning includes the following steps:
[0058] Step S10: when receiving a face-changing instruction of a video to be face-changed, obtaining a pre-stored face-changing model according to the face-changing instruction.
[0059] It should be noted that the execution subject of this embodiment is a controller, which is mainly used to control the video face-swapping method based on deep learning, and can also be any device that can achieve this function, which is not limited in this embodiment. This embodiment and the following embodiments will be specifically described by taking the controller of the video face-swapping method based on deep learning as an example.
[0060] It should be understood that the face-changing instruction refers to an instruction for instructing the start of face-changing of a video to be face-changed. The face-changing instruction can be an instruction in any form, and this embodiment does not limit this.
[0061] In a specific implementation, the pre-stored face-changing model refers to a model that is pre-processed and stored for face-changing. The pre-stored face-changing model in this embodiment is based on the FaceShifter model, and then a model is obtained by modifying some structures and adjusting parameters.
[0062] It should be noted that the video to be face-changed refers to the video that needs to execute the steps of the face-changing method, and can be a video of any length and clarity, which is not limited in this embodiment.
[0063] It should be understood that when a face-changing instruction for a video to be face-changed is received, obtaining a pre-stored face-changing model according to the face-changing instruction means that when a face-changing instruction for performing face-changing on the video to be face-changed is received, a pre-stored face-changing model is called.
[0064] Furthermore, in order to obtain a pre-trained pre-stored face-changing model in advance, before step S10, the following steps are further included:
[0065] Obtain historical face-swap images, historical replacement images, and historical target video frames;
[0066] Training the original model according to the historical face-swapped image, the historical replacement image and the historical target video frame to obtain a trained model;
[0067] The trained model is adjusted through a preset format to obtain a pre-stored face-changing model.
[0068] It should be noted that the historical face-changing image refers to the face-changing image stored in the successful face-changing method steps before the current face-changing. The face-changing image refers to the image area that needs to be replaced in the face-changing video frame determined by the pre-stored face-changing model.
[0069] It should be understood that the historical replacement image refers to the replacement image stored in the successful face-changing method steps before the current face-changing. The replacement image refers to the image that needs to replace the face-changing image on the face-changing video frame.
[0070] In a specific implementation, the historical target video frame refers to a video frame in which face replacement is completed and stored in a successful face-changing method step before the current face-changing.
[0071] It should be noted that the historical face-swapped images, historical replacement images, and historical target video frames are all stored in the form of open source datasets CelebA-HQ and FFHQ datasets.
[0072] It should be understood that training the original model according to the historical face-swapped images, the historical replacement images and the historical target video frames to obtain the trained model means extracting historical face-swapped images, historical replacement images and historical target video frames from the training data set, and then training the original model according to the historical face-swapped images, historical replacement images and historical target video frames to obtain the trained model.
[0073] In a specific implementation, the original model refers to the FaceShifter model used for face swapping that is called before training.
[0074] It should be noted that the preset format refers to the PB format, and adjusting the trained model through the preset format to obtain the pre-stored face-changing model refers to converting the trained model into the PB format to obtain the pre-stored face-changing model.
[0075] In this way, the original model can be trained accurately and quickly to obtain a pre-stored face-changing model.
[0076] Furthermore, in order to adjust the structure of the original model, the step of training the original model according to the historical face-swapped image, the historical replacement image and the historical target video frame, before obtaining the trained model, further includes:
[0077] Get several preset loss functions;
[0078] Obtaining a preset total loss function according to the preset loss function;
[0079] The original model is updated according to the preset total loss function to obtain a target model;
[0080] The training of the original model according to the historical face-swapped image, the historical image to be replaced and the historical target video frame to obtain the trained model includes:
[0081] The target model is trained according to the historical face-swapped images, the historical images to be replaced and the historical target video frames to obtain a trained model.
[0082] It should be understood that the preset loss function refers to a pre-stored loss function used to replace the function in the original model.
[0083] In a specific implementation, the preset loss function may include the following four loss functions, namely, GAN loss function, id loss function, multi-layer attribute loss function and pixel-level reconstruction loss function:
[0084]
[0085]
[0086]
[0087]
[0088] Among them, D is the discriminator, G is the generator, E is the mathematical expectation, and Z is id is the facial feature, X s is the source face, that is, the face-changing image that needs to be replaced, X t is the target face, that is, the replacement image that replaces the face-swapped image, Refers to the generated face, that is, the replaced face; Z k att is the embedding of an attribute in the kth layer.
[0089] In a specific implementation, obtaining a preset total loss function according to the preset loss function refers to obtaining a preset total loss function according to a GAN loss function, an ID loss function, a multi-layer attribute loss function, and a pixel-level reconstruction loss function.
[0090] It should be noted that the calculation method of the preset total loss function is:
[0091]
[0092] Among them, λ att , id and λ rec Each is a preset coefficient.
[0093] It should be understood that updating the original model according to the preset total loss function to obtain the target model means that after obtaining the preset total loss function, the preset total loss function replaces the loss function in the original model, and the obtained model is the target model.
[0094] In this way, the accuracy of the original model can be improved by replacing the loss function in the original model, thereby improving the accuracy and final effect of video face swapping.
[0095] Step S20: extracting the video frame to be replaced in the video to be replaced.
[0096] In a specific implementation, the video frame to be replaced with the face refers to a designated video frame in the video to be replaced with the face, and the video frame to be replaced with the face can be any frame in the video to be replaced with the face, and this embodiment does not impose any limitation on this.
[0097] It should be noted that extracting the video frames to be replaced in the video to be replaced refers to extracting the video frames that need to be replaced from the video to be replaced as the video frames to be replaced.
[0098] Step S30: When there is face information in the video frame to be replaced, the face information in the video frame to be replaced is used to determine the face-changed image through the pre-stored face-changing model to obtain the face-changed image.
[0099] It should be understood that to determine whether there is facial information in the video to be replaced, image recognition means or other methods may be used, and this embodiment does not limit this.
[0100] In a specific implementation, when there is facial information in the video frame to be replaced, the facial information in the video frame to be replaced is used to determine the face-changing image through the pre-stored face-changing model. Obtaining the face-changing image means that after detecting that there is facial information in the video frame to be replaced, the video frame to be replaced is input into the pre-stored face-changing model, and the image finally output by the pre-stored face-changing model is the determined face-changing image.
[0101] Step S40: updating the face-swapped video according to the face-swapped image to obtain a target video.
[0102] It should be noted that the target video refers to the video with the face-changing completed after this method is used.
[0103] It should be understood that updating the video to be face-swapped according to the face-swapped image to obtain the target video means that, after the face-swapped image is determined, the face-swapped image in the video frame to be face-swapped is replaced and overwritten by a pre-prepared replacement image, and then a second target video frame is obtained, and finally the video to be face-swapped is updated according to the second target video frame to obtain the target video.
[0104] This embodiment obtains a pre-stored face-changing model according to the face-changing instruction when receiving a face-changing instruction of a video to be replaced; extracts the video frame to be replaced in the video to be replaced; when there is face information in the video frame to be replaced, determines the face-changing image through the pre-stored face-changing model for the face information in the video frame to be replaced, and obtains the face-changing image; updates the video to be replaced according to the face-changing image to obtain the target video. In this way, the pre-stored face-changing model can be obtained when the face-changing instruction is received, and then the video frame to be replaced that needs to be replaced is extracted, and when there is face information in the video frame to be replaced, the face-changing image is determined through the pre-stored face-changing model, and finally the video to be replaced is updated according to the face-changing image to obtain the target video, so that only one pre-stored face-changing model is called to process the video frame and finally obtain the face-changing image, so that the number of video face-changing training times is small, the steps are short in time, and the resource consumption is small.
[0105] refer to Figure 3 , Figure 3 This is a flow chart of a second embodiment of a video face-swapping method based on deep learning according to the present invention.
[0106] Based on the above first embodiment, the video face swapping method based on deep learning in this embodiment includes in step S30:
[0107] Step S301: when there is face information in the video frame to be replaced, an aligned face image is obtained according to the video frame to be replaced.
[0108] It should be noted that the aligned face image refers to the face image obtained by processing the video frame to be replaced when there is face information in the video frame to be replaced.
[0109] It should be understood that when there is facial information in the video frame to be replaced, obtaining an aligned facial image based on the video frame to be replaced means that, when there is facial information in the video frame to be replaced, the video frame to be replaced is processed to first determine the image position of the face, and then the facial image is aligned to obtain an aligned facial image.
[0110] Furthermore, in order to accurately obtain the aligned face image, step S101 includes:
[0111] When a human face is recognized in the video frame to be replaced, the video frame to be replaced is detected to obtain a number of human face key points;
[0112] Cutting out a face region image of a preset size in the video frame to be face-swapped according to the face key points;
[0113] The face is aligned according to the face region image to obtain an aligned face image.
[0114] It should be noted that the key points of the face refer to the key image points on the face that are automatically selected after the automatic detection of the face-changing video frame, and are used to identify the image points of facial features. The number of key points of the face can be any number, and this embodiment does not impose any limit on this.
[0115] In the specific implementation, Figure 4 The figure shows a schematic diagram of selecting facial key points. The facial key points are selected based on the facial organs and other characteristic parts of the recognized face. The number of facial key points is not specifically limited in this embodiment and can be any number. Figure 4 It is for illustration only and does not limit the description of this embodiment.
[0116] It should be understood that when a face is recognized in the video frame to be replaced, the video frame to be replaced is detected to obtain a number of facial key points, which means that when facial information is detected in the video frame to be replaced, image detection is automatically performed on the video frame to be replaced, and then a number of facial key points are determined.
[0117] In a specific implementation, the preset size is a size that can be set by an administrator or a user and is used to crop a facial image. The size of the preset size is not limited in this embodiment.
[0118] It should be noted that the face area image refers to an image of a preset size cut out from the video frame to be face-swapped according to the positions of the key points of the face.
[0119] It should be understood that cutting out a face area image of a preset size in the video frame to be face-swapped according to the facial key points means that after determining a number of facial key points, an image area of a preset size is cut out in the video frame to be face-swapped according to the positions of the facial key points as the face area image.
[0120] In a specific implementation, the face is aligned according to the face area image to obtain the aligned face image, which means that after the face area image is obtained, the face image is aligned through affine transformation, that is, the position and angle of the face are adjusted to the front, and the final image obtained is the aligned face image.
[0121] In this way, the face image can be accurately and quickly transformed into an aligned face image, making the subsequent face-changing steps more convenient and improving the final effect of the face-changing.
[0122] Step S302: Determine the face-changing image by using the pre-stored face-changing model on the aligned face image to obtain the face-changing image.
[0123] It should be noted that, the aligned face image is determined by the pre-stored face-changing model to obtain the face-changing image, which means that the aligned face image is input into the pre-stored face-changing model obtained after the training is completed, and then the image output by the pre-stored face-changing model is obtained, and the image output by the pre-stored face-changing model is used as the face-changing image.
[0124] Furthermore, in order to put the video frame to be replaced back into the video to be replaced when no face is recognized in the video frame to be replaced, after extracting the video frame to be replaced in the video to be replaced, the method further includes:
[0125] When no human face is recognized in the to-be-face-swapped video frame, taking the to-be-face-swapped video frame as the first target video frame;
[0126] Querying the video frame position information of the first target video frame in the video to be face-swapped;
[0127] The first target video frame is written back to the video to be face-swapped according to the video frame position information.
[0128] It should be understood that when no face is recognized in the video frame to be replaced, taking the video frame to be replaced as the first target video frame means that when no face is recognized after image recognition is performed on the video frame to be replaced, taking the video frame to be replaced in which no face is recognized as the first target video frame.
[0129] In a specific implementation, the video frame position information refers to the frame position of the first target video frame in the video to be face-swapped, that is, the frame number of the first target video frame in the video to be face-swapped.
[0130] It should be noted that querying the video frame position information of the first target video frame in the video to be face-swapped refers to querying the video frame position information of the first target video frame in the video to be face-swapped after determining the first target video frame.
[0131] It should be understood that placing the first target video frame back into the video to be face-swapped according to the video frame position information means that after the video frame position information of the first target video frame is determined, the first target video frame is placed back into the video to be face-swapped.
[0132] In this way, when no facial information is recognized in the video frame to be replaced, the video frame to be replaced can be quickly put back into the video to be replaced, thereby improving the efficiency of video face replacement.
[0133] Further, in order to perform face swapping on the video to be face swapped after obtaining the face swapping image, the step of updating the video to be face swapped according to the face swapping image to obtain the target video includes:
[0134] Querying the corresponding position of the face-swapped image in the to-be-swapped video frame;
[0135] determining a replacement image according to the corresponding position;
[0136] Replacing the face-swapped image in the to-be-swapped video frame with the replacement image to obtain a second target video frame;
[0137] The video to be face-swapped is updated according to the second target video frame to obtain a target video.
[0138] It should be noted that querying the corresponding position of the face-swapped image in the video frame to be face-swapped refers to querying the position of the face-swapped image in the video frame to be face-swapped, that is, the corresponding position.
[0139] It should be understood that the replacement image refers to a pre-stored facial image used to replace the face-changing image, that is, the facial image in the video frame to be face-changed after the replacement is completed.
[0140] In a specific implementation, determining the replacement image according to the corresponding position means that after the corresponding position of the face-changing image is determined, the replacement image to be replaced is determined according to the corresponding position.
[0141] It should be noted that replacing the face-changing image in the video frame to be replaced with the replacement image to obtain the second target video frame means that the face-changing image in the video frame to be replaced with the replacement image, and the video frame finally obtained is the second target video frame. In other words, the second target video frame is an image in which the face-changing image in the video frame to be replaced is replaced with the replacement image.
[0142] It should be understood that updating the video to be face-swapped according to the second target video frame to obtain the target video means that after obtaining the second target video frame, the frame position of the second target video frame in the video to be face-swapped is queried, that is, the frame number of the second target video frame in the video to be face-swapped, and then the second target video frame replaces the video frame to be face-swapped and is put into the video to be face-swapped to obtain the target video.
[0143] In this embodiment, when there is face information in the video frame to be replaced, an aligned face image is obtained according to the video frame to be replaced; the aligned face image is determined by the pre-stored face replacement model to obtain a face replacement image. In this way, the video frame to be replaced can be pre-processed before using the pre-stored face replacement model to obtain an aligned face image, and then the aligned face image can be input into the pre-stored face replacement model, and the image input with high accuracy of the pre-stored face replacement model can be used to improve the effect of face replacement.
[0144] In addition, an embodiment of the present invention also proposes a storage medium, on which a deep learning-based video face-changing program is stored. When the deep learning-based video face-changing program is executed by a processor, the steps of the deep learning-based video face-changing method described above are implemented.
[0145] Since the storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0146] Reference Figure 5 , Figure 5 This is a structural block diagram of the first embodiment of the video face-changing device based on deep learning of the present invention.
[0147] like Figure 5 As shown, the deep learning-based video face-changing device proposed in the embodiment of the present invention includes:
[0148] The calling module 10 is used to obtain a pre-stored face-changing model according to the face-changing instruction when receiving a face-changing instruction of a video to be face-changed.
[0149] The extraction module 20 is used to extract the video frame to be replaced in the video to be replaced.
[0150] The processing module 30 is used to determine the face-changing image by using the pre-stored face-changing model to obtain the face-changing image when there is face information in the video frame to be face-changed.
[0151] The updating module 40 is used to update the face-changing video according to the face-changing image to obtain a target video.
[0152] It should be understood that the above is only an example and does not constitute any limitation on the technical solution of the present invention. In specific applications, technicians in this field can make settings as needed, and the present invention does not limit this.
[0153] This embodiment obtains a pre-stored face-changing model according to the face-changing instruction when receiving a face-changing instruction of a video to be replaced; extracts the video frame to be replaced in the video to be replaced; when there is face information in the video frame to be replaced, determines the face-changing image through the pre-stored face-changing model for the face information in the video frame to be replaced, and obtains the face-changing image; updates the video to be replaced according to the face-changing image to obtain the target video. In this way, the pre-stored face-changing model can be obtained when the face-changing instruction is received, and then the video frame to be replaced that needs to be replaced is extracted, and when there is face information in the video frame to be replaced, the face-changing image is determined through the pre-stored face-changing model, and finally the video to be replaced is updated according to the face-changing image to obtain the target video, so that only one pre-stored face-changing model is called to process the video frame and finally obtain the face-changing image, so that the number of video face-changing training times is small, the steps are short in time, and the resource consumption is small.
[0154] In this embodiment, the calling module 10 is also used to obtain historical face-changing images, historical replacement images and historical target video frames; train the original model according to the historical face-changing images, the historical replacement images and the historical target video frames to obtain a trained model; adjust the trained model through a preset format to obtain a pre-stored face-changing model.
[0155] In this embodiment, the calling module 10 is also used to obtain several preset loss functions; obtain a preset total loss function according to the preset loss function; update the original model according to the preset total loss function to obtain a target model; the original model is trained according to the historical face-swapped images, the historical images to be replaced and the historical target video frames to obtain a trained model, including: training the target model according to the historical face-swapped images, the historical images to be replaced and the historical target video frames to obtain a trained model.
[0156] In this embodiment, the processing module 30 is also used to obtain an aligned face image based on the video frame to be replaced when there is facial information in the video frame to be replaced; and determine the face-changing image by using the pre-stored face-changing model to obtain the face-changing image.
[0157] In this embodiment, the processing module 30 is also used to detect the video frame to be replaced to obtain a number of facial key points when a face is recognized in the video frame to be replaced; cut out a face area image of a preset size in the video frame to be replaced according to the facial key points; align the face according to the face area image to obtain an aligned face image.
[0158] In this embodiment, the extraction module 20 is also used to, when no face is recognized in the video frame to be replaced, use the video frame to be replaced as the first target video frame; query the video frame position information of the first target video frame in the video to be replaced; and put the first target video frame back into the video to be replaced according to the video frame position information.
[0159] In this embodiment, the update module 40 is also used to query the corresponding position of the face-changing image in the video frame to be face-changed; determine the replacement image according to the corresponding position; replace the face-changing image in the video frame to be face-changed with the replacement image to obtain a second target video frame; and update the video to be face-changed according to the second target video frame to obtain a target video.
[0160] Since the present device adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0161] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.
[0162] In addition, for technical details not described in detail in this embodiment, please refer to the deep learning-based video face-changing method provided in any embodiment of the present invention, which will not be repeated here.
[0163] In addition, it should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system 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 system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0164] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0165] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0166] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A video face-changing method based on deep learning, characterized in that: The video face-changing method based on deep learning includes: Obtain historical face-swap images, historical replacement images, and historical target video frames; Get several preset loss functions; Obtaining a preset total loss function according to the preset loss function; The original model is updated according to the preset total loss function to obtain a target model; Training the target model according to the historical face-swapped image, the historical replacement image and the historical target video frame to obtain a trained model; The trained model is adjusted by a preset format to obtain a pre-stored face-changing model, wherein the original model refers to the FaceShifter model used for face-changing called before training, the preset format refers to the PB format, and the trained model is adjusted by a preset format to obtain a pre-stored face-changing model, which means converting the trained model into the PB format to obtain a pre-stored face-changing model; When receiving a face-swapping instruction of a video to be face-swapped, obtaining a pre-stored face-swapping model according to the face-swapping instruction; Extracting a video frame to be replaced with a face in the video to be replaced with a face; When no human face is recognized in the to-be-face-swapped video frame, taking the to-be-face-swapped video frame as the first target video frame; Query the video frame number of the first target video frame in the video to be face-swapped; Writing the first target video frame back to the video to be face-swapped according to the video frame number; When a human face is recognized in the video frame to be replaced, the video frame to be replaced is detected to obtain key points of the human face; Cutting out a face region image of a preset size in the video frame to be face-swapped according to the face key points; According to the face region image, the position and angle of the face are adjusted to the front through affine transformation to obtain an aligned face image; Determine the face-changing image by using the pre-stored face-changing model on the aligned face image to obtain the face-changing image; Query the corresponding video frame number of the face-swapped image in the video frame to be face-swapped; Determine a replacement image according to the corresponding video frame number; Replacing the face-swapped image in the to-be-swapped video frame with the replacement image to obtain a second target video frame; Query the frame number of the second target video frame in the video to be face-swapped; The second target video frame replaces the video frame to be replaced with the face-changing video frame and is put into the video to be replaced with the face, so as to obtain the target video.
2. A video face-changing device based on deep learning, characterized in that: The deep learning-based video face-changing device comprises: A calling module is used to obtain historical face-swapped images, historical replacement images and historical target video frames; train the original model according to the historical face-swapped images, the historical replacement images and the historical target video frames to obtain a trained model; Get several preset loss functions; Obtaining a preset total loss function according to the preset loss function; The original model is updated according to the preset total loss function to obtain a target model; Training the target model according to the historical face-swapped image, the historical replacement image and the historical target video frame to obtain a trained model; The trained model is adjusted by a preset format to obtain a pre-stored face-changing model, wherein the original model refers to the FaceShifter model used for face-changing called before training, the preset format refers to the PB format, and the trained model is adjusted by a preset format to obtain a pre-stored face-changing model, which means converting the trained model into the PB format to obtain a pre-stored face-changing model; When receiving a face-swapping instruction of a video to be face-swapped, obtaining a pre-stored face-swapping model according to the face-swapping instruction; An extraction module, used for extracting the video frame to be replaced in the video to be replaced; A processing module is used for, when no face is recognized in the video frame to be replaced, using the video frame to be replaced as the first target video frame; querying the video frame number of the first target video frame in the video to be replaced; writing the first target video frame back to the video to be replaced according to the video frame number; when a face is recognized in the video frame to be replaced, detecting the video frame to be replaced to obtain face key points; cutting out a face area image of a preset size in the video frame to be replaced according to the face key points; adjusting the position and angle of the face to the front through affine transformation according to the face area image to obtain an aligned face image; determining the face replacement image through the pre-stored face replacement model, obtaining a face replacement image; An updating module is used to query the corresponding video frame number of the face-changing image in the video frame to be replaced; determine a replacement image according to the corresponding video frame number; replace the face-changing image in the video frame to be replaced with the replacement image to obtain a second target video frame; query the frame number of the second target video frame in the video to be replaced; replace the video frame to be replaced with the second target video frame, and put it into the video to be replaced to obtain a target video.
3. A video face-changing device based on deep learning, characterized in that: The device includes: a memory, a processor, and a deep learning-based video face-changing program stored in the memory and executable on the processor, wherein the deep learning-based video face-changing program is configured to implement the deep learning-based video face-changing method as described in claim 1.
4. A storage medium, characterized in that: The storage medium stores a deep learning-based video face-changing program, and when the deep learning-based video face-changing program is executed by the processor, the deep learning-based video face-changing method according to claim 1 is implemented.
Citation Information
Patent Citations
Face key point detection method, device and system
CN110222607A
Speaking video generation method and system
CN111243626A
Video face changing method and system based on mobile platform
CN111476710A
Generative adversarial network training method, image face changing and video face changing method and device
CN111783603A
Face-changing video detection method
CN111783608A
