Hair straightening and curving processing method, system, terminal device and storage medium
By combining the generation of virtual face images and autoencoders, and using normal vectors to edit hidden vectors, the problem of large image gaps in hair straightness processing in the existing technology is solved, and the accuracy of the processing is improved.
Patent Information
- Application Number
- CN202110946419.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-18
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2041-08-18
AI Technical Summary
Existing hair straightness processing methods directly modify the latent vector features, resulting in a large gap in hair color and shape between the modified image and the original image, which reduces the accuracy of the processing.
By generating multiple virtual face images, use support vector machine training to obtain the normal vector of the separation hyperplane, vector edit the latent vector, and perform image encoding and decoding through the autoencoder, calculate the loss value, and update the parameters until convergence. Ensure the accuracy of hair straightening.
It effectively improves the accuracy of hair straightening processing, prevents the problem of excessive hair color and shape differences between the output image and the image to be processed, and enhances the processing accuracy.
Smart Images

Figure CN113689327B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a method, system, terminal device and storage medium for processing hair straightness and curvature. Background Art
[0002] With the development of mobile devices and smart phones, the quality of mobile photography is getting higher and higher, and users have more and more demands for beautification or entertainment based on selfie images. Among them, due to the important role of hair in the overall image of a person, users pay more and more attention to the operation of processing the straightness of hair in facial images.
[0003] In the existing hair straightening process, the latent vector features in the image to be processed are directly modified to achieve the effect of adjusting the hair straightness in the image to be processed. However, due to the direct modification of the latent vector features, the color and shape of the hair between the modified image to be processed and the original image are greatly different, which reduces the accuracy of the hair straightening process. Summary of the invention
[0004] The purpose of the embodiments of the present invention is to provide a method, system, terminal device and storage medium for processing hair straightness, aiming to solve the problem that in the existing hair straightness processing process, due to the direct modification of latent vector features, there is a large difference in hair color and shape between the modified image to be processed and the original image.
[0005] The embodiment of the present invention is implemented as follows: a method for straightening and curly hair, the method comprising:
[0006] Generate multiple virtual face images according to the face generation model, and obtain the normal vector of the separation hyperplane according to each virtual face image through support vector machine training, wherein the separation hyperplane is used to classify the hair straightness of each virtual face image;
[0007] Performing vector editing on the latent vectors of each virtual face image according to the normal vector, and inputting the latent vectors after vector editing into the face generation model for image generation, so as to obtain a face editing image corresponding to each latent vector;
[0008] Determine a training image and a target image in the face editing image, perform image encoding on the training image according to the autoencoder to obtain an encoded image and a direction vector, and perform vector editing on the direction vector;
[0009] Performing image decoding on the direction vector and the encoded image after vector editing according to the autoencoder to obtain a decoded image, and performing loss calculation on the decoded image and the target image to obtain a loss value;
[0010] The parameters of the autoencoder are updated according to the loss value until the autoencoder converges, and the image to be processed is input into the converged autoencoder for hair straightening processing to obtain an output image.
[0011] Furthermore, the determining of the training image and the target image in the face editing image, encoding the training image according to the autoencoder to obtain the encoded image and the direction vector, includes:
[0012] Sampling the face editing image corresponding to the same latent vector to obtain the training image and the target image;
[0013] Inputting the training image into the encoder in the autoencoder for image encoding to obtain the encoded image;
[0014] Perform feature mapping on a fully connected layer connecting the encoded image input and the encoder output to obtain the direction vector.
[0015] Furthermore, the vector editing of the direction vector includes:
[0016] Determining a latent vector difference between the target image and the training image, and determining a vector edit factor according to the latent vector difference and the normal vector;
[0017] The direction vector is vector edited according to the vector edit multiple.
[0018] Furthermore, the step of performing image decoding on the direction vector and the encoded image after vector editing according to the autoencoder to obtain a decoded image includes:
[0019] Inputting the direction vector after vector editing into a direction decoder to obtain a direction feature;
[0020] The encoded image and the directional feature are feature merged and then input into the decoder to obtain the decoded image.
[0021] Furthermore, the normal vector of the separation hyperplane is obtained by training the support vector machine according to each virtual face image, including:
[0022] Classify the hair straightness of each virtual face image according to a preset straightness classifier to obtain a straight hair image and a curly hair image;
[0023] The latent vector of the straight hair image is set as a positive sample, and the latent vector of the curved hair image is set as a negative sample to train a support vector machine, and the normal vector of the separating hyperplane is determined according to the trained support vector machine.
[0024] Furthermore, after inputting each latent vector after vector editing into the face generation model to generate an image and obtaining a face editing image corresponding to each latent vector, the method further includes:
[0025] Determine the structural similarity features and peak signal-to-noise ratio of each face edited image respectively;
[0026] If the structural similarity feature and / or the peak signal-to-noise ratio of any of the face editing images is less than the corresponding feature threshold, the face editing image is deleted.
[0027] Furthermore, the step of performing vector editing on the latent vectors of each virtual face image according to the normal vectors includes:
[0028] Taking the normal vector as a reference vector, the latent vector of each virtual face image is increased or decreased by a preset vector multiple.
[0029] Another object of an embodiment of the present invention is to provide a hair straightening treatment system, the system comprising:
[0030] A normal vector determination module, used to generate multiple virtual face images according to the face generation model, and obtain the normal vector of the separation hyperplane according to each virtual face image through support vector machine training, wherein the separation hyperplane is used to classify the hair straightness of each virtual face image;
[0031] A vector editing module, used to perform vector editing on the latent vectors of each virtual face image according to the normal vector, and input the latent vectors after vector editing into the face generation model for image generation, so as to obtain a face editing image corresponding to each latent vector;
[0032] An image encoding module, used for determining a training image and a target image in the face editing image, performing image encoding on the training image according to an autoencoder to obtain an encoded image and a direction vector, and performing vector editing on the direction vector;
[0033] a loss calculation module, configured to perform image decoding on the direction vector and the encoded image after the vector editing by the autoencoder to obtain a decoded image, and perform loss calculation on the decoded image and the target image to obtain a loss value;
[0034] The hair straightening processing module is used to update the parameters of the autoencoder according to the loss value until the autoencoder converges, and input the image to be processed into the converged autoencoder for hair straightening processing to obtain an output image.
[0035] Another object of an embodiment of the present invention is to provide a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0036] Another object of an embodiment of the present invention is to provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0037] In the embodiment of the present invention, the latent vectors of each virtual face image are respectively vector-edited through the normal vector, so that the latent vectors at different scales can be effectively obtained. The latent vectors at different scales are input into the face generation model for image generation, so that the virtual images corresponding to the latent vectors at different scales can be effectively obtained. The training image is encoded by the autoencoder to obtain the encoded image and the direction vector, and the direction vector is vector-edited to ensure the consistency between the direction vector and the latent vector after the vector editing corresponding to the training image. The loss is calculated by decoding the image and the target image to obtain the loss value, and the parameters of the autoencoder are updated according to the loss value, so that the autoencoder can effectively learn the characteristics of the hair straightness between the target image and the training image. The hair straightness processing is performed on the to-be-processed image based on the converged autoencoder, so as to avoid the problem of large difference in hair color and shape between the output image and the to-be-processed image, and improve the accuracy of the hair straightness processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 is a flow chart of a hair straightening and curly processing method provided by a first embodiment of the present invention;
[0039] Figure 2 is a flow chart of a hair straightening and curly processing method provided by a second embodiment of the present invention;
[0040] Figure 3 is a structural schematic diagram of a hair straightening and curving system provided by a third embodiment of the present invention;
[0041] Figure 4 It is a schematic diagram of the structure of a terminal device provided in the fourth embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0043] In order to illustrate the technical solution of the present invention, a specific embodiment is provided below for illustration.
[0044] Embodiment 1
[0045] See also Figure 1 , is a flow chart of a hair straightening processing method provided by the first embodiment of the present invention. The hair straightening processing method can be applied to any terminal device, including a server, a mobile phone, a tablet or a wearable smart device, etc. The hair straightening processing method includes the steps of:
[0046] Step S10, generating a plurality of virtual face images according to the face generation model, and obtaining a normal vector of a separation hyperplane according to each virtual face image through support vector machine training;
[0047] The separating hyperplane is used to classify the hair straightness of each virtual face image. In this step, before generating multiple virtual face images according to the face generation model, the method also includes: training the face generation model according to the FFHQ data set until the face generation model converges. The full name of the FFHQ data set is Flickr-Faces-High-Quality (Flickr-Faces-HQ). FFHQ is a high-quality face data set, which contains 70,000 high-definition face images in PNG format with a resolution of 1024×1024. The images are rich and diverse in age, race, and image background, and have obvious differences. There are also many changes in facial attributes, including different ages, genders, races, skin colors, expressions, face shapes, hairstyles, facial postures, etc., covering a variety of facial peripheral accessories such as ordinary glasses, sunglasses, hats, hair accessories, and scarves. The accuracy of face generation model training is improved based on the FFHQ data set.
[0048] In this step, a large number of random vectors are input into the converged face generation model to generate an image to obtain the virtual face image. Optionally, in this step, separating the hyperplane by support vector machine training based on the latent vectors of each virtual face image and finding the normal vector perpendicular to the hyperplane includes:
[0049] Classify the hair straightness of each virtual face image according to a preset straightness classifier to obtain a straight hair image and a curly hair image;
[0050] Among them, there is a label straight in the CelebFaces Attribute (CelebA) public data set, and the straight label is used to distinguish positive and negative samples. Therefore, a classifier is trained based on the CelebA public data set and the straight label to obtain the preset straight and curly classifier. The preset straight and curly classifier is used to classify the straightness of the hair in each virtual face image to obtain the straight hair image and the curly hair image.
[0051] The latent vector of the straight hair image is set as a positive sample, and the latent vector of the curved hair image is set as a negative sample to train a support vector machine, and the normal vector of the separating hyperplane is determined according to the trained support vector machine;
[0052] Among them, the support vector machine (SVM) is a generalized linear classifier that performs binary classification of data in a supervised learning manner. Its decision boundary is the maximum-margin hyperplane solved for the learning samples. Therefore, based on the trained support vector machine, the normal vector of the separating hyperplane can be effectively determined.
[0053] Step S20, respectively performing vector editing on the latent vectors of each virtual face image according to the normal vector, and inputting each latent vector after vector editing into the face generation model for image generation, to obtain a face editing image corresponding to each latent vector;
[0054] Among them, the latent vector of each virtual face image is vector edited at least twice to ensure that each virtual face image corresponds to at least two face editing images. The number of vector edits for the latent vector of each virtual face image can be set according to needs. For example, the number of vector edits can be set to 5 times, 10 times or 20 times. When the number of vector edits is 5 times, there are 5 face editing images corresponding to each virtual face image. When the number of vector edits is 10 times, there are 10 face editing images corresponding to each virtual face image. It should be noted that when the latent vector of the same virtual face image is vector edited, the edited latent vectors are different. For example, when the number of vector edits is 3 times, the latent vector of the virtual face image a1 is vector edited 3 times to obtain vector b1, vector b2 and vector b3. Then vector b1, vector b2 and vector b3 are all different.
[0055] Optionally, in this step, the step of performing vector editing on the latent vectors of each virtual face image according to the normal vectors includes:
[0056] Taking the normal vector as a reference vector, increasing or decreasing the latent vector of each virtual face image by a preset vector multiple;
[0057] Among them, the preset vector multiple can be set according to demand, for example, the preset vector multiple can be -3 times, -1 times, 3 times or 5 times, etc. The preset vector multiple can also be set in the form of a multiple list. For example, the multiple list includes -3 times, -1 times, 3 times and 5 times. Then, for the latent vector of each virtual face image, 3 times the normal vector, 1 times the normal vector, 3 times the normal vector, and 5 times the normal vector are respectively subtracted, so as to achieve the effect of vector editing of the latent vector of each virtual face image. Optionally, in this step, the number of preset vectors in the multiple list and the order between the preset vectors can be set according to demand.
[0058] Furthermore, in this step, after inputting each latent vector after vector editing into the face generation model to generate an image and obtaining a face editing image corresponding to each latent vector, the method further includes:
[0059] Determine the structural similarity features and peak signal-to-noise ratio of each face edited image respectively;
[0060] If the structural similarity feature and / or the peak signal-to-noise ratio of any of the face editing images is less than the corresponding feature threshold, deleting the face editing image;
[0061] Among them, the sizes of the structural similarity features and the peak signal-to-noise corresponding feature thresholds can be set according to needs. In this step, if the structural similarity features and / or the peak signal-to-noise ratio of any face editing image are less than the corresponding feature threshold, it is determined that the image quality of the face editing image is low. By deleting the face editing images with low image quality, the accuracy of subsequent autoencoder training can be improved.
[0062] Optionally, in this step, the quality of the edited face image may be detected based on image features, and the edited face image may be screened based on the quality detection result to remove images with poor quality in the edited face image.
[0063] Step S30, determining a training image and a target image in the face editing image, performing image encoding on the training image according to the autoencoder to obtain an encoded image and a direction vector, and performing vector editing on the direction vector;
[0064] Among them, for the face editing image corresponding to each latent vector, the corresponding training image and target image are determined respectively, and the autoencoder is provided with an image encoder, a direction encoder, a direction decoder, and an image decoder.
[0065] In this step, the training image is encoded according to the autoencoder to extract the image features and hair straightness features in the training image, thereby obtaining the encoded image and the direction vector. Based on the vector editing difference between the training image and the target image, the direction vector is vector edited to ensure the consistency between the direction vector and the latent vector of the corresponding vector of the training image after editing.
[0066] Step S40, performing image decoding on the direction vector and the encoded image after the vector editing by the autoencoder to obtain a decoded image, and performing loss calculation on the decoded image and the target image to obtain a loss value;
[0067] The direction vector and the encoded image after vector editing are decoded by the autoencoder to restore the image based on the direction vector and the encoded image to obtain the decoded image. The error of the autoencoder is obtained by performing loss calculation based on the decoded image and the target image. The smaller the loss value is, the more accurate the image after the hair straightening process by the autoencoder is.
[0068] Optionally, in this step, performing image decoding on the direction vector and the encoded image after vector editing according to the autoencoder to obtain a decoded image includes:
[0069] Inputting the direction vector after vector editing into a direction decoder to obtain a direction feature;
[0070] The direction decoder module is used to restore the edited direction vector to a feature image of an output size corresponding to a specified layer in the fully connected hierarchy, and the specified layer can be set according to requirements.
[0071] The encoded image and the directional feature are feature merged and then input into the decoder to obtain the decoded image.
[0072] Among them, by merging the encoded image and the direction feature, the decoded image can effectively carry the hair straightness feature in the edited direction vector, thereby achieving the effect of controlling the hair straightness to different degrees.
[0073] Furthermore, in this step, the absolute error (L1 loss) and perceptual loss (VGG loss) are minimized for the decoded image and the target image, respectively, to obtain the loss value.
[0074] Step S50, updating the parameters of the autoencoder according to the loss value until the autoencoder converges, and inputting the image to be processed into the converged autoencoder to perform hair straightening processing to obtain an output image;
[0075] Among them, the decoded image and the target image are respectively calculated by minimizing the absolute error (L1 loss) and the perceptual loss (VGG loss) to obtain a first loss value and a second loss value, and the weight parameters of the image encoder, the direction encoder, the direction decoder, and the image decoder are respectively updated based on the first loss value and the second loss value. When the image encoder, the direction encoder, the direction decoder, and the image decoder all converge, it is determined that the autoencoder has converged, and the image to be processed is input into the converged autoencoder for hair straightening processing to achieve the effect of adjusting the hair straightness of the image to be processed.
[0076] Specifically, in this step, by adjusting the preset vector multiple, hair straightening effects with different hair straightening editing degrees can be effectively obtained.
[0077] In this embodiment, the latent vectors of each virtual face image are respectively vector-edited through the normal vector, so that the latent vectors at different scales can be effectively obtained. The latent vectors at different scales are input into the face generation model for image generation, so that the virtual images corresponding to the latent vectors at different scales can be effectively obtained. The training image is encoded by the autoencoder to obtain the encoded image and the direction vector, and the direction vector is vector-edited to ensure the consistency between the direction vector and the latent vector after vector editing corresponding to the training image. The loss is calculated by decoding the image and the target image to obtain the loss value, and the parameters of the autoencoder are updated according to the loss value, so that the autoencoder can effectively learn the characteristics of the hair straightness between the target image and the training image. The hair straightness processing is performed on the image to be processed based on the converged autoencoder, which prevents the problem of large difference in hair color and shape between the output image and the image to be processed, and improves the accuracy of the hair straightness processing.
[0078] Embodiment 2
[0079] See also Figure 2 , is a flow chart of a hair straightening and curving processing method provided by a second embodiment of the present invention, and this embodiment is used to further refine step S30, including the steps of:
[0080] Step S31, sampling the face editing image corresponding to the same latent vector to obtain the training image and the target image;
[0081] Among them, the sampling number and sampling round of the face editing map corresponding to the same latent vector can be set according to the needs or the total number of face editing maps. The sampling number is the sampling number of face editing maps corresponding to the same latent vector in the same sampling round, and the sampling round is the number of rounds when sampling the face editing map corresponding to the same latent vector.
[0082] For example, when the face editing graph corresponding to the latent vector a1 includes face editing graph c1, face editing graph c2, face editing graph c3 and face editing graph c4, the sampling number is 2 and the sampling round is 3, then in the first sampling round, two images are randomly extracted from face editing graph c1, face editing graph c2, face editing graph c3 and face editing graph c4, and the extracted images are randomly set as training images and target images. In the second sampling round, two images are randomly extracted from face editing graph c1, face editing graph c2, face editing graph c3 and face editing graph c4. The training images in the first round are deleted from the face editing image c4, two images are randomly selected from the face editing image after the training images are deleted, and the extracted images are randomly set as training images and target images. In the third sampling round, the training images in the first and second rounds are deleted from the face editing images c1, c2, c3 and c4, two images are randomly selected from the face editing image after the training images are deleted, and the extracted images are randomly set as training images and target images.
[0083] Optionally, in this step, when the face editing image corresponding to the latent vector a1 includes face editing image c1, face editing image c2, face editing image c3 and face editing image c4, the sampling number is 2 times and the sampling round is 3 times, then in the first sampling round, two images are randomly extracted from the face editing image c1, face editing image c2, face editing image c3 and face editing image c4, and the extracted images are randomly set as training images and target images. In the second sampling round, two images are randomly extracted from the face editing image c1, face editing image c2, face editing image c3 and face editing image c4, and it is detected whether the images extracted in the second round are the same as the images extracted in the first round. When the images extracted in the second round are the same as the images extracted in the first round, the face editing images c1, face editing images c2, face editing images c3 are re-examined. and face editing map c4 for image extraction until the image extracted in the second round is different from the image extracted in the first round, and the extracted images are randomly set as training images and target images. In the third sampling round, two images are randomly extracted from face editing map c1, face editing map c2, face editing map c3 and face editing map c4, and it is detected whether the image extracted in the third round is the same as the image extracted in the first round or the second round. When the image extracted in the third round is the same as the image extracted in the first round or the second round, image extraction is performed again on face editing map c1, face editing map c2, face editing map c3 and face editing map c4 until the image extracted in the third round is different from the image extracted in the first round or the second round, and the extracted images are randomly set as training images and target images.
[0084] Furthermore, in this step, the face editing images corresponding to each latent vector are sampled respectively to obtain corresponding training images and target images.
[0085] Step S32, inputting the training image into the encoder in the autoencoder for image encoding to obtain the encoded image;
[0086] The training image is input into an image encoder for image compression to obtain the encoded image features. In this step, the size of the convolution kernel in the image encoder can be set according to requirements.
[0087] Step S33, inputting the encoded image features into the encoded direction encoder for feature mapping to obtain the direction vector;
[0088] The directional features in the coded image features are extracted by inputting the coded image features into the fully connected layer of the directional encoder for feature mapping, thereby obtaining the directional vector.
[0089] Step S34, determining a latent vector difference between the target image and the training image, and determining a vector edit factor according to the latent vector difference and the normal vector;
[0090] The difference of the latent vector between the target image and the training image is calculated to obtain the latent vector difference, and the quotient between the latent vector difference and the normal vector is calculated to obtain the vector edit multiple. In this step, the vector edit multiple can also be obtained by directly taking the difference of the preset vector multiple between the target image and the training image.
[0091] Step S35, performing vector editing on the direction vector according to the vector editing multiple;
[0092] Among them, when the vector editing multiple is a negative number, the direction vector is reduced according to the absolute value of the vector editing multiple. When the vector editing multiple is a positive number, the direction vector is enlarged according to the vector editing multiple to achieve the vector editing effect on the direction vector.
[0093] In this embodiment, the face editing image corresponding to the same latent vector is sampled to ensure the setting of the training image and the target, the training image is input into the encoder for image encoding to extract the image features in the training image to obtain the encoded image, the encoded image is input into the fully connected layer for feature mapping to extract the directional features in the encoded image to obtain the direction vector, the latent vector difference between the target image and the training image is determined, and the vector editing multiple is determined according to the latent vector difference and the normal vector, and the direction vector is vector edited based on the vector editing multiple, so as to ensure the consistency between the direction vector and the latent vector after vector editing corresponding to the training image, so that the fully connected layer can effectively learn the features of the straightness and curvature of the hair in the face editing image, thereby improving the accuracy of the autoencoder in processing the straightness and curvature of the hair of the processed image.
[0094] Embodiment 3
[0095] See also Figure 3 , is a schematic diagram of the structure of a hair straightening and curving processing system 100 provided in a third embodiment of the present invention, comprising: a normal vector determination module 10, a vector editing module 11, an image encoding module 12, a loss calculation module 13 and a hair straightening and curving processing module 14, wherein:
[0096] The normal vector determination module 10 is used to generate multiple virtual face images according to the face generation model, and obtain the normal vector of the separation hyperplane according to each virtual face image through support vector machine training, and the separation hyperplane is used to classify the hair straightness of each virtual face image.
[0097] The normal vector determination module 10 is further used to: classify the hair straightness of each virtual face image according to a preset straightness classifier to obtain a straight hair image and a curly hair image;
[0098] The latent vector of the straight hair image is set as a positive sample, and the latent vector of the curved hair image is set as a negative sample to train a support vector machine, and the normal vector of the separating hyperplane is determined according to the trained support vector machine.
[0099] The vector editing module 11 is used to perform vector editing on the latent vectors of each virtual face image according to the normal vector, and input the latent vectors after vector editing into the face generation model for image generation to obtain the face editing image corresponding to each latent vector.
[0100] The vector editing module 11 is further used to: respectively determine the structural similarity features and peak signal-to-noise ratio of each face editing image;
[0101] If the structural similarity feature and / or the peak signal-to-noise ratio of any of the face editing images is less than the corresponding feature threshold, the face editing image is deleted.
[0102] Optionally, the vector editing module 11 is further used to: use the normal vector as a reference vector to increase or decrease the latent vector of each virtual face image by a preset vector multiple.
[0103] The image encoding module 12 is used to determine the training image and the target image in the face editing image, perform image encoding on the training image according to the autoencoder to obtain the encoded image features and direction vector, and perform vector editing on the direction vector.
[0104] The image editing module 12 is further used for: sampling the face editing image corresponding to the same latent vector to obtain the training image and the target image;
[0105] Inputting the training image into the encoder in the autoencoder for image encoding to obtain the encoded image features;
[0106] The encoded image feature input is feature mapped with the direction encoder to obtain the direction vector.
[0107] Optionally, the image editing module 12 is further used to: determine a latent vector difference between the target image and the training image, and determine a vector editing factor according to the latent vector difference and the normal vector;
[0108] The direction vector is vector edited according to the vector edit multiple.
[0109] The loss calculation module 13 is used to perform image decoding on the direction vector and the encoded image after the vector editing by the autoencoder to obtain a decoded image, and perform loss calculation on the decoded image and the target image to obtain a loss value.
[0110] The loss calculation module 13 is further used to: input the direction vector after vector editing into a direction decoder, and decode to obtain the edited direction feature.
[0111] The encoded image features and the edited directional features are superimposed and input into the decoder to obtain the decoded image.
[0112] The hair straightening processing module 14 is used to update the parameters of the autoencoder according to the loss value until the autoencoder converges, and input the image to be processed into the converged autoencoder for hair straightening processing to obtain an output image.
[0113] In this embodiment, the latent vectors of each virtual face image are respectively vector-edited through the normal vector, so that the latent vectors at different scales can be effectively obtained. The latent vectors at different scales are input into the face generation model for image generation, so that the virtual images corresponding to the latent vectors at different scales can be effectively obtained. The training image is encoded by the autoencoder to obtain the encoded image and the direction vector, and the direction vector is vector-edited to ensure the consistency between the direction vector and the latent vector after the vector editing corresponding to the training image. The loss is calculated by decoding the image and the target image to obtain the loss value, and the parameters of the autoencoder are updated according to the loss value, so that the autoencoder can effectively learn the characteristics of the straightness and curvature of the hair between the target image and the training image. The hair straightness processing is performed on the to-be-processed image based on the converged autoencoder, which prevents the problem of large difference in hair color and shape between the output image and the to-be-processed image, and improves the accuracy of the hair straightness processing.
[0114] Embodiment 4
[0115] Figure 4 2 is a block diagram of a terminal device 2 provided in the fourth embodiment of the present application. Figure 4 As shown, the terminal device 2 of this embodiment includes: a processor 20, a memory 21, and a computer program 22 stored in the memory 21 and executable on the processor 20, such as a program for a hair straightening method. When the processor 20 executes the computer program 22, the steps in each embodiment of the hair straightening method described above are implemented, such as Figure 1 S10 to S50 as shown, or Figure 2 Alternatively, the processor 20 implements the above when executing the computer program 22 Figure 3 The functions of each unit in the corresponding embodiment are, for example, Figure 3 For details on the functions of units 10 to 14 shown, please refer to Figure 3 The relevant descriptions in the corresponding embodiments are not repeated here.
[0116] Exemplarily, the computer program 22 may be divided into one or more units, which are stored in the memory 21 and executed by the processor 20 to complete the present application. The one or more units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 22 in the terminal device 2. For example, the computer program 22 may be divided into a normal vector determination module 10, a vector editing module 11, an image encoding module 12, a loss calculation module 13, and a hair straightening processing module 14, and the specific functions of each unit are as described above.
[0117] The terminal device may include, but is not limited to, a processor 20 and a memory 21. Those skilled in the art will appreciate that Figure 3 It is only an example of the terminal device 2 and does not constitute a limitation of the terminal device 2. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.
[0118] The processor 20 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0119] The memory 21 may be an internal storage unit of the terminal device 2, such as a hard disk or memory of the terminal device 2. The memory 21 may also be an external storage device of the terminal device 2, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 2. Further, the memory 21 may also include both an internal storage unit and an external storage device of the terminal device 2. The memory 21 is used to store the computer program and other programs and data required by the terminal device. The memory 21 may also be used to temporarily store data that has been output or is to be output.
[0120] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0121] If the integrated module is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Among them, the computer-readable storage medium can be non-volatile or volatile. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in computer-readable storage media can be appropriately increased or decreased according to the requirements of legislation and patent practices in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practices, computer-readable storage media do not include electrical carrier signals and telecommunication signals.
[0122] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for straightening hair. It is characterized in that The method comprises: Generate multiple virtual face images according to the face generation model, and obtain the normal vector of the separation hyperplane according to each virtual face image through support vector machine training, wherein the separation hyperplane is used to classify the hair straightness of each virtual face image; Performing vector editing on the latent vectors of each virtual face image according to the normal vector, and inputting the latent vectors after vector editing into the face generation model for image generation, so as to obtain a face editing image corresponding to each latent vector; Determine a training image and a target image in the face editing image, perform image encoding on the training image according to the autoencoder to obtain an encoded image and a direction vector, and perform vector editing on the direction vector; Performing image decoding on the direction vector and the encoded image after vector editing according to the autoencoder to obtain a decoded image, and performing loss calculation on the decoded image and the target image to obtain a loss value; The parameters of the autoencoder are updated according to the loss value until the autoencoder converges, and the image to be processed is input into the converged autoencoder for hair straightening processing to obtain an output image.
2. The method for straightening hair according to claim 1, It is characterized in that The determining of the training image and the target image in the face editing image, and encoding the training image according to the autoencoder to obtain the encoded image and the direction vector, comprises: Sampling the face editing image corresponding to the same latent vector to obtain the training image and the target image; Inputting the training image into the encoder in the autoencoder for image encoding to obtain the encoded image; Perform feature mapping on a fully connected layer connecting the encoded image input and the encoder output to obtain the direction vector.
3. The method for straightening hair according to claim 2, It is characterized in that The vector editing of the direction vector comprises: Determining a latent vector difference between the target image and the training image, and determining a vector edit factor according to the latent vector difference and the normal vector; The direction vector is vector edited according to the vector edit multiple.
4. The method for straightening hair according to claim 1, It is characterized in that The step of performing image decoding on the direction vector and the encoded image after vector editing according to the autoencoder to obtain a decoded image comprises: Inputting the direction vector after vector editing into a direction decoder to obtain a direction feature; The encoded image and the directional feature are feature merged and then input into the decoder to obtain the decoded image.
5. The method for straightening hair according to claim 1, It is characterized in that The method of obtaining the normal vector of the separation hyperplane by training the support vector machine according to each virtual face image includes: Classify the hair straightness of each virtual face image according to a preset straightness classifier to obtain a straight hair image and a curly hair image; The latent vector of the straight hair image is set as a positive sample, and the latent vector of the curved hair image is set as a negative sample to train a support vector machine, and the normal vector of the separating hyperplane is determined according to the trained support vector machine.
6. The method for straightening hair according to claim 1, It is characterized in that After inputting each latent vector after vector editing into the face generation model to generate an image and obtaining a face editing image corresponding to each latent vector, the method further includes: Determine the structural similarity features and peak signal-to-noise ratio of each face edited image respectively; If the structural similarity feature and / or the peak signal-to-noise ratio of any of the face editing images is less than the corresponding feature threshold, the face editing image is deleted.
7. The method for straightening hair according to any one of claims 1 to 6, It is characterized in that The step of respectively performing vector editing on the latent vectors of each virtual face image according to the normal vector comprises: Taking the normal vector as a reference vector, the latent vector of each virtual face image is increased or decreased by a preset vector multiple.
8. A hair straightening system, It is characterized in that The system comprises: A normal vector determination module, used to generate multiple virtual face images according to the face generation model, and obtain the normal vector of the separation hyperplane according to each virtual face image through support vector machine training, wherein the separation hyperplane is used to classify the hair straightness of each virtual face image; A vector editing module, used to perform vector editing on the latent vectors of each virtual face image according to the normal vector, and input the latent vectors after vector editing into the face generation model for image generation, so as to obtain a face editing image corresponding to each latent vector; An image encoding module, used for determining a training image and a target image in the face editing image, performing image encoding on the training image according to an autoencoder to obtain an encoded image and a direction vector, and performing vector editing on the direction vector; a loss calculation module, configured to perform image decoding on the direction vector and the encoded image after the vector editing by the autoencoder to obtain a decoded image, and perform loss calculation on the decoded image and the target image to obtain a loss value; The hair straightening processing module is used to update the parameters of the autoencoder according to the loss value until the autoencoder converges, and input the image to be processed into the converged autoencoder for hair straightening processing to obtain an output image.
9. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Image processing method and device, computer equipment and storage medium
CN112991160A
Face editor training, face editing and live broadcasting methods and related devices
CN113255551A
Apparatus and method for processing video data
US20060133681A1
Systems and methods for prior knowledge transfer for image inpainting
WO2021077140A2
