赞
踩
通道注意力有效提升了CNN的性能,但是随着一系列复杂注意力模块的提出不可避免增加了计算成本。为了平衡性能和复杂度,论文《ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks》设计了一种超轻量级的注意力模块-ECA Module(Efficient Channel Attention)来提升大型CNN的性能。ECA Module只包含k个参数(k<=9)。
分析SE注意力机制,发现避免降维和适当的跨通道交互对于学习有效和高效的通道注意分别很重要。在此基础上提出了ECA注意力机制,应用了一种不降维的局部跨通道交互策略,该策略可以通过一维卷积有效地实现。
论文中提出的ECA模块的结构图如下所示:
ECA模块的代码实现如下:
- import torch
- from torch import nn
- from torch.nn.parameter import Parameter
-
- class eca_layer(nn.Module):
- """Constructs a ECA module.
- Args:
- channel: Number of channels of the input feature map
- k_size: Adaptive selection of kernel size
- """
- def __init__(self, channel, k_size=3):
- super(eca_layer, self).__init__()
- self.avg_pool = nn.AdaptiveAvgPool2d(1)
- self.conv = nn.Conv1d(1, 1, kernel_size=k_size, padding=(k_size - 1) // 2, bias=False)
- self.sigmoid = nn.Sigmoid()
-
- def forward(self, x):
- # feature descriptor on the global spatial information
- y = self.avg_pool(x)
-
- # Two different branches of ECA module
- y = self.conv(y.squeeze(-1).transpose(-1, -2)).transpose(-1, -2).unsqueeze(-1)
-
- # Multi-scale information fusion
- y = self.sigmoid(y)
-
- return x * y.expand_as(x)
-
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。