A method and device for removing hair from portrait images based on a GAN network

By constructing gender boundaries and hair hidden code sets in StyleGAN hidden space, the problem of hair removal in portrait images is solved, and high-quality bald portrait image generation is achieved, suitable for diverse face shapes.

CN114663274BActive Publication Date: 2025-06-10ZHEJIANG UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210172409.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-24
Publication Date
2025-06-10
Estimated Expiration
2042-02-24

AI Technical Summary

Technical Problem

The prior art is difficult to effectively remove hair from portrait images, especially in the hidden space of StyleGAN, which lacks semantic information of the female-bald combination, resulting in poor hair removal effect.

Method used

By constructing gender boundaries in StyleGAN hidden space, the problem of lack of female-bald semantic information in hidden space is solved, and a model is built based on the hair hidden code set of StyleGAN hidden space to achieve hair removal while keeping other features of the face unchanged.

Benefits of technology

It realizes rapid and automatic removal of hair from portrait images and generates high-quality bald portrait images, suitable for face shapes of various expressions, postures, ages and genders.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114663274B_ABST
    Figure CN114663274B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for removing hair from portrait images based on a GAN network, including: Step 1, randomly sampling latent codes in the StyleGAN latent space to obtain a hair latent code-score dataset; Step 2, training through a support vector machine to obtain a hair separation boundary and a gender separation boundary; Step 3, editing through the hair separation boundary to obtain male bald latent codes; Step 4, based on the data in Step 3, training to obtain a Male HairMapper model for editing male latent codes with hair; Step 5, editing through the gender separation boundary and the Male HairMapper model to obtain female bald latent codes; Step 6, based on the above data, training to obtain a hair removal model for generating high-quality bald portrait images; Step 7, inputting the portrait image with hair to be removed into the hair removal model, and after calculation, outputting the portrait image with hair removed. The present invention also provides a device for removing hair from portrait images. Through the method provided by the present invention, high-quality bald portrait images can be generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of portrait editing, and particularly to a method and device for removing hair from portrait images based on a GAN network. Background Art

[0002] Hair is not only an important part of the human body but also a key element representing personality and fashion. However, the presence of hair in portrait images poses significant challenges to digital hairstyle design and 3D face reconstruction. In digital hairstyle design, directly overlaying a new hairstyle on the original image can easily mix with the old hair, causing problems; while replacing the old hairstyle with a new one requires the use of image matting and image inpainting techniques, both of which are very error-prone. For 3D face reconstruction, most existing methods cannot handle the hair that obscures the face, and the hair remains in the texture, so obvious artifacts will appear in the reconstructed face. This prompts us to develop a hair processing method that can naturally remove hair from portraits to facilitate practical applications.

[0003] Traditional methods for removing hair usually generate a training set by modifying and calibrating actual male and female images, but this method is time-consuming and laborious, and the obtained training set has a small capacity, resulting in a suboptimal effect of the finally trained model. At present, some scientific research scholars have used the latent codes in the StyleGAN latent space to represent image information and then completed image calibration through a computer. However, there is a problem in the StyleGAN latent space: the semantic information of the combination of female-bald head is missing in the latent space, making such methods only able to obtain the latent code pairs of male hair and bald head.

[0004] The academic literature "Interpreting the Latent Space of GANs for Semantic Face Editing. (In Advances in Neural Information Processing Systems 33 (2020): pages 12104 - 12114, 2020)" discloses a method of establishing a separation boundary in the StyleGAN latent space to edit face semantics through simple linear combinations, but this method cannot guarantee that the face features remain unchanged before and after editing.

[0005] The academic literature "Styleclip: Text-driven manipulation of stylegan imagery. (In Proceedings of the IEEE / CVF International Conference on Computer Vision. 2021., pages 2085-2094, 2021)" discloses a CILP language-image pre-training model, which realizes text-based semantic image manipulation by dynamically searching for the direction of a given text prompt in the StyleGAN latent space.

