Region-wise Generative Adversarial ImageInpainting for Large Missing Areas
Yuqing Ma Xianglong Liu Shihao Bai Lei Wang Aishan Liu Dacheng Tao Edwin Hancock

























Recently deep neutral networks have achieved promising performance for filling large missing regions in image inpainting tasks. They usually adopted the standard convolutional architecture over the corrupted image, leading to meaningless contents, such as color discrepancy, blur and artifacts. Moreover, most inpainting approaches cannot well handle the large contiguous missing area cases. To address these problems, we propose a generic inpainting framework capable of handling with incomplete images on both contiguous and discontiguous large missing areas, in an adversarial manner. From which, region-wise convolution is deployed in both generator and discriminator to separately handle with the different regions, namely existing regions and missing ones. Moreover, a correlation loss is introduced to capture the non-local correlations between different patches, and thus guides the generator to obtain more information during inference. With the help of our proposed framework, we can restore semantically reasonable and visually realistic images. Extensive experiments on three widely-used datasets for image inpainting tasks have been conducted, and both qualitative and quantitative experimental results demonstrate that the proposed model significantly outperforms the state-of-the-art approaches, both on the large contiguous and discontiguous missing areas. 




image inpainting, region-wise convolutions, correlation loss, generative adversarial networks




Region-wise Generative Adversarial Image Inpainting for Large Missing Areas
    
Yuqing Ma, Xianglong Liu, Shihao Bai, Lei Wang, Aishan Liu, Dacheng Tao, Edwin Hancock

Y. Ma, X. Liu, S. Bai, L. Wang, and A. Liu are with the State Key Lab of Software Development Environment, Beihang University, Beijing 100191, China. X. Liu is also with Beijing Advanced Innovation Center for Big Data-Based Precision Medicine (Corresponding author: Xianglong Liu, xlliu@nlsde.buaa.edu.cn)
D. Tao is with the UBTECH Sydney Artificial Intelligence Centre and the School of Information Technologies, Faculty of Engineering and Information Technologies, The University of Sydney, Darlington, NSW 2008, Australia
E. Hancock is with the Department of Computer Science, University of York, York, U.K.

    December 30, 2023
================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================





§ INTRODUCTION

Image inpainting (i.e., image completion or image hole-filling), synthesizing visually realistic and semantically plausible contents in missing regions, has attracted great attentions in recent years. It can be widely applied in many tasks <cit.>, such as photo editing, image-based rendering, computational photography, etc. In recent decades, there have been many image inpainting methods proposed for generating desirable contents in different ways. For instance, context encoders <cit.> first exploit GANs to restore images, using a channel-wise fully connected layer to propagate information between encoder and decoder. To perceptually enhance image quality, several studies <cit.> attempted to extract features using a pre-trained VGG network to reduce the perceptual loss <cit.> or style loss <cit.>. More recently, <cit.> further concentrated on irregular missing regions and achieved satisfying performance especially for the highly structured images. 

Despite the encouraging progress in image inpainting, most existing methods still face the inconsistency problem, such as distorted structures and blurry textures, especially when the missing regions are large. Figure <ref> shows that the very recent method EC <cit.> (the second column) suffers severe artifacts in the consecutive large missing region. This phenomenon is much likely due to the inappropriate convolution operation over the two types of regions, i.e., existing and missing regions. 

Intuitively, different feature representations should be extracted to characterize different types of regions, since there is sufficient content information in existing regions, but none in the missing ones, which needs to be inferred from existing regions. Therefore, directly applying the same convolution filters to generate semantic contents inevitably leads to visual artifacts such as color discrepancy, blur and spurious edge responses surrounding holes. The changeable mask was been proposed in recent work <cit.> to handle the difference. However, relying on the same filters for different regions, they still fail to generate favourable results. Meanwhile, many discriminators proposed in inpainting tasks take the whole image as input, and use the same filter to deal with the reconstructed content and inferred content, which inevitably caused an unsatisfied compromise.






In this paper, to generate desirable contents for missing regions, we develop a region-wise generative adversarial framework to handle the different regions in each image. Figure <ref> shows the architecture of our whole framework. Note that we extend upon our prior conference publication <cit.> that mainly concentrated on the discontiguous missing areas using region-wise convolutions and suffered severe artifacts when the large missing areas are contiguous. Figure <ref> (a) shows the different types of missing regions, namely discontiguous and contiguous missing regions. For discontiguous missing regions, even though the total missing area is large, but it is still easier to infer the missing information from the surrounding area. However, for large contiguous missing regions, it is hard to infer semantically plausible and visually realistic information. This can be confirmed by the observations in Figure <ref> (b) and (c), where both EdgeConnect (EC) <cit.> and our previous model Region-wise Encoder-Decoder (RED) <cit.> can infer the semantic content in discontiguous missing areas in the first row, even facing distortion and inconsistency problem. However, they usually fail to infer the semantic information for contiguous missing areas (the second row in Figure <ref>).


