{'fraction_non_alphanumeric': 0.0332008090953477, 'fraction_numerical': 0.013531422194322382, 'mean_word_length': 4.80230675839741, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Segmentation-Reconstruction-Guided Facial Image De-occlusion

Occlusions are very common in face images in the wild, leading to the degraded performance of face-related tasks. Although much effort has been devoted to removing occlusions from face images, the varying shapes and textures of occlusions still challenge the robustness of current methods. As a result, current methods either rely on manual occlusion masks or only apply to specific occlusions. This paper proposes a novel face de-occlusion model based on face segmentation and 3D face reconstruction, which automatically removes all kinds of face occlusions with even blurred boundaries,e.g., hairs. The proposed model consists of a 3D face reconstruction module, a face segmentation module, and an image generation module. With the face prior and the occlusion mask predicted by the first two, respectively, the image generation module can faithfully recover the missing facial textures. To supervise the training, we further build a large occlusion dataset, with both manually labeled and synthetic occlusions. Qualitative and quantitative results demonstrate the effectiveness and robustness of the proposed method.


Introduction
Thanks to deep Convolutional Neural Networks (CNNs), massive training data, and the widespread use of cameras, face-related techniques have successfully found many applications in our daily life, covering the fields of entertainment, media, art, security, etc. However, face images in the wild may be occluded by various objects, which leads to loss of information and undesirable noise, further resulting in degraded performance of algorithms for face analysis. To address this issue, researchers typically combine methods such as augmenting training data with synthesized occlusions [1,2], designing more sophisticated metrics and network structures [3][4][5][6], exploiting elaborated training strategies [7][8][9]. Despite their effectiveness, most of them are task-specific and cannot be migrated to other face-related tasks. A relatively more general solution is to de-occlude the face image before passing it to the downstream tasks. Before the widespread use of deep learning-based methods, the dominant approaches were based on matching and copying visible patches to the missing parts. A representative one is PatchMatch [10], which recursively searches the nearest neighbor textures to fill in the holes. Such copy-andpast-based methods work well in recovering simple lowfrequency textures and obtain smooth results; however, they cannot recover high-level textures with complex structures, e.g., eyes, nose, mouth. [11][12][13][14] leveraged Principal Component Analysis (PCA) to recover high-level semantic face textures. Nevertheless, such methods are based on the assumption that face images are in a linear space. Even for images acquired under constrained conditions, the results are blurry and far from satisfactory. As pointed out by [15], the deep autoencoder is a non-linear generalization of the PCA. Therefore, it is reasonable to replace the PCA part of the above methods with an autoencoder. SSDA [16] proposed a deep sparse autoencoder to remove Gaussian noises and superimposed text from images, pioneered the use of deep neural networks in this area. Influenced by the great success of Generative Adversarial Networks (GAN) [17] in image generation, Context Encoder [18] introduced adversarial training to image inpainting for the first time. Its im-pressive performance led to the prosperity of GAN-based image inpainting methods. Since then, the combination of autoencoder and discriminator has been adopted as the basic model structure for image inpainting tasks [19][20][21][22]. Despite the remarkable progress so far achieved, current methods mainly focus on filling the holes with visually plausible textures and neglect the detection of imperfectness. When applied to the face de-occlusion task, images must be accompanied by manually labeled masks. One strategy to address this problem is to train the model to detect the occlusions automatically. Due to the lack of well-labeled paired training data, existing methods mainly train on the synthetic occluded face images [23][24][25][26][27][28]. Unfortunately, these methods either generate low-resolution results or only tackle specific occlusion types. We attribute this to the limited variety of synthetic occlusions. Real occlusions have different shapes, textures, and blurred boundaries, making it infeasible for synthesis-based methods to cover all possibilities of occlusion. In addition, collecting completely occlusion-free face images as ground truth is not easy because the forehead part of the face is often occluded by bangs, which is perhaps why none of the existing methods consider hair as a source of occlusion.
Given the limitations of existing methods, this paper explores how to enable neural networks to remove arbitrary kinds of face occlusions. Our main contributions are summarized as follows: • We propose a novel face de-occlusion framework robust to all types of occlusions, regardless of their shapes and textures.
• We build a large occlusion dataset with extensive manually labeled occlusions from real face images.
• The proposed method outperforms the state-of-the-art baselines quantitatively and qualitatively.

Mask-Dependent Face Inpainting
Image inpainting aims to recover the missing textures of the input image. Recently, the autoencoder-GAN-based models have achieved impressive results. Benefiting from such structure, Context Encoder [18] successfully predicts the 64 × 64 missing part of 128 × 128 images. To make the model further concentrate on the missing parts, [19,20] leverage two discriminators: a global discriminator, which takes the whole image as input, and a local discriminator, which only takes the small region around the missing part. However, such a design is only suitable for a single rectangular(or even square) hole and cannot be applied to images with irregular and arbitrarily distributed holes. To properly handle free-form masks, [21] proposed a Partial Convolu-tional Layer, comprising a masked and re-normalized convolution operation followed by a mask-update step. [22] proposed a Gated Convolution module, which learns a soft mask for the features in different layers. However, due to the ineffectiveness of CNNs in modeling long-range correlations between distant textures and the hole regions, the inpainting results often have boundary artifacts and look unreal. [20] proposed a Contextual Attention module, which utilizes the image features as a convolution kernel, forcing the distant textures to interact with each other; this could be simply achieved by attention. [29] proposed a Self Attention module, which allows long-range dependency modeling of features; since then the attention mechanism has been widely applied in image generation tasks [30][31][32][33]. To make the generated image faithfully recover the facial topology, [34] leverages facial landmarks as a shape prior. [33] proposed a two-path probabilistic framework to generate pluralistic inpainting results. The common problem of the above methods is that they cannot detect the occluded parts automatically and rely on manually specified masks, limiting their usage scenarios.

Mask Free Face De-occlusion
Some methods are devoted to getting rid of masks' dependence and making the face de-occlusion process fully automated. They are typically trained on face pairs with synthesized occlusions. [23] proposed an LSTM-Autoencoder to gradually substitute the occlusions with facial textures. Benefiting from an elaborated forward pass, [24] proposed a semi-supervised face de-occlusion method, which is trained to predict the occlusion mask without the supervision of ground-truth. [25] proposed a two-stage GAN, where the first GAN aims to reconstruct the occlusion part solely, and the second GAN takes the result of the first GAN as a hint making the input image occlusion-free. Due to the limited variety of occlusions in the training set, the above methods can only generate images in 128 × 128 resolution with noticeable artifacts, restricting their application to face recognition. Given the complexity of occlusion types, a relatively simple task would be to deal with only specific occlusion: [27,28] for eyeglasses and [35] for masks. Besides being limited by the occlusion variety, as they lack face topology information, the results are often far from satisfactory, especially on large-angled face images.

3D-Guided Face De-occlusion
The work closest to ours is FD3D [26], where we both use 3D Morphable Model [36] (3DMM)-based reconstruction results as guidance. FD3D feeds the synthetic occluded face and the 3D reconstructed one to an adversarial auto-encoder and expects the output to be occlusion-free. Our method surpasses theirs in the following aspects: 1) They inpaint directly on the occluded face despite the chal-  Figure 2. Overview of the proposed method, which does not include the discriminator part for space limitation lenge of converting various occlusion textures to face textures; in contrast, our method explicitly removes occlusions with predicted masks before inpainting, bypassing the disturbance of the occlusion textures. 2) FD3D entirely relies on supervised learning, which requires occlusion-free images to serve as the ground truth, while our method can be trained on initially occluded images. 3) They synthesize images with fixed occlusions, namely, cup, glasses, hand, mask, and scarf, which have 99 variations in total; by detecting the face mask instead of innumerable types of occlusions, our method can handle all types of occlusion. Figure 2 illustrates the overview of our method. Given that covering all possible occlusions is impossible, we consider the opposite direction. We employ a face segmentation module N S to predict the face mask M f , which is much easier than predicting the mask of all kinds of occlusions. Then, we use the 3D reconstruction module N R to predict the prior 3DMM-based texture and the corresponding mask for the whole face, denoted as I m and M m , respectively. The mask of the occlusions M o can then be calculated as:

