目的:what to transfer,以及如何有效避免negative transfer上。
假设:所有的域之间有着公有的特征(Shared)和私有的特征(Private),如果将各个域的私有特征也进行迁移的话就会造成负迁移(negative transfer)。
基于此,提出了Domain Separation Networks(DSNs)。
Domain Separation Networks (DSNs)
网络结构包含:
- Shared Encoder E c ( x ) E_{c}(x) Ec(x): 提取共有特征,使得不同域之间迁移。
- Private Source Encoder E p s ( x s ) E_{p}^{s}(x^{s}) Eps(xs) : 源域私有编码器, 用于提取源域数据私有特征。
- Private Target Encoder E p t ( x t ) E_{p}^{t}(x^{t}) Ept(xt): 目标域私有编码器,用来提取目标域的私有特征。
- Shared Decoder: 共享的解码器,输入时私有特征和共有特征,用于重构图像。
- 源域分类器 G ( E c ( x s ) ) G\left(E_{c}\left(x^{s}\right)\right) G(Ec(xs)): 源域数据的分类器,输入是公有特征。训练完成之后,可以用来对目标域数据上分类。
其中, x s , x t x^s, x^t xs,xt分别表示源域和目标域输入,通过公有和私有编码器之后,分别输出 h p s , h c s h_p^s, h_c^s hps,hcs、 对应源域私有特征和共有特征, h p t , h c t h_p^t, h_c^t hpt,hct,对应目标域特征。
Loss
difference loss
为什么 E p t ( x ) , E p s ( x ) E_p^t(x), E_p^s(x) Ept(x),Eps(x)就能输出私有特征呢?
作者损失函数层面进行了限制,定义差异损失:
L
difference
=
∥
H
c
s
⊤
H
p
s
∥
F
2
+
∥
H
c
t
⊤
H
p
t
∥
F
2
\mathcal{L}_{\text {difference }}=\left\|\mathbf{H}_{c}^{s \top} \mathbf{H}_{p}^{s}\right\|_{F}^{2}+\left\|\mathbf{H}_{c}^{t^{\top}} \mathbf{H}_{p}^{t}\right\|_{F}^{2}
Ldifference =∥∥Hcs⊤Hps∥∥F2+∥∥∥Hct⊤Hpt∥∥∥F2
∥
⋅
∥
F
2
\|\cdot\|_{F}^{2}
∥⋅∥F2表示矩阵范式,而中间是
H
c
s
⊤
H
p
s
\mathbf{H}_{c}^{\mathbf{s} \top} \mathbf{H}_{p}^{s}
Hcs⊤Hps,只有两个矩阵正交,范式才为0,所以这个损失鼓励私有特征和共有特征不相似,正交的时候最小。
Similarity loss
为什么 E c ( x ) E_c(x) Ec(x)就能输出共有特征?
为了保证源域和目标域是可迁移的,就要保证 h c t , h c s h_c^t, h_c^s hct,hcs的分布相似性。
注意是 h c t , h c s h_c^t, h_c^s hct,hcs的分布相似性,非向量相似性,因为本来就是不同输入,不能适得其输出相似。
作者用到了Gradient Reversal Layer (GRL):
简单讲就是找到一个函数Q(f(u)),使得梯度取反:
d
d
u
Q
(
f
(
u
)
)
=
−
d
d
u
f
(
u
)
\frac{d}{d \mathbf{u}} Q(f(\mathbf{u}))=-\frac{d}{d \mathbf{u}} f(\mathbf{u})
dudQ(f(u))=−dudf(u)
损失函数:
L
similarity
D
A
N
N
=
∑
i
=
0
N
s
+
N
t
{
d
i
log
d
^
i
+
(
1
−
d
i
)
log
(
1
−
d
^
i
)
}
\mathcal{L}_{\text {similarity }}^{\mathrm{DANN}}=\sum_{i=0}^{N_{s}+N_{t}}\left\{d_{i} \log \hat{d}_{i}+\left(1-d_{i}\right) \log \left(1-\hat{d}_{i}\right)\right\}
Lsimilarity DANN=i=0∑Ns+Nt{dilogd^i+(1−di)log(1−d^i)}
使用了对抗学习的思想,通过一个域分类器
Z
(
Q
(
h
c
)
;
θ
z
)
,
h
c
=
E
c
(
x
;
θ
c
)
Z\left(Q\left(\mathbf{h}_{c}\right) ; \boldsymbol{\theta}_{z}\right), \mathbf{h}_{c}=E_{c}\left(\mathbf{x} ; \boldsymbol{\theta}_{c}\right)
Z(Q(hc);θz),hc=Ec(x;θc),来区分
h
c
t
,
h
c
s
h_c^t, h_c^s
hct,hcs是属于源域还是目标域。对于分类器的参数
θ
z
\theta_z
θz通过梯度求导来最小化分类损失,让分类器分的更准。而通过加入Q,来使用GRL,使得在优化
θ
c
\theta_c
θc的时候让分类器无法分辨输入属于source还是target。
Reconstruction loss
怎么保证 h p s , h p t , h c s , h c t h_{p}^{s}, h_{p}^{t}, h_{c}^{s},h_{c}^{t} hps,hpt,hcs,hct都是有意义的呢?例如 h p s = 0 , h p t = 0 , h c s = h c t = 1 h_{p}^{s}=0, \quad h_{p}^{t}=0, \quad h_{c}^{s}=h_{c}^{t}=1 hps=0,hpt=0,hcs=hct=1的时候,上述损失就可以达到0.
所以作者引入了重构损失。
L
recon
=
∑
i
=
1
N
s
L
si
−
mse
(
x
i
s
,
x
^
i
s
)
+
∑
i
=
1
N
t
L
s
i
−
mse
(
x
i
t
,
x
^
i
t
)
L
s
i
−
m
s
e
(
x
,
x
^
)
=
1
k
∥
x
−
x
^
∥
2
2
−
1
k
2
(
[
x
−
x
^
]
⋅
1
k
)
2
(3)
\mathcal{L}_{\text {recon }}=\sum_{i=1}^{N_{s}} \mathcal{L}_{\text {si }_{-} \text {mse }}\left(\mathrm{x}_{i}^{s}, \hat{\mathrm{x}}_{i}^{s}\right)+\sum_{i=1}^{N_{t}} \mathcal{L}_{\mathrm{si}_{-} \text {mse }}\left(\mathrm{x}_{i}^{t}, \hat{\mathrm{x}}_{i}^{t}\right) \tag{3} \\ \mathcal{L}_{\mathrm{si}_{-} \mathrm{mse}}(\mathrm{x}, \hat{\mathrm{x}})=\frac{1}{k}\|\mathrm{x}-\hat{\mathrm{x}}\|_{2}^{2}-\frac{1}{k^{2}}\left([\mathrm{x}-\hat{\mathrm{x}}] \cdot 1_{k}\right)^{2}
Lrecon =i=1∑NsLsi −mse (xis,x^is)+i=1∑NtLsi−mse (xit,x^it)Lsi−mse(x,x^)=k1∥x−x^∥22−k21([x−x^]⋅1k)2(3)
其中k为输入x的像素个数,1k为长度为k的向量;
∥
⋅
∥
2
2
\|\cdot\|_{2}^{2}
∥⋅∥22是向量的平方模。
虽然均值平方误差损失传统上用于重建任务,但它会惩罚在缩放项下正确的预测。相反,尺度不变的均方误差抵消了像素对之间的差异。这允许模型学习复制被建模对象的整体形状,而不需要在输入的绝对颜色或强度上花费建模能力。
在实验中,作者用传统的均方误差损失代替式3中的尺度不变损失,验证了这种重构损失确实是正确的选择。
task loss
最后是分类器
G
(
E
c
(
x
s
)
)
G\left(E_{c}\left(x^{s}\right)\right)
G(Ec(xs))的分类损失:
L
t
a
s
k
=
−
∑
i
=
0
N
s
y
i
s
⋅
log
y
^
i
s
\mathcal{L}_{\mathrm{task}}=-\sum_{i=0}^{N_{s}} \mathbf{y}_{i}^{s} \cdot \log \hat{\mathbf{y}}_{i}^{s}
Ltask=−i=0∑Nsyis⋅logy^is
注意分类器的输入是共有特征,因此保证对于目标域,能够直接迁移过来,使用此分类器做分类任务。
Expriment
作者提供四组迁移的实验,五个数据集。Source-only表示没有进行迁移,只用源域数据进行训练得到的模型的精度;Target-only表示没有迁移,只有带标记的目标域数据进行训练得到的模型的精度;中间五行表示当目标域数据无标记,进行迁移之后各个模型的精度。
可以看出,DSNs算法还是有明显的提高。
Reference
- Domain Separation Networks.
- Domain-adversarial training of neural networks.