Training Vision Transformers for Image Retrieval

Inc Lomin's avatar
Oct 29, 2021
Training Vision Transformers for Image Retrieval
 

Introduction

 
notion image
  • 근래 NLP 분야에서 성공적으로 사용된 transformer 구조가 computer vision 영역에 도입되고 있으며, 이는 convolution 구조와는 다른 세트의 inductive biases를 제공하기 때문에 흥미로운 발전입니다.
  • 기존 image를 대상으로 attention-based metric learning을 시도한 사례가 있지만, plain transformer를 기반으로 연구된 바가 없습니다.
  • 본 연구에서는 Image Retrieval Transformer (IRT)를 제안합니다.
    • 그림 1에서 볼 수 있듯이, IRT 모델은 transformer 백본이 있는 Siamese architecture를 사용합니다.
 
  • 본 연구에서는 Image Retrieval Transformers(IRT)를 소개하고 연구합니다. 그림 1에서 볼 수 있듯이 IRT 모델은 transformer 백본이 있는 Siamese architecture를 사용합니다.
  • metric learning techniques의 적용을 조사하고 transformer와 상호 작용하는 방법을 평가합니다.
  • 특히, 본 논문에서는 contrastive loss를 채택했는데, 이는 최근 매우 효과적인 metric learning objective로 재확인되었습니다.
  • 또한 표현 공간에 대한 균일성을 선호하고 성능을 향상시키는 differential entropy regularization를 사용합니다.
 
본 논문에서의 main contributions는 다음과 같습니다.
  • category-based level 및 particular object 검색 모두를 위해 vision transformer를 훈련하는 간단한 방법을 제안하고 유사한 capacity의 컨볼루션 모델과 비교할 때 경쟁력 있는 성능을 달성합니다.
  • 결과적으로 3가지 인기있는 category-level retrieval 벤치마크에서 SOTA를 달성합니다.
  • particular object 검색의 경우, shortvector representation(128 components)에서 ROxford 및 RParis에 대한 결과는 훨씬 더 높은 해상도 및 FLOPS에서 작동하는 convnet의 결과와 비슷합니다.
  • differential entropy regularizer가 contrastive loss를 향상시키고 전반적인 성능을 높이는 것을 보입니다.
 
 

Proposed Method

 
  • Previous works에서는 category-level retrieval과 particular object retrieval이 별개의 기술로 해결되었습니다.
  • 본 논문에서는 두 가지 문제에 대해 동일한 접근 방식을 사용합니다.
  • 다음과 같이 다양한 구성 요소를 점진적으로 도입합니다.
    • : ImageNet을 대상으로 pre-trained된 ViT backbone에서의 feature extraction
    • : contrastive loss로의 metric learning으로 transformer를 fine-tining
    • : uniformity를 향상시키기 위해 output feature를 regularizing
 

Preliminaries: Vision Transformer

