Hair editing method, device and computer equipment for images
The method uses high-dimensional vectors and iterative loss functions to enhance hair editing precision and quality in images by accurately representing initial features and incorporating target hair characteristics, addressing the limitations of existing hair editing technologies.
Patent Information
- Application Number
- CN202210203313.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-03
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2042-03-03
AI Technical Summary
The hair shape generated by the hair editing scheme in the prior art is uncontrollable and has poor texture, and has low processing accuracy and practicality.
By generating the initial high-dimensional vector, iteratively optimize the initial high-dimensional vector using the first loss function and the second loss function, the corrected high-dimensional vector and the target high-dimensional vector are generated to achieve accurate editing of hair features.
Improves the processing accuracy and practicality of hair editing, ensuring that the hair edited images can accurately represent the information of the initial face image and have the characteristics of the target hair.
Smart Images

Figure CN114581551B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more particularly, to a method, an apparatus, and a computer device for editing hair in an image. Background Art
[0002] With the development of science and technology, more and more intelligent devices have entered people's lives. These intelligent devices generally have a photographing function and a video recording function, and people can use the intelligent devices to take pictures anytime and anywhere.
[0003] In the related art, after a user takes a self-portrait or takes a picture of someone else to obtain an image including a human face, the image can generally be edited through some image processing software. For example, the hair in these images can be edited. Specifically, the attributes such as the color, texture, and trend of the hair in the image can be changed.
[0004] Since there are many details to be processed when editing hair, however, the shape of the hair generated by the hair editing solution in the related art is uncontrollable and the generated hair texture is poor. Therefore, the solutions in the related art have problems of low processing accuracy and poor practicability. Summary of the Invention
[0005] The purpose of the present application is to provide a method, an apparatus, and a computer device for editing hair in an image, which can achieve the effect of improving processing accuracy and practicability.
[0006] The embodiments of the present application are implemented as follows:
[0007] In the first aspect of the embodiments of the present application, a method for editing hair in an image is provided. The method includes:
[0008] Generating a face image to be edited according to an initial high-dimensional vector, where the face image to be edited includes a human face and hair, and the initial high-dimensional vector is used to represent the features of the human face and the features of the hair in the initial face image input by the user;
[0009] Determining a first loss value between the face image to be edited and the initial face image input by the user through a first loss function;
[0010] Iteratively optimizing the initial high-dimensional vector based on the first loss value, taking the initial high-dimensional vector that reaches a first preset condition as a corrected high-dimensional vector, and generating a corrected face image according to the corrected high-dimensional vector;
[0011] Determining a second loss value among the corrected face image, the initial face image, and a reference image through a second loss function, where the reference image includes the target hair selected by the user;
[0012] Iteratively optimize the corrected high-dimensional vector based on the second loss value, take the corrected high-dimensional vector that meets the second preset condition as the target high-dimensional vector, and generate the final edited face image according to the target high-dimensional vector. The hair in the target face image has at least one feature of the target hair.
[0013] Optionally, the generating the face image to be edited according to the initial high-dimensional vector includes:
[0014] Calculate the initial high-dimensional vector based on the initial face image;
[0015] Input the initial high-dimensional vector into a pre-trained image generator to generate the face image to be edited. The image generator is a progressive neural network model.
[0016] Optionally, the first loss function includes a mean squared error (MSE) loss function and a perceptual loss function;
[0017] The determining the first loss value between the face image to be edited and the initial face image through the first loss function includes:
[0018] Determine the first mean value of the sum of squared errors of corresponding points between the face image to be edited and the initial face image through the mean squared error loss function;
[0019] Extract the feature maps of the face image to be edited and the initial face image through the perceptual loss function, and determine the second mean value of the sum of squared errors of corresponding points between the feature maps of the face image to be edited and the initial face image;
[0020] Determine the first loss value according to the first mean value and the second mean value.
[0021] Optionally, the determining the first mean value of the sum of squared errors of corresponding points between the face image to be edited and the initial face image through the mean squared error loss function includes:
[0022] Determine the first mean value of the hair in the face image to be edited and the hair in the initial face image through the mean squared error loss function;
[0023] The extracting the feature maps of the face image to be edited and the initial face image through the perceptual loss function, and determining the second mean value of the sum of squared errors of corresponding points between the feature maps of the face image to be edited and the initial face image includes:
[0024] Determine the feature map of the hair in the to-be-edited face image and the feature map of the hair in the initial face image through a perceptual loss function, and determine the second mean value of the sum of the squared errors of the corresponding points between the feature map of the hair in the to-be-edited face image and the feature map of the hair in the initial face image.
[0025] Optionally, the determining the first loss value according to the first mean value and the second mean value includes:
[0026] Taking the sum obtained by adding the first mean value and the second mean value as the first loss value.
[0027] Optionally, the second loss function includes a cross-entropy loss function (CrossEntropy), a style loss function, and a cosine distance (Cos) loss function;
[0028] The determining the second loss value between the corrected face image and the reference image through the second loss function includes:
[0029] Determining the cross-entropy loss of the hair in the corrected face image and the target hair in the reference image through the cross-entropy loss function;
[0030] Determining the style loss value between the corrected face image and the initial face image through the style loss function;
[0031] Determining the angular loss value between the corrected high-dimensional vector and the high-dimensional vector corresponding to the initial face image through the cosine distance loss function;
[0032] Determining the second loss value according to the cross-entropy loss, the style loss value, and the angular loss value.
[0033] Optionally, the determining the second loss value according to the cross-entropy loss, the style loss value, and the angular loss value includes:
[0034] Taking the sum obtained by adding the cross-entropy loss, the style loss value, and the angular loss value as the second loss value.
[0035] Optionally, before the determining the second loss value between the corrected face image and the reference image through the second loss function, the method further includes:
[0036] Performing a segmentation process on the corrected face image to obtain the hair in the corrected face image.
[0037] Optionally, the iteratively optimizing the corrected high-dimensional vector based on the second loss value includes:
[0038] Determine the difference features between the hair in the corrected face image and the hair in the reference image, where the difference features include at least one of the following: the trend of the hair, the length of the hair, and the color of the hair;
[0039] Iteratively optimize the corrected high-dimensional vector according to the second loss value and the difference features.
[0040] In a second aspect of the embodiments of the present application, an apparatus for editing the hair of an image is provided, and the apparatus includes:
[0041] A generation module, configured to generate a face image to be edited according to an initial high-dimensional vector;
[0042] A first determination module, configured to determine a first loss value between the face image to be edited and an initial face image input by a user through a first loss function;
[0043] A first optimization and generation module, configured to iteratively optimize the initial high-dimensional vector based on the first loss value, use the initial high-dimensional vector that reaches a first preset condition as a corrected high-dimensional vector, and generate a corrected face image according to the corrected high-dimensional vector;
[0044] A second determination module, configured to determine a second loss value among the corrected face image, the initial face image, and a reference image through a second loss function;
[0045] A second optimization and generation module, configured to iteratively optimize the corrected high-dimensional vector based on the second loss value, use the corrected high-dimensional vector that reaches a second preset condition as a target high-dimensional vector, and generate a final face image after editing according to the target high-dimensional vector.
[0046] In a third aspect of the embodiments of the present application, a computer device is provided, and the computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the method for editing the hair of an image described in the first aspect is implemented.
[0047] In a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, and the computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the method for editing the hair of an image described in the first aspect is implemented.
[0048] The beneficial effects of the embodiments of the present application include:
[0049] A method for editing hair in an image provided by an embodiment of the present application generates a face image to be edited based on an initial high-dimensional vector, then determines a first loss value between the face image to be edited and an initial face image input by a user through a first loss function, iteratively optimizes the initial high-dimensional vector based on the first loss value, uses the initial high-dimensional vector that meets a first preset condition as a corrected high-dimensional vector, generates a corrected face image based on the corrected high-dimensional vector, then determines a second loss value between the corrected face image, the initial face image, and a reference image through a second loss function, and finally iteratively optimizes the corrected high-dimensional vector based on the second loss value, uses the corrected high-dimensional vector that meets a second preset condition as a target high-dimensional vector, and generates a final face image after editing based on the target high-dimensional vector. Among them, iteratively optimizing the initial high-dimensional vector based on the first loss value, using the initial high-dimensional vector that meets the first preset condition as the corrected high-dimensional vector, and generating a corrected face image based on the corrected high-dimensional vector can ensure that the corrected high-dimensional vector can accurately represent the information of the initial face image. In addition, iteratively optimizing the corrected high-dimensional vector based on the second loss value, using the corrected high-dimensional vector that meets the second preset condition as the target high-dimensional vector, and generating a final face image after editing based on the target high-dimensional vector can ensure that on the basis of retaining the features and / or information of the initial face image, the hair in the final face image can also have at least one feature of the target hair. In this way, the purpose of editing the hair in the initial face image or the hair in the face image to be edited can be achieved, and further, the effect of improving the processing accuracy of the hair in the image and the practicality of the method for editing the hair in the image can be achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] To more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application and should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can also be obtained based on these drawings without creative efforts.
[0051] Figure 1 It is a flowchart of the first method for editing hair in an image provided by an embodiment of the present application;
[0052] Figure 2 It is a flowchart of the second method for editing hair in an image provided by an embodiment of the present application;
[0053] Figure 3 It is a flowchart of the third method for editing hair in an image provided by an embodiment of the present application;
[0054] Figure 4Flowchart of the fourth method for editing hair in an image provided by an embodiment of the present application;
[0055] Figure 5 Flowchart of the fifth method for editing hair in an image provided by an embodiment of the present application;
[0056] Figure 6 Schematic structural diagram of a device for a method of editing hair in an image provided by an embodiment of the present application;
[0057] Figure 7 Schematic structural diagram of a computer device provided by an embodiment of the present application. Detailed implementation manners
[0058] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. Generally, the components of the embodiments of the present application described and illustrated in the accompanying drawings here can be arranged and designed in various different configurations.
[0059] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the claimed present application, but merely represents selected embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0060] In daily life, people can edit images through some image processing software. For example, they can edit the hair in these images. Specifically, they can change attributes such as the color, texture, and trend of the hair in the image. Since there are many details to be processed when editing hair, however, in the related art, the shape of the hair generated by the solution for editing hair is uncontrollable and the generated hair texture is poor. Therefore, the solutions in the related art have problems of low processing accuracy and poor practicability.
[0061] To this end, the embodiments of the present application provide a method for editing hair in an image. By generating an image of a face to be edited according to an initial high-dimensional vector, determining a first loss value between the image of the face to be edited and the initial face image input by the user through a first loss function, iteratively optimizing the initial high-dimensional vector based on the first loss value, using the initial high-dimensional vector that reaches a first preset condition as a corrected high-dimensional vector, generating a corrected face image according to the corrected high-dimensional vector, determining a second loss value among the corrected face image, the initial face image, and a reference image through a second loss function, iteratively optimizing the corrected high-dimensional vector based on the second loss value, using the corrected high-dimensional vector that reaches a second preset condition as a target high-dimensional vector, and generating a final face image after editing according to the target high-dimensional vector, it is possible to improve the processing accuracy of the hair in the image and enhance the practicality of the method for editing hair in the image.
[0062] The embodiments of the present application are described by taking the method for editing hair in an image applied to a computer device as an example. However, it does not mean that the embodiments of the present application can only be applied to a computer device for editing hair in an image.
[0063] Optionally, the computer device may be a smart phone, a computer, a tablet computer, or other devices with processing functions. The embodiments of the present application do not limit this.
[0064] The following provides a detailed explanation of the method for editing hair in an image provided by the embodiments of the present application.
[0065] Figure 1 It is a flowchart of a method for editing hair in an image provided by the present application. This method can be applied to a computer device, which may be the above-mentioned computer device or server.
[0066] See Figure 1 , the embodiments of the present application provide a method for editing hair in an image, including:
[0067] Step 1001: Generate an image of a face to be edited according to an initial high-dimensional vector.
[0068] Optionally, the initial high-dimensional vector may be a high-dimensional vector calculated according to the initial face image taken and / or input by the user, or a pre-recorded high-dimensional vector, or a high-dimensional vector sent by the user to the above-mentioned computer device through other terminal devices or servers. The embodiments of the present application do not limit this.
[0069] Optionally, the initial face image may be an image including a face, or an image including a face and hair. The embodiments of the present application do not limit this.
[0070] Exemplarily, a Convolutional Neural Network (CNN) model can be used to process the initial face image. The initial face image is input into the CNN model, and several cascaded convolutional layers and pooling layers in the CNN model process the input initial face image. For example, the input initial face image is decoupled and / or feature extracted. During this process, the size of the initial face image gradually decreases, while the corresponding dimension gradually increases, which is beneficial for extracting the semantic features of the initial face image. Finally, the data corresponding to the processed initial face image is input into a fully connected layer to obtain the initial high-dimensional vector of the initial face image. The initial high-dimensional vector is a high-level semantic description of the initial face image. Naturally, other methods can also be used to calculate the initial high-dimensional vector. The embodiments of this application do not limit this.
[0071] Optionally, decoupling and / or feature extraction of the input initial face image can obtain the content information and color information of the initial face image. For example, the face and hair in the initial face image can be obtained, the style of the initial face image can also be obtained, the color of the face and the color of the hair in the initial face image can also be obtained, and information such as the trend of the hair, the length of the hair, and the relative position between the hair and the face in the initial face image can also be obtained. The embodiments of this application do not limit this.
[0072] Correspondingly, the above-mentioned initial high-dimensional vector can be constructed according to the content information and color information of the initial face image extracted above, so that the initial high-dimensional vector can describe the features of the initial face image, such as information about the color, style, color difference, etc. of the initial face image.
[0073] Specifically, the initial high-dimensional vector is used to represent the features of the face and the features of the hair in the initial face image.
[0074] Optionally, the features of the face can include information such as the color of the face, the position of the face, the size of the face, and the positions of the respective feature points on the face. The respective feature points on the face can be points used to indicate the positions of the nose, eyes, forehead, chin, mouth, and / or ears. The embodiments of this application do not limit this.
[0075] Optionally, the features of the hair can include information such as the trend of the hair, the length of the hair, the color of the hair, the area where the hair exists, and the relative position between the hair and the face. The embodiments of this application do not limit this.
[0076] Optionally, the dimension of the initial high-dimensional vector can be relatively high. For example, the dimension of the initial high-dimensional vector can be 4096 dimensions or 8192 dimensions. Of course, the dimension of the initial high-dimensional vector can also be other possible values. The embodiments of this application do not limit this.
[0077] Optionally, the face image to be edited includes a face and hair.
[0078] Optionally, the user can edit the face or hair in the face image to be edited. For example, the user can edit features such as the length of the hair, the trend of the hair, the color of the hair, and the style of the hair in the face image to be edited.
[0079] Optionally, the face image to be edited can be generated based on the initial high-dimensional vector and an image generator.
[0080] Optionally, the face image to be edited can be edited or modified by encoding, optimizing, or modifying the initial high-dimensional vector.
[0081] It should be noted that since the initial high-dimensional vector is obtained after decoupling and / or feature extraction of the initial face image, that is, the initial high-dimensional vector includes most of the information of the initial face image. By generating the face image to be edited through the initial high-dimensional vector, the initial high-dimensional vector can be reconverted into an image, which is convenient for performing subsequent operations.
[0082] Step 1002: Determine a first loss value between the face image to be edited and the initial face image input by the user through a first loss function.
[0083] Optionally, the first loss function can be a pre-set function. The first loss function can be a single loss function or a function obtained by combining multiple loss functions.
[0084] For example, the first loss function can include a mean squared error loss function and a perceptual loss function. Optionally, the perceptual loss function can be a VGG loss function. The embodiments of the present application do not make any limitations in this regard.
[0085] Optionally, the first loss value can represent the difference between the face image to be edited and the initial face image input by the user. If the first loss value is large, it can be determined that the difference between the face image to be edited and the initial face image input by the user is large. If the first loss value is small, it can be determined that the difference between the face image to be edited and the initial face image input by the user is small.
[0086] Exemplarily, a first loss threshold may be set. If the first loss value is greater than or equal to the first loss threshold, it can be determined that the difference between the face image to be edited and the initial face image input by the user is relatively large, and the initial high-dimensional vector needs to be iteratively optimized. Conversely, if the first loss value is less than the first loss threshold, it can be determined that the difference between the face image to be edited and the initial face image input by the user is relatively small, and the initial high-dimensional vector does not need to be iteratively optimized. Additionally, the first loss threshold can be set to be relatively small, so as to ensure that the initial high-dimensional vector can accurately represent the information of the initial face image.
[0087] It should be noted that in this way, the size of the difference between the face image to be edited generated based on the initial high-dimensional vector and the initial face image can be determined. That is to say, it can be determined whether the initial high-dimensional vector accurately represents the facial features and / or hair features of the initial face image, which is convenient for performing subsequent operations.
[0088] Step 1003: Iteratively optimize the initial high-dimensional vector based on the first loss value, use the initial high-dimensional vector that reaches the first preset condition as the corrected high-dimensional vector, and generate a corrected face image according to the corrected high-dimensional vector.
[0089] Optionally, the initial high-dimensional vector can be iteratively optimized by an optimizer based on the first loss value. Specifically, the initial high-dimensional vector can be iteratively optimized by the optimizer based on the first loss value and the initial face image, so as to write the information and / or features of the initial face image into the initial high-dimensional vector.
[0090] Optionally, the iterative optimization of the initial high-dimensional vector can be to re-decouple and / or extract features from the initial face image by the optimizer, and encode the information obtained by re-decoupling and / or extracting features from the initial face image into each dimension of the initial high-dimensional vector by the optimizer.
[0091] For example, the initial face image can be re-decoupled and / or feature-extracted to extract features such as the style, size, pixel values of each pixel point, hair length, hair position, hair quantity, hair trend, and hair color of the initial face image, and these features are correspondingly encoded into each dimension of the initial high-dimensional vector, so that the face image to be edited generated according to the initial high-dimensional vector includes these features. The embodiments of the present application do not limit this.
[0092] Optionally, all or part of these features can also be selectively encoded into the respective dimensions of the initial high-dimensional vector. For example, if the pixel values of the pixels of the face image to be edited differ significantly from the pixel values of the pixels of the initial face image, only the pixel values of the pixels of the initial face image can be correspondingly encoded into the respective dimensions of the initial high-dimensional vector. The embodiments of the present application do not limit this.
[0093] Optionally, the first preset condition may be that the first loss value between the face image to be edited generated based on the initial high-dimensional vector and the initial face image is less than the first loss threshold. The first preset condition may also be that the number of iterations for iteratively optimizing the initial high-dimensional vector is equal to a preset first number threshold, and the first number threshold may be 10 or any other possible value. Of course, the first preset condition may also be other possible conditions. The embodiments of the present application do not limit this.
[0094] Optionally, the corrected high-dimensional vector is the initial high-dimensional vector that meets the first preset condition.
[0095] Optionally, the corrected high-dimensional vector can be input into the above-mentioned image generator to generate a corrected face image.
[0096] Optionally, the corrected face image can be edited or modified by encoding, optimizing, or modifying the corrected high-dimensional vector.
[0097] In this way, the obtained corrected high-dimensional vector can more accurately represent the information of the initial face image. Then, the difference between the corrected face image generated based on the corrected high-dimensional vector and the initial face image is relatively small. In this way, it can be ensured that the corrected high-dimensional vector can accurately represent the information of the initial face image, and further, the effect of improving the processing accuracy of the hair in the image and enhancing the practicality of the hair editing method for the image can be achieved.
[0098] Step 1004: Determine the second loss value between the corrected face image, the initial face image, and the reference image through a second loss function.
[0099] Optionally, the reference image includes the target hair selected by the user.
[0100] Optionally, the reference image can be an image input by the user, and the reference image can also be a pre-set image. The embodiments of the present application do not limit this.
[0101] Optionally, the corrected face image and / or the corrected high-dimensional vector can be edited or modified according to the target hair. The target hair can be hair of any color, any length, and any trend. The embodiments of the present application do not limit this.
[0102] Optionally, the second loss function may be a pre-set function, which may be a single loss function or a function obtained by combining multiple loss functions.
[0103] For example, the second loss function may include a cross-entropy loss function, a style loss function, and a cosine distance loss function. Optionally, the style loss function may be a Gram matrix. The embodiments of the present application do not limit this.
[0104] Optionally, the second loss value may characterize the difference between the corrected face image and the initial face image and the reference image. If the second loss value is large, it can be determined that the difference between the corrected face image and the initial face image and / or the reference image is large. If the second loss value is small, it can be determined that the difference between the corrected face image and the initial face image and the reference image is small.
[0105] Exemplarily, a second loss threshold may be set. If the second loss value is greater than or equal to the second loss threshold, it can be determined that the difference between the corrected face image and the initial face image and the reference image is large, and the corrected high-dimensional vector needs to be iteratively optimized. Conversely, it can be determined that the difference between the corrected face image and the initial face image and the reference image is small, and the corrected high-dimensional vector does not need to be iteratively optimized. Additionally, the second loss threshold can be set to be small, so that it can be ensured that the difference between the corrected high-dimensional vector, the corrected face image and the initial face image and the reference image is small, and further, the effect of improving the processing accuracy of the hair in the image and the practicality of the hair editing method of the image can be achieved.
[0106] Step 1005: Iteratively optimize the corrected high-dimensional vector based on the second loss value, use the corrected high-dimensional vector that reaches the second preset condition as the target high-dimensional vector, and generate the final edited face image according to the target high-dimensional vector.
[0107] Optionally, the hair in the final face image has at least one feature of the target hair.
[0108] Optionally, the features of the target hair may include at least one of the following: the length of the target hair, the color of the target hair, the trend of the target hair, the position of the target hair, and the quantity of the target hair.
[0109] Optionally, the optimizer may iteratively optimize the corrected high-dimensional vector based on the second loss value through backpropagation. Specifically, the optimizer may iteratively optimize the corrected high-dimensional vector based on the second loss value, the initial face image, and the reference image to write the features of the initial face image and the features of the target hair in the reference image into the corrected high-dimensional vector.
[0110] Optionally, the iterative optimization of the corrected high-dimensional vector may be to decouple and / or extract features from the initial face image and the reference image, and encode the information and / or features obtained by re-decoupling and / or extracting features from the initial face image and the reference image into each dimension of the corrected high-dimensional vector. The embodiments of the present application do not limit this.
[0111] Optionally, all or part of the information and / or features obtained by re-decoupling and / or extracting features from the initial face image and the reference image may also be selectively encoded into each dimension of the corrected high-dimensional vector. The embodiments of the present application do not limit this.
[0112] Optionally, the second preset condition may be that the second loss value between the corrected face image generated according to the corrected high-dimensional vector and the reference image and the initial face image is less than the second loss threshold. The second preset condition may also be that the number of times of iterative optimization of the corrected high-dimensional vector is equal to a preset second number threshold, and the second number threshold may be 5 or any other possible value. Of course, the second preset condition may also be other possible conditions. The embodiments of the present application do not limit this.
[0113] Optionally, the target high-dimensional vector may represent a high-dimensional vector for which editing and / or optimization is completed.
[0114] Exemplarily, the target high-dimensional vector may represent that the hair in the final face image generated according to the target high-dimensional vector has at least one feature of the target hair.
[0115] Optionally, the target high-dimensional vector may be input into the above-mentioned image generator to generate a final face image.
[0116] Optionally, the final face image may represent an image in which the hair in the initial face image is edited, or an image in which the hair in the image has at least one feature of the target hair, or an image in which the hair in the initial face image is edited into the target hair.
[0117] In this way, it can be ensured that the target high-dimensional vector can accurately represent the information of the initial face image and the reference image, and it can also be ensured that the difference between the final face image generated according to the target high-dimensional vector and the initial face image and the reference image is small. That is to say, it can be ensured that on the basis of retaining the features and / or information of the initial face image, the hair in the final face image can also have at least one feature of the target hair. In this way, the purpose of editing the hair in the initial face image or the hair in the face image to be edited can be achieved.
[0118] In an embodiment of the present application, a to-be-edited face image is generated according to an initial high-dimensional vector, and then a first loss value between the to-be-edited face image and an initial face image input by a user is determined through a first loss function. The initial high-dimensional vector is iteratively optimized based on the first loss value, and the initial high-dimensional vector that meets a first preset condition is used as a corrected high-dimensional vector. A corrected face image is generated according to the corrected high-dimensional vector, and then a second loss value among the corrected face image, the initial face image, and a reference image is determined through a second loss function. Finally, the corrected high-dimensional vector is iteratively optimized based on the second loss value, and the corrected high-dimensional vector that meets a second preset condition is used as a target high-dimensional vector. An edited final face image is generated according to the target high-dimensional vector. Among them, the initial high-dimensional vector is iteratively optimized based on the first loss value, and the initial high-dimensional vector that meets the first preset condition is used as the corrected high-dimensional vector, and a corrected face image is generated according to the corrected high-dimensional vector, which can ensure that the corrected high-dimensional vector can accurately represent the information of the initial face image. In addition, the corrected high-dimensional vector is iteratively optimized based on the second loss value, and the corrected high-dimensional vector that meets the second preset condition is used as the target high-dimensional vector, and an edited final face image is generated according to the target high-dimensional vector, which can ensure that on the basis of retaining the features and / or information of the initial face image, the hair in the final face image can also have at least one feature of the target hair. In this way, the purpose of editing the hair in the initial face image or the hair in the to-be-edited face image can be achieved, and further, the effect of improving the processing accuracy of the hair in the image and the practicality of the hair editing method for the image can be achieved.
[0119] In a possible implementation manner, referring to Figure 2 , generating a to-be-edited face image according to an initial high-dimensional vector includes:
[0120] Step 1006: Calculate the initial high-dimensional vector according to the initial face image.
[0121] Optionally, the initial face image may be a face image that the user inputs and needs to edit the hair. In addition, the initial face image may be an image including a face captured by the user through the computer device, or an arbitrary image including a face selected by the user from the memory of the computer device, or an arbitrary image including a face sent to the computer device by other terminals or other servers. The embodiments of the present application do not limit this.
[0122] Exemplarily, a CNN model can be used to decouple the initial face image and extract the semantic features of the initial face image to obtain the initial high-dimensional vector of the initial face image. Naturally, the initial high-dimensional vector can also be calculated by any other possible means. The embodiments of the present application do not limit this.
[0123] Step 1007: Input the initial high-dimensional vector into a pre-trained image generator to generate the face image to be edited.
[0124] Optionally, the image generator is a progressive neural network model, and can generate a high-definition face image by means of convolution and upsampling.
[0125] Optionally, the image generator can be a pre-trained generator. Specifically, a fully connected mapping network can be jointly trained with the image generator to convert a random variable into a high-dimensional vector through the mapping network, and then input the high-dimensional vector into the image generator to achieve the generation of a high-definition face. In addition, the mapping network can be a multi-layer perceptron.
[0126] In this way, the face image to be edited including the information and / or features of the initial face image can be generated through the initial high-dimensional vector. By editing or optimizing or modifying the initial high-dimensional vector, the face image to be edited can be edited or modified.
[0127] In a possible implementation manner, the first loss function includes a mean squared error loss function and a perceptual loss function.
[0128] See Figure 3 , determining the first loss value between the face image to be edited and the initial face image through the first loss function includes:
[0129] Step 1008: Determine the first mean value of the sum of squared errors of the corresponding points between the face image to be edited and the initial face image through the mean squared error loss function.
[0130] Optionally, the corresponding points of the face image to be edited may include points indicating the positions of eyes, nose, eyebrows, and mouth in the face image to be edited, and may also include points indicating the position, length, and trend of hair in the face image to be edited. The embodiments of the present application do not limit this.
[0131] Optionally, the corresponding points of the initial face image may be points indicating the positions of eyes, nose, eyebrows, and mouth in the initial face image, and may also be points indicating the position, length, and trend of hair in the initial face image. The embodiments of the present application do not limit this.
[0132] Exemplarily, the to-be-edited face image and the initial face image can be input into an optimizer, which respectively determines the positions of corresponding points of the to-be-edited face image and the initial face image, and calculates a first mean value of the sum of squared errors of the corresponding points of the to-be-edited face image and the initial face image through the following formula (1).
[0133]
[0134] Referring to the above formula (1), where x represents the to-be-edited face image, y represents the initial face image, n represents the total number of pixels in the to-be-edited face image and the initial face image, and MSELoss(x, y) represents the first mean value.
[0135] A possible way to determine the first mean value of the sum of squared errors of the corresponding points of the to-be-edited face image and the initial face image through the mean squared error loss function includes:
[0136] Determining the first mean value of the hair in the to-be-edited face image and the hair in the initial face image through the mean squared error loss function.
[0137] Exemplarily, in this case, the corresponding points of the to-be-edited face image may only include the points indicating the position, length, and trend of the hair in the to-be-edited face image. The corresponding points of the initial face image may only include the points indicating the position, length, and trend of the hair in the initial face image. In this way, the first mean value of the hair in the to-be-edited face image and the hair in the initial face image can be accurately determined.
[0138] Step 1009: Extracting the feature maps of the to-be-edited face image and the initial face image through a perceptual loss function, and determining a second mean value of the sum of squared errors of the corresponding points between the feature maps of the to-be-edited face image and the feature maps of the initial face image.
[0139] Optionally, the perceptual loss function may be a VGG16 network, and the VGG16 network may be a pre-trained network. The embodiments of the present application do not limit this.
[0140] Optionally, the to-be-edited face image and the initial face image can be input into the optimizer, and the optimizer extracts the feature maps of the to-be-edited face image and the initial face image respectively by calling the VGG16 network, and calculates the mean squared error loss of the corresponding points of the feature map of the to-be-edited face image and the corresponding points of the feature map of the initial face image through the following formula (2) to determine the second mean value.
[0141]
[0142] Referring to the above formula (2), where VGG(x) represents the feature map of the face image to be edited, VGG(y) represents the feature map of the initial face image, VGG represents the VGG16 network, n represents the total number of pixels of the feature map of the face image to be edited and the feature map of the initial face image, and VGGLoss(x, y) represents the second mean value.
[0143] Optionally, the corresponding points of the feature map of the face image to be edited can be in one-to-one correspondence with the corresponding points of the face image to be edited, or multiple corresponding points can be reselected in the feature map of the face image to be edited according to certain rules. The embodiments of the present application do not limit this.
[0144] Optionally, the corresponding points of the feature map of the initial face image can be in one-to-one correspondence with the corresponding points of the initial face image, or multiple corresponding points can be reselected in the feature map of the initial face image according to certain rules. The embodiments of the present application do not limit this.
[0145] Step 1010: Determine the first loss value according to the first mean value and the second mean value.
[0146] Further, determining the first loss value according to the first mean value and the second mean value includes:
[0147] Taking the sum of the first mean value and the second mean value as the first loss value.
[0148] Specifically, referring to the following formula (3), ReconsLoss(x, y) is the first loss value.
[0149] ReconsLoss(x,y) = MSELoss(x,y) + VGGLoss(x,y) (3)
[0150] A possible way is to extract the feature map of the face image to be edited and the feature map of the initial face image through a perceptual loss function, and determine the second mean value of the sum of the squared errors of the corresponding points between the feature map of the face image to be edited and the feature map of the initial face image, including:
[0151] Determining the feature map of the hair in the face image to be edited and the feature map of the hair in the initial face image through a perceptual loss function, and determining the second mean value of the sum of the squared errors of the corresponding points between the feature map of the hair in the face image to be edited and the feature map of the hair in the initial face image.
[0152] Exemplarily, in this case, the corresponding points of the feature map of the face image to be edited can only correspond to the points indicating the position, length, and trend of the hair in the face image to be edited. The corresponding points of the feature map of the initial face image can only correspond to the points indicating the position, length, and trend of the hair in the initial face image. In this way, the second mean values of the feature map of the hair in the face image to be edited and the feature map of the hair in the initial face image can be accurately determined.
[0153] It should be noted that the first loss value between the face image to be edited and the initial face image can be accurately calculated, and the magnitude of the difference between the face image to be edited and the initial face image can also be accurately determined. That is to say, it can be determined whether the initial high-dimensional vector accurately represents the features of the face of the initial face image and / or the features of the hair of the initial face image, which is convenient for iteratively optimizing the initial high-dimensional vector according to the first loss value so that the initial high-dimensional vector meets the first preset condition. In this way, the practicability of the hair editing method for images can be improved.
[0154] In a possible implementation manner, the second loss function may include a cross-entropy loss function, a style loss function, and a cosine distance loss function.
[0155] See Figure 4 , determining the second loss value among the corrected face image, the initial face image, and the reference image through the second loss function includes:
[0156] Step 1011: Determine the cross-entropy loss between the hair in the corrected face image and the target hair in the reference image through the cross-entropy loss function.
[0157] Optionally, the hair in the corrected face image can be extracted through a pre-trained hair segmentation network, specifically, the mask of the hair in the corrected face image can be extracted.
[0158] Exemplarily, the mask of the hair in the corrected face image can be extracted through the following formula (4).
[0159] m mask = SegmentNet(m) (4)
[0160] Referring to formula (4), where m is the corrected face image, SegmentNet represents the hair segmentation algorithm, and m mask is the mask of the hair in the corrected face image.
[0161] Optionally, the reference image may only include the target hair, or may include the target hair and the human face. If the reference image includes the target hair and the human face, the target hair in the reference image can be extracted by the hair segmentation network.
[0162] Exemplarily, the cross-entropy loss between the hair in the corrected face image and the target hair in the reference image can be determined by the following formula (5).
[0163] CrossEntropyLoss(M,N)=-[M*logN+(1-M)*log(1-N)] (5)
[0164] Referring to formula (5), where M is the mask of the hair in the corrected face image, N is the target hair, and CrossEntropyLoss(M, N) represents the cross-entropy loss.
[0165] Optionally, the cross-entropy loss can be used to represent the magnitude of the difference between the hair in the corrected face image and the target hair. If the cross-entropy loss is larger, it indicates that the difference between the hair in the corrected face image and the target hair is larger; conversely, if the cross-entropy loss is smaller, it indicates that the difference between the hair in the corrected face image and the target hair is smaller, that is, it indicates that the hair in the corrected face image fits the target hair better.
[0166] Step 1012: Determine the style loss value between the corrected face image and the initial face image through a style loss function.
[0167] Optionally, the style loss function can be a Gram matrix.
[0168] Exemplarily, the style characteristics of the corrected face image can be calculated by the following formula (6).
[0169] Gram(m)=VGG(m) T *VGG(m) (6)
[0170] Referring to formula 6, where m is the corrected face image, m T is the transpose of m, VGG represents the VGG16 network, and Gram(m) can characterize the style value of the corrected face image.
[0171] Naturally, the style value of the initial face image can also be calculated by the above formula (6).
[0172] Exemplarily, the style loss value can be calculated by the following formula (7).
[0173]
[0174] Referring to Equation (7), where m is the corrected face image, y is the initial face image, Gram(m) can represent the style value of the corrected face image, Gram(y) can represent the style value of the initial face image, and GramLoss(m, y) is the style loss value.
[0175] It should be noted that if only the cross-entropy loss is calculated, it can only ensure that the hairstyle such as hair color, hair trend, and hair texture is close to the target hair, but it will cause great changes in the features other than hair in the corrected face image, such as the style, color, etc. of the corrected face image, and even the generated corrected face image will directly collapse. Therefore, it is necessary to use the Gram matrix to calculate the style loss to constrain the style of the corrected face image to be consistent with the initial face image.
[0176] Step 1013: Determine the angular loss value between the corrected high-dimensional vector and the high-dimensional vector corresponding to the initial face image through the cosine distance loss function.
[0177] Exemplarily, the angular loss value between the corrected high-dimensional vector and the high-dimensional vector corresponding to the initial face image can be calculated by the following Equation (8).
[0178]
[0179] Referring to Equation (8), where j is the corrected high-dimensional vector, k is the high-dimensional vector corresponding to the initial face image, and CosLoss(j, k) is the angular loss value.
[0180] It should be noted that if only the cross-entropy loss and the style loss are calculated, it may cause uncontrollable changes in the areas other than hair in the corrected face image, and further cause the distortion of the corrected face image. By using the cosine distance loss function, the angular loss value between the corrected high-dimensional vector and the high-dimensional vector corresponding to the initial face image can be determined, so that the angle between the corrected high-dimensional vector and the high-dimensional vector corresponding to the initial face image can be constrained. In this way, it can be ensured that the areas other than hair in the corrected face image are consistent with the initial face image, and thus it can be ensured that the corrected face image will not be distorted, and further the effect of improving the processing accuracy of hair in the image and the practicality of the hair editing method for the image can be achieved.
[0181] Step 1014: Determine the second loss value according to the cross-entropy loss, the style loss value, and the angular loss value.
[0182] Furthermore, determining the second loss value according to the cross-entropy loss, the style loss value, and the angular loss value includes:
[0183] Multiply the cross - entropy loss, the style loss value, and the included - angle loss value by weights respectively, and sum the products obtained after multiplication as the second loss value.
[0184] Exemplarily, the second loss value can be determined according to the following formula (9).
[0185] Loss=αCrossEntropyLoss+βGramLoss+γCosLoss (9)
[0186] Referring to formula (9), where α is the first weight corresponding to the cross - entropy loss, CrossEntropyLoss is the cross - entropy loss, β is the second weight corresponding to the style loss value, GramLoss is the style loss value, γ is the third weight corresponding to the included - angle loss value, CosLoss is the included - angle loss value, and Loss is the second loss value.
[0187] Optionally, the first weight, the second weight, and the third weight can be values set according to actual needs. The embodiments of the present application do not limit this.
[0188] Exemplarily, if it is required that the hair in the corrected face image fits the target hair better, or it is required that the hair in the corrected face image has more features of the target hair, the first weight can be set larger. If it is required that the style of the corrected face image is consistent with the initial face image, the second weight can be set larger. If it is required to ensure that the corrected face image does not show distortion, the third weight can be set larger.
[0189] It should be noted that calculating the cross - entropy loss and optimizing the corrected high - dimensional vector according to the cross - entropy loss can make the hair in the corrected face image fit the target hair, that is, make the hair in the corrected face image have at least one feature of the target hair. Calculating the style loss value and optimizing the corrected high - dimensional vector according to the style loss value can make the style of the corrected face image consistent with the initial face image. Calculating the included - angle loss value and optimizing the corrected high - dimensional vector according to the included - angle loss value can ensure that the corrected face image does not show distortion. In this way, the purpose of editing the hair in the initial face image or the hair in the to - be - edited face image can be achieved, and further, the effect of improving the processing accuracy of the hair in the image and the practicality of the hair - editing method for the image can be achieved.
[0190] In a possible implementation, referring to Figure 5 , before determining the second loss value between the corrected face image, the initial face image, and the reference image through the second loss function, the method further includes:
[0191] Step 1015: Segment the corrected face image to obtain the hair in the corrected face image.
[0192] Optionally, the corrected face image may be segmented by the above-mentioned hair segmentation network.
[0193] In this way, the hair in the corrected face image can be accurately segmented, so as to determine the cross-entropy loss between the hair in the corrected face image and the target hair in the reference image through the cross-entropy loss function. In this way, the processing accuracy of the hair in the image can be improved.
[0194] In a possible implementation manner, iterative optimization of the corrected high-dimensional vector based on the second loss value includes:
[0195] Determine the distinguishing features between the hair in the corrected face image and the hair in the reference image.
[0196] Optionally, the distinguishing features include at least one of the following: the trend of the hair, the length of the hair, the color of the hair, the area where the hair exists, the number of hairs, and the distance between the hairs.
[0197] Optionally, the distinguishing feature may be information indicating that the features of the hair in the corrected face image are different from the features of the hair in the reference image.
[0198] Iteratively optimize the corrected high-dimensional vector according to the second loss value and the distinguishing features.
[0199] Optionally, the iterative optimization of the corrected high-dimensional vector may be to decouple and / or extract features from the reference image, and encode the information obtained by re-decoupling and / or extracting features from the reference image into the corrected high-dimensional vector.
[0200] For example, features such as the number of target hairs, the trend of the target hairs, and the color of the target hairs in the reference image can be extracted, and these features are correspondingly encoded into each dimension of the corrected high-dimensional vector, so that the corrected face image generated according to the corrected high-dimensional vector includes these features. The embodiments of the present application do not limit this.
[0201] In this way, it can be ensured that the corrected high-dimensional vector can finally meet the second preset condition, and it can also be ensured that the hair in the finally generated edited face image according to the target high-dimensional vector has at least one feature of the target hair. In this way, the purpose of editing the hair in the image according to the target hair of the reference image can be achieved, and further, the processing accuracy of the hair in the image can be improved and the practicability of the hair editing method of the image can be enhanced.
[0202] In a possible implementation, the initial high-dimensional vector can be any initialized high-dimensional vector. The initial high-dimensional vector can be input into the above-mentioned image generator to generate a face image. Then, this face image, the initial high-dimensional vector, and the initial face image are input into the above-mentioned optimizer. The optimizer decouples and extracts features from the initial face image and this face image respectively, and determines the loss value between this image and the initial face image through the above-mentioned first loss function. When the loss value between this image and the initial face image is less than a pre-set comparison threshold, the initial high-dimensional vector can be used as the high-dimensional vector of the initial face image.
[0203] Optionally, the comparison threshold can be a pre-set threshold. Generally, the comparison threshold can be set to be relatively small.
[0204] In this way, the information of the initial face image can also be encoded into this initialized high-dimensional vector through the iterative process of the optimizer, and then steps 1001 - 1005 are continued to implement the editing or modification of the face image to be edited.
[0205] The following describes the device, equipment, computer-readable storage medium, etc. for implementing the hair editing method of the image provided by the present application. For the specific implementation process and technical effects, refer to the above, and will not be elaborated below.
[0206] Figure 6 is a schematic structural diagram of a hair editing device for an image provided by an embodiment of the present application. Refer to Figure 6 , the device includes:
[0207] A generation module, configured to generate a face image to be edited according to an initial high-dimensional vector.
[0208] A first determination module, configured to determine a first loss value between the face image to be edited and an initial face image input by a user through a first loss function.
[0209] A first optimization and generation module, configured to iteratively optimize the initial high-dimensional vector based on the first loss value, use the initial high-dimensional vector that reaches a first preset condition as a corrected high-dimensional vector, and generate a corrected face image according to the corrected high-dimensional vector.
[0210] A second determination module, configured to determine a second loss value between the corrected face image, the initial face image, and a reference image through a second loss function.
[0211] A second optimization and generation module, configured to iteratively optimize the corrected high-dimensional vector based on the second loss value, use the corrected high-dimensional vector that reaches a second preset condition as a target high-dimensional vector, and generate a final face image after editing according to the target high-dimensional vector.
[0212] The above-mentioned device is used to execute the method provided in the foregoing embodiment, and its implementation principle and technical effects are similar, so they will not be elaborated here.
[0213] The above modules can be one or more integrated circuits configured to implement the above method. For example: one or more Application Specific Integrated Circuits (ASICs), or, one or more microcontrollers, or, one or more Field Programmable Gate Arrays (FPGAs), etc. Again, when a certain module above is implemented in the form of a processing element dispatching program code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processors that can call program code. Again, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0214] Figure 7 It is a schematic structural diagram of a computer device provided by an embodiment of the present application. Refer to Figure 7 , the computer device includes: a memory 301 and a processor 302. The memory 301 stores a computer program that can run on the processor 302. When the processor 302 executes the computer program, the steps in any of the above method embodiments are implemented.
[0215] An embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments can be implemented.
[0216] Optionally, the present application also provides a program product, such as a computer-readable storage medium, including a program, which is used to execute the hair editing method embodiment of any of the above images when executed by a processor.
[0217] In several embodiments provided by the present invention, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point, the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.
[0218] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or may be distributed over multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0219] In addition, each functional unit in various embodiments of the present invention can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of a combination of hardware and software functional units.
[0220] The above-mentioned integrated units implemented in the form of software functional units can be stored in a computer-readable storage medium. The above-mentioned software functional units stored in a storage medium include several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute some steps of the methods in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (abbreviation: ROM), random access memories (abbreviation: RAM), magnetic disks, or optical discs that can store program codes.
[0221] The above is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in this application, and all should be covered by the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.
[0222] The above are only the preferred embodiments of this application and are not used to limit this application. For those skilled in the art, this application can have various changes and modifications. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of this application should be included in the protection scope of this application.
Claims
1. A method for editing hair in an image, characterized in that, The method includes: Generating an editable face image according to an initial high-dimensional vector, where the editable face image includes a face and hair, and the initial high-dimensional vector is used to characterize the features of the face and the features of the hair in the initial face image input by the user; Determining a first loss value between the editable face image and the initial face image input by the user through a first loss function; Iteratively optimizing the initial high-dimensional vector based on the first loss value, taking the initial high-dimensional vector that reaches a first preset condition as a corrected high-dimensional vector, and generating a corrected face image according to the corrected high-dimensional vector; Determining a second loss value between the corrected face image, the initial face image, and a reference image through a second loss function, where the reference image includes the target hair selected by the user; Iteratively optimizing the corrected high-dimensional vector based on the second loss value, taking the corrected high-dimensional vector that reaches a second preset condition as a target high-dimensional vector, and generating a final edited face image according to the target high-dimensional vector, where the hair in the final face image has at least one feature of the target hair; The second loss function includes a cross-entropy loss function, a style loss function, and a cosine distance loss function; The determining the second loss value between the corrected face image, the initial face image, and the reference image through the second loss function includes: Determining the cross-entropy loss between the hair in the corrected face image and the target hair in the reference image through a cross-entropy loss function; Determining a style loss value between the corrected face image and the initial face image through a style loss function; Determining an angle loss value between the corrected high-dimensional vector and the high-dimensional vector corresponding to the initial face image through a cosine distance loss function; Determining the second loss value according to the cross-entropy loss, the style loss value, and the angle loss value.
2. The hair editing method of an image according to claim 1, wherein, The generating the editable face image according to the initial high-dimensional vector includes: Calculating the initial high-dimensional vector according to the initial face image; Inputting the initial high-dimensional vector into a pre-trained image generator to generate the editable face image, and the image generator is a progressive neural network model.
3. The hair editing method of an image according to claim 1, wherein The first loss function includes a mean squared error loss function and a perceptual loss function; The determining the first loss value between the editable face image and the initial face image through the first loss function includes: Determining a first mean value of the sum of squared errors of corresponding points between the editable face image and the initial face image through a mean squared error loss function; Extracting the feature maps of the editable face image and the feature maps of the initial face image through a perceptual loss function, and determining a second mean value of the sum of squared errors of corresponding points between the feature maps of the editable face image and the feature maps of the initial face image; Determining the first loss value according to the first mean value and the second mean value.
4. The method for editing the hair of an image according to claim 3, characterized in that, The determining the first mean value of the sum of squared errors of corresponding points between the editable face image and the initial face image through a mean squared error loss function includes: Determine the first mean value of the hair in the to-be-edited face image and the hair in the initial face image through the mean squared error loss function; The extracting the feature maps of the to-be-edited face image and the initial face image through the perceptual loss function, and determining the second mean value of the sum of the squared errors of the corresponding points between the feature map of the to-be-edited face image and the feature map of the initial face image includes: Determine the feature maps of the hair in the to-be-edited face image and the feature maps of the hair in the initial face image through the perceptual loss function, and determine the second mean value of the sum of the squared errors of the corresponding points between the feature map of the hair in the to-be-edited face image and the feature map of the hair in the initial face image.
5. The hair editing method of an image according to claim 1, characterized in that Before determining the second loss value between the corrected face image, the initial face image and the reference image through the second loss function, the method further includes: Perform segmentation processing on the corrected face image to obtain the hair in the corrected face image.
6. The hair editing method of an image according to any one of claims 1-5, characterized in that, The iteratively optimizing the corrected high-dimensional vector based on the second loss value includes: Determine the distinguishing features between the hair in the corrected face image and the hair in the reference image, and the distinguishing features include at least one of the following: the trend of the hair, the length of the hair, the color of the hair, the quantity of the hair; Iteratively optimize the corrected high-dimensional vector according to the second loss value and the distinguishing features.
7. A hair editing device for an image, characterized in that, The device includes: A generation module, configured to generate a to-be-edited face image according to an initial high-dimensional vector; A first determination module, configured to determine a first loss value between the to-be-edited face image and the initial face image input by the user through a first loss function; A first optimization generation module, configured to iteratively optimize the initial high-dimensional vector based on the first loss value, use the initial high-dimensional vector that reaches a first preset condition as a corrected high-dimensional vector, and generate a corrected face image according to the corrected high-dimensional vector; A second determination module, configured to determine a second loss value between the corrected face image, the initial face image and the reference image through a second loss function; A second optimization generation module, configured to iteratively optimize the corrected high-dimensional vector based on the second loss value, use the corrected high-dimensional vector that reaches a second preset condition as a target high-dimensional vector, and generate a final edited face image according to the target high-dimensional vector; The second loss function includes a cross-entropy loss function, a style loss function and a cosine distance loss function; The second determination module is specifically configured to: determine the cross-entropy loss of the hair in the corrected face image and the target hair in the reference image through the cross-entropy loss function; determine the style loss value between the corrected face image and the initial face image through the style loss function; determine the included angle loss value between the corrected high-dimensional vector and the high-dimensional vector corresponding to the initial face image through the cosine distance loss function; determine the second loss value according to the cross-entropy loss, the style loss value and the included angle loss value.
8. A computer device, characterized in that, Includes: A memory and a processor, wherein the memory stores a computer program that can run on the processor, and when the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Guiding type face image editing method and system based on jump connection attention
CN113724340A
System and method for editing portrait hairstyle in two-dimensional image
CN113744367A