We attempt to address these problems for both contiguous and discontiguous large missing regions using one generic framework in this paper. Our adversarial inpainting framework utilizes the region-wise generative adversarial networks to accomplish the image inpainting task. The region-wise generator integrating two consecutive encoder-decoder networks, first infers the missing semantic contents roughly and captures the correlations between missing regions and existing regions guided by correlation loss, and further adversarially enhances the naturally visual appearance via region-wise discriminator. The key contributions of this paper can be summarized as follows:


  * A generic inpainting framework is proposed to handle the images with both contiguous and discontiguous large missing areas at the same time, in an adversarial learning manner, consisting of region-wise generator and region-wise discriminator.


  * To locally handle features in different regions, the region-wise generator employs and integrates a region-wise convolution in semantic inferring networks, accomplishing the inpainting task at pixel level based on the ℓ_1 reconstruction loss.


  * To model non-local correlation between existing regions and missing regions, the correlation loss guides the region-wise generator to infer semantic contents and generate more detailed information.

  * To further eliminate large area artifacts and obtain visually realistic generated contents, the framework introduces a region-wise discriminator and utilizes the adversarial loss and the popular style loss to enhance the image quality respectively from local and global perspective.


  * Extensive experiments on various popular datasets, including face (CelebA-HQ <cit.>), and natural scenes (Paris StreetView <cit.> and Places2 <cit.>), demonstrate that our proposed method can significantly outperform other state-of-the-art approaches in image inpainting for both discontiguous and contiguous missing areas.


The remaining sections are organized as follows. Section <ref> discusses the related work for image inpainting. In Section <ref> we introduce our inpainting framework and the formulation. Comprehensive experiments over three popular datasets are presented in Section <ref>. Finally, we conclude in Section <ref>. 




§ RELATED WORK
 

Until now, there have been many methods proposed for generating desirable contents in different ways, including the traditional methods using handcrafted features and the deep generative models. We mainly focus on the deep models and introduce three different types of deep methods in detail.



 §.§ Traditional Methods

Traditional approaches can be roughly divided into two types: diffusion-based and patch-based. The former methods propagate background data into missing regions by following a diffusive process typically modeled using differential operators  <cit.>. Patch-based methods  <cit.> fill in missing regions with patches from a collection of source images that maximize the patch similarity. These methods have good effects on the completion of repeating structured images. However, they are usually time-consuming and besides they cannot hallucinate semantically plausible contents for challenging cases where inpainting regions involve complex, non-repetitive structures, e.g., faces, objects, etc.



 §.§ Deep Generative Methods

The development of deep neural networks <cit.> significantly promoted the progress of computer vision tasks <cit.>. Generative models <cit.> are widely used in many areas for its strong ability of modeling and learning approximately true dataset distributions, including image generation <cit.>, representation learning <cit.>, image retrieval <cit.>, object detection <cit.>, video applications <cit.> and image translation <cit.>. In general, the framework for solving image inpainting task using deep generative methods mainly consists of an encoder and a decoder. The encoder aims to capture and extract the context of an image into a compact latent feature representation. After that, the decoder uses the extracted representation to produce the missing image content, thus combine the original existing regions and the generating content in order to obtain the final restoring results.



  §.§.§ Synthesising Realistic Contents

Inspired by the prevalence of GANs <cit.>, many works force the restored contents to be consistent with existing regions using the adversarial loss. By picking a particular mode from the distribution of complete images, Context Encoders <cit.> attempted to get “hints” from pixels near the missing areas of the images. The authors connected the encoder and decoder through a channel-wise fully-connected layer, which allows each unit in the decoder to reason about the entire image content. After that, Semantic Inpainting <cit.> was proposed to solve image inpainting task by treating it as a constrained image generation problem. Based on that observation, the authors first trained a generative adversarial network on real images, then they recovered the encoding of the corrupted image to the “closest” intact one  while being constrained to the real image manifold. 
Meanwhile, in the work of GLCIC <cit.>, global and local context discriminators were utilized to distinguish real images from completed ones. Among them, the global discriminator looked at the entire images to assess its coherency and completeness, while the local discriminator only concentrated on a small area centered at the completed region to ensure the local consistency of the generated patches.




  §.§.§ Inferring High Frequency Details

It is hard to restore the low-level information, such as texture, illumination if we only use adversarial loss. Thus, several studies attempted to not only preserve contextual structures but also produce high frequency details. These methods are classified into optimization-based approaches and exemplar-based approaches.

Optimization-based Approach This type of method usually utilizes regularization to guide the whole framework to produce high frequency details which can be computed and extracted from pretrained-VGG network. Yang et al. <cit.> proposed a multi-scale neural patch synthesis approach based on joint optimization of image content and texture constraints. They first trained a holistic content network and fed the output into a local texture network to compute the texture loss which penalizes the differences of the texture appearance between the missing and existing regions. Wang et al. <cit.> further proposed an implicit diversified MRF regularization method which extracts features from a pre-trained VGG to enhance the diversification of texture pattern generation process in the missing region. 

