ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • BAM : Bottleneck Attention Module
    2022_Project 2022. 2. 22. 16:19

    최근들어 CNN에 attention을 적용시킨 연구들에 흥미가 생겨 Squeeze and Excitation network (SENet)을 비롯해 여러 attention module들에 대해 공부해보았다. (SENet은 다음 포스트에서 상세하게 다루도록 하겠다)

    3D image에 대해서는 대부분의 attention이 channel 방향으로 이루어졌는데 (아마도 input data가 거의 비디오기 때문이라 추측) 내 경우에는 channel보단 spatial 방향으로 attention을 해주는 것이 더 의미있을 것 같았다. 따라서 spatial 쪽으로 attention map을 생성한 논문들을 찾아보던 도중 BAM과 CBAM에 대해 알게되었으며 이를 오늘 포스트에서 다루도록 하겠다.

    BAM : Bottleneck Attention Module

    2018년에 소개된 이 논문은 반갑게도 한국 연구원들이 작성하였다. 논문에 따르면 BAM은 두개의 독립적인 pathway (channel 그리고 spatial 방향으로의)를 통해 attention map을 생성한다고 한다. 이 모듈은 bottleneck 부분에서 hierachical한 attention을 구성하고 있으며 end-to-end로 학습이 가능하다. 논문의 저자들은 CIFAR-100, ImageNet-IK, VOC 2007 그리고 MS COCO 등 다양한 open dataset에 대해 BAM을 실험해보았으며 classification과 detection 부분에 있어서 뛰어난 성능을 보였다고 한다.

     

    1. Introduction

    지난 수년동안 많은 연구원들은 딥러닝의 성능을 높이기 위해 다양한 방면에서 노력해왔다. ( designing optimizers, proposing adversarial training scheme, or task-specific meta architecture like 2-stage architectures for detection)

    성능을 좋게하기 위한 근본적인 접근은 좋은 backbone architecture를 디자인하는 것이다. 이전 연구들과는 별개로, 논문 저자들은 DNN에서의 attention의 효과를 조사하였고, 그 결과 일반적인 DNN 모델에 대해 적용할 수 있는 간단하고 가벼운 모듈을 제안하였다. (BAM은 그 어떤 CNN에 대해서도 implement할 수 있다고 한다.) 주어진 3D feature map에 대해 BAM은 주요한 element를 강조하는 3D attention map을 생성한다.

    Contribution. Our main contribution is three-fold
    1. We propose a simple and effective attention module, BAM, which can be integratedwith any CNNs without bells and whistles.
    2. We validate the design of BAM through extensive ablation studies.
    3. We verify the effectiveness of BAM throughout extensive experiments with various baseline architectures on multiple benchmarks (CIFAR-100, ImageNet-1K, VOC 2007 and MS COCO).

     

    3. Bottleneck Attention Module

    위 그림은 BAM에 대한 전반적인 구조를 보여준다. 주어진 input feature map F(dimension of C*H*W)에 대해 BAM은 3d attention map인 M(F)를 생성하며 따라서 변경된 feature map F'는 아래와 같이 표현 가능하다. (이떄 F와 M(F)는 서로 같은 차원을 지니고 있다.)

    또한 여기서 최종적인 attention map인 M(F)를 계산하기 위해 1차적으로 channel attention 인 Mc(F)를 구한 다음, spatial attention  Ms(F)를 구하였다.

    이때, Mc(F)의 경우 dimension이 C, Ms(F)의 경우에는 H*W이기 때문에 각각의 attention map을 서로 합쳐주기 전에 C*H*W로 차원을 resize해준다. (SENet의 경우 Excitation 부분에 해당되는 파트 같다..)

     

    ▶ Channel Attention Branch

    각각의 channel들은 특정 feature response를 포함하고 있기 때문에 저자들은 channel branch에서의 inter-channel relationship을 살펴보았다. 각 채널마다의 feature map을 aggregate하기 위해 global average pooling을 사용하였으며 feature map F에 대해 channel vector Fc (dimension of C*1*1)를 생성하였다. 이 벡터는 각각의 채널별로의 global한 정보를 담고 있다. Fc로부터 채널들간의 attention을 측정하기 위해 하나의 hiddenlayer를 지니고 있는 MLP를 사용하였다. 

    ▶ Spatial Attention Branch

    Spatial branch는 spatial attention map인 Ms(F) (dimension of H*W)를 생성하며 각각의 다른 spatial location 별로의 feature들을 강조하거나 억제한다. 효과적으로 문맥상의 정보를 담아내기 위해서는 큰 receptive field를 사용하는 것이 중요하기 떄문에 논문 저자들은 dilated convolution을 사용했다고 한다. feature F은 1*1 convoluion을 사용해 channel dimension으로 feature map을 integrate * compress해주었으며 그 결과 C/r*H*W의 dimension을 갖도록 projected되었다. Reduction 이후에 문맥상의 정보를 효과적으로 추출하기 위해 3*3 dilated convolution이 사용되었다. 마지막으로 feature들은 다시 1*1 convolution을 이용해 1*H*W의 dimension을 갖도록 축소되었다. Spatial attention은 아래와 같이 계산되어진다.

    4. Experiments

    https://github.com/Jongchan/attention-module/blob/master/MODELS/bam.py

     

    GitHub - Jongchan/attention-module: Official PyTorch code for "BAM: Bottleneck Attention Module (BMVC2018)" and "CBAM: Convoluti

    Official PyTorch code for "BAM: Bottleneck Attention Module (BMVC2018)" and "CBAM: Convolutional Block Attention Module (ECCV2018)" - GitHub - Jongchan/attention-module: Officia...

    github.com

    [1] Park, Jongchan, et al. "Bam: Bottleneck attention module." arXiv preprint arXiv:1807.06514 (2018).

    '2022_Project' 카테고리의 다른 글

    Graph attention network (GATs)  (0) 2022.04.14
    Multihead Self Attention  (0) 2022.03.24

    댓글

Designed by Tistory.