原文地址
代码地址
从文章的标题来看, partial convolution(局部卷积)是方法核心。实际上这个思想还是很直观的:
x ′ = { W T ( X ⊙ M ) s u m ( 1 ) s u m ( M ) + b , i f s u m ( M ) > 0 0 , o t h e r w i s e x'= \left\{ \begin{array}{ll} \bold{W}^T ( \bold{X}\odot\bold{M} )\frac{sum(\bold{1})}{sum(\bold{M})} +b,& if \ sum(\bold{M}) >0\\ 0, & otherwise \\ \end{array} \right. x′={WT(X⊙M)sum(M)sum(1)+b,0,if sum(M)>0otherwise
在原来的卷积层的基础上,加入一个二进制的Mask M \bold{M} M,标准化之后作为该层的输出,通俗来讲就是“不想让你看的东西别看”。 M \bold{M} M的确定方式也是一个简单的One for all思路,如果对应的上一层的receptive field存在有效pixel,则归为1.
m ′ = { 1 i f s u m ( M ) > 0 0 , o t h e r w i s e m'= \left\{ \begin{array}{ll} 1& if \ sum(\bold{M}) >0\\ 0, & otherwise \\ \end{array} \right. m′={10,if sum(M)>0otherwise
所以,这种局部卷积的方法就是通过“蒙住”无效区域,以减少噪声,从而使该方法对不规则区域的inpainting适用。
我之前没有看过inpainting的文章,也不是数学专业,所以当看到论文的Loss Functions这一节如获至宝。
L h o l e = 1 N I g t ∣ ∣ ( 1 − M ) ⊙ ( I o u t − I g t ) ∣ ∣ 1 \mathcal{L}_{hole} = \frac{1}{N_{\bold{I}_{gt}}}||(\bold{1}-\bold{M})\odot(\bold{I}_{out}-\bold{I}_{gt})||_1 Lhole=NIgt1∣∣(1−M)⊙(Iout−Igt)∣∣1
L v a l i d = 1 N I g t ∣ ∣ ( M ) ⊙ ( I o u t − I g t ) ∣ ∣ 1 \mathcal{L}_{valid} = \frac{1}{N_{\bold{I}_{gt}}}||(\bold{M})\odot(\bold{I}_{out}-\bold{I}_{gt})||_1 Lvalid=NIgt1∣∣(M)⊙(Iout−Igt)∣∣1
累死打完这两个公式才发现,这TM就不是输入和gt差的一范数?写两个式子?
感知损失,这名字顿时高大上,公式下标累死人
L p c p t = ∑ p = 0 P − 1 ∣ ∣ Ψ p I o u t − Ψ p I g t ∣ ∣ 1 N Ψ p I g t + ∑ p = 0 P − 1 ∣ ∣ Ψ p I c o m p − Ψ p I g t ∣ ∣ 1 N Ψ p I g t \mathcal{L}_{pcpt} =\sum_{p=0}^{P-1} \frac{||\bold{\Psi}_{p}^{\bold{I}_{out}}-\bold{\Psi}_{p}^{\bold{I}_{gt}}||_1}{N_{\bold{\Psi}_{p}^{\bold{I}_{gt}}}} + \sum_{p=0}^{P-1} \frac{||\bold{\Psi}_{p}^{\bold{I}_{comp}}-\bold{\Psi}_{p}^{\bold{I}_{gt}}||_1}{N_{\bold{\Psi}_{p}^{\bold{I}_{gt}}}} Lpcpt=p=0∑P−1NΨpIgt∣∣ΨpIout−ΨpIgt∣∣1+p=0∑P−1NΨpIgt∣∣ΨpIcomp−ΨpIgt∣∣1
Ψ p I ∗ ∗ \bold{\Psi}_{p}^{\bold{I}_{**}} ΨpI∗∗是输入为 I ∗ ∗ \bold{I}_{**} I∗∗下,被选取出的第p层的activation map。本文中选取的activation map是3个池化层的输出。
I c o m p \bold{I}_{comp} Icomp是洞的网络输出+非洞的GT, I o u t \bold{I}_{out} Iout是纯输出
feature map的意思在计算机视觉领域基本一致,可以草率的翻译成特征图。
activation map是对feature map 的进一步处理
from fuqiang liu知乎回答链接
这一个loss是网络中间层级别上的map对比,分了两个部分计算,一个是纯输出,一个是输出拼接,貌似这样算可以优化一下洞边缘信息?总之有好处就对了。
L s t y l e o u t = ∑ p = 0 P − 1 1 C p C p ∣ ∣ K p ( ( Ψ p I o u t ) T ( Ψ p I o u t ) − ( Ψ p I g t ) T ( Ψ p I g t ) ) ∣ ∣ 1 \mathcal{L}_{style_{out}} =\sum_{p=0}^{P-1} \frac{1}{C_pC_p}||K_p((\bold{\Psi}_{p}^{\bold{I}_{out}})^T(\bold{\Psi}_{p}^{\bold{I}_{out}})-(\bold{\Psi}_{p}^{\bold{I}_{gt}})^T(\bold{\Psi}_{p}^{\bold{I}_{gt}}))||_1 Lstyleout=p=0∑P−1CpCp1∣∣Kp((ΨpIout)T(ΨpIout)−(ΨpIgt)T(ΨpIgt))∣∣1
L s t y l e c o m p = ∑ p = 0 P − 1 1 C p C p ∣ ∣ K p ( ( Ψ p I c o m p ) T ( Ψ p I c o m p ) − ( Ψ p I g t ) T ( Ψ p I g t ) ) ∣ ∣ 1 \mathcal{L}_{style_{comp}} =\sum_{p=0}^{P-1} \frac{1}{C_pC_p}||K_p((\bold{\Psi}_{p}^{\bold{I}_{comp}})^T(\bold{\Psi}_{p}^{\bold{I}_{comp}})-(\bold{\Psi}_{p}^{\bold{I}_{gt}})^T(\bold{\Psi}_{p}^{\bold{I}_{gt}}))||_1 Lstylecomp=p=0∑P−1CpCp1∣∣Kp((ΨpIcomp)T(ΨpIcomp)−(ΨpIgt)T(ΨpIgt))∣∣1
C p C_p Cp是通道数,这里用到了Gram矩阵算自相关,这个灵感来自于风格迁移,所以被称为style loss。
gram矩阵可以看做feature之间的偏心协方差矩阵(即没有减去均值的协方差矩阵),Gram计算的实际上是两两特征之间的相关性,哪两个特征是同时出现的,哪两个是此消彼长的等等,同时,Gram的对角线元素,还体现了每个特征在图像中出现的量
来自于GRAM矩阵
L t v = ∑ ( i , j ) ∈ R , ( i , j + 1 ) ∈ R ∣ ∣ I c o m p i , j + 1 − I c o m p i , j ∣ ∣ 1 N I c o m p + ∑ ( i , j ) ∈ R , ( i + 1 , j ) ∈ R ∣ ∣ I c o m p i + 1 , j − I c o m p i , j ∣ ∣ 1 N I c o m p \mathcal{L}_{tv}=\sum_{(i,j)\in R, (i,j+1)\in R}\frac{||\bold{I}_{comp}^{i,j+1}-\bold{I}_{comp}^{i,j}||_1}{N_{\bold{I}_{comp}}} +\sum_{(i,j)\in R, (i+1,j)\in R}\frac{||\bold{I}_{comp}^{i+1,j}-\bold{I}_{comp}^{i,j}||_1}{N_{\bold{I}_{comp}}} Ltv=(i,j)∈R,(i,j+1)∈R∑NIcomp∣∣Icompi,j+1−Icompi,j∣∣1+(i,j)∈R,(i+1,j)∈R∑NIcomp∣∣Icompi+1,j−Icompi,j∣∣1
R R R是洞的一个像素的膨胀区域。
用的是一个简单的x,y方向的平滑度惩罚,为什么这位亲不能写一个简单的卷积核公式,要写得如此费劲。
总之,这五个loss最后通过线性组合加到一块
L t o t a l = [ 1 6 0.05 120 120 0.1 ] [ L v a l i d L h o l e L p c p t L s t y l e o u t L s t y l e i n L t v ] T \mathcal{L}_{total}=[1 \quad6\quad0.05\quad120\quad120\quad0.1][\mathcal{L}_{valid}\quad\mathcal{L}_{hole}\quad\mathcal{L}_{pcpt}\quad\mathcal{L}_{style_{out}} \quad\mathcal{L}_{style_{in}} \quad\mathcal{L}_{tv}]^T Ltotal=[160.051201200.1][LvalidLholeLpcptLstyleoutLstyleinLtv]T
先写到这,挖个源码解读的坑。