Exemplar-based Approach It is believed that the missing part is the spatial rearrangement of the patches in the existing region, and thus the inpainiting or completion process can be regarded as a searching and copying process using the existing regions from the exterior to the interior of the missing part.
Based on the above assumption, Contextual-based Image Inpainting <cit.> and Shift-Net <cit.> were proposed by designing a “patch-swap” layer and a “shift-connection” layer respectively which high-frequency texture details from the existing regions to the missing regions are propagated. Similarly, Yu et al. <cit.> introduced CA which adopted a two-stage coarse-to-fine network. The first part made an initial coarse prediction, the model further computed the similarity between existing patches through a contextual attention layer and restored the patches predicted by the coarse network.



  §.§.§ Filling Irregular Holes

As discussed above, previous approaches mainly focus on rectangular shape holes which were often assumed to be at the center part of an image. Obviously, this kind of assumption contains strong limitations which may lead to overfitting to the rectangular holes, meanwhile ultimately limits the utilities in more widely used applications. Thus, several strategies have been proposed to fill irregular holes.
Liu et al. <cit.> first proposed a partial convolutional layer, which consists of a masked and a re-normalized convolution operation to be conditioned on only valid pixels, followed by a mask-update step.
Meanwhile, Yu et al. <cit.> introduced a gated convolution, which generalizes partial convolution by providing a learnable dynamic feature selection machanism for each channel at each spatial location across all layers.
More recently, a two-stage adversarial model that consists of an edge generator followed by an image completion network was proposed in <cit.>. According to the paper, the edge generator hallucinated edges of the missing region of the image, meanwhile the image completion network filled in the missing regions using hallucinated edges as a priori.
Moreover, Zhang et al. <cit.> came up with a probabilistically principled strategy named PIC to deal with the problem, which mainly contains two parallel paths including reconstructive path and generative path. Thus, PIC is able to resolve non-unique ground truth problem, with diverse information filled in the missing region.



§ THE APPROACH
 
In this section, we elaborate the details of our adversarial inpainting framework. We will first introduce the whole framework which utilizes region-wise generative adversarial network to accomplish image inpainting task. The region-wise generator recovers the missing information with two consecutive networks based on region-wise convolution and non-local correlation, while region-wise discriminator further enhances the image quality adversarially in a region-wise manner. Finally, the whole formulation and optimization strategies will be provided.



 §.§ The Adversarial Inpainting Framework

The state-of-the-art image inpainting solutions often ignore either the difference or the correlation between the existing and missing regions, and thus suffer from the inferior content quality for restoring large missing areas. What's worse, they cannot fill appropriate content and show particularly bad performance when facing large contiguous missing region. To simultaneously address these issues, we introduce our generic region-wise generative adversarial inpainting framework which is suitable for both discontiguous and contiguous missing cases as follows:

The region-wise generator recovers the semantic content in missing regions and pursues visually realistic, consisting of semantic inferring networks and global perceiving networks.
The semantic inferring networks focus on dealing with the differences and correlations between different regions, using region-wise convolution and non-local operation, respectively. We will further discuss them in Section <ref> and Section <ref>. The global perceiving networks consider the two different regions together using a style loss over the whole image, which perceptually enhance the image quality in a region-wise manner. Note that we take the two different regions into consideration over the whole image only to pursue the semantic and appearance information filled in missing region. 

Specifically, as shown in Figure <ref>, the region-wise generator takes the incomplete image Î_g and a binary mask as input, and attempts to restore the complete image close to ground truth image 𝐈_g, where 𝐌 indicates the missing regions (the mask value is 0 for missing pixels and 1 for elsewhere), Î_g=𝐈_g⊙𝐌 and ⊙ denotes dot product. To accomplish this goal, the semantic inferring networks infer the semantic contents from the existing regions. Encoder E_s extracts semantic features from Î_g, decoder D_s composing of the proposed region-wised convolutional layers is employed after encoder E_s to restore the semantic contents for different regions, and generates the predicted image 𝐈^(1)_p=D_s(E_s(Î_g)). After feeding the composited image 𝐈_c^(1)=Î_g+𝐈^(1)_p⊙ (1-𝐌) to global perceiving encoder E_g, global perceiving decoder D_g further globally and perceptually synthesizes the refined image 𝐈^(2)_p=D_g(E_g(𝐈^(1)_c)). Still, the composited image 𝐈_c^(2)=Î_g+𝐈^(2)_p⊙ (1-𝐌) could be obtained. 

