Attention Augmented Convolutional Networks

Inc Lomin's avatar
Apr 19, 2021
Attention Augmented Convolutional Networks

Introduction

Computer vision에서 많이 사용되는 CNN의 convolution layer는 1) 제한된 receptive field, 2) weight sharing을 통한 translation equivariance를 가정합니다. 이는 대부분 이미지 모델에 필요한 inductive bias이지만, global context를 보는데에는 오히려 방해가 됩니다. 반면 self-attention은 sequence modeling 쪽에서 long range interaction을 포착하는데 큰 효과를 보여주고 있습니다. Self-attention은 weight가 고정된 convolution과는 다르게 weight가 input signal 자체로부터 계산되는 dynamic 특성을 가지기 때문에, parameter를 증가시키지 않고도 long range interaction을 가능하게 합니다.
이 논문에서는 self-attention을 convolution을 대체하는 primitive로 사용할 수 있는 구조를 제안합니다. 하지만 실험에서 이 둘을 병용하는 것이 더 성능이 좋았기 때문에, convolution을 버리는 대신 attention 메커니즘으로 convolution을 augment하는 방법을 택하였습니다.
 

Proposed Method

Self-attention over images

Input feature map X 의 크기가 (H, W, F_in)이라고 할 때, 이를 flatten하여 (HW, F_in) 크기로 만든 뒤 multi-head attention을 적용합니다.
notion image
모든 head의 output은 concat, project되어 원래의 크기를 맞춥니다.
notion image
Two-dimensional Positional Embeddings
위치 정보를 가지고 있지 않을 때, self-attention은 permutation equivariant합니다. (\pi는 임의의 permutation)
notion image
이러한 이슈를 방지하기 위하여 Transformer 논문에서도 positional embedding을 제안하였고, Image Transformer, CoordConv 등의 논문에서 이를 2D로 확장한 방법을 제안하였습니다. 하지만 실험에서 이것들은 image classification과 object detection에서 효과가 없었습니다. 이는 아마도 translation equivariance를 만족하지 않기 때문이라고 예상됩니다. 따라서 여기서는 relative encodings(P. Shaw 2018)을 사용하겠습니다.
2D relative encoding에서 attention logit은 아래와 같이 계산됩니다. 아래에서 i, j는 두 픽셀의 좌표를 나타내며 r은 상대 좌표(j-i)의 embedding입니다.
notion image
이로부터 head의 output은 다음과 같이 계산됩니다.
notion image
 

Attention augmented convolution

제안되는 attention augmented convolution의 전체적인 구조는 아래와 같습니다.
notion image
먼저 head의 갯수만큼의 attention map이 생성된 후, 각각 input과 attention map을 weighted average합니다. 이들은 concatenate 및 projection되어 input feature map의 크기와 맞춥니다. Self-attention된 결과는 일반 convolution(standard convolution) 결과와 concatenate되어 최종 output이 됩니다.
notion image
Effect on number of parameters
Multihead attention으로 인해 증가하는 파라미터의 갯수는 아래와 같습니다. 아래에서 v, k는 각각 output filter 중 attention channel 및 key depth number의 비율입니다.
notion image
이는 3x3 convolution을 self-attention으로 대체하였을 때 약간 감소하는 정도입니다.
Attention Augmented Convolutional Architectures
Augmented convolution 레이어는 batch normalization으로 normalize됩니다. 여기서는 이 augmented convolution을 residual block마다 사용하였고, 메모리가 허용하는 범위에서 뒷쪽 레이어부터 앞으로 최대한 적용하였습니다.
 

Experiment

제안된 Attention Augmentation은 ResNets, MNasNet에 적용되었고 CIFAR-100, ImageNet, COCO 데이터셋에 실험되었습니다.
  1. CIFAR-100
    1. 이 실험에서는 Wide-ResNet의 각각의 residual block의 첫 번째 convolution을 N_h=20, k=2v=0.2로 augment하여 실험하였습니다. Squeeze-Excitation (SE), Gather-Excite (GE)에 비해 나은 성능을 보여줌을 알 수 있습니다.
      notion image
  1. ImageNet with ResNet
    1. ResNet에서는 마지막 3 stage에 대하여 bottleneck의 3x3 convolution을 augment하였습니다. 결과는 아래와 같습니다.
      notion image
      notion image
  1. ImageNet with MNasNet
    1. resource constrained setting에서 실험해보기 위해 MNasNet을 사용하겠습니다. 결과는 아래와 같이 parameter의 갯수 대비 성능이 더 높게 나오는 것을 볼 수 있습니다.
      notion image
       
      notion image
  1. Object Detection with COCO
    1. RetinaNet에 실험한 결과입니다. 비슷한 parameter 대비 최대 1.4% 향상된 결과를 보여줍니다.
      notion image
  1. Ablation study
    1. Attention channel의 비율을 달리하며 실험한 결과입니다. 0.25에서 가장 좋은 결과를 보여주었습니다.
      notion image
       
      notion image
       
      아래는 Position encoding의 종류에 따른 비교 실험입니다. 본 연구에서 사용한 relative encoding이 성능 향상을 보여주었습니다.
      notion image
      아래는 COCO 데이터셋에 실험한 결과입니다.
      notion image
 

Conclusions

이 논문에서는 convolution 연산을 대체할 수 있도록 self-attention을 사용하는 방법을 제안합니다. 특히 image classification에 적용될 수 있는 2D relative fully self-attention 모델을 개발하였다는 것에 의의가 있습니다. 실험에서는 이 self-attention과 기존의 convolution을 병용하여 더 높은 성능을 보일 수 있다는 것을 classification, object detection 데이터셋에서 보였습니다.
 
 
Share article