[0006] Patent document CN111598762A discloses a generative robust image steganography method, including: constructing a graph data set and pre-training the image data set; constructing and initializing a deep learning network architecture; training the deep learning network architecture by using a joint-fine tuning method to obtain a network architecture model; using the network architecture model to generate a stego pseudo-image and perform secret communication to complete the image steganography process. This method adopts an image steganography method. By using the generative adversarial network StyleGAN, the embedding process of the secret information is integrated into the image generation process. Therefore, the obtained generative image steganography method has the advantages of large embedding capacity, good quality of the generated image, strong statistical undetectability of the stego image, and high practicability, and overcomes the problems of poor quality of the stego image generated by the existing generative image steganography, low embedding capacity, and low information extraction accuracy. However, this method cannot handle the hair removal problem well because there is no semantic information of the combination of female-bald head in the StyleGAN latent space, and there is no mention of how to solve this problem in the invention content. Summary of the Invention

[0007] To solve the above problems, the present invention proposes a method for removing hair from portrait images based on the GAN network, which solves the problem that there is no semantic information of the combination of female-bald head in the StyleGAN latent space through the gender boundary; furthermore, a model is constructed based on the hair latent code set in the StyleGAN latent space, so that the hair can be removed while keeping other features of the human face unchanged, realizing the fast and automatic removal of hair from portrait images.

[0008] A method for removing hair from portrait images based on the GAN network includes:

[0009] Step 1: Randomly sample the latent codes in the StyleGAN latent space to obtain a latent code set, label the latent codes in the latent code set to obtain hair labels and bald head labels, and combine the latent code set with the labeled labels into a hair latent code-score data set;

[0010] Step 2: Obtain the hair separation boundary and the gender separation boundary through support vector machine training. The hair separation boundary can only edit the latent codes of male hair and cannot guarantee that the facial features of the portrait image output by the latent codes remain unchanged. The gender separation boundary is used to edit the gender corresponding to the latent codes while ensuring that the facial features of the portrait image output by the latent codes remain unchanged;

[0011] Step 3: Edit the latent codes of male with hair in the hair latent code-score dataset through the hair separation boundary, and use semantic diffusion refinement to optimize and obtain the latent codes of male bald heads corresponding to the latent codes of male with hair in the hair latent code-score dataset. The facial features of the portrait image output by the latent codes of male bald heads are consistent with those of the portrait image output by the latent codes of male with hair;

[0012] Step 4: Combine the latent codes of male bald heads obtained in Step 3 with the corresponding latent codes of male with hair to form a training set, and input it into the pre-constructed Male HairMapper model. After iterative training, obtain the Male HairMapper model for editing male latent codes to remove the hair in the portrait image while keeping the facial features of the portrait image unchanged;

[0013] Step 5: Convert the latent codes of female with hair in the hair latent code-score dataset into latent codes of male with hair through the gender separation boundary, input the converted latent codes of male with hair into the trained Male HairMapper model to obtain the latent codes of male bald heads, and optimize the latent codes of male bald heads through semantic diffusion refinement to obtain the corresponding latent codes of female bald heads;

[0014] Step 6: Combine the latent codes of male bald heads generated in Step 3 with the corresponding latent codes of male with hair, and the latent codes of female bald heads generated in Step 5 with the corresponding latent codes of female with hair to form a dataset, and input it into the pre-constructed hair removal model. After iterative training, obtain the hair removal model for generating high-quality bald portrait images;

[0015] Step 7: Input the portrait image to be de-haired into the hair removal model. After editing calculation and image fusion and stitching, output the portrait image after removing the hair.

[0016] Specifically, the latent code set in Step 1 includes the latent codes of female with hair, the latent codes of male with hair, and the corresponding latent codes of male bald heads.

[0017] Specifically, the hair separation boundary and the gender separation boundary are obtained through support vector machine training in Step 2. The specific steps are as follows:

[0018] Step 2.1: Based on the latent codes of male with hair and the corresponding latent codes of male bald heads in the hair latent code-score dataset, obtain the hair separation boundary through support vector machine training;

[0019] Step 2.2. Edit the randomly generated latent code through the StyleFlow software to obtain a gender latent code-score dataset with the opposite gender of the portrait image. Train a gender separation boundary based on the gender latent code-score dataset through a support vector machine.