With the region-wise image generation, the region-wise discriminator is further introduced to stress the importance of inferred regions in restoring results, which means, we still need to consider the difference between the two types of region. It is worth noting that, undesired artifacts only exist in inferred regions, which means there is no need to penalize the existing regions. In fact, focusing on the whole images, with existing regions involved, inevitably exerts bad influence on inferred regions. Therefore, here we only feed the inferred regions into region-wise discriminator. The region-wise discriminator forces the appearance of inferred content to approximate the true images, and further visually enhances the image quality. The inferred content of the predicted image and refined image 𝐈^(1)_p ⊙ (1-𝐌), 𝐈^(2)_p ⊙ (1-𝐌) are fed into discriminator D_r to adversarially enhance the capability of the region-wise generator. With the region-wise generator that distinguishingly deals with the different types of regions to infer the missing information, and the region-wise discriminator that adversarially guides the networks to enhance the image quality, our framework could accomplish the inpainting tasks and produce visually realistic and semantically reasonable restored images. We finally have the visually and semantically realistic inpainting result 𝐈_c^(2) close to the ground truth image 𝐈_g. More details will be presented in Section <ref>. 

In the following part of this section, we will present the key components and the corresponding techniques of our framework.



 §.§ Generating Region-wise Contents

For image inpainting tasks, the input images are composed of both existing regions with the valid pixels and the missing regions (masked regions) with invalid pixels in mask to be synthesized. During the inpainting process, the existing regions are basically reconstructing themselves which is easy to accomplish, while the missing region should be inferred from existing region and kept semantically reasonable and visually realistic from both local and global perspectives. That is to say, different learning operations should be conducted on these two types of regions. Only relying on the same convolution filter, we can hardly synthesis the appropriate features over different regions, which in practice usually leads to the visual artifacts such as color discrepancy, blur and obvious edge responses surrounding the missing regions. Motivated by this observation, we first propose region-wise convolutions to seperately handle with the different regions using different convolution filters, in avoid of compromise between the two different learning operations. 

Specifically, let 𝐖, Ŵ be the weights of the region-wise convolution filters for existing and missing regions respectively, and 𝐛, 𝐛̂ correspond to the biases. 𝐱 is the feature for the current convolution (sliding) window belonging to the whole feature map 𝐗. Then, the region-wise convolutions at every location can be formulated as follows:

    𝐱'= 
    Ŵ^⊤𝐱+𝐛̂,   𝐱∈𝐗⊙ (1-𝐌) 
    𝐖^⊤𝐱+𝐛,   𝐱∈𝐗⊙𝐌

This means that for different types of regions, different convolution filters will be learnt for feature representation respectively for inferring and reconstruction. 

In practice, we can accomplish region-wise convolutions through separating the two types of regions by channel according to masks which are resized proportionally as feature maps down-sampled through convolution layers. Thus, the information in different regions can be learned separately and transmitted consistently across layers.

Reconstruction Loss We employ ℓ_1 reconstruction loss over the two predicted images generated by region-wise generator, to promise the reconstruction of existing regions and generation for missing regions inferred from existing regions. Note that, although we only need the inferred contents for missing regions, the framework should have a better understanding of existing regions and infer the missing information from both local and global perspectives. Thus, it is essential to reconstruct the existing information as well. The reconstruction loss is defined as follows:

    ℒ_r=𝐈^(1)_p-𝐈_g_1 + 𝐈^(2)_p-𝐈_g_1.

The reconstruction loss is useful for region-wise convolution filters to learn to generate meaningful contents for different regions, especially for semantic inferring networks.




 §.§ Inferring Missing Contents via Correlations

The reconstruction loss treats all pixels independently without consideration of their correlation, and thus the framework generates a coarse predicted image. However, the inferred missing contents are similar to surrounding existing regions, which is hard to achieve semantically meaningful and visually realistic. This is mainly because the convolution operations are skilled in processing local neighborhoods whereas fail to model the correlation between distant positions.

To address this problem and further guide the region-wise convolutions to infer semantic contents from the existing regions, a non-local correlation loss is adopted following prior studies <cit.>. Traditional non-local operation computes the response at a position as a weighted sum of the features at all positions in the input feature map during the feed-forward process. It can capture long-distance correlation between patches inside an image at the expense of a large amount of calculations. Therefore, it is not appropriate for large feature maps in our generative models, where the smallest feature map is 128×128. Besides, we prefer to build the same correlations between different patches just as ground-truth image, which is hard to accomplish only guided by reconstruction loss. Therefore, in this paper, we introduce the correlation loss to model the non-local correlations and further guide the region-wise convolution to infer the missing information according to such correlations.

Formally, given an image 𝐈^(1)_c, Ψ(𝐈^(1)_c) denotes the  c×h×w feature map computed by feature extraction method Ψ. In practice, in order to index an output position in space dimension easily, we reshape the feature map to the size of c×n, where n = h×w.  Correspondingly, Ψ^i(𝐈_c) is the i-th column in the reshaped feature map Ψ(𝐈_c), where i=1,…,n, of length c. Then, a pairwise function f_ij can be defined as a non-local operation, which generates a n×n gram matrix evaluating the correlation between position i and j:

    f_ij(𝐈^(1)_c)= (Ψ^i(𝐈^(1)_c))^⊤(Ψ^j(𝐈^(1)_c)).