Overview
where denotes element-wise product. For face inpainting, we replace the occluded part of the input image I with Gaussian noise to obtain I n , which minimizes the disturbance of the occlusion textures. I n , I m , and M o are concatenated and fed into the inpainting module N G , and the outputÎ is expected to be occlusion-free. The following terms supervise the inpainting: 1) the background region I bg , 2) the non-occluded face region I f , 3) the Poisson blending result of I f and I m , denoted as I p .
The overall framework contains three modules, N S , N R , and N G , for face segmentation, 3D reconstruction, and image inpainting. We present the implementation details of each module separately in the following.

Face Segmentation
Extracting face regions from occluded face images is a simple, valuable, but never seriously addressed problem. As a result, the recent 3D face reconstruction method [37] requires this functionality still needs to resort to a Naive Bayesian classifier. We present our solution to the problem in this section.
Data Preparation. We build our training data based on CelebAMask-HQ [38], which has 30,000 high-resolution face images, each with a segmentation mask of facial attributes. Basically, given a segmentation mask of a face image, we can easily get the face region by gathering the labels of eyes, nose, lips, mouth, and skin. Unfortunately, the segmentation mask in the dataset does not consider the occlusions, e.g., hands, accessories, microphones, which are all misclassified as skin. In addition, the segmentation masks in the dataset do not distinguish between sunglasses and spectacles; however, in our task, we should not discard the skin and eyes under the transparent lenses of the spectacles. To solve the above problems, we manually picked out the occluded face images with incorrect segmentation  masks and labeled more than 1700 occlusions from them. We also collected about 300 occlusions from Google to get a more balanced occlusion type (e.g., masks, scarfs). In addition, we collected more than 800 texture patches covering every type we can think of, which will substitute for the original occlusion textures during training to produce more occlusion variations. Those occlusions are utilized for data augmentation, as illustrated in Figure 3 (a) and the following equation.
Model Structure. N S follows the classical U-Net structure [39], with ResNet18 [40] as encoder, while the decoder is a stack of convolutional blocks corresponding to each stage of the encoder. Each decoder block takes features from its previous block and its symmetric encoder stage through skip-connection. Since the target mask is binary, a single channel output for the decoder suffices.
Losses. The training is guided by the Dice loss [41] and the Binary Cross-Entropy loss (BCE): where W and H represent the width and height of the mask, respectively. Further, we apply the "online hard example mining" (OHEM) [42] strategy to the BCE loss to make The proposed segmentation module achieves a precision of 0.981 and an IoU score of 0.954 on the validation dataset, which is acceptable considering the inaccurate edge region of the ground truth. By random checking the results, we surprisingly find that the predicted face region is often more accurate than the ground truth. We use this module to extract the face regions of the images in CelebA-HQ and FFHQ, which greatly facilitates the training of the other two modules, i.e., the reconstruction module N R and the inpainting module N G .

