Face stylization processing method, device and computer equipment based on AI model
Through the face stylization processing method based on the AI model, the style weight is used to integrate multiple style elements, which solves the problem of single style and single applicable scene in the existing technology, and achieves the improvement of dynamic stylization processing and diversity effects.
Patent Information
- Application Number
- CN202311550362.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-20
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2043-11-20
AI Technical Summary
The face stylization processing algorithm in the existing technology can only process a specific style, is difficult to achieve dynamic stylization processing, and is applicable to a single scenario.
The face stylization processing method based on the AI model is adopted, the style is encoded through the StarGAN stylization processing model, and the second AI model is used to determine the style weight at the timing of each video frame to achieve the fusion and balance of multiple style elements and generate a unique Dynamic style face video.
It realizes dynamic style processing of static images, expands the applicable scenarios of stylization processing, and generates stylized face images with diverse and realistic effects, maintaining the coherence of image content and style.
Smart Images

Figure CN118014854B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a method, device and computer equipment for face stylization processing based on an AI model. Background Art
[0002] Image stylization is a branch of non-photorealistic rendering technology with broad applications and market prospects. It will generate huge economic value in the digital entertainment industry, such as film and television production, home entertainment, digital games, advertising, and more. Face stylization refers to transforming a face into a face of a specified style. Common styles include the second dimension and ancient costumes. The stylized face image is required to have a texture of a specified style and retain the general outline of the face.
[0003] At present, most stylization algorithms are based on deep learning, especially convolutional neural networks (CNN). However, there are many other types of neural network models, such as self-attention networks (Self-Attention Network), generative adversarial networks (GAN), etc. The current stylization algorithms can usually only process a specific style, that is, they can only convert face images into one style, the stylization processing is single, and the processing of specified styles on face images mostly exists in static images, and it is difficult to achieve good dynamic stylization processing. Therefore, the stylization processing of existing technologies has the defects of single processing style and single applicable scenarios. Summary of the invention
[0004] The purpose of the present invention is to provide a face stylization processing method based on an AI model to solve the technical problems of single processing style and single applicable scenario in the prior art.
[0005] In order to solve the above technical problems, the present invention specifically provides the following technical solutions:
[0006] A face stylization processing method based on an AI model comprises the following steps:
[0007] Acquire a first face image and a second face video, wherein the second face video comprises a group of second face video frames arranged continuously in a video frame time sequence, the first face image is an original face image to be stylized, and the second face video frame is a reference face image containing a target style of the stylized first face image;
[0008] According to a set of second face video frames, stylized encoding is performed by the first AI model to obtain a set of target styles, where the target styles correspond to the style encoding, and the first AI model corresponds to the StarGAN stylized processing model;
[0009] According to the first face image and a set of target styles, weight determination is performed at each video frame timing in the second face video by a second AI model to obtain a style weight at each video frame timing, wherein the style weight corresponds to a fusion weight of each target style in the first face image, and the second AI model corresponds to a neural network that characterizes a mapping relationship between the first face image and the target style and the style weight;
[0010] According to a set of target styles and style weights at each video frame sequence, the first AI model is used to stylize the first face image at each video frame sequence in the second face video to obtain a third face video. The third face video is composed of third face images at each video frame sequence arranged in video frame sequence, and the third face image corresponds to the first face image stylized by the target style.
[0011] According to a set of second face video frames, stylized encoding is performed through the first AI model to obtain a set of target styles, including:
[0012] By using the style encoder or mapping network in the StarGAN stylization processing model, the style features of the second face video frame at each video frame sequence in the second face video are encoded respectively to obtain the style encoding of the second face video frame at each video frame sequence; the style encoding of the second face video frame at each video frame sequence is used as the target style at each video frame sequence to obtain a group of target styles corresponding to a group of second face video frames.
[0013] As a preferred solution of the present invention, according to the first face image and a set of target styles, a weight is determined at each video frame timing in the second face video by a second AI model to obtain a style weight at each video frame timing, including:
[0014] The first face image and a set of target styles, as well as each video frame sequence in the second face video, are sequentially input into the second AI model to obtain the style weights of each target style at each video frame sequence;
[0015] The construction of the second AI model includes:
[0016] Randomly select two groups of sample images from the sample image library as first sample images and second sample images respectively;
[0017] Obtaining the target style of each second sample image to obtain a set of sample styles;
[0018] Randomly setting a plurality of groups of style weights of a group of sample styles for each first sample image to obtain a plurality of groups of sample weights for each first sample image;
[0019] For each first sample image, a group of sample styles are style-fused using multiple groups of sample weights to obtain multiple groups of stylized processed images of each first sample image;
[0020] In each first sample image, the style weight is used as an input item of the CNN neural network, and the stylized processed image of the first sample image is used as an output item of the CNN neural network. The CNN neural network is used to perform deep learning on the input item and the output item of the CNN neural network to obtain a stylized processing result prediction network, wherein the expression of the stylized processing result prediction network is:
[0021] G = CNN({W1,W2,W3,…,Wn});
[0022] Where g is the stylized image, W1 is the style weight of the first target style, W2 is the style weight of the second target style, W3 is the style weight of the third target style, Wn is the style weight of the nth target style, n is the total number of target styles, and CNN is the CNN neural network;
[0023] In each first sample image, all combinations of style weights are calculated one by one using the stylized processing result prediction model to obtain stylized processed images of all combinations of style weights;
[0024] The style weight corresponding to the optimal stylized image is used as the optimal static style weight of the first sample image;
[0025] The first sample image and the sample style are used as input items of the second CNN neural network, and the optimal static style weight is used as the output item of the second CNN neural network. The second CNN neural network is used to perform deep learning on the input items and the output items of the second CNN neural network to obtain a static weight prediction network, wherein the expression of the static weight prediction network is:
[0026] {W1 best1 ,W2 best1 ,W3 best1 ,…,Wn best1}=CNN2(G,{F1,F2,F3,…,Fn});
[0027] Where W1 best1 is the optimal static style weight of the first target style, W2 best1 is the optimal static style weight of the style weight of the second target style, W3 best1 is the optimal static style weight of the style weight of the third target style, Wn best1is the optimal static style weight of the style weight of the nth target style, n is the total number of target styles, G is the first sample image, F1 is the first target style, F2 is the second target style, F3 is the third target style, Fn is the nth target style, and CNN2 is the second CNN neural network;
[0028] The static weight prediction model is combined with a multi-objective optimization algorithm to obtain the optimal dynamic style weight of the first face image at each video frame time sequence;
[0029] The first face image and a set of target styles are used as input items of the third CNN neural network, the optimal dynamic style weight is used as the output item of the third CNN neural network, and the third CNN neural network is used to perform deep learning on the input items of the third CNN neural network and the output items of the third CNN neural network to obtain a dynamic weight prediction network, wherein the expression of the dynamic weight prediction network is:
[0030] {W1 best2 ,W2 best2 ,W3 best2 ,…,Wn best2}=CNN3(G2,{F1,F2,F3,…,Fn});
[0031] Where W1 best2 is the optimal dynamic style weight of the first target style, W2 best2 is the optimal dynamic style weight of the style weight of the second target style, W3 best2 is the optimal dynamic style weight of the style weight of the third target style, Wn best2 is the optimal dynamic style weight of the style weight of the nth target style, n is the total number of target styles, G2 is the first face image, F1 is the first target style, F2 is the second target style, F3 is the third target style, Fn is the nth target style, and CNN3 is the third CNN neural network.
[0032] As a preferred solution of the present invention, the determination of the optimal stylized processed image includes:
[0033] The style features and content features of each stylized image are compared with those of the first sample image, wherein:
[0034] The stylized image having the smallest similarity with the style feature of the first sample image and the largest similarity with the content feature of the first sample image is used as the optimal stylized image of the first sample image;
[0035] The similarity is quantified using one of the Euclidean distance, correlation coefficient and Jaccard coefficient.
[0036] As a preferred solution of the present invention, the determination of the optimal dynamic style weight includes:
[0037] The static weight prediction model is used to obtain the optimal static style weight of the first face image at each video frame time sequence;
[0038] A first dynamic target is set. The first dynamic target corresponds to minimizing the degree of change of style features of the first face image after stylization by the dynamic style weight between adjacent video frames. The expression of the first dynamic target is:
[0039]
[0040] In the formula, K1 is the first dynamic target, min is the minimization operator, sim is the similarity operator, G3H t is the style feature of the first face image at the tth video frame sequence after stylization by dynamic style weight, G3H t+1 is the style feature of the first face image at the t+1th video frame sequence after stylization by dynamic style weight, m is the total number of video frames, sim(G3H t ,G3H t+1 ) is G3H t and G3H t+1 The similarity between them, t is a counting variable;
[0041] A second dynamic target is set, and the second dynamic target corresponds to maximizing the degree of change of content features between adjacent video frames in the first face video after stylization by the dynamic style weight. The expression of the second dynamic target is:
[0042]
[0043] In the formula, K2 is the second dynamic target, max is the minimization operator, sim is the similarity operator, G3S t G3S is the content feature of the first face image at the tth video frame sequence after stylization by dynamic style weights, t+1 is the content feature of the first face image at the t+1th video frame sequence after stylization by dynamic style weight, m is the total number of video frames, sim(G3S t ,G3S t+1 ) is G3S t and G3S t+1 The similarity between them, t is a counting variable;
[0044] G3 is the first face image after stylization processing with dynamic style weights {W12, W22, W32, …, Wn2}, W12 is the dynamic style weight of the first target style, W22 is the dynamic style weight of the style weight of the second target style, W32 is the dynamic style weight of the style weight of the third target style, Wn2 is the dynamic style weight of the style weight of the nth target style, and n is the total number of target styles.
[0045] Taking the optimal static style weight as the solution constraint, solving the first dynamic target and the second dynamic target, and obtaining the optimal solution of the dynamic style weight {W12, W22, W32, …, Wn2};
[0046] The optimal solution of the dynamic style weights {W12, W22, W32, …, Wn2} is used as the optimal dynamic style weight {W12, W22, W32, …, Wn2} for stylizing the first face image at each video frame time sequence. best2 ,W2 best2 ,W3 best2 ,…,Wn best2}.
[0047] As a preferred solution of the present invention, according to a set of target styles and the style weights at each video frame timing, a first AI model is used to perform stylization processing on the first face image at each video frame timing in the second face video to obtain a third face video, including:
[0048] Inputting the first face image, a set of target styles, and the dynamic style weights at each video frame time sequence into the first AI model, and the first AI model outputs the stylized processed image of the first face image at each video frame time sequence;
[0049] Marking the stylized processed image of the first face image at each video frame time sequence as a third face image;
[0050] The third face images at each video frame time sequence are arranged in time sequence to obtain a third face video.
[0051] As a preferred solution of the present invention, the first face image and the second face video are subjected to image preprocessing after being acquired, and the image preprocessing includes at least one of resizing, cropping and grayscale conversion.
[0052] As a preferred solution of the present invention, the third facial image is subjected to image post-processing after being acquired, and the image post-processing includes at least one of image enhancement, denoising and edge enhancement.
[0053] As a preferred solution of the present invention, the present invention provides a face stylization processing device, comprising:
[0054] A data acquisition module, configured to acquire a first face image and a second face video, wherein the second face video comprises a group of second face video frames arranged continuously in a video frame time sequence, the first face image is an original face image to be stylized, and the second face video frame is a reference face image containing a target style of the stylized first face image;
[0055] A data processing module, configured to perform stylized encoding through a first AI model according to a set of second face video frames to obtain a set of target styles;
[0056] for determining weights at each video frame sequence in the second face video by a second AI model according to the first face image and a set of target styles, so as to obtain a style weight at each video frame sequence; and
[0057] Used to perform stylized processing on the first face image at each video frame sequence in the second face video by using the first AI model according to a set of target styles and the style weight at each video frame sequence, so as to obtain a third face video;
[0058] The data storage module is used to store the first AI model and the second AI model.
[0059] As a preferred solution of the present invention, the present invention provides a computer device,
[0060] at least one processor; and
[0061] a memory communicatively coupled to the at least one processor;
[0062] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the computer device to execute the AI model-based face stylization processing method.
[0063] Compared with the prior art, the present invention has the following beneficial effects:
[0064] The present invention proposes to use style weights to combine various target styles, fuse the portrait styles at different time sequences in dynamic videos, generate face images with multiple style elements, realize dynamic style processing of static images, and construct a second AI model to adaptively determine the weight of each style, thereby achieving balance and fusion between different styles. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] In order to more clearly illustrate the implementation methods of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the implementation methods or the description of the prior art. Obviously, the drawings in the following description are only exemplary, and for ordinary technicians in this field, other implementation drawings can be derived from the provided drawings without creative work.
[0066] Figure 1 A flow chart of a face stylization processing method based on an AI model provided in an embodiment of the present invention;
[0067] Figure 2 A block diagram of a face stylization processing device provided by an embodiment of the present invention;
[0068] Figure 3 An internal structure diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0069] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0070] like Figure 1 As shown, the present invention provides a face stylization processing method based on an AI model, comprising the following steps:
[0071] Acquire a first face image and a second face video, wherein the second face video comprises a group of second face video frames arranged continuously in a video frame time sequence, the first face image is an original face image to be stylized, and the second face video frame is a reference face image containing a target style of the stylized first face image;
[0072] According to a set of second face video frames, stylized encoding is performed by the first AI model to obtain a set of target styles, where the target styles correspond to the style encoding, and the first AI model corresponds to the StarGAN stylized processing model;
[0073] According to the first face image and a set of target styles, a weight is determined at each video frame timing in the second face video by a second AI model to obtain a style weight at each video frame timing, wherein the style weight corresponds to a fusion weight of each target style in the first face image, and the second AI model corresponds to a neural network that characterizes a mapping relationship between the first face image and the target style and the style weight;
[0074] According to a set of target styles and style weights at each video frame sequence, the first AI model is used to stylize the first face image at each video frame sequence in the second face video to obtain a third face video. The third face video is composed of third face images at each video frame sequence arranged in video frame sequence, and the third face image corresponds to the first face image stylized by the target style.
[0075] In order to realize dynamic stylized processing of facial images, the present invention performs stylized processing on the facial images to be stylized according to the specified video style, thereby converting the facial images from a static form to a dynamic form of the specified style, and transforming the stylized processing from a static level to a dynamic level, thereby expanding the applicable scenarios of portrait style processing.
[0076] In order to improve the effect of stylized processing of facial images under a specified video style, the present invention obtains the specified style (i.e., target style) of each video frame sequence in the video style, thereby determining all target styles in the specified video (second portrait video), and applies all target style combinations to the facial image to be stylized (first facial image), generating a facial image with multiple style elements, so that the first facial image is integrated with all target styles in the second portrait video, thereby enhancing the diversity of stylized processing of the first facial image and achieving the specified video style, that is, being able to accurately convert the portrait image into a portrait video (third portrait video) that is consistent with the video style of the second portrait video, and the image content of the first portrait image and the video style of the second portrait video are maintained in the third portrait video.
[0077] Furthermore, when combining target styles, the present invention utilizes a weight combination method to combine target styles. The style weight of the target style represents the influence of each target style. Therefore, the style weight determines the fusion effect of various target styles. In order to improve the fusion effect of various target styles on the first face image, a second AI model is constructed, and a neural network that characterizes the mapping relationship between the first face image and the target style and style weight is obtained, so as to adaptively determine the style weight of each target style. The determined style weight can achieve static balance and dynamic balance between various target styles when the first face image is stylized, thereby achieving the optimal fusion effect.
[0078] Furthermore, in order to enable the second AI model to achieve static balance and dynamic balance between various target styles, the present invention constructs a static weight prediction network so that the predicted static weights can be realized in each video frame sequence. In the stylized processing of the first face image, each target style is fused according to the static weight to achieve a stylized processing effect with the minimum similarity with the style features of the first face image and the maximum similarity with the content features of the first face image in the video frame sequence. The higher the degree of authenticity of the stylized processed image of the first face image in the video frame sequence, and the higher the degree of stylized application of the video style, that is, the better the combination effect of the content information of the first face image and the video style, so that the first face image achieves the optimal static stylized processing effect in each video frame sequence, and obtains a more realistic and accurate stylized processed image of the first face image converted into the video style in each video frame sequence. The static style weight can achieve a static balance between various target styles when the first face image is stylized.
[0079] The static balance between various target styles in the stylized processed image of the first face image at each video frame sequence is ensured, and the stylized effect is realistic and accurate. The present invention utilizes a multi-objective optimization algorithm to enable the predicted dynamic weights to be realized in the adjacent video frame sequence. In the stylized processing of the first face image, each target style is fused according to the dynamic weights to achieve the following stylized processing effect in the adjacent video frame sequence: the degree of change of style features of the first face image after stylized processing with the dynamic style weights between adjacent video frame sequences is minimized, and the degree of change of content features of the first face video after stylized processing with the dynamic style weights between adjacent video frame sequences is maximized.
[0080] The stylized processed image corresponding to the first face image achieves a small degree of style change in the timing of adjacent video frames, maintains the smoothness of the fused style in the scene where the video frame timing changes, maintains the style consistency of the dynamic style processing, and achieves a small degree of content change in the timing of adjacent video frames, maintains the variability of the fused content in the scene where the video frame timing changes, and maintains the content dynamics of the dynamic style processing. The style consistency and content dynamics in the timing of adjacent video frames ensure that the first face image maintains the best stylization effect when converted into a dynamic video of a specified style, which is more realistic and accurate. The dynamic style weight can achieve a dynamic balance between various target styles when stylizing the first face image.
[0081] The weight adaptive model performs stylization processing based on the input image and the target style to obtain a multimodal style image;
[0082] According to a set of second face video frames, stylized encoding is performed through the first AI model to obtain a set of target styles, including:
[0083] By using the style encoder or mapping network in the StarGAN stylization processing model, the style features of the second face video frame at each video frame sequence in the second face video are encoded respectively to obtain the style encoding of the second face video frame at each video frame sequence; the style encoding of the second face video frame at each video frame sequence is used as the target style at each video frame sequence to obtain a group of target styles corresponding to a group of second face video frames.
[0084] In the present invention, since the second face video is a dynamic video and is composed of different static video frames, it naturally contains different image styles. In order to enable the first face image to be fully converted into the video style of the second face video, all static image styles contained in the second face video are weighted and combined at each video frame sequence, rather than using a single static image style at the video frame sequence to stylize the first face image. All static image styles are weighted and combined to perform multi-style fusion processing on the first face image at each video frame sequence, so that the video style of the second face video is dynamically displayed on the first face image at each video frame sequence, and the stylized processing of the first face image is converted into dynamic stylized processing, which ensures that the stylized processed images of the first face image have style associations between adjacent images, thereby ensuring that in the scene where the video frame sequence changes, the fluency of the fusion style is maintained, and the style consistency of the dynamic style processing is maintained, that is, the style consistency between adjacent sequences in the third face video is maintained, which is more realistic and accurate.
[0085] In order to improve the fusion effect of various target styles on the first face image, the present invention constructs a second AI model, obtains a neural network that characterizes the mapping relationship between the first face image and the target style and style weight, and realizes adaptive determination of the style weight of each target style, as follows:
[0086] According to the first face image and a set of target styles, a weight is determined at each video frame timing in the second face video by a second AI model to obtain a style weight at each video frame timing, including:
[0087] The first face image and a set of target styles, as well as each video frame sequence in the second face video, are sequentially input into the second AI model to obtain the style weights of each target style at each video frame sequence;
[0088] Among them, the construction of the second AI model includes:
[0089] Randomly select two groups of sample images from the sample image library as first sample images and second sample images respectively;
[0090] Obtaining the target style of each second sample image to obtain a set of sample styles;
[0091] Randomly setting a plurality of groups of style weights of a group of sample styles for each first sample image to obtain a plurality of groups of sample weights for each first sample image;
[0092] For each first sample image, a group of sample styles are style-fused using multiple groups of sample weights to obtain multiple groups of stylized processed images of each first sample image;
[0093] In each first sample image, the style weight is used as the input item of the CNN neural network, and the stylized processed image of the first sample image is used as the output item of the CNN neural network. The CNN neural network is used to perform deep learning on the input item and the output item of the CNN neural network to obtain a stylized processing result prediction network, wherein the expression of the stylized processing result prediction network is:
[0094] G = CNN({W1,W2,W3,…,Wn});
[0095] Where g is the stylized image, W1 is the style weight of the first target style, W2 is the style weight of the second target style, W3 is the style weight of the third target style, Wn is the style weight of the nth target style, n is the total number of target styles, and CNN is the CNN neural network;
[0096] In each first sample image, all combinations of style weights are calculated one by one using the stylized processing result prediction model to obtain stylized processed images of all combinations of style weights;
[0097] The style weight corresponding to the optimal stylized image is used as the optimal static style weight of the first sample image;
[0098] The first sample image and the sample style are used as input items of the second CNN neural network, and the optimal static style weight is used as the output item of the second CNN neural network. The second CNN neural network is used to perform deep learning on the input items and the output items of the second CNN neural network to obtain a static weight prediction network, wherein the expression of the static weight prediction network is:
[0099] {W1 best1 ,W2 best1 ,W3 best1 ,…,Wn best1}=CNN2(G,{F1,F2,F3,…,Fn});
[0100] Where W1 best1 is the optimal static style weight of the first target style, W2best1 is the optimal static style weight of the style weight of the second target style, W3 best1 is the optimal static style weight of the style weight of the third target style, Wn best1 is the optimal static style weight of the style weight of the nth target style, n is the total number of target styles, G is the first sample image, F1 is the first target style, F2 is the second target style, F3 is the third target style, Fn is the nth target style, and CNN2 is the second CNN neural network;
[0101] The static weight prediction network in the present invention can also be used to fuse images of different styles and generate a face image with multiple style elements, that is, to fuse different style applications into the same static image, that is, to obtain multiple reference images of specified styles, and then use the static weight prediction network to determine the style weights of multiple specified styles in the face image to be stylized, and then use the style weights to fuse the multiple specified styles into the face image to be stylized, generate a face image with multiple style elements, and complete the stylization processing between static images.
[0102] The static weight prediction model is combined with a multi-objective optimization algorithm to obtain the optimal dynamic style weight of the first face image at each video frame time sequence;
[0103] The first face image and a set of target styles are used as input items of the third CNN neural network, and the optimal dynamic style weight is used as the output item of the third CNN neural network. The third CNN neural network is used to perform deep learning on the input items of the third CNN neural network and the output items of the third CNN neural network to obtain a dynamic weight prediction network, wherein the expression of the dynamic weight prediction network is:
[0104] {W1 best2 ,W2 best2 ,W3 best2 ,…,Wn best2}=CNN3(G2,{F1,F2,F3,…,Fn});
[0105] Where W1 best2 is the optimal dynamic style weight of the first target style, W2 best2 is the optimal dynamic style weight of the style weight of the second target style, W3 best2 is the optimal dynamic style weight of the style weight of the third target style, Wn best2is the optimal dynamic style weight of the style weight of the nth target style, n is the total number of target styles, G2 is the first face image, F1 is the first target style, F2 is the second target style, F3 is the third target style, Fn is the nth target style, and CNN3 is the third CNN neural network.
[0106] Determination of the optimal stylized image, including:
[0107] The style features and content features of each stylized image are compared with those of the first sample image, wherein:
[0108] The stylized image having the smallest similarity with the style feature of the first sample image and the largest similarity with the content feature of the first sample image is used as the optimal stylized image of the first sample image;
[0109] Similarity is quantified using one of the following: Euclidean distance, correlation coefficient, and Jaccard coefficient.
[0110] Determination of the optimal dynamic style weight includes:
[0111] The static weight prediction model is used to obtain the optimal static style weight of the first face image at each video frame time sequence;
[0112] A first dynamic target is set. The first dynamic target corresponds to minimizing the degree of change of style features of the first face image after stylization by the dynamic style weight between adjacent video frames. The expression of the first dynamic target is:
[0113]
[0114] In the formula, K1 is the first dynamic target, min is the minimization operator, sim is the similarity operator, G3H t is the style feature of the first face image at the tth video frame sequence after stylization by dynamic style weight, G3H t+1 is the style feature of the first face image at the t+1th video frame sequence after stylization by dynamic style weight, m is the total number of video frames, sim(G3H t ,G3H t+1 ) is G3H t and G3H t+1 The similarity between them, t is a counting variable;
[0115] A second dynamic target is set. The second dynamic target corresponds to maximizing the degree of change of content features between adjacent video frames in the first face video after stylization by the dynamic style weight. The expression of the second dynamic target is:
[0116]
[0117] In the formula, K2 is the second dynamic target, max is the minimization operator, sim is the similarity operator, G3S t G3S is the content feature of the first face image at the tth video frame sequence after stylization by dynamic style weights, t+1 is the content feature of the first face image at the t+1th video frame sequence after stylization by dynamic style weight, m is the total number of video frames, sim(G3S t ,G3S t+1 ) is G3S t and G3S t+1 The similarity between them, t is a counting variable;
[0118] G3 is the first face image after stylization processing with dynamic style weights {W12, W22, W32, …, Wn2}, W12 is the dynamic style weight of the first target style, W22 is the dynamic style weight of the style weight of the second target style, W32 is the dynamic style weight of the style weight of the third target style, Wn2 is the dynamic style weight of the style weight of the nth target style, and n is the total number of target styles.
[0119] Taking the optimal static style weight as the solution constraint, solving the first dynamic target and the second dynamic target, and obtaining the optimal solution of the dynamic style weight {W12, W22, W32, …, Wn2};
[0120] The optimal solution of the dynamic style weights {W12, W22, W32, …, Wn2} is used as the optimal dynamic style weight {W12, W22, W32, …, Wn2} for stylizing the first face image at each video frame time sequence. best2 ,W2 best2 ,W3 best2 ,…,Wn best2}.
[0121] In order to enable the second AI model to achieve static balance and dynamic balance between various target styles, the present invention constructs a static weight prediction network so that the predicted static weights can be realized in each video frame sequence. In the stylized processing of the first face image, each target style is fused according to the static weight to achieve a stylized processing effect with the minimum similarity with the style features of the first face image and the maximum similarity with the content features of the first face image in the video frame sequence. The higher the degree of authenticity of the stylized processed image of the first face image in the video frame sequence, and the higher the degree of stylized application of the video style, that is, the better the combination effect of the content information of the first face image and the video style, so that the first face image achieves the optimal static stylized processing effect in each video frame sequence, and obtains a more realistic and accurate stylized processed image of the first face image converted into the video style in each video frame sequence. The static style weight can achieve a static balance between various target styles when the first face image is stylized.
[0122] The static balance between various target styles in the stylized processed image of the first face image at each video frame sequence is ensured, and the stylized effect is realistic and accurate. The present invention utilizes a multi-objective optimization algorithm to enable the predicted dynamic weights to be realized in the adjacent video frame sequence. In the stylized processing of the first face image, each target style is fused according to the dynamic weights to achieve the following stylized processing effect in the adjacent video frame sequence: the degree of change of style features of the first face image after stylized processing with the dynamic style weights between adjacent video frame sequences is minimized, and the degree of change of content features of the first face video after stylized processing with the dynamic style weights between adjacent video frame sequences is maximized.
[0123] The stylized processed image corresponding to the first face image achieves a small degree of style change in the timing of adjacent video frames, maintains the smoothness of the fused style in the scene where the video frame timing changes, maintains the style consistency of the dynamic style processing, and achieves a small degree of content change in the timing of adjacent video frames, maintains the variability of the fused content in the scene where the video frame timing changes, and maintains the content dynamics of the dynamic style processing. The style consistency and content dynamics in the timing of adjacent video frames ensure that the first face image maintains the best stylization effect when converted into a dynamic video of a specified style, which is more realistic and accurate. The dynamic style weight can achieve a dynamic balance between various target styles when stylizing the first face image.
[0124] According to a set of target styles and style weights at each video frame time sequence, a first AI model is used to perform stylization processing on the first face image at each video frame time sequence in the second face video to obtain a third face video, including:
[0125] Inputting the first face image, a set of target styles, and the dynamic style weights at each video frame time sequence into the first AI model, and the first AI model outputs the stylized processed image of the first face image at each video frame time sequence;
[0126] Marking the stylized processed image of the first face image at each video frame time sequence as a third face image;
[0127] The third face images at each video frame time sequence are arranged in time sequence to obtain a third face video.
[0128] The first face image and the second face video are pre-processed after being acquired, and the image pre-processing includes at least one of resizing, cropping, and grayscale conversion.
[0129] The third face image is subjected to image post-processing after being acquired, and the image post-processing includes at least one of image enhancement, denoising and edge enhancement.
[0130] like Figure 2 As shown, the present invention provides a face stylization processing device, comprising:
[0131] A data acquisition module is used to acquire a first face image and a second face video, wherein the second face video includes a group of second face video frames arranged continuously in a video frame time sequence, the first face image is an original face image to be stylized, and the second face video frame is a reference face image including a target style of the stylized first face image;
[0132] A data processing module, configured to perform stylized encoding through a first AI model according to a set of second face video frames to obtain a set of target styles;
[0133] for determining weights at each video frame sequence in the second face video by a second AI model according to the first face image and a set of target styles, so as to obtain a style weight at each video frame sequence; and
[0134] Used to perform stylized processing on the first face image at each video frame sequence in the second face video by using the first AI model according to a set of target styles and the style weight at each video frame sequence, so as to obtain a third face video;
[0135] The data storage module is used to store the first AI model and the second AI model.
[0136] like Figure 3 As shown, the present invention provides a computer device,
[0137] at least one processor; and
[0138] a memory communicatively coupled to the at least one processor;
[0139] The memory stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor to enable the computer device to perform a face stylization processing method based on an AI model.
[0140] The present invention proposes to use style weights to combine various target styles, fuse the portrait styles at different time sequences in dynamic videos, generate face images with multiple style elements, realize dynamic style processing of static images, and construct a second AI model to adaptively determine the weight of each style, thereby achieving balance and fusion between different styles.
[0141] The above embodiments are only exemplary embodiments of the present application and are not intended to limit the present application. The protection scope of the present application is defined by the claims. Those skilled in the art may make various modifications or equivalent substitutions to the present application within the essence and protection scope of the present application, and such modifications or equivalent substitutions shall also be deemed to fall within the protection scope of the present application.
Claims
1. A face stylization processing method based on an AI model, characterized by: The following steps are involved: Acquire a first face image and a second face video, wherein the second face video comprises a group of second face video frames arranged continuously in a video frame time sequence, the first face image is an original face image to be stylized, and the second face video frame is a reference face image containing a target style of the stylized first face image; According to a set of second face video frames, stylized encoding is performed by the first AI model to obtain a set of target styles, where the target styles correspond to the style encoding, and the first AI model corresponds to the StarGAN stylized processing model; According to the first face image and a set of target styles, weight determination is performed at each video frame timing in the second face video by a second AI model to obtain a style weight at each video frame timing, wherein the style weight corresponds to a fusion weight of each target style in the first face image, and the second AI model corresponds to a neural network that characterizes a mapping relationship between the first face image and the target style and the style weight; According to a set of target styles and style weights at each video frame timing, stylizing the first face image at each video frame timing in the second face video by a first AI model to obtain a third face video, wherein the third face video is composed of third face images at each video frame timing arranged in the video frame timing, and the third face image corresponds to the first face image stylized by the target style; According to the first face image and a set of target styles, a weight is determined at each video frame timing in the second face video by a second AI model to obtain a style weight at each video frame timing, including: The first face image and a set of target styles, as well as each video frame sequence in the second face video, are sequentially input into the second AI model to obtain the style weights of each target style at each video frame sequence; The construction of the second AI model includes: Randomly select two groups of sample images from the sample image library as first sample images and second sample images respectively; Obtaining the target style of each second sample image to obtain a set of sample styles; Randomly setting a plurality of groups of style weights of a group of sample styles for each first sample image to obtain a plurality of groups of sample weights for each first sample image; For each first sample image, a group of sample styles are style-fused using multiple groups of sample weights to obtain multiple groups of stylized processed images of each first sample image; In each first sample image, the style weight is used as an input item of the CNN neural network, and the stylized processed image of the first sample image is used as an output item of the CNN neural network. The CNN neural network is used to perform deep learning on the input item and the output item of the CNN neural network to obtain a stylized processing result prediction network, wherein the expression of the stylized processing result prediction network is: g = CNN(G,{W1,W2,W3,…,Wn}); Where g is the stylized image of the first sample image, G is the first sample image, W1 is the style weight of the first target style, W2 is the style weight of the second target style, W3 is the style weight of the third target style, Wn is the style weight of the nth target style, n is the total number of target styles, and CNN is the CNN neural network; In each first sample image, all combinations of style weights are calculated one by one using the stylized processing result prediction model to obtain stylized processed images of all combinations of style weights; The style weight corresponding to the optimal stylized image is used as the optimal static style weight of the first sample image; The first sample image and the sample style are used as input items of the second CNN neural network, and the optimal static style weight is used as the output item of the second CNN neural network. The second CNN neural network is used to perform deep learning on the input items and the output items of the second CNN neural network to obtain a static weight prediction network, wherein the expression of the static weight prediction network is: <h2 style=";text-align:left;direction:ltr">{W1<h2 style=";text-align:left;direction:ltr"> best1 <h2 style=";text-align:left;direction:ltr"> W2<h2 style=";text-align:left;direction:ltr"> best1 <h2 style=";text-align:left;direction:ltr"> W3<h2 style=";text-align:left;direction:ltr"> best1 <h2 style=";text-align:left;direction:ltr"> ,…,Wn<h2 style=";text-align:left;direction:ltr"> best1 <h2 style=";text-align:left;direction:ltr">}=CNN2(G,{F1,F2,F3,...,Fn}); Where W1 best1 is the optimal static style weight of the style weight of the first target style, W2 best1 is the optimal static style weight of the style weight of the second target style, W3 best1 is the optimal static style weight of the style weight of the third target style, Wn best1 is the optimal static style weight of the style weight of the nth target style, n is the total number of target styles, G is the first sample image, F1 is the first target style, F2 is the second target style, F3 is the third target style, Fn is the nth target style, and CNN2 is the second CNN neural network; The static weight prediction model is combined with a multi-objective optimization algorithm to obtain the optimal dynamic style weight of the first face image at each video frame time sequence; The first face image and a set of target styles are used as input items of the third CNN neural network, the optimal dynamic style weight is used as the output item of the third CNN neural network, and the third CNN neural network is used to perform deep learning on the input items of the third CNN neural network and the output items of the third CNN neural network to obtain a dynamic weight prediction network, wherein the expression of the dynamic weight prediction network is: <h2 style=";text-align:left;direction:ltr">{W1<h2 style=";text-align:left;direction:ltr"> best2 <h2 style=";text-align:left;direction:ltr"> W2<h2 style=";text-align:left;direction:ltr"> best2 <h2 style=";text-align:left;direction:ltr"> W3<h2 style=";text-align:left;direction:ltr"> best2 <h2 style=";text-align:left;direction:ltr"> ,…,Wn<h2 style=";text-align:left;direction:ltr"> best2 <h2 style=";text-align:left;direction:ltr">}=CNN3(G2,{F1,F2,F3,…,Fn}); Where W1 best2 is the optimal dynamic style weight of the style weight of the first target style, W2 best2 is the optimal dynamic style weight of the style weight of the second target style, W3 best2 is the optimal dynamic style weight of the style weight of the third target style, Wn best2 is the optimal dynamic style weight of the style weight of the nth target style, n is the total number of target styles, G2 is the first face image, F1 is the first target style, F2 is the second target style, F3 is the third target style, Fn is the nth target style, and CNN3 is the third CNN neural network; The determination of the optimal stylized image includes: The style features and content features of each stylized image are compared with those of the first sample image, wherein: The stylized image having the smallest similarity with the style feature of the first sample image and the largest similarity with the content feature of the first sample image is used as the optimal stylized image of the first sample image; The determination of the optimal dynamic style weight includes: The static weight prediction model is used to obtain the optimal static style weight of the first face image at each video frame time sequence; A first dynamic target is set. The first dynamic target corresponds to minimizing the degree of change of style features of the first face image after stylization by the dynamic style weight between adjacent video frames. The expression of the first dynamic target is: ; In the formula, K1 is the first dynamic target, min is the minimization operator, sim is the similarity operator, G3H t is the style feature of the first face image at the tth video frame sequence after stylization by dynamic style weight, G3H t+1 is the style feature of the first face image at the t+1th video frame sequence after stylization by dynamic style weight, m is the total number of video frames, sim(G3H t ,G3H t+1 ) is G3H t and G3H t+1 The similarity between them, t is a counting variable; A second dynamic target is set, and the second dynamic target corresponds to maximizing the degree of change of content features between adjacent video frames in the first face video after stylization by the dynamic style weight. The expression of the second dynamic target is: ; In the formula, K2 is the second dynamic target, max is the minimization operator, sim is the similarity operator, G3S t G3S is the content feature of the first face image at the tth video frame sequence after stylization by dynamic style weights, t+1 is the content feature of the first face image at the t+1th video frame sequence after stylization by dynamic style weight, m is the total number of video frames, sim(G3S t ,G3S t+1 ) is G3S t and G3S t+1 The similarity between them, t is a counting variable; G3 is the first face image after stylization processing with dynamic style weights {W12, W22, W32, …, Wn2}, W12 is the dynamic style weight of the style weight of the first target style, W22 is the dynamic style weight of the style weight of the second target style, W32 is the dynamic style weight of the style weight of the third target style, Wn2 is the dynamic style weight of the style weight of the nth target style, and n is the total number of target styles; Taking the optimal static style weight as the solution constraint, solving the first dynamic target and the second dynamic target, and obtaining the optimal solution of the dynamic style weight {W12, W22, W32, …, Wn2}; The optimal solution of the dynamic style weights {W12, W22, W32, …, Wn2} is used as the optimal dynamic style weight {W12, W22, W32, …, Wn2} for stylizing the first face image at each video frame time sequence. best2 ,W2 best2 ,W3 best2 ,…,Wn best2 }.
2. The method for face stylization based on an AI model according to claim 1, characterized in that: According to a set of second face video frames, stylized encoding is performed through the first AI model to obtain a set of target styles, including: Using the style encoder or mapping network in the StarGAN stylization processing model, the style features of the second face video frame at each video frame time sequence in the second face video are respectively encoded to obtain the style encoding of the second face video frame at each video frame time sequence; The style encoding of the second face video frame at each video frame time sequence is used as the target style at each video frame time sequence, and a group of target styles corresponding to a group of second face video frames are obtained.
3. The method for face stylization based on AI model according to claim 2, characterized in that: The similarity is quantified using one of the Euclidean distance, correlation coefficient and Jaccard coefficient.
4. The method for face stylization based on an AI model according to claim 3, characterized in that: According to a set of target styles and style weights at each video frame time sequence, a first AI model is used to perform stylization processing on the first face image at each video frame time sequence in the second face video to obtain a third face video, including: Inputting the first face image, a set of target styles, and the dynamic style weights at each video frame time sequence into the first AI model, and the first AI model outputs the stylized processed image of the first face image at each video frame time sequence; Marking the stylized processed image of the first face image at each video frame time sequence as a third face image; The third face images at each video frame time sequence are arranged in time sequence to obtain a third face video.
5. The method for face stylization based on AI model according to claim 1, characterized in that: The first face image and the second face video are subjected to image preprocessing after being acquired, and the image preprocessing includes at least one of resizing, cropping and grayscale conversion.
6. The method for face stylization based on an AI model according to claim 1, characterized in that: The third face image is subjected to image post-processing after being acquired, and the image post-processing includes at least one of image enhancement, denoising and edge enhancement.
7. A face stylization processing device, characterized in that: A method for face stylization processing based on an AI model as described in any one of claims 1 to 6, the system comprising: A data acquisition module, configured to acquire a first face image and a second face video, wherein the second face video comprises a group of second face video frames arranged continuously in a video frame time sequence, the first face image is an original face image to be stylized, and the second face video frame is a reference face image containing a target style of the stylized first face image; A data processing module, configured to perform stylized encoding through a first AI model according to a set of second face video frames to obtain a set of target styles; for determining weights at each video frame sequence in the second face video by a second AI model according to the first face image and a set of target styles, so as to obtain a style weight at each video frame sequence; and Used to perform stylized processing on the first face image at each video frame sequence in the second face video by using the first AI model according to a set of target styles and the style weight at each video frame sequence, so as to obtain a third face video; A data storage module, used to store the first AI model and the second AI model; According to the first face image and a set of target styles, a weight is determined at each video frame timing in the second face video by a second AI model to obtain a style weight at each video frame timing, including: The first face image and a set of target styles, as well as each video frame sequence in the second face video, are sequentially input into the second AI model to obtain the style weights of each target style at each video frame sequence; The construction of the second AI model includes: Randomly select two groups of sample images from the sample image library as first sample images and second sample images respectively; Obtaining the target style of each second sample image to obtain a set of sample styles; Randomly setting a plurality of groups of style weights of a group of sample styles for each first sample image to obtain a plurality of groups of sample weights for each first sample image; For each first sample image, a group of sample styles are style-fused using multiple groups of sample weights to obtain multiple groups of stylized processed images of each first sample image; In each first sample image, the style weight is used as an input item of the CNN neural network, and the stylized processed image of the first sample image is used as an output item of the CNN neural network. The CNN neural network is used to perform deep learning on the input item and the output item of the CNN neural network to obtain a stylized processing result prediction network, wherein the expression of the stylized processing result prediction network is: g = CNN(G,{W1,W2,W3,…,Wn}); Where g is the stylized image of the first sample image, G is the first sample image, W1 is the style weight of the first target style, W2 is the style weight of the second target style, W3 is the style weight of the third target style, Wn is the style weight of the nth target style, n is the total number of target styles, and CNN is the CNN neural network; In each first sample image, all combinations of style weights are calculated one by one using the stylized processing result prediction model to obtain stylized processed images of all combinations of style weights; The style weight corresponding to the optimal stylized image is used as the optimal static style weight of the first sample image; The first sample image and the sample style are used as input items of the second CNN neural network, and the optimal static style weight is used as the output item of the second CNN neural network. The second CNN neural network is used to perform deep learning on the input items and the output items of the second CNN neural network to obtain a static weight prediction network, wherein the expression of the static weight prediction network is: <h2 style=";text-align:left;direction:ltr">{W1<h2 style=";text-align:left;direction:ltr"> best1 <h2 style=";text-align:left;direction:ltr"> W2<h2 style=";text-align:left;direction:ltr"> best1 <h2 style=";text-align:left;direction:ltr"> W3<h2 style=";text-align:left;direction:ltr"> best1 <h2 style=";text-align:left;direction:ltr"> ,…,Wn<h2 style=";text-align:left;direction:ltr"> best1 <h2 style=";text-align:left;direction:ltr">}=CNN2(G,{F1,F2,F3,...,Fn}); Where W1 best1 is the optimal static style weight of the style weight of the first target style, W2 best1 is the optimal static style weight of the style weight of the second target style, W3 best1 is the optimal static style weight of the style weight of the third target style, Wn best1 is the optimal static style weight of the style weight of the nth target style, n is the total number of target styles, G is the first sample image, F1 is the first target style, F2 is the second target style, F3 is the third target style, Fn is the nth target style, and CNN2 is the second CNN neural network; The static weight prediction model is combined with a multi-objective optimization algorithm to obtain the optimal dynamic style weight of the first face image at each video frame time sequence; The first face image and a set of target styles are used as input items of the third CNN neural network, the optimal dynamic style weight is used as the output item of the third CNN neural network, and the third CNN neural network is used to perform deep learning on the input items of the third CNN neural network and the output items of the third CNN neural network to obtain a dynamic weight prediction network, wherein the expression of the dynamic weight prediction network is: <h2 style=";text-align:left;direction:ltr">{W1<h2 style=";text-align:left;direction:ltr"> best2 <h2 style=";text-align:left;direction:ltr"> W2<h2 style=";text-align:left;direction:ltr"> best2 <h2 style=";text-align:left;direction:ltr"> W3<h2 style=";text-align:left;direction:ltr"> best2 <h2 style=";text-align:left;direction:ltr"> ,…,Wn<h2 style=";text-align:left;direction:ltr"> best2 <h2 style=";text-align:left;direction:ltr">}=CNN3(G2,{F1,F2,F3,…,Fn}); Where W1 best2 is the optimal dynamic style weight of the style weight of the first target style, W2 best2 is the optimal dynamic style weight of the style weight of the second target style, W3 best2 is the optimal dynamic style weight of the style weight of the third target style, Wn best2 is the optimal dynamic style weight of the style weight of the nth target style, n is the total number of target styles, G2 is the first face image, F1 is the first target style, F2 is the second target style, F3 is the third target style, Fn is the nth target style, and CNN3 is the third CNN neural network.
8. A computer device, characterized in that: at least one processor; and a memory communicatively coupled to at least one of the processors; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the computer device to execute the method according to any one of claims 1 to 6.
