当前位置:网站首页>[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
边栏推荐
- Basic use of MySQL (it is recommended to read and recite the content)
- pd. to_ numeric
- Explain in simple terms node template parsing error escape is not a function
- Lora gateway Ethernet transmission
- 绑定在游戏对象上的脚本的执行顺序
- Viewing and verifying backup sets using dmrman
- Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
- PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
- DM8 archive log file manual switching
- coreldraw2022新版本新功能介绍cdr2022
猜你喜欢

math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi

CertBot 更新证书失败解决

TCP/IP协议里面的网关地址和ip地址有什么区别?

About some basic DP -- those things about coins (the basic introduction of DP)

MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0

coreldraw2022新版本新功能介绍cdr2022

Viewing and verifying backup sets using dmrman

MySQL master-slave replication

During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input

R note prophet
随机推荐
Certbot failed to update certificate solution
MySql數據庫root賬戶無法遠程登陸解决辦法
Use js to complete an LRU cache
拉格朗日插值法
P2022 interesting numbers (binary & digit DP)
P2102 floor tile laying (DFS & greed)
VPP performance test
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
npm命令--安装依赖包--用法/详解
[tomato assistant installation]
Comprehensive ability evaluation system
Recommendation system (IX) PNN model (product based neural networks)
绑定在游戏对象上的脚本的执行顺序
Fedora/rehl installation semanage
coreldraw2022新版本新功能介绍cdr2022
Codeforces Round #770 (Div. 2) B. Fortune Telling
tengine 内核参数
20、 EEPROM memory (AT24C02) (similar to AD)
【leetcode】1189. Maximum number of "balloons"
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control