3D Face Reconstruction
The reconstruction module is adapted from [37], the state-of-the-art 3D reconstruction method with a ResNet50 [40] as its backbone. Given a face image, it predicts a vector c ∈ R 239 , containing 6 translation and rotation parameters; 144 shape and 80 texture coefficients of the 3DMM; and nine illumination coefficients of the Spherical Harmonics [43,44] model. With vector c, the face is reconstructed and further rendered to the image through a differentiable renderer.
Although [37] performs well on occlusion-free faces and even demonstrates certain robustness to small occlusions, it still cannot handle severe occlusions, e.g., sunglasses and masks. As shown in the second row of Figure 5, sunglasses make the reconstructed face have dark circles. In the third column, they even change the color of the reconstructed skin. Therefore, in our usage scenario, i.e., face de-occlusion, it is necessary to retrain an occlusion-robust 3D face reconstruction module. Now we present, as shown Figure 4, our training strategy.
Training data. The training is based on CelebA-HQ and FFHQ. Firstly, we use the pre-trained model of [37] to predict the reconstruction parameters of the training data, denoted as c gt . Then, we filter out all the images with sun- Figure 5. The first row shows the input images; the second row and the last row are reconstructed faces by [37] and ours, respectively. glasses since their corresponding c gt risk to be inaccurate. Next, we leverage the face segmentation module N S to detect the face masks of the training data, denoted as M f , for calculating the face-related losses. At last, as with the previous section, we randomly superimpose heavy occlusions to I during training to get occluded input images for N R .
Losses. Since we already have c gt , the most straightforward option is to use it as supervision; the loss is as: whereĉ is the predicted coefficient, and N is its dimension. Training solely with Equation 5 will result in inaccurate and non-discriminative results. Since it equally optimizes all the coefficients. However, different parts ofĉ obviously have different impacts on the reconstruction result, e.g., the poses play a more critical role than the illumination coefficients. Therefore, we also leverage the pixel-wise and the perceptual [45] losses to reduce the discrepancy between the reconstructed faceÎ and the real face I f : where M is the overlap of the original face mask M f and the reconstruction mask M m ; F(·) denotes the feature embedding function of a pre-trained face recognition model, and we use Arcface [46] here. We only extract the feature of I f , rather than the entire image I, to avoid the noises introduced by the non-facial patterns.
To accelerate the training, we also use the landmark loss. Thanks to c gt , we have ground truth 3D facial landmarks q, thus eliminating the need for a 2D facial landmark detector as required in other methods. The loss is calculated as : real fake? Figure 6. Overview of the inpainting module.
where n pt denotes the number of landmarks,q i denotes the predicted 3D coordinates of the i-th facial landmark. The weights ω n are set to 20 for the nose and inner mouth points and 1 for others.
As c gt provides sufficient regularity, we discard the complex regularization terms in [37]. The overall loss is the weighted sum of the above losses: where λ pix = 1.92, λ id = 0.2, λ ldmk = 1.6e −3 . Figure 5 compares our results with those of [37], demonstrating the effectiveness of the proposed training strategy in improving the occlusion-robustness of the model. A quantitative comparison is also performed: we use [37] and our model to reconstruct 1000 face images with synthetic occlusions, the L pix of our model is 0.153, which is much less than 0.177 of [37].

