【CA】《Coordinate Attention for Efficient Mobile Network Design》

在这里插入图片描述

CVPR-2021

github:https://github.com/Andrew-Qibin/CoordAttention



1 Background and Motivation

SENet(【SENet】《Squeeze-and-Excitation Networks》) 注意力忽视了 position information

作者 embedding positional information into channel attention,采用 two 1D feature encoding processes,提出 coordinate attention,direction-aware and position-sensitive

在这里插入图片描述

2 Related Work

  • Mobile Network Architecture
  • Attention Mechanisms

3 Advantages / Contributions

  • 设计提出轻量级 Coordinate Attention,兼顾 channel 和 spatial
  • 在分类 / 目标检测 / 分割 benchmarks 上验证了其有效性

在这里插入图片描述

4 Method

SE / CBAM / CA 结构对比

在这里插入图片描述
CBAM 虽然有 spatial attention,但是 fail in modeling long-range dependencies that are essential for vision tasks

下面看看 CA 的公式表达

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

结合代码看看

import torch
import torch.nn as nn
import math
import torch.nn.functional as F
 
class h_sigmoid(nn.Module):
    def __init__(self, inplace=True):
        super(h_sigmoid, self).__init__()
        self.relu = nn.ReLU6(inplace=inplace)
 
    def forward(self, x):
        return self.relu(x + 3) / 6
 
class h_swish(nn.Module):
    def __init__(self, inplace=True):
        super(h_swish, self).__init__()
        self.sigmoid = h_sigmoid(inplace=inplace)
 
    def forward(self, x):
        return x * self.sigmoid(x)
 
class CoordAtt(nn.Module):
    def __init__(self, inp, oup, reduction=32):
        super(CoordAtt, self).__init__()
        self.pool_h = nn.AdaptiveAvgPool2d((None, 1))
        self.pool_w = nn.AdaptiveAvgPool2d((1, None))
 
        mip = max(8, inp // reduction)
 
        self.conv1 = nn.Conv2d(inp, mip, kernel_size=1, stride=1, padding=0)
        self.bn1 = nn.BatchNorm2d(mip)
        self.act = h_swish()
        
        self.conv_h = nn.Conv2d(mip, oup, kernel_size=1, stride=1, padding=0)
        self.conv_w = nn.Conv2d(mip, oup, kernel_size=1, stride=1, padding=0)
        
 
    def forward(self, x):
        identity = x
        
        n,c,h,w = x.size()
        x_h = self.pool_h(x) #(n, c, h, 1)
        x_w = self.pool_w(x).permute(0, 1, 3, 2)  #(n, c, 1, w)-> (n, c, w, 1) 注意这里转化成和 x_h 一样的排列形式了
        
        y = torch.cat([x_h, x_w], dim=2)  # 方便拼一起,conv->bn->act
        y = self.conv1(y)
        y = self.bn1(y)
        y = self.act(y) 
        
        x_h, x_w = torch.split(y, [h, w], dim=2)  # 再拆开
        x_w = x_w.permute(0, 1, 3, 2)  # 这里转化回去了
 
        a_h = self.conv_h(x_h).sigmoid()
        a_w = self.conv_w(x_w).sigmoid()
 
        out = identity * a_w * a_h
 
        return out

在网络中的插入位置,以 mobileNetV2(【MobileNet V2】《MobileNetV2:Inverted Residuals and Linear Bottlenecks》) 和 MobileNeXt 为例
在这里插入图片描述

5 Experiments

5.1 Datasets and Metrics

  • ImageNet:Top-1 Acc
  • COCO:mAP
  • Cityscapes:mIoU

5.2 Ablation Studies

(1)Importance of coordinate attention
在这里插入图片描述
相比于仅水平或者竖直方向的 spatial attention,合起来最猛

(2)Different weight multipliers
在这里插入图片描述
在这里插入图片描述
0.25,0.75,1.0 均有一致性的提升

比 NAS 出来的 MobileNeXt + SE 都猛

AutoML 时代,提点的方式之一,加新的原料,加 search space 中的素材

(3)The impact of reduction ratio r
在这里插入图片描述
猛,均有提升

5.3 Comparison with Other Methods

(1)Attention for Mobile Networks
在这里插入图片描述
capture long-range dependencies among spatial locations that are essential for vision tasks

(2)Stronger Baseline

在这里插入图片描述

5.4 Applications

(1) Object Detection
在这里插入图片描述
在这里插入图片描述

COCO 和 VOC 都有提升

(2) Semantic Segmentation
在这里插入图片描述
比 CBAM 猛

6 Conclusion

来自:注意力的理解心得

在这里插入图片描述

  • 23
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
坐标注意力是一种新的注意力机制,通过将位置信息嵌入到通道注意力中,为移动网络提供了一种有效的方式来生成空间选择性注意力图。坐标注意力将通道注意力分解为两个一维特征编码过程,并沿空间方向聚合特征。这样做可以捕获远程依赖关系,并保留精确的位置信息。通过将得到的特征图编码成方向感知和位置敏感的注意力图,可以增强感兴趣对象的表示。坐标注意力可以灵活地插入到经典的移动网络中,几乎没有计算开销,并在下游任务中表现出更好的性能,如对象检测和语义分割。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* [CVPR2021注意力机制——Coordinate Attention || Pytorch代码实现](https://blog.csdn.net/qq_42962681/article/details/120417410)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [注意力机制——Coordinate Attention](https://blog.csdn.net/qq_40716944/article/details/121787103)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值