[0020] Preferably, in the semantic diffusion refinement optimization, the facial features in the original portrait image are diffused into the edited latent code, and the target latent code is iteratively optimized. When the total loss function reaches the minimum, a pair of latent codes with hair and bald heads is output. In this step, the initialization value of the semantic diffusion refinement is improved, and only the facial features need to be moved, which is simpler and faster than moving the hair features.

[0021] Specifically, when iteratively optimizing the target latent code, the total loss function adopted is specifically:

[0022] L diffuse = λ rec L rec + λ per L per

[0023] where L rec is the pixel-level reconstruction loss, L per is the structure-level reconstruction loss, λ rec is the weight of the pixel-level reconstruction loss, and λ per is the weight of the structure-level reconstruction loss.

[0024] Preferably, when the hair removal model in step 6 is iteratively trained, the target loss function formula is as follows:

[0025] L = λ l L latent + λ h L hair + λ f L face + λ i L id

[0026] where L is the total loss, L latent is the latent code loss, λ l is the weight of the latent code loss, L hair is the pixel-level loss of the hair area, λ h is the weight of the pixel loss of the hair area, L face is the pixel-level loss of the face area, λ f is the weight of the pixel-level loss of the face area, L id is the facial feature loss, and λ iThe weight for facial feature loss adds calculation parameters for latent code loss and pixel loss on the basis of the traditional loss function formula, thereby improving the quality of the portrait image output by the final model.

[0027] Preferably, the hair removal model in step 6 further includes an encoder and an image generator. The encoder is used to encode the input portrait image to obtain a corresponding latent code, and after calculation and editing, a corresponding bald latent code is obtained. The image generator generates a portrait image with hair removed based on the obtained bald latent code.

[0028] Preferably, the fusion splicing in step 7 is to seamlessly fuse the facial features of the portrait image with hair to be removed with the portrait image output by the bald latent code obtained through editing calculation by Poisson editing operation to obtain a portrait image with hair removed.

[0029] The present invention also provides a portrait image hair removal device for quickly removing hair from a portrait image, including:

[0030] A computer memory, a computer processor, and a computer program stored in the computer memory and executable on the computer processor, wherein the computer processor executes the above-mentioned portrait image hair removal method; when the computer processor executes the computer program, the following steps are implemented: input the portrait image with hair to be removed into the portrait image hair removal device, and output a portrait image with hair removed after calculation.

[0031] Compared with the prior art, the beneficial effects of the present invention are:

[0032] (1) The present invention proposes a "female - male - bald" process, thereby solving the problem that there is no semantic information of the combination of female - bald in the StyleGAN latent space.

[0033] (2) Based on the hair latent code in the StyleGAN latent space, a portrait image hair removal model is constructed, so that it can process face shapes with different expressions, postures, ages, and genders, and at the same time generate high-quality corresponding bald portrait images. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 It is a flowchart of the portrait image hair removal method provided by the present invention;

[0035] Figure 2 It is a training flowchart of the Male HairMapper model and the hair removal model in this embodiment;

[0036] Figure 3 It is a flowchart of the hair removal model removing hair in this embodiment;

[0037] Figure 4 The portrait image with hair to be removed in this embodiment;

[0038] Figure 5 The portrait image after hair removal in this embodiment. Specific implementation manner

[0039] As Figure 1 shown, a method for removing hair from a portrait image based on a GAN network includes:

[0040] Step 1: Randomly sample the latent codes in the StyleGAN latent space to obtain a latent code set, label the latent codes in the latent code set to obtain hair labels and bald labels, and combine the latent code set and the labeled labels into a hair latent code-score data set (W, S) hair :

[0041] Step 1.1: Randomly sample to obtain 2N w latent codes where N w latent codes form the data set D 0 :

[0042]

[0043] Calculate the standard deviation w w of N std latent codes, and calculate the proportion value of the noise according to Equation (II):

[0044] scale noise =(0.5w std ) 2 (II)

[0045] Randomly generate noise between [0, 1], and use scale noise to control the weight of the noise to obtain the final noise data set D noise :

