Skip to main content
Efficient Channel Attention
Supplementary RC 2020 Refined Report for the paper ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks by Wang et. al., accepted to CVPR 2020.
Last updated: April 2, 2021
Abstract
Attention mechanisms in computer vision has been an important subject of research in the recent years owing to their capability of improving model performance by a substantial margin at the cost of negligible parametric overhead. The central interpretable feature of any attention mechanism is that they allow the model to put emphasis on those features which are more important and deterministic. However, as in the case of any trainable layer or module, attention mechanisms do induce additional parametric complexity. This paper aims at providing a novel approach of applying channel attention in computer vision models at the cheapest parametric cost while being able to provide state of the art performance in competitive tasks like image classification, object detection and instance segmentation. Reproducibility code for the paper can be found at https://github.com/digantamisra98/Reproducibilty-Challenge-ECANET
Introduction
Attention mechanisms have become an integral component of modern deep neural networks in a bid to improve generalisation capabilities of these architectures. Over time there have been many novel attention mechanisms proposed in the domain of computer vision. Some of the prominent ones include Squeeze-and-Excitation Networks, Convolutional Block Attention Module (CBAM), Bottleneck Attention Module (BAM), Global Context (GC) Nets, Attention Augmented Networks (AANets) and Nets. However, most of these attention mechanisms which incorporate any form of channel attention have significant drawbacks which include: Significant increased parametric complexity, Dimensionality reduction and absence of Cross Channel Interaction (CCI). This paper aims to address these shortcomings by proposing a novel attention mechanism known as . ECA is a lightweight, easy-to-plug in module that can be used in all types of deep convolution neural networks which efficiently computes channel attention at every point of introduction in the architecture.
Related Methods
Self Attention Generative Adversarial Network (SAGAN) was the first major stride towards normalising the use of attention mechanisms in the domain of computer vision. While Self Attention does present an optimal way of computing attention maps for each pixel in the query image, the complexity is in the order of where is the number of pixels in each channel of the image and is the total number of channels. Following this, Squeeze-and-Excitation Networks (SENets) popularised the approach of introducing a channel attention into the distinct blocks of the network. While SENet is extremely successful and is used actively in state of the art architectures like Efficient Nets, they still introduce dimensionality reduction and are quite costly. The additional drawbacks introduced by increased parametric and operations complexity is it increases latency and reduces throughput for the network. Similarly in case of CBAM and BAM which incorporate two modules dedicated for computing channel and spatial attention face the common issue of dimensionality reduction in the channel attention module. Additionally methods like GCNets and -Nets although are capable of providing significant gains are extremely costly.
| Attention Mechanism | DR | CCI | Parameters | Overhead (ResNet-50) |
|---|---|---|---|---|
| SENet | Yes | Yes | 2C2r\frac{2C^{2}}{r} | 2.514 M |
| CBAM | Yes | Yes | 2C2r+2k2\frac{2C^{2}}{r} + 2k^{2} | 2.532 M |
| BAM | Yes | Yes | Cr(3C+2k2Cr+1)\frac{C}{r}(3C + \frac{2k^{2}C}{r} + 1) | 0.358 M* |
| GCNet | Yes | Yes | 2C2r+C\frac{2C^{2}}{r}+C | 2.548 M |
| ECANet | No | Yes | kk |
Efficient Channel Attention

