A Simple Framework for Contrastive Learning of Visual Representations (ICML2020)

Balin
5 min readAug 27, 2021

Introduction

Contrastive Learning 這種訓練方式往往會用 data augmentation 伴隨一些新的 loss (像是 feature representation 的部分),所以怎樣的 data augmentation 對其來說很重要。

更精確地來說就是在一群資料中(可以是 batch)中給定一個 x,透過 x 產生一個或一群正樣本 x` (x 的不同 augmentation),然後把剩下的圖像 y (可能包含其他 augmentation 例如 y`)當負樣本計算 loss,拉近 x 和 x` 之間的距離,推開 x 和 y 之間的距離。

  1. Data augmentation 在訓練上是非常重要的,且 unsupervised contrastive learning 相較於 supervised learning 更有感。
  2. 在 learned representation 和 contrastive loss 之間學習 nonlinear transformation
  3. contrastive learning 相較於 supervised learning 需要比較大的 batch sizes 和 training steps,且兩者都可以透過比較深和廣的網路提升效能,但 contrastive learning 的效果更為明顯。

Method

  • x 做不同的兩個 augmentation,分別透過 f() encode、 g() 的 output 算 loss。

we use random crop and resize (with random flip), color distortions, and Gaussian blur

  • 可以說上述 g() 產生出來的 z 只是用來透過 Maximize agreement 計算 contrastive loss 而已, encode 完到下游任務的 representation 會使用 f() 出來的結果也就是 h,主要原因是他們透過實驗結果證實 h 做下游任務還是有比較好的效果,且 g() 是訓練在不同 augmentation 的情況下,容易忽略掉方向或顏色這些資訊。
  • g() 是如下公式的一個 MLP,z 可以比 h 有效的定義 contrastive loss。
  • 以下是示意圖,使狗和狗、椅子和椅子的分布更近,狗和椅子的分布更遠,實作上在每個 minibatch 會產生兩倍的資料,只產生 positive examples,而個 minibatch 的 2(N-1) 筆資料就可以順便當成 negative examples,因此 batch size 需要有一定的大小。
  • 下方的公式表示 l_2 normalized 過後的 u 和 v (cosine similarity)。
  • 詳細 positive example 的 loss 如下,i 和 j 表示 positive pair,τ 表示 temperature parameter,是一個可以調的參數。
  • 詳細的演算法計算流程如下。

Data Augmentation

  • 下圖表格是針對他們的方法,且只套用在一個 augmentation 的 branch 上面 (Method 那邊有提到他們有兩個分支),最後對不同 augmentation 方式的準確度進行評比,其實沒有任何一個的效果是很好的,但有一個很重要的論點就是因為如果單純 crop 的話可能對模型來說只需要找到相似的顏色區塊就可以並沒有辦法很好的學習到特徵,因此需要搭配 color 才有辦法學到比較 generalizable 的 features。

Experiment

  • 論文還有他的附錄裡有非常多實驗結果,有興趣可以自己去看。
  • Semi-Supervised 的結果
  • transfer-learning 的結果

Reference

[arxiv]

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response