当前位置:网站首页>[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
边栏推荐
- 绑定在游戏对象上的脚本的执行顺序
- [tomato assistant installation]
- Certbot failed to update certificate solution
- Recommendation | recommendation of 9 psychotherapy books
- pd. to_ numeric
- P3500 [POI2010]TES-Intelligence Test(二分&离线)
- How to execute an SQL statement in MySQL
- DM8 archive log file manual switching
- DM8 backup set deletion
- Query the number and size of records in each table in MySQL database
猜你喜欢
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
Tips for using dm8huge table
颠覆你的认知?get和post请求的本质
Viewing and verifying backup sets using dmrman
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
How does computer nail adjust sound
Fundamentals of SQL database operation
Lombok原理和同时使⽤@Data和@Builder 的坑
10個 Istio 流量管理 最常用的例子,你知道幾個?
Fedora/REHL 安装 semanage
随机推荐
IDEA编译JSP页面生成的class文件路径
P2022 interesting numbers (binary & digit DP)
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
Execution order of scripts bound to game objects
. Net interprocess communication
Mixed development of QML and QWidget (preliminary exploration)
P2102 floor tile laying (DFS & greed)
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
729. 我的日程安排表 I(set or 动态开点线段树)
How does computer nail adjust sound
P2102 地砖铺设(dfs&贪心)
E. Best Pair
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
2/12 didn't learn anything
The value of two date types is subtracted and converted to seconds
捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
lora网关以太网传输
Certbot failed to update certificate solution
Basic knowledge of binary tree, BFC, DFS