Face Inpainting
With the N S and N R described above, we get the follow- The generator N G is constructed from stacked gated residual blocks [22] and follows the classical encoderdecoder structure; a self-attention [47] module is applied to the bottleneck features. As shown in Figure 6, the input is composed of three parts: the occlusion mask M o , the face image with noised occlusion I n , and the reconstructed face I m . The outputÎ is the de-occluded image. A VGG [48] shaped discriminator is further employed to increase the photorealism toÎ.
We randomly superimpose occlusions to the training data and train N G to recover the missing textures. One issue to note is that the input image itself always contains occlusions, such as bangs, and we do not have ground truth for these parts. So we use Poisson Blending [49] to seamlessly merge I f and I m and get I p , which provides weak supervi-sion for the inpainting task. The training is guided by the following losses: Pixel-wise face loss.
where M = M m M f , limiting the loss to be calculated on the face region solely. This loss serves for recovering textures occluded by the synthetic occlusion and cannot recover the initially occluded textures. SSIM loss. We use I p to guide the generation of initially occluded textures. Although the Poisson blending result is visually pleasing, it changes the color of I f , so we cannot simply apply L 1 or L 2 loss. Instead, we leverage the Structural Similarity loss (SSIM) [50], emphasizing the structural level discrepancy: where SSIM stands for the similarity mapping function (see Appendix for details);M m is the eroded M m , eliminating the edge effects in the similarity map. To further mitigate the impact of inaccurate color of I p and make the loss focus on the missing textures, we apply the OHEM again as in Equation 4. Background loss. Areas other than the face should remain unchanged: where M bg denotes the background mask, calculated by 1− M m . We also erode M b g to alleviate the edge effects. Identity loss. The generated image should have the same identity as the original image, so we also leverage Equation 7 to add feature level identity constraints.
TV loss. To penalize the noises inÎ, we adopt the total variation loss [51].
where W , H, C are the width, height, and the number of channels, respectively, ∇ calculates the image gradient along a direction. Adversarial loss. To further makeÎ photorealistic, we employ the adversarial loss: where D(·) denotes the output of the discriminator, which is the term to be maximized by the generator.
The global objective function of the generator can be summarized as follows: where the weights are empirically set to λ pix = 10, λ sm = 5, λ bg = 5, λ id = 0.2, λ tv = 0.1, λ adv = 0.01. Discriminator loss. We use the BCE loss to train the discriminator, aiming to distinguishÎ from real images: where I is the real image with less occlusion, selected from CelebA-HQ and FFHQ according to the overlap rate of its corresponding M m and M f .

