number of original output ﬁlters and =dk
Foutthe ratio of
key depth to number of original output ﬁlters. Similarly to
the convolution, the proposed attention augmented convolution 1) is equivariant to translation and 2) can readily operate on inputs of different spatial dimensions. We include
Tensorﬂow code for the proposed attention augmented convolution in the Appendix A.3.
Effect on number of parameters: Multihead attention
introduces a 1x1 convolution with Fininput ﬁlters and
(2dk+dv) =Fout(2+)output ﬁlters to compute queries,
keys and values and an additional 1x1 convolution with
dv=Foutinput and output ﬁlters to mix the contribution of different heads. Considering the decrease in ﬁlters
in the convolutional part, this leads to the following change
in parameters:
paramsFinFout(2+ (1k2)+Fout
Fin2);(5)
where we ignore the parameters introduced by relative position embeddings for simplicity as these are negligible. In
practice, this causes a slight decrease in parameters when
replacing 3x3 convolutions and a slight increase in parameters when replacing 1x1 convolutions. Interestingly, we ﬁnd
Convolutional networks have been the paradigm of choice in many computer
vision applications. The convolution operation however has a significant
weakness in that it only operates on a local neighborhood, thus missing global
information. Self-attention, on the other hand, has emerged as a recent advance
to capture long range interactions, but has mostly been applied to sequence
modeling and generative modeling tasks. In this paper, we consider the use of
self-attention for discriminative visual tasks as an alternative to
convolutions. We introduce a novel two-dimensional relative self-attention
mechanism that proves competitive in replacing convolutions as a stand-alone
computational primitive for image classification. We find in control
experiments that the best results are obtained when combining both convolutions
and self-attention. We therefore propose to augment convolutional operators
with this self-attention mechanism by concatenating convolutional feature maps
with a set of feature maps produced via self-attention. Extensive experiments
show that Attention Augmentation leads to consistent improvements in image
classification on ImageNet and object detection on COCO across many different
models and scales, including ResNets and a state-of-the art mobile constrained
network, while keeping the number of parameters similar. In particular, our
method achieves a $1.3\%$ top-1 accuracy improvement on ImageNet classification
over a ResNet50 baseline and outperforms other attention mechanisms for images
such as Squeeze-and-Excitation. It also achieves an improvement of 1.4 mAP in
COCO Object Detection on top of a RetinaNet baseline.
Irwan Bello Barret Zoph Ashish Vaswani Jonathon Shlens Quoc V. Le