Once we have the non-local correlation, we can bring it into the inpainting framework by introducing a correlation loss.

Correlation Loss Since the relationship among distant local patches plays a critical role in keeping the semantic and visual consistency between the generated missing regions and the existing ones, we further introduce a correlation loss that can help to determine the expected non-local operation. Namely, for image 𝐈^(1)_c, the correlation loss is defined based on f_ij(·):

    ℒ_c=σ∑_i,j^nf_ij(𝐈^(1)_c)-f_ij(𝐈_g)_1,
 
where σ denotes the normalization factor by position. The correlation loss forces the region-wise convolution to infer missing information with semantic details much closer to the realistic image according to semantic-related patches, rather than surrounding ones.



 §.§ Eliminating large area artifacts

With the consideration of both differences and correlations between different regions, the framework could infer the semantically reasonable contents filled in the missing regions. However, it is very common to produce unwanted artifacts in unstable generative models, which could cause visually unrealistic results. Some work <cit.> tried to analyze the reason behind, but still cannot totally overcome this problem. 

Image generation tasks usually adopt style loss which poses as an effective tool to combat “checkerboard” artifacts <cit.>. Since our region-wise convolutions and non-local operation are handling with the difference and correlations between local patches, it is reasonable to adopt style loss over the whole image and perceptually enhance the image quality and remove some unpleasant artifacts. Thus, we use style loss to globally and perceptually enhance the image quality.

Style Loss  After projecting image 𝐈^(2)_c into a higher level feature space using a pre-trained VGG, we could obtain the feature map Φ_p(𝐈^(2)_p) of the p-th layer with size c_p ×h_p ×w_p, and thus the style loss is formulated as follows:

    ℒ_s= ∑_pδ_p(Φ_p(𝐈^(2)_c))^⊤(Φ_p(𝐈^(2)_c))-(Φ_p(𝐈_g))^⊤(Φ_p(𝐈_g))_1,

where δ_p denotes the normalization factor for the p-th selected layer by channel. The style loss focuses on the relationship between different channels to transfer the style for the composited image 𝐈^(2)_c, and thus globally perceiving over the whole image, rather than separately dealing with the different regions. Here, different from the prior work of PConv, we only consider the style loss for the composited image.

Even with the style loss involved, the contents are still covered with lots of artifacts and not as realistic as the completed ground truth. Such phenomenon is particularly obvious when facing large contiguous missing regions. We speculate that there are two main reasons for this phenomenon: First, the encoder tries to capture the information contained by existing regions, and the missing region could still obtain the information from surrounding pixels due to the essence of convolutional operation. For pixels inside the missing region, the pixels near the boundary could soon obtain effective information from existing region. However, the pixels deep inside only obtain few information depending on the distance between them and the boundary. Only with the network deepening can the distant pixels obtain information from effective existing regions, which could be seen as an uneven sample, easily contributing to artifacts. Second, as the network deepening, the nearby pixels obtain more information which might not be accurate, meanwhile the distant pixels obtain much inaccurate information and thus learn undesired features.

To address the issues, we introduce a region-wise discriminator to guide the region-wise generator. After locally handling the two types of regions and globally perceiving over the whole image, we further adopt a region-wise discriminator operating on output of both networks in region-wise generator to eliminate artifacts and force the generated content as realistic as real ground-truth image. 

Adversarial Loss 
Formally, given I_p^(1), I_p^(2), I_g, we extract the missing regions of each image and concatenate the mask as the input, instead of the whole image. It could help the generator to pay more attention to specific regions. For existing regions containing enough information, it is easy to reconstruct without too much guidance. However, for the inferred contents, the case is contrary. Penalizing these two regions at the same time and still using the same filters, is likely to cause an unwanted compromise and affect the visual appearance of the inferred contents. Thus, we deploy the region-wise discriminator architecture, penalizing input images at the scale of patches, which could further preserve local details. While training the region-wise generator, the generated patches will be considered as real and thus labeled as 1. As the discriminator improves, the generators enhance their ability to generate realistic images. After several iterations, the generative networks and discriminator gradually reach a balance, eliminating the unpleasant artifacts and generate visually realistic inpainting results. We minimize following loss to enhance the output of region-wise generator: 

    ℒ_a= α   𝔼(D_r(𝐈_g⊙(1-𝐌),𝐌))
    
    +   𝔼(1-D_r(𝐈^(1)_p⊙(1-𝐌),𝐌))
    
    +   𝔼(1-D_r(𝐈^(2)_p⊙(1-𝐌), 𝐌)),

where α is a hyper-parameter to define the significance of each part of adversarial loss. We concatenate mask 𝐌 to separate inferred contents and existing contents, which seems better than simply concatenating (1-𝐌). The reason we speculate is that, via defining inferred regions as 1 will introduce some noises and affect the final visual appearance. 







 §.§ The Formulation and Optimization

