当前位置:网站首页>[network] channel attention network and spatial attention network
[network] channel attention network and spatial attention network
2022-07-06 04:18:00 【Hard working yuan】
CBAM: Address of thesis
Purpose :
Convolution is to extract features by mixing the information of channel and space dimensions . In terms of attention ,SE Only pay attention to channel attention , Did not consider spatial attention . therefore , This paper proposes CBAM—— A convolution module that focuses on both channels and spatial attention , It can be used for CNNs Architecture , To improve feature map The ability to express the characteristics of .Network structure :
Main network structure
CAM and SAM Structure
CAM: The channel attention mechanism is to learn the weighting coefficient of a different channel , At the same time, all areas are considered

SAM: Spatial attention mechanism is to learn the coefficients of different areas of the whole picture , All channels are considered at the same time .
Pytorch Code implementation :
import torch from torch import nn class ChannelAttention(nn.Module): def __init__(self, in_planes, ratio=16): super(ChannelAttention, self).__init__() self.avg_pool = nn.AdaptiveAvgPool2d(1) self.max_pool = nn.AdaptiveMaxPool2d(1) self.fc1 = nn.Conv2d(in_planes, in_planes // 16, 1, bias=False) self.relu1 = nn.ReLU() self.fc2 = nn.Conv2d(in_planes // 16, in_planes, 1, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, x): avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x)))) max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x)))) out = avg_out + max_out return self.sigmoid(out) class SpatialAttention(nn.Module): def __init__(self, kernel_size=7): super(SpatialAttention, self).__init__() assert kernel_size in (3, 7), 'kernel size must be 3 or 7' padding = 3 if kernel_size == 7 else 1 self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=padding, bias=False) self.sigmoid = nn.Sigmoid() self.register_buffer() def forward(self, x): avg_out = torch.mean(x, dim=1, keepdim=True) max_out, _ = torch.max(x, dim=1, keepdim=True) x = torch.cat([avg_out, max_out], dim=1) x = self.conv1(x) return self.sigmoid(x)Reference resources :https://blog.csdn.net/oYeZhou/article/details/116664508
边栏推荐
- SharedPreferences 源码分析
- Tips for using dm8huge table
- The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
- 捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
- Overturn your cognition? The nature of get and post requests
- VNCTF2022 WriteUp
- asp. Core is compatible with both JWT authentication and cookies authentication
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- 2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
- [disassembly] a visual air fryer. By the way, analyze the internal circuit
猜你喜欢

Detailed explanation of serialization and deserialization

JVM garbage collector concept

Cross domain and jsonp details

Interface idempotency

10个 Istio 流量管理 最常用的例子,你知道几个?

颠覆你的认知?get和post请求的本质

Stable Huawei micro certification, stable Huawei cloud database service practice

Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution

题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》

捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
随机推荐
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
Redis (replicate dictionary server) cache
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
How many of the 10 most common examples of istio traffic management do you know?
查询mysql数据库中各表记录数大小
QML和QWidget混合开发(初探)
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
Stable Huawei micro certification, stable Huawei cloud database service practice
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
2328. 网格图中递增路径的数目(记忆化搜索)
Slow SQL fetching and analysis of MySQL database
HotSpot VM
User datagram protocol UDP
Lora gateway Ethernet transmission
拉格朗日插值法
Cross domain and jsonp details
E. Best Pair
Query the number and size of records in each table in MySQL database
[Zhao Yuqiang] deploy kubernetes cluster with binary package