Experiments
The proposed method can effectively remove the occlusions from face images. To demonstrate the power of our model, we qualitatively compare our results with state-ofthe-art methods, including those for face de-occlusion and for image inpainting. Quantitative experiments are conducted in two aspects as well, namely reconstruction ability and identity recovery ability.

Implementation Details
We follow an incremental training strategy: 1) We train the segmentation module N S . 2) we train the reconstruction module N R based on N S . 3) We train the inpainting module N G based on the result of the first two. The training is performed on two public datasets, CelebAMask-HQ [38] and FFHQ [52], and our manually labeled/collected occlusions and textures. All the images are aligned with facial landmarks detected by [53] and cropped to 256 × 256.
The training of N S consists of two rounds: In the first round, we train on 300,000 images of CelebAMask-HQ with our manually labeled occlusions to obtain a coarse model. In the second round, we apply the coarse model to both CelebAMask-HQ and FFHQ [54], select 500 hard examples from the results, relabel and add them to the occlusion dataset to retrain a more accurate model. Each round is trained for 30 epochs with a batch size of 16 and a learning rate of 1e −4 . The training takes about two hours on two Nvidia GTX 1080 GPUs. The 3D reconstruction module and the face inpainting modules are trained on 100,000 images of CelebAMask-HQ and FFHQ, with an initial learning rate of 1e −4 . For the reconstruction module N R , we train 50 epochs with a batch size of 16, and for the inpainting module N G , we train 80 epochs with a batch size of 4. The learning rates of both modules are dropped halfway through the training with ratios of 0.2 and 0.1, respectively. All three modules are optimized using Adam [55] with a weight decay of 0. Betas are set to [0.9, 0.999] for N S and N R , [0.5, 0.999] for N G . It takes about 80 hours to train N R and 40 hours to train N G on two Titan X Pascal GPUs.

Qualitative Results
The method closest to ours is FD3D [26]; we both leverage 3D face reconstruction for face de-occlusion. Unfortu-