Formulation To guide the learning of the region-wise generator, we combines the reconstruction, correlation, styles, and adversarial loss as the overall loss ℒ:

    ℒ=ℒ_r + λ_1 ℒ_c + λ_2 ℒ_s + λ_3 ℒ_a,

and ℒ_a is maximized only to guide the discriminator to distinguish the generated contents and the real contents. We alternatively train the generators and discriminator, until the loss is convergent. 

Implementation For our method, we basically develop the model based on the encoder-decoder architecture of CA, discarding its contextual attention module and discriminator but adding the region-wise convolutions. We adopt the idea of patch discriminator and utilize the spectral normalization to stabilize the training, with leaky ReLU used as activation function. Input images are resized to 256× 256, and the proportion of irregular missing regions varies from 0 to 40% in the training process. We empirically choose the hyper-parameters λ_1=10^-5, λ_2=10^-3. λ_3=0 for previous 20 epochs, λ_3=1 for later 9 epochs. The α is set as 0.01, which means heavy penalization for inferred contents and thus could better eliminate the artifacts. The initial learning rate is 10^-4 using the Adam optimizer.

We also adopt skip links in our encoder-decoder architecture, which as <cit.> claimed, may propagate the noises or mistakes for most inpainting architectures. However, we find that skip links will not suffer the negative effect in our framework due to the region-wise convolutions and thus enable the detailed output from existing regions.


In practice, we exploit the widely-adopted pre-trained VGG network to extract features for the calculation of correlation loss as well as style loss. For the computation of correlation loss, only feature maps extracted by pool2 are adopted due to the weak semantic representation capability of pool1 and the blur caused by pool3 and pool4. In order to calculate the style loss, we use the output of pool1, pool2, and pool3 together. In another word, Ψ(·)=Φ_p(·) when p=2.
 

Optimization The whole optimization process is described in Algorithm <ref>. It follows the standard forward and backward optimization paradigm. In our framework, the reconstruction and adversarial loss work on two consecutive networks in region-wise generator, to respectively guarantee the pixel-wise consistency between the two predicted images and the ground truth, and produce natural visual appearance especially for inferred contents. To capture the relationship among different regions and generate detailed contents, the correlation loss is adopted to guide the training of the semantic inferring networks. Moreover, the style loss helps perceptually enhance the image quality by considering the whole image in global perceiving networks. 
In the forward step, given a ground truth image 𝐈_g, we first sample an irregular binary mask 𝐌 and subsequently generate the incomplete image Î_g. The region-wise generator takes the concatenation of Î_g and 𝐌 as the input, and outputs the predicted image 𝐈^(1)_p and 𝐈^(2)_p. In the backward step, in avoid of unstabilized character of generative models, we only adopt ℒ_1, ℒ_c, ℒ_s over the predicted and composited images in previous epochs. After several epochs, we introduce the adversarial loss ℒ_a to further guide the previous networks. Instead of taking the whole image as input, we specifically highlight the restored information for missing regions, which further enhances the inpainting results.








§ EXPERIMENTS
 
In this section, we first analyze the effect of different loss functions, and study the performance caused by each component of our adversarial inpainting framework. Then we evaluate our proposed method visually and quantitatively over several common datasets in image inpainting compared to state-of-the-art methods. Our code is available at <https://github.com/vickyFox/Region-wise-Inpainting>.




 §.§ Datasets and Protocols
 
We employ the widely-used datasets in prior studies, including  CelebA-HQ
<cit.>, Places2 <cit.>, and Paris StreetView <cit.>. CelebA-HQ contains 30k high-resolution face images, and we adopt the same partition as <cit.> did. The Places2 dataset includes 8,097,967 training images with diverse scenes. The Paris StreetView contains 14,900 training images and 100 test images. For both datasets, we adopt the original train, test, and validate splits. 

We compare our method with four state-of-the-art models, namely, Contextual Attention (CA) <cit.>, Partial Convolution (PConv) <cit.>, EdgeConnect (EC) <cit.>, and Pluralistic Image Completion (PIC) <cit.>. Among those models, CA are initially designed for regular missing regions, while PConv, EC, PIC and ours focus on irregular holes. We directly apply their released pre-trained models in our experiments. As to PConv, since there is no published codes, we borrow the implementation on github [https://github.com/MathiasGruber/PConv-Keras], and retrain the model following the authors' advice.
 
We compare our model with state-of-the-art both visually and quantitatively. As for quantitative protocols, following <cit.>, we use the following quantitative metrics: 1) ℓ_1 error, 2) ℓ_2 error, 3) peak signal-to-noise ratio (PSNR), and 4) structural similarity index (SSIM). These metrics assume pixel-wise independence, and can help to compare the visual appearance of different inpainting images. But in practice, they may assign favorable scores to perceptually inaccurate results. Recent studies <cit.> have shown that metrics based on deep features are closer to those based on human perception. Therefore, we also adopt another metric, namely Frechet Inception Dsitance (FID).











 §.§ Ablation Study

