摘要
-
不同於
vanilla convolution
,將所有輸入的像素做為有效像素(valid pixels)
,gated convolution
,是一個基於partial convolution
的,不同的是gated convolution
為所有通道和每一個維度的位置(inside or outside masks, RGB channels or user-guidance channels
)提供了一種可學習的,動態的特征選擇機制。 -
為了穩定加速訓練,提出了
patch-based GAN loss
,即SN-PatchGAN
。SN-patchGAN
是通過應用spectral normalized discriminator on dense image patches.
Introduction
-
圖像修復別名:
Image inpainting
、image completion
、image hole-filling
。 -
圖像修復定義:在缺失區域圖像中,合成替代內容。
-
圖像修復的用途:可以用於移除分散注意力的物體或修改照片中不需要的區域。還可以擴展到圖像/視頻剪切(
un-cropping
)、旋轉、拼接、重新定位(re-targeting
)、重新組合(recompression
)、超分辨率、協調(harmonization
)和許多其它任務。 -
圖像修復分類:
- 使用低階圖像特征的塊(patch)匹配。
- 生成看似合理的平穩紋理(
stationary textures
)。 - 在處理復雜的場景,例如人臉和物體時候,常出現嚴重給的錯誤。
- 生成看似合理的平穩紋理(
- 使用卷積神經網絡的前饋生成模型。
- 從大規模數據集中學習到的語義,以端到端的方式合成非平穩圖像中的內容。
- 但是普通卷積的深度生成模型,在圖像的填充上存在嚴重的問題,因為普通卷積視所有輸入的像素和特征,均為有效像素。對於圖像填充來說,每一層的輸入是由缺失外(hole 外)的有效像素/特征和缺失區域(掩碼區域)的無效像素組成的。普通卷積使用了相同的卷積核,適用於所有有效、無效和混合(列如,那些空洞邊界)的像素/特征,在自由形狀上的掩碼做測試時,導致視覺的偽影(如顏色差異,模糊和孔周圍明顯的邊緣響應)
- 使用低階圖像特征的塊(patch)匹配。
-
為了解決這一局限性,部分卷積(
PartialConv
),其中卷積被掩蔽(masked
)和歸一化,僅以有效像素為條件。基於規則的掩碼更新策略,用於更新下一層的有效位置。部分卷積將所有位置視為無效或有效,並用0
或1
掩碼乘以所有層的輸入,該掩碼可以看做是一個單一的不可學習的特征門(gate
)通道。 -
然而,這種假設是有個幾個局限性:
- 考慮跨網絡不同層的輸入空間位置,他們可能包括:
- 輸入圖像中有有效像素
- 輸入圖像中有掩蔽像素
- 感受野的神經元沒有覆蓋到輸入圖像的有效像素
- 感受野的神經元覆蓋了不同數量的輸入圖像的有效像素(這些有效的圖像像素也可能有不同的相對位置)
- 深層合成的像素。
- 啟發式的將所有的位置歸類為無效或有效,會忽略以上這些重要信息。
- 如果我們拓展到用戶指導的圖像修復,用戶在掩碼內提供的稀疏的草圖(sparse sketch),這些像素位置應該被視為有效的還是無效的?如何正確地更新下一層的掩碼?
- 對於部分卷積,無效的像素將逐層逐漸消失,基於規則的掩碼將在深層全部消失。然而,為了合成孔內的像素,這些深層可能還需要知道當前位置是在孔內還是孔外?全
1
掩碼的部分卷積不能提供這樣的信息。
- 考慮跨網絡不同層的輸入空間位置,他們可能包括:
-
gated convolution 掩碼更新過程
:the input feature is firstly used to compute gating values \(g = σ(w_gx)\) (\(σ\) is sigmoid function, \(w_g\) is learnable parameter). The final output is a multiplication of learned feature and gating values \(y = φ(wx)⊙g\) where φ can be any activation function. -
與其他算法對比優勢:
Approach
目錄結構:1.Gated Convolution,SN-PatchGAN
,2.inpainting network
,3. our extension to allow optional user guidance
.
Gated Convolution
- 證明為什么
vanilla convolutions
不適合圖像修復任務
The equation shows that for all spatial locations (y, x), the same filters are applied to produce the output in vanilla convolutional layers.This makes sense for tasks such as image classification and object detection, where all pixels of input image are valid, to extract local features in a sliding window fashion.
However, for image inpainting, the input are composed(組成) of both regions with valid pixels/features outside holes and invalid pixels/features (in shallow layers) or synthesized pixels/features (in deep layers) in masked regions. This causes ambiguity (歧義) during training and leads to visual artifacts such as color discrepancy(差異), blurriness and obvious edge responses during testing.
- 普通卷積是將每一個像素都當成有效值去計算的,這個特性適用於分類和檢測任務,但是不適用於
inpainting
任務,因為inpainting
任務中hole
里面的像素是無效值,因此對hole
里面的內容和外面的內容要加以區分,partial conv
雖然將里面和外面的內容加以區分了,但是它將含有1個有效值像素的區域與含有9個有效值像素的區域同等對待,這明顯是不合理的,gated conv
則是使用卷積和sigmoid函數來使得網絡去學習這種區分。
partial conv
的不足之處:- Partial convolution improves the quality of inpainting on irregular mask, but it still has remaining issues:
(1) It heuristically(啟發式) classifies all spatial locations to be either valid or invalid. The mask in next layer will be set to ones no matter how many pixels are covered by the filter range in previous layer (for example, 1 valid pixel and 9 valid pixels are treated as same to update current mask).
無論像素多少,只要存在至少一個,就將mask
設置為1
。(2) It is incompatible(不兼容) with additional user inputs. We aim at a user-guided image inpainting system where users can optionally(隨意) provide sparse sketch(草圖) inside the mask as conditional channels. In this situation, should these pixel locations be considered as valid or invalid? How to properly update the mask for next layer?
(3) For partial convolution the invalid pixels will progressively disappear in deep layers, gradually converting all mask values to ones. However, our study shows that if we allow the network to learn optimal(最佳) mask automatically, the network assigns soft mask values to every spatial locations even in deep layers.
(4) All channels in each layer share the same mask, which limits the flexibility. Essentially, partial convolution can be viewed as un-learnable single-channel feature hard-gating.
- Gated Convolution
- Instead of hard-gating mask updated with rules, gated convolutions learn soft mask automatically
from data. It is formulated as: gated convolution learns a dynamic feature selection mechanism for each channel and each spatial location. Interestingly(有趣的是), visualization(可視化) of intermediate gating values(中間的gate值) show that it learns to select the feature not only according to background, mask, sketch, but also considering semantic segmentation in some channels. Even in deep layers, gated convolution learns to highlight the masked regions and sketch information in separate(單獨,分開) channels to better generate inpainting results.
- Instead of hard-gating mask updated with rules, gated convolutions learn soft mask automatically
Spectral Normalized Markovian Discriminator (SNPatchGAN)光譜歸一化馬爾可夫判別器
-
之前的修復網絡,為了修復帶有矩形缺失部分的圖片,提出了
local GAN
(局部GAN)來提升實驗的結果。 -
然而,我們要研究的是對任意形狀的缺失的情況,借鑒
global and local GANs
、MarkovianGANs
、perceptual loss
、spectral-normalized GANs
,作者提出了一個有效的GAN loss
,即為SN-PatchGAN
。 -
SN-PatchGAN
的組成,是由卷積網絡構成,輸入為image
、mask
、guidance channel
,輸出是一個形狀為h×w×c
的3維特征,h、w、c
分別代表高、寬和通道數。 -
如圖
3
,SN-PatchGAN
由6個卷積層(卷積核大小為2,步幅為2)堆疊來獲得Markovian Patches
特征的統計信息。然后直接將SN-PatchGAN
應用到特征圖的每一個特征元素,以輸入圖像的不同位置和不同語義(在不同的通道中表示)的形式表示GAN的h×w×c
個。 -
值得注意的是,在訓練的環境中,輸出圖中每個神經元的感受野可以覆蓋整個輸入圖像,因此
不需要全局判別器
。 -
作者也采用了最近提出的
Spectral normalization
來進一步穩定GANs
的訓練。我們采用SN-GANs
中描述的默認Spectral normalization
的fast approximation
算法。 -
為了判別輸入的真假,作者也采用了
hings loss
來作為目標函數,生成器:\[L_G=-E_{z-p{z(z)}}[D^{sn}(G(z))] \]判別器:
\[L_{D^{sn}}=E_{x-p{data(x)}}[RELU(1-D^{sn}(x))]+E_{z-p{z(z)}}[RELU(1+D^{sn}(G(z)))] \]其中\(D^{sn}\)表示
spectral-normalized discriminator
,\(G\)表示輸入缺失圖像\(z\)的圖像修復網絡。 -
未采用
Perceptual loss
的原因是相似的patch-level information
已經被編碼在SN-PatchGAN
中。 -
最后的目標函數:
pixel-wise ℓ1 reconstructionloss and SN-PatchGAN loss
,權重為1:1.
Inpainting Network Architecture
- 作者定制了一個帶有
Gated convolution layer
和SN-PatchGan loss
的generative inpainting network
。 - 網絡結構由粗修復和細修復兩個網絡構成,采用了
encoder-decoder network
(PartialConv采用的是類似U-net的結構)。 - 網絡為全卷積神經網絡,支持不同分辨率圖片的輸入。訓練是一個端到端的過程。
Free-Form Mask Generation
- 見論文的補充材料。
- 大致思路是:繪制一些直線和橢圓,然后通過隨機的平移和旋轉來模擬用戶塗改圖像的過程。
Extension to UserGuided Image Inpainting
- 通過草繪來做為示例指導圖像修復。具體看補充材料。
Results
- 數據集:
Places2
、CelebA-HQ faces
- 網絡參數量:
4.1M
- 輸入網絡的圖片平均大小為:
512×512
。(無論缺失部分的大小為多少)
Quantitative Results
- 評估的標准是:
mean ℓ1 error and mean ℓ2 error
。 - 評估的數據集是:
validation images of Places2
- 評估的種類:
both center rectangle mask and free-form mask
- 從圖可以看出:
- 基於學習的方法要優於基於Patch-Match的方法。
- 在相同的網絡結構中,
Partial Convolution
得到了比較糟糕的效果,這要是因為不可學習的掩碼更新規則(un-learnable rule-based gating
)。
Qualitative Comparisons
Object Removal and Creative Editing
- Object Removal
- Creative Editing
Ablation Study of SNPatchGAN
- 作者證明了
SN-PatchGAN
損失和逐像素ℓ1
損失的簡單組合,默認損失平衡超參數為1:1,產生了逼真的修復效果。
Conclusions
- We presented a novel
free-form image inpainting system
basd on anend-to-end generative network
withgated convolution
,trained withpixel-wise ℓ1 loss
andSN-PatchGAN
. - We demonstrated that gated convolutions significantly improve inpainting results with free-form masks and user guidance input. We showed user sketch as an exemplar guidance to help users quickly remove distracting objects, modify image layouts, clear watermarks, edit faces and interactively create novel objects in photos.Quantitative results, qualitative comparisons and user studies demonstrated the superiority of our proposed free-form image inpainting system.