DualRC-Net(2020 NIPS)特征点检测与匹配论文笔记

论文地址
代码地址

test 计算流程

1. 总流程概述

(1) I a , I b ⟶ R e s n e t + F P N ⟶ { f a 4 , f b 4 ( b , 1024 , h 4 , w 4 ) f a 16 , f b 16 ( b , 1024 , h 16 , w 16 ) I_a,I_b \longrightarrow \mathrm{Resnet+FPN} \longrightarrow \begin{cases} f_{a4},f_{b4}&(b,1024,h_{4},w_{4})\\ f_{a16},f_{b16}&(b,1024,h_{16},w_{16}) \end{cases} Ia,IbResnet+FPN{ fa4,fb4fa16,fb16(b,1024,h4,w4)(b,1024,h16,w16)

(2) f a 16 , f b 16 ⟶ N C N e t 匹 配 ⟶ c o r r 4 d : ( b , 1 , h a 16 , w a 16 , h b 16 , w b 16 ) f_{a16},f_{b16} \longrightarrow \mathrm{NCNet匹配} \longrightarrow \mathrm{corr4d}:(b,1,h_{a16},w_{a16},h_{b16},w_{b16}) fa16,fb16NCNetcorr4d:(b,1,ha16,wa16,hb16,wb16)

(3) c o r r 4 d ⟶ 挑 出 I a 上 匹 配 的 较 好 的 一 批 点 ⟶ P a 1 : ( b , h a 16 ∗ w a 16 / 2 ∗ 4 ∗ 4 , 2 ) \mathrm{corr4d} \longrightarrow 挑出I_a上匹配的较好的一批点 \longrightarrow P_{a1}:(b,h_{a16}*w_{a16}/2*4*4,2) corr4dIaPa1:(b,ha16wa16/244,2)

(4.1) c o r r 4 d + P a 1 + f a 4 , f b 4 ⟶ D u a l R C N e t 匹 配 ⟶ P b 1 , S 1 \mathrm{corr4d}+P_{a1}+f_{a4},f_{b4} \longrightarrow \mathrm{DualRCNet匹配} \longrightarrow P_{b1},S_1 corr4d+Pa1+fa4,fb4DualRCNetPb1,S1

(4.2) c o r r 4 d + P b 1 + f a 4 , f b 4 ⟶ D u a l R C N e t 匹 配 ⟶ P a 2 , S 2 \mathrm{corr4d}+P_{b1}+f_{a4},f_{b4} \longrightarrow \mathrm{DualRCNet匹配} \longrightarrow P_{a2},S_2 corr4d+Pb1+fa4,fb4DualRCNetPa2,S2

(5) M a t c h 1 ( P a 1 , P b 1 , S 1 ) + M a t c h 2 ( P a 2 , P b 1 , S 2 ) ⟶ 最 终 匹 配 结 果 \mathrm{Match_1}(P_{a1},P_{b1},S_1)+\mathrm{Match_2}(P_{a2},P_{b1},S_2) \longrightarrow 最终匹配结果 Match1(Pa1,Pb1,S1)+Match2(Pa2,Pb1,S2)

2. 步骤细节

(1)Resnet-101 + FPN 提取特征图
在这里插入图片描述

  输入一对图像 I a , I b : ( 3 , h a , w a ) , ( 3 , h b , w b ) I_a,I_b:(3,h_a,w_a),(3,h_b,w_b) Ia,Ib:(3,ha,wa),(3,hb,wb),上图中标红的 f 3 , f 123 f_3,f_{123} f3,f123 经过 L2Norm 后用于后续步骤,记作 f a 16 , f b 16 , f a 4 , f b 4 f_{a16},f_{b16},f_{a4},f_{b4} fa16,fb16,fa4,fb4,下标代表下采样的倍率。

(2)NC-Net 计算特征匹配
  计算流程和 NC-Net 一样,输入特征 f a 16 , f b 16 f_{a16},f_{b16} fa16,fb16,做点积运算得到初始匹配结果 c o r r 4 d : ( b , 1 , h a 16 , w a 16 , h b 16 , w b 16 ) \mathrm{corr4d}:(b,1,h_{a16},w_{a16},h_{b16},w_{b16}) corr4d:(b,1,ha16,wa16,hb16,wb16),后面就是经过 soft mutual nearest neighbour filtering + neighbourhood consensus network + soft mutual nearest neighbour filtering 得到最终的匹配结果。
  具体细节可以看 NC-Net 博客,代码是完全一样的。

'''特征匹配计算流程'''
corr4d = self.FeatureCorrelation(feature_A2, feature_B2)
corr4d = MutualMatching(corr4d)
corr4d = self.NeighConsensus(corr4d)
corr4d = MutualMatching(corr4d)	

'''点积运算'''
b, c, hA, wA = feature_A.size()
b, c, hB, wB = feature_B.size()
feature_A = feature_A.view(b, c, hA * wA).transpose(1, 2)
feature_B = feature_B.view(b, c, hB * wB)
feature_mul = torch.bmm(feature_A, feature_B)  # [b, hA * wA, hB * wB]
correlation_tensor = feature_mul.view(b, hA, wA, hB, wB).unsqueeze(1)

(3)挑点
  输入匹配得分 c o r r 4 d : ( b , 1 , h a 16 , w a 16 , h b 16 , w b 16 ) \mathrm{corr4d}:(b,1,h_{a16},w_{a16},h_{b16},w_{b16}) corr4d:(b,1,ha16,wa16,hb16,wb16),计算 f a 16 f_{a16} fa16 每个特征的最高匹配得分 ( b , 1 , h a 16 , w a 16 ) (b,1,h_{a16},w_{a16}) (b,1,ha16,wa16),对其进行排序选出得分较高的一半特征坐标 ( b , h a 16 ∗ w a 16 / 2 , 2 ) (b,h_{a16}*w_{a16}/2,2) (b,ha16wa16/2,2),将这些坐标扩充到 f 4 f_{4} f4 的特征图上,也就是每个坐标扩充为 4 × 4 4\times4 4×4 个坐标,得到 I a I_a Ia 上的一些坐标 P a 1 : ( b , h a 16 ∗ w a 16 / 2 ∗ 4 ∗ 4 , 2 ) P_{a1}:(b,h_{a16}*w_{a16}/2*4*4,2) Pa1:(b,ha16wa16/244,2)

(4)DualRC-Net 匹配
  令 n = h a 16 ∗ w a 16 / 2 ∗ 4 ∗ 4 n=h_{a16}*w_{a16}/2*4*4 n=ha16wa16/244,取出这些坐标的匹配结果 ( b , n , h b 16 ∗ w b 16 ) (b,n,h_{b16}*w_{b16}) (b,n,hb16wb16),同时除以对 d i m = 2 dim=2 dim=2 的求和作为标准化,也就是将占比作为匹配得分 S 16 : ( b , n , h b 16 , w b 16 ) S_{16}:(b,n,h_{b16},w_{b16}) S16:(b,n,hb16,wb16)
  取出 P a 1 P_{a1} Pa1 坐标对应的 f a 4 f_{a4} fa4 上的特征与 f b 4 f_{b4} fb4 所有特征做点积运算,得到匹配得分 S 4 : ( b , n , h b 4 , w b 4 ) S_4:(b,n,h_{b4},w_{b4}) S4:(b,n,hb4,wb4)
  将 S 16 S_{16} S16 插值到和 S 4 S_{4} S4 相同的分辨率,并与之相乘,得到匹配得分,取得分最高的为匹配点,得到 P b 1 : ( b , n , 2 ) P_{b1}:(b,n,2) Pb1:(b,n,2) S 1 : ( b , n , 1 ) S_1:(b,n,1) S1:(b,n,1)
  此时得到第一组匹配结果 P a 1 , P b 1 , S 1 P_{a1},P_{b1},S_1 Pa1,Pb1,S1,也就是 P a 1 P_{a1} Pa1 的最佳匹配结果。将 P b 1 P_{b1} Pb1 按照上面的流程再来一遍得到第二组匹配结果 P a 2 , P b 1 , S 2 P_{a2},P_{b1},S_2 Pa2,Pb1,S2,也就是 P b 1 P_{b1} Pb1 的最佳匹配结果。

(5)融合两组匹配结果
  把两组结果中重复的匹配对挑出来,两组的得分相加作为最终的匹配得分,取得分前 k = 2000 k=2000 k=2000 对匹配作为最终的匹配结果。

train 计算流程

1. 数据

'index':item,
'source_image': image1,
'target_image': image2,
'source_points': source_points,
'target_points': target_points,
'assignment': assignment

'''
source_points, target_points: 两幅图像的稀疏点对 [n,3], 3 对应(x,y,1)
assignment: torch.eye(n)
'''

  这里看了下数据,每一对图像都是给了128对匹配点。

2. loss

  基本和 test 的计算流程差不多,只是初始的 P a 1 P_{a1} Pa1 P b 1 P_{b1} Pb1 换成了训练数据中提供的 source_points 和 target_points,loss 的基本原理就是用网络输出的得分和根据 ground truth 生成的 one-hot 得分计算 MSE。
  由于整个 loss 都是用的别的论文中现成的,所以描述比较少。公式还算比较清晰,loss 分为两个部分:
L = L k + λ L o \mathcal{L}=\mathcal{L}_{k}+\lambda \mathcal{L}_{o} L=Lk+λLo

L k = ∥ M A B − M g t A B ∥ F + ∥ M B A − M g t B A ∥ F \mathcal{L}_{k}=\left\|\mathbf{M}^{A B}-\mathbf{M}_{g t}^{A B}\right\|_{F}+\left\|\mathbf{M}^{B A}-\mathbf{M}_{g t}^{B A}\right\|_{F} Lk=MABMgtABF+MBAMgtBAF

  第一项是主要部分, M A B ∈ R N × T \mathbf{M}^{A B} \in \mathbb{R}^{N \times T} MABRN×T T = H b × W b T=H_{b} \times W_{b} T=Hb×Wb,其实就是 P a 1 P_{a1} Pa1 f b 4 f_{b4} fb4 所有的匹配得分,ground truth 可以生成一个 one-hot 形式的匹配得分,从而类似分类问题计算 loss。

L o = ∥ M A B M A B ⊤ − M g t A B M g t A B ⊤ ∥ F + ∥ M B A M B A ⊤ − M g t B A M g t B A ⊤ ∥ F \mathcal{L}_{o}=\left\|\mathbf{M}^{A B} \mathbf{M}^{A B^{\top}}-\mathbf{M}_{g t}^{A B} \mathbf{M}_{g t}^{A B^{\top}}\right\|_{F}+\left\|\mathbf{M}^{B A} \mathbf{M}^{B A^{\top}}-\mathbf{M}_{g t}^{B A} \mathbf{M}_{g t}^{B A^{\top}}\right\|_{F} Lo=MABMABMgtABMgtABF+MBAMBAMgtBAMgtBAF

  第二项是一个正则化项,用来将匹配限制为一对一的。从公式分析,与自身转置相乘,ground truth 正常是一对一的,那么只有主对角线为1,其余位置都是0;输出的得分比较分散的话非主对角线位置会产生数值使 loss 增大,而得分经过 norm 操作主对角线应该是可以不产生 loss 的,所以这一项可以让得分集中,趋向于产生一对一的匹配结果。

  这里的 one-hot 向量会在常规的基础上做一个高斯滤波,代码中选用的 [ 1 / 16 1 / 8 1 / 16 1 / 8 1 / 4 1 / 8 1 / 16 1 / 8 1 / 16 ] \begin{bmatrix} 1/16& 1/8& 1/16\\ 1/8& 1/4&1/8 \\ 1/16& 1/8& 1/16 \end{bmatrix} 1/161/81/161/81/41/81/161/81/16

猜你喜欢

转载自blog.csdn.net/weixin_43605641/article/details/123005360