In this part, we will analyze the effect of different components in our model, proving that our method mainly gains from the region-wise generative adversarial networks architecture. Before that we first study the commonly-used loss functions in several state-of-the-art inpainting models, aiming to explain what they actually do for improving inpainting quality.



  §.§.§ Loss Analysis
 
Table <ref> illustrates the widely used loss functions for inpainting, including  reconstruction loss ℒ_r, style loss ℒ_s, perceptual loss ℒ_p, adversarial loss ℒ_a, KL divergence loss ℒ_k and feature  matching loss ℒ_f. They have been used in the typical models including PConv, EC, PIC and our model. Among all these models, EC proposed a two-stage architecture that divides the image inapinting into two easier tasks, i.e., edge recovery for missing regions and colorization according to surrounding existing regions. Thus, it depends on the adversarial loss ℒ_a and feature matching loss ℒ_f to recover the missing edge in the first stage , and restore the color and texture information based on the recovered edges. Removing ℒ_a and ℒ_f in the first stage, it is hard for EC to generate any meaningful contents. Thus, we only remove loss functions used in the second stage. Similar to Pconv, removing ℒ_p seems not make much difference from the full models(see Figure <ref> (b), (c), and (d), (e)). Besides, without considering the correlations and differences between existing and missing regions, the inpainting results contain obvious inconsistency.
(see Figure <ref> (b) and (c)). As to PConv, generation of the final inpainting results is guided by reconstruction loss ℒ_r, perceptual loss ℒ_p, and style loss ℒ_s. As shown in Figure <ref> , removing ℒ_p seems not make much difference from the full models. Besides, without considering the correlations and differences between existing and missing regions, the inpainting results contain obvious inconsistency.


We also study the PIC model, which is merely guided by reconstruction loss, adversarial loss and KL divergence loss ℒ_k due to their motivation of generating diverse inpainting results rather than one ground-truth image. Without high-level semantic guidance, such as style loss or perceptual loss, it is difficult to capture the semantic information for complicated structures in images. Therefore, PIC performs well on faces dataset, especially when the missing regions lying on faces. When facing complex structures, such as scene data or the background around the faces, it can hardly approximate the image distribution, and thus generates undesired inpainting contents. 

Different from the prior models like EC, PConv and PIC, our method mainly gains from region-wise generative adversarial networks architecture. We adopt the reconstruction loss to help region-wise convolution learn to represent features distinguishingly at local and pixel level. The correlation loss is introduced to capture the non-local relations between different regions and thus further fill semantically meaningful details in the missing regions. To guarantee the visual appearance of inpainting contents, style loss and adversarial loss are used to eliminate the artifacts and approximate the ground-truth data distribution both from global and local perspectives. 



  §.§.§ Component Analysis
 
To validate the effect of different components in our adversarial image inpainting framework, Figure <ref> respectively shows the inpainting results obtained by our framework, and the framework using different settings: standard convolution filters instead of region-wise ones, removing correlation loss, using ℒ_c and ℒ_s at the same networks, only adopting semantic inferring networks without global perceiving, and removing region-wise discriminator (namely RED<cit.>). From the results, we can see that without region-wise convolutional layers, the framework can hardly infer the consistent information with existing regions. Furthermore, without considering the non-local correlation, the framework restores the missing regions only according to the surrounding areas. Moreover, using ℒ_c, ℒ_s at the same stage will cause artifacts and cannot restore semantic contents. Besides, we can see that only relying on semantic inferring network can restore the semantic information, and the outputs still contain strange artifacts. Without the help of region-wise discriminator, the inpainting results contain some fold-like artifacts. Together with region-wise convolutions, non-local correlation and region-wise discriminator, our framework enjoys strong power to generate visually and semantically close images to the ground truth.







 §.§ Comparison with State-of-the-arts

Now we compare our region-wise generative adversarial method with the state-of-the-art inpainting models, in terms of both qualitative and quantitative evaluations.



  §.§.§ Qualitative Results









Figure <ref>, <ref> and <ref> show the inpainting results of different methods on several examples from CelebA-HQ, Paris StreetView, Places2, respectively, where “GT” stands for the ground truth images. We compare all the models both on the discontiguous and contiguous missing regions, to prove the superior generalization ability of our method in different scenarios. All the reported results are the direct outputs from trained models without using any post-processing. 

From Figure <ref>, we can see that CA brings strong distortions in the inpaiting images, while PConv, EC and PIC can recover the semantic information for the missing irregular regions in most cases, but still face obvious deviations from the ground truth. EC performs well when discontiguous missing regions occur, but also fails to infer the correct edge information for large holes, even filling some inappropriate semantic content into the missing regions, such as the eye-like content shown in the fourth row of Figure <ref>(d). For either discontiguous or contiguous missing regions, PIC could relatively better restore the missing regions on the faces. But it cannot handle the surrounding areas without distinguishing their semantic differences. Among all the methods, we can observe that our model can recover the incomplete images with more natural contents in the missing regions, i.e., the structure and detailed information for faces, which looks more consistent with existing regions and much closer to the ground truth. 