Efficient Channel Attention (ECA) is an extremely light-weight efficient channel attention module which is built on the foundation of enforcing cross channel interaction while having no dimensionality reduction during the computation of the channel attention. The parametric overhead introduced by ECA is negligible and directly equivalent to the kernel size used in the 1-D convolution layer inherently present in ECA. The following subsections will go through the fundamental core concepts behind ECA which includes Cross Channel Interaction (CCI) and avoiding Dimensionality Reduction (DR). This will be followed by a walkthrough the architectural design of the ECA Module.
Avoiding Dimensionality Reduction
ECA is inspired from one of the fundamental methods of attention in computer vision known as Squeeze-and-Attention Networks (SENets). SENets incorporate a three module approach - (i) Squeeze module, (ii) Excitation module and (iii) Scale module. Squeeze module essentially decomposes each feature map/ channel ( in terms of dimension) in the tensor () to a space, essentially a single pixel. Thus, it reduces the tensor to a space of which is achieved by using Global Average Pool (GAP). This is followed by the Excitation module where the resultant tensor from the Squeeze module is passed through two fully connected layers where the first layer acts as a bottleneck defined by a reduction ratio . This results in the issue of Dimensionality Reduction (DR) and is done to keep the parametric overhead cheap. The authors of ECANet found that replacing the Excitation module with a simple one-to-one mapping by a single layer where each channel's attention weights are computed independently performs better than SENets at a much lower cost. Additionally, the authors also found that a single fully connected layer instead of two with DR as in the case of SENets performs better. These confirmed that DR is harmful to the overall performance and confirmed the hypothesis of the authors.
Cross Channel Interaction
To demonstrate the importance of Cross Channel Interaction (CCI), the paper conducts simple benchmarking experiments where they take the most optimal variant for channel attention labelled as SE-Var 3 and compare it to a non-optimal one labelled as SE-Var 2. The difference between the two is that the former allows cross channel interaction for each channel amongst every other channel in the whole tensor. Thus, this involves a parametric space. While in the case of latter, it limits each channel to only have one-to-one interdependence with other channels, however, it requires a smaller parametric space defined by , where denotes the total number of channels. The results obtained by SE Var 3 far exceeds the boost provided by SE Var 2, confirming the importance of having full CCI. However, since, the parametric cost of having full CCI is very high, the authors propose a compromise to avail the benefits of CCI at a much lower cost.
Local Cross Channel Interaction
To allow CCI at a much lower cost, the authors introduce Local CCI where they allow each channel to have interdependence on every other channel in a small local group. The caveat in this is that each group has overlap with every nearby preceding and succeeding group. Thus, this decomposes the global parametric space defined by to a much smaller localised space defined by , where is the pre-determined size of the local region, such that . Local Cross Channel Interaction based attention can thus be written as the following equation:
, where is the set of adjacent channels of the query channel and represents the sigmoid activation function.
To further optimise and generalise local CCI, the authors proposed the channels to share the same learning weights. This reduces the parametric space overhead introduced by the attention mechanism from to which is extremely small. Thus, now, the above equation can be further composed to the following equation.
In terms of layers, this form of shared local cross channel interaction can be implemented using a simple 1D convolution kernel with kernel size of . Thus, can be represented as:
Coverage of Local CCI
The aim of the authors was to provide the cheapest and most efficient attention mechanisms which is supported by Local CCI. However, to optimally decide the area of coverage, the authors make the kernel size of the 1D convolution to be adaptive and proportional to the number of channels . The central claim here is that higher dimensional channels require larger range of interaction and similarly lower dimensional channels require smaller range. Firstly, there exists a mapping between and which is defined by the following function:
The simplest mapping would that be of a linear one, i.e., . However, the relations derived by a linear mapping is too limited and obsolete. To induce more characterisation capacity, the authors introduce a non-linear mapping with the knowledge that in most deep convolutional neural networks, the number of channels is set to . This non-linear mapping is thus defined as:
Thus, given the channel dimension , kernel size , i.e., the local region of coverage can be adaptively calculated as:
where indicates the nearest odd number of . The authors set the values of the two hyper-parameters and to be 2 and 1 respectively for all experiments in the paper. Using PyTorch this can be implemented in the following way:
import torchfrom torch import nnimport mathclass ECA(nn.Module):"""Constructs a ECA module.Args:channels: Number of channels in the input tensorb: Hyper-parameter for adaptive kernel size formulation. Default: 1gamma: Hyper-parameter for adaptive kernel size formulation. Default: 2"""def __init__(self, channels, b=1, gamma=2):super(ECA, self).__init__()self.avg_pool = nn.AdaptiveAvgPool2d(1)self.channels = channelsself.b = bself.gamma = gammaself.conv = nn.Conv1d(1, 1, kernel_size=self.kernel_size(), padding=(self.kernel_size() - 1) // 2, bias=False)self.sigmoid = nn.Sigmoid()def kernel_size(self):k = int(abs((math.log2(self.channels)/self.gamma)+ self.b/self.gamma))out = k if k % 2 else k+1return outdef forward(self, x):# feature descriptor on the global spatial informationy = self.avg_pool(x)# Two different branches of ECA moduley = self.conv(y.squeeze(-1).transpose(-1, -2)).transpose(-1, -2).unsqueeze(-1)# Multi-scale information fusiony = self.sigmoid(y)return x * y.expand_as(x)
Experiments
The authors provide extensive results using ECANets in different tasks like Image Classification on ImageNet, Object Detection and Instance Segmentation on MS-COCO dataset. The results are compared with other standard attention mechanism based architectures. In the following sections we provide results on additional experiments that we conducted to validate the efficiency of ECANets.
CIFAR-10:
To validate on CIFAR-10 dataset, a ResNet-18 with various attention mechanisms including Squeeze-and-Excitation, Triplet Attention, CBAM and ECA. Each model was run for 5 runs of 50 epochs at a batch size of 128 and a learning rate of 0.1 using the SGD optimiser. The results demonstrate that ECANet was able to obtain the second highest mean Top-1 Accuracy behind CBAM. Additionally ECANet was able to obtain the highest Top-1 Accuracy across all runs as compared to all other variants. However, ECANets recorded the highest standard deviation across the runs. Although CIFAR-10 isn't a strong indicator of performance at only 50 epochs, the results do suggest that ECANets are able to obtain competitive results as compared to other standard attention mechanisms while being extremely cheaper in terms of parametric cost.
Hyperparameter Sweeps
We also conducted hyperparameter sweeps for various attention mechanisms to find the best hyperparameters and understand which attention mechanism is more robust. We chose batch size, optimiser and choice of attention mechanism as the range of hyperparameters with the goal of minimising loss. In the ResNet-20 model we used, ECA combined with SGD across 128 and 256 batch sizes were able to obtain the lowest loss in the 10 epoch run. Based on the results, ECANets were able to demonstrate that they're efficient and robust in case of hyperparameter changes.
MS COCO
We reproduced the Mask RCNN-ECANet-50 model for object detection and instance segmentation using the exact training settings provided in the paper. We used the ECANet-50 trained weights provided by the author along with the open source MMDetection framework to train the Mask R-CNN model in accordance to the information provided in the paper.
Reproduced Results
| Backbone | Detectors | BBox_AP | BBox_AP50 | BBox_AP75 | BBox_APS | BBox_APM | BBox_APL | Segm_AP | Segm_AP50 | Segm_AP75 | Segm_APS | Segm_APM | Segm_APL |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ECANet-50 | Mask RCNN | 34.1 | 53.4 | 37.0 | 21.1 | 37.2 | 42.9 | 31.4 | 50.6 | 33.2 | 18.1 | 34.3 | 41.1 |
Original Results:
| Backbone | Detectors | BBox_AP | BBox_AP50 | BBox_AP75 | BBox_APS | BBox_APM | BBox_APL | Segm_AP | Segm_AP50 | Segm_AP75 | Segm_APS | Segm_APM | Segm_APL |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ECANet-50 | Mask RCNN | 39.0 | 61.3 | 42.1 | 24.2 | 42.8 | 49.9 | 35.6 | 58.1 | 37.7 | 17.6 | 39.0 | 51.8 |
The results we obtained were far off from the results provided in the paper, even being lower than the vanilla baseline and thus couldn't validate the claims made by the paper. We have provided the logs of the complete training in our reimplementation repository.
Conclusion
Although ECANets were able to obtain very competitive results at a very low overhead as compared to other attention mechanisms, it comes with it's fair share of flaws which include:
- Absence of Spatial Attention: ECANet is a standalone channel attention module and doesn't have the capacity of modelling spatial attention which has been shown to be crucial in various attention mechanisms including Triplet Attention and CBAM.
- Kernel Size discrepancy: Although the authors emphasise on the importance of the adaptive selection of kernel size using the formula presented in equation (12) in the paper, they do not use it in the training of the models whose results are presented in the paper.
- Lack of ablation study on adaptive kernel size formula hyperparameters: The authors fail to do extensive study on the effect of the and hyperparameters used in the selection of the adaptive kernel size and pre-emptively set it to 2 and 1 respectively.
Overall, the paper is a good modular approach towards designing efficient attention mechanisms which can provide competitive performance. The main strength of the paper is the ease of understanding the intuition behind ECA which is local cross channel interaction.