当前位置:网站首页>[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
边栏推荐
- Certbot failed to update certificate solution
- Stack and queue
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- 拉格朗日插值法
- P2102 floor tile laying (DFS & greed)
- npm命令--安装依赖包--用法/详解
- 20、 EEPROM memory (AT24C02) (similar to AD)
- Web components series (VII) -- life cycle of custom components
- Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
- Basic use of MySQL (it is recommended to read and recite the content)
猜你喜欢
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
MySql数据库root账户无法远程登陆解决办法
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
The value of two date types is subtracted and converted to seconds
Comprehensive ability evaluation system
Execution order of scripts bound to game objects
coreldraw2022新版本新功能介绍cdr2022
满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
随机推荐
Record an excel xxE vulnerability
软考 系统架构设计师 简明教程 | 总目录
The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
R note prophet
MySQL transaction isolation level
Mixed development of QML and QWidget (preliminary exploration)
综合能力测评系统
Query the number and size of records in each table in MySQL database
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
POI add border
Hashlimit rate control
npm命令--安装依赖包--用法/详解
Stable Huawei micro certification, stable Huawei cloud database service practice
1291_Xshell日志中增加时间戳的功能
【HBZ分享】ArrayList的增删慢查询快的原因
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
Web components series (VII) -- life cycle of custom components
HotSpot VM
捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
Several important classes in unity