Similarly, for the natural scene images, as shown in Figure <ref> and <ref>, we can get close conclusions as that in Figure <ref>. For example, CA still suffers from the heavy distortions, while Pconv and EC face the inconsistency and blurry problems in the filled contents. However, here the performance of PIC shows obvious degradation, since it can hardly infer the appropriate information. The phenomenon seems more obvious on Paris dataset, which contains more complicated structure. This is mainly because it is unlikely to well approximate the distribution of complete image only guided KL divergence or adversarial loss. Different from these methods, our method can well address the severe issues with the region-wise generative adversarial learning, and thus stably generates the satisfying results on scene dataset. The superior performance further proves that our method is powerful for the generic image inpainting task.  
















  §.§.§ Quantitative Results
 
Table <ref>, <ref> list the results of all methods on CelebA-HQ, Paris Street View and Place2 in terms of different metrics, with respect to contiguous and discontiguous missing areas of different sizes. First, from the table we can observe that comparing to discontiguous missing areas, all the methods show obvious degradation on contiguous missing areas, which proves that it is much more difficult to restore the contiguous missing areas than discontiguous ones, which means that for the satisfying performance, the inpainting models need to be guided by well-designed regularization. Second, we can easily get the conclusion that our proposed method can achieve superior performance on both discontiguous and contiguous masks in most cases, and keep comparatively stable performance on the two types of masks. Moreover, as the missing area gradually increases, all the methods perform worse in terms of all metrics. But compared to others, our method consistently obtains the best performance in most cases, and decreases the performance much more slowly when the mask size enlarges. This means that our method can stably and robustly infer the missing contents, especially for input images with large missing regions.

In terms of PSNR, ℓ_1 and ℓ_2 errors, the superior performance of our method over the others further proves that our framework enjoys strong capability of generating more detailed contents for better visual quality. On discontiguous missing areas, we achieve the best performance at most cases, except for small missing areas (0-40%) on CelebA-HQ and Paris Street View according to ℓ_1, where EC and PConv have a narrow lead over us in certain cases. However, we achieve the best according to ℓ_2, which means we restore the detailed information due to the correlation loss, as ℓ_2 is sensitive to outliers. That is to say, our method could well restore the missing information in pixel-level and recover the detailed information thanks to the correlation loss. Usually EC is the second best among all the methods. However, on contiguous missing areas, it achieves comparative performance as ours on Paris Street View dataset, while PConv performs even better than EC and achieves the second best on Places2 dataset. 

Besides, in terms of FID, our method obviously achieves much more significant improvement over the state-of-the-art methods like PConv, EC and PIC, which indicates that the proposed adversarial framework can pursue more semantically meaningful contents for missing regions. PLU also shows relatively good performance than other state-of-the-art approaches according to FID, due to their guidance of KL divergence, which is only inferior to ours in most cases.



 §.§ Unwanted Object Removal

Unwanted object removal is one of the most useful applications of image inpainting. Therefore, we also study the performance of our method in this task, and show several examples in Figure <ref>. Our model has the capability of removing watermark or editing images. It is obvious that the inpainting images seem very natural and harmonious, even the unwanted objects appear with complex shapes and backgrounds.



§ CONCLUSION

We propose a generic inpainting framework capable of handling the images with both contiguous and discontiguous missing areas at the same time, in an adversarial manner, where region-wise convolution layers are deployed in both generator and discriminator to locally handle the different regions, namely existing regions and missing ones, which could synthesis semantically reasonable and visually realistic inpainting results. The correlation loss is proposed to guide the generator to capture the non-local semantic relation between patches inside the image, and further provides more information to inference. We show that our proposed method is able to restore meaningful contents for missing regions and connects existing and missing regions naturally and thus significantly improves inpainting results. Furthermore, we demonstrate that our inpainting framework can edit face, clear watermarks, and remove unwanted objects in practical applications. Extensive experiments on various datasets such as faces, street views and natural scenes demonstrate that our proposed method can significantly outperform other state-of-the-art approaches in image inpainting.



§ ACKNOWLEDGMENT

This work was supported by National Natural Science Foundation of China (61690202, 61872021), Fundamental Research Funds for Central Universities (YWF-19-BJ-J-271), Beijing Municipal Science and Technology Commission (Z171100000117022), State Key Lab of Software Development Environment (SKLSDE-2018ZX-04), and Australian Research Council Projects: FL-170100117, DE-180101438, DP-180103424, and
LP-150100671.





















§ PROOF OF THE FIRST ZONKLAR EQUATION

Appendix one text goes here.





§ 

Appendix two text goes here.


  

§ ACKNOWLEDGMENTS



  



The authors would like to thank...






























IEEEtran