[0046]

[0047] where n i0 , ……, n i17 is the noise added to each layer;

[0048] Step 1.2: Input the latent codes in D 0 and D noise into the generator of StyleGAN2-ada to obtain the corresponding randomly sampled portrait images, train a hair classifier to score the randomly sampled portrait images, and obtain the score corresponding to each latent code according to Equation (IV):

[0049] s = C(g(w + )) (IV)

[0050] where s is the hair score, C is the hair classifier, g is the generator of StyleGAN2-ada, and g(w + ) is the portrait image output by the generator. Among them, the hair classifier adopts the ResNeXt-50(32x4d) structure, scores the portrait image with hair as 1, and scores the bald portrait image as 0, thus completing the labeling of the presence or absence of hair in the latent code sets D 0 and D noise ;

[0051] Step 1.3: Combine the latent codes of the above D 0 data set and the corresponding hair scores to form a hair latent code-score data set (W, S) hair :

[0052]

[0053] Step 2: Obtain a hair separation boundary and a gender separation boundary through support vector machine training. The hair separation boundary can only edit the latent codes of male hair and cannot guarantee that the facial features of the portrait image output by the latent code remain unchanged. The gender separation boundary is used to edit the gender corresponding to the latent code while ensuring that the facial features of the portrait image output by the latent code remain unchanged:

[0054] Step 2.1: Based on the hair latent code-score data set (W, S) hair , use support vector machine training to output a normal vector n h of a rough hair separation boundary b h ;

[0055] Step 2.2: Use StyleFlow to randomly edit and generate N gender latent codes according to Equation (VII) to obtain the latent codes after gender conversion

[0056]

[0057] The usage method of this formula has been published in the academic literature Styleflow: Attribute-conditioned exploration of stylegan-generated images using conditional continuous normalizing flows. (In ACM Transactions on Graphics (TOG), 2021, 40(3): 1-21., 2021), so it will not be elaborated here;

[0058] Step 2.3: Set all male hidden code scores in and w + to 1, and set all female hidden code scores to 0, obtaining a gender hidden code - score dataset (W, S) gender :

[0059]

[0060] wherein, refers to or w + ;

[0061] Step 2.4: Based on the gender hidden code - score dataset (W, S) gender , use a support vector machine to train and output a normal vector n g of the gender separation boundary b g .

[0062] Step 3: Edit the male with - hair hidden codes in the hair - hidden code - score dataset through the hair separation boundary, and use semantic diffusion refinement to optimize and obtain the male bald - head hidden codes corresponding to the male with - hair hidden codes in the hair - hidden code - score dataset. The facial features of the portrait image output by the male bald - head hidden codes are consistent with those of the portrait image output by the male with - hair hidden codes:

[0063] Step 3.1: Edit the hidden codes with the hair separation boundary This is the hidden code of the corresponding male portrait image in D 0 and D noise , and obtain an intermediate hidden code without hair according to Equation (IX)

[0064]

[0065] wherein, n h is the normal vector of the hair separation boundary b h ;

[0066] Step 3.2: Use FaceParsing to extract the mask m of the hair region of the corresponding original portrait image h ;

[0067] Step 3.3: Based on the original portrait image and the intermediate portrait image calculate and output the prior information according to Equation (X)

[0068]

[0069] Among them, ⊙ represents element-wise multiplication;

[0070] Step 3.4: Take as the initial value of the latent code to be optimized ;

[0071] Step 3.5: Calculate the pixel-level reconstruction loss L rec :

[0072]

[0073] Step 3.6: Calculate the structure-level reconstruction loss L per :

[0074]

[0075] Among them, φ represents the trained VGG16 model;

[0076] Step 3.7: Calculate the total loss L diffuse :

[0077] L diffuse = λ rec L rec + λ per L per (XIII)

[0078] Among them, λ rec is the weight of the pixel-level reconstruction loss, and λ per is the weight of the structure-level reconstruction loss;

[0079] Step 3.8: Use continuous iterative optimization to minimize the total loss L diffuse to obtain the final semantic diffusion result to obtain the latent code of the portrait image without hair and with unchanged facial features

