简介
paper:Exploring Simple Siamese Representation Learning
code:暂未开源,可参考PatrickHua/SimSiam
Kaiming He大神的自监督学习新作。这篇论文相比于之前的SimCLR
、BLOY
,不需要negative sample pairs
、large batches
、momentum encoders
,可以说是将基于孪生网络的自监督模型简化到了极致,而这也是这篇论文想引导大家思考的,即基于孪生网络的自监督学习模型中,究竟是什么在起作用。
主要内容
如上图所示,是SimSiam
的主要结构,整个模型非常简单:
- 对图片 x x x进行随机图像增强得到 x 1 x_1 x1和 x 2 x_2 x2;
- 将
x
1
x_1
x1和
x
2
x_2
x2输入到
encoder network
f f f(encoder
f f f共线参数),其中 f f f由一个backbone
(e.g.,ResNet)和一个projection MLP head
组成. - 之后,将其中一个输出输入到一个
prediction MLP head
h h h中,最后计算两个分支的negative cosine similarity
.
用数学公式表示为:
p
1
≜
h
(
f
(
x
1
)
)
p_{1} \triangleq h\left(f\left(x_{1}\right)\right)
p1≜h(f(x1))
z
2
≜
f
(
x
2
)
z_{2} \triangleq f\left(x_{2}\right)
z2≜f(x2)
D
(
p
1
,
z
2
)
=
−
p
1
∥
p
1
∥
2
⋅
z
2
∥
z
2
∥
2
\mathcal{D}\left(p_{1}, z_{2}\right)=-\frac{p_{1}}{\left\|p_{1}\right\|_{2}} \cdot \frac{z_{2}}{\left\|z_{2}\right\|_{2}}
D(p1,z2)=−∥p1∥2p1⋅∥z2∥2z2
where ∥ ⋅ ∥ 2 \|\cdot\|_{2} ∥⋅∥2 is l 2 l_2 l2-norm.
为了防止出现collapse
的问题,这篇论文使用了stop-gradient
(论文后文重点说明这个是关键),即:
D ( p 1 , stopgrad ( z 2 ) ) \mathcal{D}\left(p_{1}, \text { stopgrad }\left(z_{2}\right)\right) D(p1, stopgrad (z2))
将 x 1 x_1 x1和 x 2 x_2 x2交换位置后可以得到另一半损失,最终的损失函数可以表示为:
L = 1 2 D ( p 1 , stopgrad ( z 2 ) ) + 1 2 D ( p 2 , stopgrad ( z 1 ) ) . \mathcal{L}=\frac{1}{2} \mathcal{D}\left(p_{1}, \text { stopgrad }\left(z_{2}\right)\right)+\frac{1}{2} \mathcal{D}\left(p_{2}, \text { stopgrad }\left(z_{1}\right)\right) . L=21D(p1, stopgrad (z2))+21D(p2, stopgrad (z1)).
Here the encoder on x 2 x_2 x2 receives no gradient from z 2 z_2 z2 in the first term, but it receives gradients from p 2 p_2 p2 in the second term (and vice versa for x 1 x_1 x1).
整个算法用伪代码表示为:
实验验证
这篇论文用了大量实验在分析避免collapse
的因素,试图寻找基于孪生网络的自监督学习模型的学习核心。
从上图可以看出,如果不使用stop-gradient
模型不work!
上面这个图说明了去除掉prediction
h
h
h模型也不work!
上面这个图说明了SimSiam
不需要大的batch size
.
论文中,作者还试图从EM模型的角度分析stop-gradient
起作用的原因,感兴趣的可以阅读原文.
实验结果
小结
自监督对比学习领域真是越来越热闹了,MocoV1
、SimCLR
、BLOY
,SwAV
,包括这篇的SimSiam
,都在挖掘基于孪生网络的自监督学习模型的潜力,我等闲人也就只能吃吃瓜了。