Input PConv
DeepFill-v2 PICNet LaFIn FD3D ours nately, they do not release their code, so we use images from their paper to conduct the qualitative evaluation. Figure 7 compares our method with FD3D and several other publicly available image inpainting methods, including DeepFill-v2 [22], PConv [21], PICNet [56], and LaFIn [34]. The FD3D results are taken from their paper, while the rest are generated from their official implementations with models pre-trained on face images. We provide those inpainting methods with manually labeled occlusion masks for a fair comparison. One issue to note is that when FD3D compares with other methods in their paper, the images are not prealigned according to the rules of the corresponding method, resulting in questionable inferior results.
As shown in Figure 7, our method generally outperforms FD3D and other image inpainting methods, especially on face images with large yaw angles. We argue that the image inpainting methods are purely based on statistical learning, thus highly dependent on the training data distribution. When a few face images with large yaw angles occur, these methods record dramatic performance degradation. Although FD3D does not require a manual mask for the de-occlusion, they apparently can only handle limited types of occlusions: the bangs in the third row and the hat in the fourth row are not identified as occlusions. In addi-tion, FD3D produces low-quality face images with blurred boundaries and unreal textures, as evidenced in the images from the second to the last row. We believe this is due to the following reasons: 1) they do not explicitly detect the occlusions and mask them out, causing the generator to only cope with the occlusions it has ever seen while failing to deocclude arbitrary occlusions; 2) they use a very coarse 3D reconstruction method, which cannot provide correct and effective face prior to the generator.

Quantitative Results
This section evaluates the proposed method in two aspects: the reconstruction ability and the identity recovery ability. We synthesize 1000 sunglasses-occluded face images and use DeepFill-v2, PICNet, LaFIn, and our method to recover the initial images. Since the image inpainting methods only synthesize the missing region, the reconstruction ability is evaluated only in that region, with the following metrics: L1 loss, SSIM [50] score, and PSNR score. The identity recovery ability is evaluated by the cosine similarity of the features extracted by the pre-trained ArcFace [46]. Results are reported in Table 1.
As can be seen, our method outperforms the state-of-theart image inpainting methods across all listed metrics. It performs particularly well in recovering the identity, much exceeding its comparators. We attribute this mainly to the occlusion-robust face reconstruction module.

Ablation Study
The three modules in our framework are interdependent, making it impossible to remove one for ablation study. Instead, we mainly focus on the SSIM loss of the inpainting module, as the reconstruction and identity losses are conventional practices.
As Table 1 shows, without the SSIM loss, the model degrades in all aspects of metrics (nevertheless, benefiting from the 3D prior, it still outperforms others). Moreover, the initially occluded textures are now only supervised by the adversarial loss; thus, the results are not guaranteed to be occlusion-free (see Appendix for examples).

Discussion
Limitation.The proposed method focuses on removing the occlusions within the 3D reconstructed face mask. For occlusions spanning the face and the background, it can only rigidly remove the parts above the face without producing a smooth transition, creating an unrealistic scene where the face seems to hover above the occlusions, as Figure 8 shows. We have tried to create a gap between the face area and the background through mask erosion, and the gap is solely supervised by the adversarial loss during training. This trick alleviates the boundary effect to some extent but still cannot cope with large-sized occlusions.
Social impacts. Our method helps pre-process face images to avoid the negative impact of occlusions such as hair, glasses, hands, etc., on downstream tasks (e.g., fine-grained 3D face reconstruction, face recognition). Despite the benefits it brings, it also risks violating human privacy. To quantify this risk, we further conduct experiments to analyze the identity recovery ability across different types of occlusions. Figure 9 shows that the proposed method performs well on sunglasses-occluded faces; the performance decreases for the mask-type occlusion; and when combining the mask with sunglasses, the method can no longer recover the face identity. The above observation proves that the method is controllable for privacy violations. People's  identities can be safely protected when they simultaneously wear sunglasses and masks.

Conclusion
This work proposes a segmentation-3D reconstructionguided facial image de-occlusion method that automatically removes all types of occlusions. We first analyze the limitations of current face de-occlusion methods: they either require a manually labeled mask or can only handle a limited number of occlusion types, which mainly stems from the vast diversity of possible occlusions. Our key innovation is bypassing the segmentation of infinite occlusions and instead segmenting the face regions, which is much easier. We manually labeled a large face occlusion dataset, based on which we trained a face segmentation module N S and an occlusion-robust 3D reconstruction module N G . Given an occluded face image, N S and N G work collaboratively to mask the occlusions and provide beneficial priors to guide the subsequent face inpainting module. Qualitative and quantitative evaluations demonstrate the superiority of the proposed method.