[0080] Step 4: Combine the latent code of the male bald head obtained in Step 3 with the corresponding latent code of the male with hair to form a training set, and input it into the pre-constructed Male HairMapper model. After iterative training, obtain the Male HairMapper model for editing the latent code of the male to remove the hair in the portrait image and keep the facial features of the portrait image unchanged:

[0081] Step 4.1: Based on the paired latent codes of the male with hair and without hair obtained in Step 3 and obtain the corresponding latent code-score dataset H m :

[0082]

[0083] where n m is the number of male latent code pairs in the dataset H m ;

[0084] Step 4.2: Train a fully connected network Male HairMapper, denoted as M m , M n edits the latent code according to Equation (XV):

[0085]

[0086] where β is a hyperparameter controlling the weight;

[0087] Step 4.3: Calculate the latent code loss L latent according to Equation (XVI):

[0088]

[0089] Step 4.4: S44 calculates the pixel-level loss L hair of the hair region according to Equation (XVII):

[0090]

[0091] Step 4.5: S45 calculates the pixel-level loss L face of the face region according to Equation (XVIII):

[0092]

[0093] Step 4.6: Calculate the face feature loss L id using ArcFace according to Equation (XIX):

[0094]

[0095] where R is the ArcFace network, and <·,·> calculates the cosine value;

[0096] Step 4.7: Calculate the total loss L according to Equation (XX):

[0097] L = λ l L latent + λ h L hair + λ f L face + λ i L id (XX)

[0098] where λl The weight for the latent code loss, λ h The weight for the pixel-level loss of the hair region, λ f The weight for the pixel-level loss of the face region, λ i The weight for the face feature loss;

[0099] Step 4.8, continuously iterate and optimize the parameters of M m to reduce the total loss L and obtain the trained MaleHairMapper model; this Male HairMapper model is used to directly edit the male latent code to remove the hair in the portrait image while keeping the facial features in the portrait image unchanged.

[0100] Step 5, convert the female with-hair latent code in the hair latent code-score dataset into a male with-hair latent code through the gender separation boundary, input the converted male with-hair latent code into the trained Male HairMapper model to obtain a male bald latent code, and optimize the male bald latent code through semantic diffusion refinement to obtain the corresponding female bald latent code:

[0101] Step 5.1, edit the latent code using the gender separation boundary The said is D 0 and D noise the latent code of the corresponding female portrait image in, and obtain the male intermediate latent code with basically unchanged facial pose and skin color according to Equation (XXX)

[0102]

[0103] where, n g is the normal vector of the gender separation boundary b g ;

[0104] Step 5.2, input the male latent code with hair into the Male HairMapper model, and through calculation, obtain the corresponding male latent code with hair removed

[0105]

[0106] where the latent code compared with has the hair removed, but the facial features have changed;

[0107] Step 5.3, use FaceParsing to extract the mask m of the hair region of the corresponding original female portrait image h ;

[0108] Step 5.4. Based on the original female portrait image and the intermediate male bald portrait image Calculate the output prior information according to formula (L)

[0109]

[0110] where, ⊙ represents element-wise multiplication;

[0111] Step 5.5. Take as the initial value of the latent code to be optimized ;

[0112] Step 5.6. Calculate the pixel-level reconstruction loss L according to formula (LX) rec :

[0113]

[0114] Step 5.7. Calculate the structure-level reconstruction loss L according to formula (LXX) per :

[0115]

[0116] where, φ represents the trained VGG16 model;

[0117] Step 5.8. Calculate the total loss L according to formula (LXXX) diffuse :

[0118] L diffuse = λ rec L rec + λ per L per (LXXX)

[0119] where, λ rec is the weight of the pixel-level reconstruction loss, and λ per is the weight of the structure-level reconstruction loss;

[0120] Step 5.9. Use continuous iterative optimization to minimize the total loss L diffuse to obtain the final semantic diffusion result and constitute a pair of female latent codes with hair and without hair.