transformer-based models의 main building blocks, 보다 구체적으로 Dosovitskiy에 의해 최근에 제안된 ViT 아키텍처를 사용합니다.
  • An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale (https://arxiv.org/abs/2010.11929)
    • 입력 이미지는 먼저 M개의 고정 크기 패치(예: 16×16)로 분해됩니다.
    • 각 패치는 M개의 벡터 모양 토큰에 linearly projected되고 permutation-invariant 방식으로 transformer에 대한 입력으로 사용됩니다.
    • 이전 위치는 학습 가능한 1D positional encoding vector를 입력 토큰에 추가하여 통합됩니다.
    • 추가 학습 가능한 CLS 토큰이 입력 시퀀스에 추가되어 해당 출력 토큰이 global image representation으로 사용됩니다.
 
notion image
 

: off-the-shelf features with Transformers

  • 먼저 ImageNet pre-trained transformer으로 feature를 직접 추출하는 naive한 접근 방식인 를 수행합니다.
  • Pooling
    • ViT 아키텍처에서 pre-classification layers은 M 입력 패치 및 클래스(CLS) 임베딩에 해당하는 M + 1 벡터를 출력합니다.
    • BERT 및 ViT 모델에서 착안하여 referent pooling approach인 클래스(CLS) 임베딩을 global image descriptor로 간주합니다.
    • 또한 convolutional metric learning models에서 일반적으로 사용하는 average, maximum 및 Generalized Mean(GeM)과 같은 global pooling을 M개의 출력 토큰에 적용하고 CLS pooling과 비교 분석 합니다.
  • l2-Normalization and Dimensionality Reduction
    • pooling 이후, discriptor vector를 unit ball에 projecting하는 common practice을 따릅니다.
    • target dimensionality가 architecture에서 제공하는 것보다 작은 경우, normalizing하기 전에 Principal Component Analysis (PCA)을 통해 벡터를 선택적으로 줄입니다.
 

: Learning the Metric for Image Retrieval

  • 이제 이미지 검색을 위한 metric learning approach을 고려합니다. 이는 category-level 및 particular object 검색 모두가 가능한 접근 방식입니다. 본 논문은 "the contrastive loss with cross-batch memory by Wang et al. (2020)"의 접근 방식을 채택하고, margin β = 0.5를 default로 수정합니다.
  • contrastive loss는 동일한 레이블 y (또는 다른 사전 정의된 similarity rule)를 가진 샘플의 인코딩된 low-dimensional representations() 간의 유사성을 최대화합니다. 동시에 negatives라고 하는 일치하지 않는 레이블이 있는 샘플 representations 간의 유사성을 최소화합니다. contrastive loss의 경우 유사도가 constant margin β보다 큰 negative pairs에만 손실에 기여합니다. 이것은 training signal이 쉽게 negatives로 압도되는 것을 방지합니다.
    • notion image
      표현은 l2-normalized 상태를 가정하므로 inner product은 Cosine similarity와 동일합니다.
 

: Differential Entropy Regularization

  • 최근 learned representations Z = {}와 해당 정답 레이블 Y = {} 간의 mutual information을 maximization하는 연구가 진행되었습니다.
notion image
 
  • contrastive loss의 positive term은 조건부 미분 엔트로피 H(Z|Y)의 최소화로 이어집니다. 여기서 직관적으로 동일한 category에 속하는 samples representations이 더 유사하도록 훈련됩니다.
    • notion image
 
  • 다른 한편으로, 이 손실의 negative term은 모든 샘플 표현이 단일 지점으로 축소되는 사소한 solution을 방지하는 역할을 합니다. 따라서 학습된 표현의 엔트로피를 최대화합니다.
    • notion image
 
  • margin β는 training dynamics에서 중요한 역할을 합니다. β 값이 낮으면 더 많은 negative samples을 탐색할 수 있습니다. 그러나 이 경우 easy negatives가 훈련을 지배하고 성능이 정체될 수 있습니다. 대조적으로, β의 더 높은 값은 하드 네거티브(hard negatives)만을 수용할 것이고, 아마도 noisy gradients와 unstable training으로 이어질 수 있습니다.
 
  • Our regularizer
    • Equation 4에서 negative contrastive term의 엔트로피 최대화 관점에서 착안하여, margin에 의해 허용되는 negative samples와 독립적인 entropy maximization term을 추가합니다. 이는 Kozachenko & Leonenko(1987) 미분 엔트로피 추정기를 기반으로 한 "the differential entropy loss proposed by Sablayrolles et al. (2019)"을 사용합니다.
      • notion image
        notion image
      • 즉, 이 정규화는 모든 점과 가장 가까운 이웃 간의 거리를 최대화하므로 collapse issue를 완화합니다. regularization strength coefficient λ로 가중된 regularization term을 contrastive loss에 단순히 추가합니다.
        •  
          notion image
         
      • 직관적으로, different entropy regularization는 positive examples 및 hard negatives 거리를 늘려서 서로 다른 샘플의 표현이 hypersphere에 너무 가깝게 놓이는 것을 방지합니다. 과거 연구에 의해 밝혀진 것처럼, 거리가 매우 작은 hard negatives는 training signal의 주요 noise source입니다.
 

Analysis

notion image
 
  • PCA in the Embedding Space
    • 훈련되지 않은 모델에 비해 contrastive loss로 훈련한 이후에 feature collapse 현상이 두드러짐
    • differential entropy regularization를 통해 contrastive loss를 증가시키면 cumulative energy가 더 많은 차원에 걸쳐 확산됨
    • transformer-based architecture가 convnet보다 feature collapse의 영향을 덜 받음
      • 아마도 Multi-head attention에서의 input features가 attention 작업전에 서로 다른 sub-spaces에 projection되어 collapse risk가 감소하기 때문
 
  • Gradient Analysis
    • gradient direction covariance의 nuclear norm을 계산하여 noisy gradients를 표현함
    • 매우 높거나 낮은 margin β값에 따른 noisy gradients의 변화를 통해 매우 쉽거나 어려운 negatives가 각각 less informative 및 less stable training sinal로 이어질 수 있음을 알려줌
    • entropy regularization term을 추가한 경우 noisy gradients가 감소
 

Experiment

Datasets

  • Category-level Retrieval
    • Stanford Online Products (SOP)
      • 22,634개의 카테고리를 가지는 online products images
      • 11,318개를 training하고 11,316를 testing함
    • CUB-200-2011
      • 200개의 bird 카테고리를 가지는 11,788개의 images
      • 100개씩 나누어 training/testing에 활용
    • In-Shop
      • 7,986개의 clothing items 카테고리를 가지는 72,712개의 images
      • 3,997개는 training, 3,985개는 testing
  • Particular Object Retrieval
    • SFM120k
      • large unlabelled image collections에 structure from motion 및 3D reconstruction을 적용
      • positive images는 query image와 함께 충분한 3D points가 관찰되는 경우
      • negative images는 서로 다른 3D model로부터 생성된 경우
      • 551개의 3D models를 training, 162개를 validation에 사용
    • evaluation을 위해 Oxford 및 Paris datasets를 사용
      • 두 데이터셋 모두 70개의 buildings가 묘사된 query images와 각각 4993, 6322개의 query image와 동일한 building 이미지가 추가적으로 포함
      • Easy(E), Medium(M), Hard(H)로 Benchmarks가 split을 가지며, E는 hard queries를 무시, M은 전부를 포함, H는 hard queries만을 고려
      • 본 논문에서는 M, H split에서의 Mean Average Precision을 report
 

Implementation & Training Details

  • Category-level Retrieval
    • transformer-based 모델과 pre-trained 가중치는 Timm 라이브러리를 기반으로 구축한 DeiT의 public implementation1을 기반으로 함
    • learning rate : , weight decay : , batch size : 64
    • AdamW optimizer
    • β = 0.5, λ = 0.7
    • image size는 256 x 256로 resizing한 이후에, 224 X 224 크기의 random crop과 random horizontal flipping을 수행하여 augmentation을 수행
    • SOP 및 In-Shop models는 35k iterations, CUB-200-2011 model은 2000 iterations 학습
 
  • Particular Object Retrieval
    • object retrieval experiments을 위해 기존 공개된 코드를 기반으로 구현을 구축
    • tranformer-based 및 convolutional 모두 SFM120k 데이터를 기반으로 fine-tuning을 수행
    • images는 224 x 224 및 384 x 384 두 개의 동일한 width, height에 대한 report를 수행
    • 각 batch는 (1 anchor, 1 positive, 5 negative)로 구성된 5개의 tuple로 구성
    • 각 epoch 당 2,000개의 positive pairs 및 22,000개의 negative candidates(using hard-negative mining)를 randomly selected 함
    • Adam optimizer
    • learning rate : , weight decay :
    • β = 0.85
    • GeM pooling을 사용한 모델은 pooling exponent value p 값으로 3을 사용
    • SFM120k 데이터셋으로 학습된 모델을 PCA를 통해 dimensionality reduction을 수행함
    • evaluation 단계에서는 모든 query 및 database images는 finetuning stage와 동일한 resolution을 가지는 동일 크기로 resize 됨
 

Results

  • Category-level Retrieval
    • notion image
 
  • Particular Object Retrieval
    • notion image
      notion image
 

Ablations

 
  • Different Methods of Supervision
notion image
notion image
 
  • Choice of Feature Extractor: Pooling Methods
notion image
 
  • Performance across Objective Functions
    • notion image
 
  • Regularizing Hyper-parameter λ
    • notion image
 
 
Share article