当前位置:网站首页>SEAttention 通道注意力机制
SEAttention 通道注意力机制
2022-06-29 04:05:00 【ViatorSun】

基于通道的注意力机制 源自于 CVPR2018: Squeeze-and-Excitation Networks
官方代码:https://github.com/hujie-frank/SENet

import numpy as np
import torch
from torch import nn
from torch.nn import init
class SEAttention(nn.Module):
def __init__(self, channel=512,reduction=16):
super().__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.se = nn.Sequential(nn.Linear(channel, channel // reduction, bias=False),
nn.ReLU(inplace=True),
nn.Linear(channel // reduction, channel, bias=False),
nn.Sigmoid() )
def init_weights(self):
for m in self.modules():
if isinstance(m, nn.Conv2d):
init.kaiming_normal_(m.weight, mode='fan_out')
if m.bias is not None:
init.constant_(m.bias, 0)
elif isinstance(m, nn.BatchNorm2d):
init.constant_(m.weight, 1)
init.constant_(m.bias, 0)
elif isinstance(m, nn.Linear):
init.normal_(m.weight, std=0.001)
if m.bias is not None:
init.constant_(m.bias, 0)
def forward(self, x):
b, c, _, _ = x.size()
y = self.avg_pool(x).view(b, c)
y = self.se(y).view(b, c, 1, 1)
return x * y.expand_as(x)
if __name__ == '__main__':
feature = torch.randn(50,512,7,7)
se = SEAttention(channel=512,reduction=8)
output = se(feature)
print(output.shape)
边栏推荐
- 【Laravel系列8】走出 Laravel 的世界
- Pytorch read / write file
- 树莓派用VNC Viewer方式远程连接
- 【滤波器设计】根据设计指标使用matlab定制滤波器
- MySQL review materials (additional) case when
- Kingbase export table structure
- Data collection and management [4]
- [nrf51][nrf52] nrfconnect installation instructions guide
- Implementing mqtt communication with PHP
- PostgreSQL 出现cross-database references are not implemented的bug
猜你喜欢

开发者方案 · 环境监测设备(小熊派物联网开发板)接入涂鸦IoT开发平台

要不是和阿里P7聊过,我也不知道自己是个棒槌

百度智能云服务网格产品CSM发布 | 火热公测中

What is the dry goods microservice architecture? What are the advantages and disadvantages?

女程序员晒出5月的工资条:工资是高,但是真累,网友评论炸锅了

科班出身,结果外包都不要

Microsecond TCP timestamp

微秒级 TCP 时间戳

iNFTnews | 元宇宙技术将带来全新的购物体验
![[new function] ambire wallet integrates Metis network](/img/29/8a8c0cd40c51cef1174ee59706d4c9.png)
[new function] ambire wallet integrates Metis network
随机推荐
欧拉开源社区第二届理事会第二次会议召开,新华三、超聚变和龙芯中科成为理事会成员单位
科班出身,结果外包都不要
Source code analysis of go redsync distributed lock
Data statistical analysis (SPSS) [8]
Data collection and management [3]
Pytorch read / write file
Data collection and management [15]
请问大佬,Oracle CDC报错 Call snapshotState on closed sou
树莓派用VNC Viewer方式远程连接
百度智能云服务网格产品CSM发布 | 火热公测中
[FPGA mathematical formula] use FPGA to realize common mathematical formulas
为什么说测试岗位是巨坑?8年测试人告诉你千万别上当
PATH 与 LD_LIBRARY_PATH 的用法举例
Binary tree serialization and deserialization (leetcode (difficult))
webassembly学习-动态链接
Data collection and management [9]
【C语言】开启一个线程
情绪的变化需要控制
CDC2.2.1还不支持postgresql14.1么?基于pgbouncer连接方式下,以5433
Devops note-05: what are the roles of Ba, SM, Po, PM, PD, dev, OPS and QA in the IT industry