[0121] Step 6. Combine the male bald hidden codes generated in Step 3 with the corresponding male with-hair hidden codes, and the female bald hidden codes generated in Step 5 with the corresponding female with-hair hidden codes to form a dataset, and input it into a pre-constructed hair removal model. After iterative training, obtain a hair removal model for generating high-quality bald portrait images:

[0122] Step 6.1. Based on the paired with-hair and hairless male hidden codes obtained in Step 3 and the paired with-hair and hairless female hidden codes obtained in Step 5 and constitute dataset H:

[0123]

[0124] where n m is the number of male hidden code pairs in dataset H, and n f is the number of female hidden code pairs;

[0125] Step 6.2. Construct a hair removal model, including an identification module, a hair removal module, an imaging module, and a fusion module:

[0126] Among them, the identification module includes an encoder, which is used to encode the input portrait image to obtain the corresponding hidden code in the StyleGAN latent space and input it into the hair removal module. The encoder selects the projector proposed in Designing an encoder for StyleGAN image manipulation, which is a prior art and the specific operation process will not be elaborated here;

[0127] The hair removal module is a fully connected network, which is used to edit the hair hidden code in the portrait image hidden code into a bald hidden code and input the edited portrait image hidden code into the imaging module;

[0128] The imaging module includes an image generator, which generates the corresponding bald portrait image according to the input bald hidden code and obtains the portrait image after hair removal through an image fusion method.

[0129] The specific image fusion method is as follows:

[0130] First, use FaceParsing to extract the mask m of the hair area of the portrait image X input into the hair removal model test ;

[0131] Then, perform dilation and blurring operations on m test to obtain a mask with blurred edges

[0132] Finally, the new portrait image is seamlessly fused with the portrait image from which hair needs to be removed through Poisson editing, and the portrait image X after hair removal is calculated res :

[0133]

[0134] where P is the Poisson editing operation;

[0135] Step 6.3: Based on the dataset H, the hair removal model is iteratively trained, and finally a hair removal model for generating high-quality bald portrait images is obtained. The training method is the same as that of the Male HairMapper model in Step 4, so it will not be elaborated here.

[0136] As Figure 2 shown, the training flowcharts of the Male HairMapper model and the hair removal model.

[0137] As Figure 3 shown, the specific process of the hair removal model for removing hair is as follows: Transfer the facial features of the original portrait image to the generated bald portrait image to complete the hair removal of the original portrait image. Since the movement of facial features in the StyleGAN latent space is linear, it is simpler and faster compared to moving hair features, and at the same time, the problem of missing hair features during movement is avoided, thus obtaining a high-quality fused portrait image.

[0138] Step 7: Input the portrait image to be de-haired as Figure 4 shown into the hair removal model, and encode the input portrait image through the projector provided by Designingan encoder for StyleGAN image manipulation to obtain the corresponding latent code According to the formula (XCIX), the latent code is edited and calculated to obtain the corresponding latent code for hair removal

[0139]

[0140] Input the latent code for hair removal into the image generator to obtain a new portrait image without hair and with other facial features unchanged:

[0141]

[0142] Finally, the mask of the hair area of the portrait image with hair to be removed is seamlessly fused with the new portrait image and the portrait image with hair removed through Poisson editing, and the portrait image after hair removal as shown in Figure 5 is calculated and obtained.

Claims

