当前位置:网站首页>[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
边栏推荐
- Fedora/REHL 安装 semanage
- Practical development of member management applet 06 introduction to life cycle function and user-defined method
- Stable Huawei micro certification, stable Huawei cloud database service practice
- Mlapi series - 04 - network variables and network serialization [network synchronization]
- 729. 我的日程安排表 I(set or 动态开点线段树)
- Determine which week of the month the day is
- Script lifecycle
- Lora gateway Ethernet transmission
- 题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
- How can programmers resist the "three poisons" of "greed, anger and ignorance"?
猜你喜欢
Detailed explanation of serialization and deserialization
Stack and queue
Fedora/rehl installation semanage
综合能力测评系统
How does computer nail adjust sound
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
The value of two date types is subtracted and converted to seconds
Lombok principle and the pit of ⽤ @data and @builder at the same time
随机推荐
Python book learning notes - Chapter 09 section 01 create and use classes
Lombok principle and the pit of ⽤ @data and @builder at the same time
[face recognition series] | realize automatic makeup
查询mysql数据库中各表记录数大小
P3500 [poi2010]tes intelligence test (two points & offline)
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
Mixed development of QML and QWidget (preliminary exploration)
Certbot failed to update certificate solution
Web components series (VII) -- life cycle of custom components
Data processing methods - smote series and adasyn
1291_Xshell日志中增加时间戳的功能
2/12 didn't learn anything
Detailed explanation of serialization and deserialization
VPP performance test
How does computer nail adjust sound
[FPGA tutorial case 11] design and implementation of divider based on vivado core
VPP性能测试
Redis (replicate dictionary server) cache
POI add border
pd. to_ numeric