1. A method for removing hair from portrait images based on a GAN network, characterized in that, it includes: Step 1: Randomly sample the latent codes in the latent space to obtain a latent code set, label the latent codes in the latent code set to obtain hair labels and bald labels, and combine the latent code set and the labeled labels into a hair latent code-score data set; Step 2: Obtain a hair separation boundary and a gender separation boundary through support vector machine training. The hair separation boundary can only edit the latent code of male hair and cannot ensure that the facial features of the portrait image output by the latent code remain unchanged. The gender separation boundary is used to edit the gender corresponding to the latent code while ensuring that the facial features of the portrait image output by the latent code remain unchanged; Step 3: Edit the male hair-encoded data in the hair-encoded score dataset through the hair separation boundary, and use semantic diffusion refinement optimization to obtain the corresponding male bald-encoded data in the hair-encoded score dataset. The facial features of the portrait image output by the male bald-encoded data are consistent with those of the portrait image output by the male hair-encoded data. The semantic diffusion refinement optimization is to diffuse the facial features in the original portrait image into the edited encoded data, and iteratively optimize the target encoded data. When the total loss function reaches the minimum, output a pair of encoded data pairs with hair and bald. When iteratively optimizing the target encoded data, the specific total loss function used is: ; where is the pixel-level reconstruction loss, is the structure-level reconstruction loss, is the weight of the pixel-level reconstruction loss, is the weight of the structure-level reconstruction loss; Step 4: Combine the male bald-encoded data obtained in Step 3 with the corresponding male hair-encoded data to form a training set, and input it into the pre-constructed model. After iterative training, obtain a model for editing male encoded data to remove the hair in the portrait image and keep the facial features of the portrait image unchanged; Step 5: Convert the female hair-encoded data in the hair-encoded score dataset into male hair-encoded data through the gender separation boundary, input the converted male hair-encoded data into the trained model to obtain male bald-encoded data, and optimize the male bald-encoded data through semantic diffusion refinement to obtain the corresponding female bald-encoded data; Step 6: Combine the male bald-encoded data generated in Step 3 with the corresponding male hair-encoded data, and the female bald-encoded data generated in Step 5 with the corresponding female hair-encoded data to form a dataset, and input it into the pre-constructed hair removal model. After iterative training, obtain a hair removal model for generating high-quality bald portrait images; Step 7: Input the portrait image to be hair-removed into the hair removal model. After editing calculation and fusion splicing with the image, output the portrait image after hair removal.

2. The method for removing hair from portrait images based on a GAN network according to claim 1, characterized in that, the latent code set in step 1 includes latent codes of women with hair, latent codes of men with hair, and corresponding latent codes of bald men.

3. The method for removing hair from portrait images based on a GAN network according to claim 1, characterized in that, the steps for obtaining a hair separation boundary and a gender separation boundary through support vector machine training in step 2 are as follows: Step 2.1: Based on the latent codes of men with hair and the corresponding latent codes of bald men in the hair latent code-score dataset, obtain a hair separation boundary through support vector machine training; Step 2.2: By editing the randomly generated hidden code through software, a gender hidden code-score data set with a gender hidden code opposite to that of the portrait image is obtained, and a gender separation boundary is obtained through support vector machine training based on the gender hidden code-score data set.

4. The method for removing hair from portrait images based on a GAN network according to claim 1, characterized in that, When the hair removal model in step 6 is iteratively trained, the target loss function formula is as follows: ; where is the total loss, is the latent code loss, is the weight of the latent code loss, is the pixel-level loss of the hair region, is the weight of the pixel loss of the hair region, is the pixel-level loss of the face region, is the weight of the pixel-level loss of the face region, is the face feature loss, is the weight of the face feature loss.

5. The method for removing hair from portrait images based on a GAN network according to claim 1, characterized in that, the hair removal model in step 6 further includes an encoder and an image generator. The encoder is used to encode the input portrait image to obtain a corresponding latent code, and after calculation and editing, obtain a corresponding latent code of a bald head. The image generator generates a portrait image with hair removed based on the obtained latent code of a bald head.

6. The method for removing hair from portrait images based on a GAN network according to claim 1, characterized in that, the fusion splicing in step 7 is to seamlessly fuse the facial features of the portrait image with hair to be removed with the portrait image output by the latent code of a bald head obtained through editing calculation by Poisson editing operation to obtain a portrait image with hair removed.

7. A device for removing hair from portrait images, including a computer memory, a computer processor, and a computer program stored in the computer memory and executable on the computer processor, characterized in that, the computer processor executes the method for removing hair from portrait images based on a GAN network according to any one of claims 1-6; when the computer processor executes the computer program, the following steps are implemented: input the portrait image with hair to be removed into the device for removing hair from portrait images, and output a portrait image with hair removed after calculation.

Citation Information

Patent Citations

  • Generative robust image steganography method

    CN111598762A