当前位置:网站首页>SEAttention 通道注意力機制
SEAttention 通道注意力機制
2022-06-29 04:06: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)
边栏推荐
- Technology: how to design zkvm circuit
- [fpga+sin] FPGA implementation of sinusoidal signal generator module based on DDS (direct digital synthesis)
- 选对学校,专科也能进华为~早知道就好了
- Ansible最佳实践之Playbook不同上下文提权Demo
- Call snapstateon closed sou from Oracle CDC
- Data collection and management [9]
- How to back up all data on Apple mobile phone in 2 steps (free)
- 基于可变参模板实现的线程池
- [MCU framework][dfu] DFU upgrade example with CRC verification + timeout mechanism +led indicator + chip locking + chip self erasure
- Zhai Jia: from technical engineer to open source entrepreneur of "net red"
猜你喜欢

Common methods of JS date and time

Wi-Fi 7 来啦,它到底有多强?

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

Share 60 divine vs Code plug-ins

Microsecond TCP timestamp

Influence of air resistance on the trajectory of table tennis

【FPGA+sin】基于DDS(直接数字合成)的正弦信号发生器模块FPGA实现

Why are you a test / development programmer? Can you recall

Four distributed session solutions

Yangzhou needs one English IT Helpdesk Engineer -20220216
随机推荐
百度智能云服务网格产品CSM发布 | 火热公测中
源代码防泄露技术种类浅析
HCIE-Security Day41:理论学习:信息收集与网络探测
MySQL can only add small tables when adding tables dynamically. If you increase the size of tables, you won't read data when running tasks. Is there any solution
[nrf51][nrf52] nrfconnect installation instructions guide
Is the sink usually the JDBC insert update delete?
Data statistical analysis (SPSS) [7]
Efficientnetv2 - get smaller models and faster training with NAS, scaling, and fused mbconv
SQL two columns become multi row filter display
Data statistical analysis (SPSS) [3]
情绪的变化需要控制
Here comes Wi Fi 7. How strong is it?
The efficiency of 20 idea divine plug-ins has been increased by 30 times, and it is necessary to write code
PostgreSQL 出现cross-database references are not implemented的bug
Data statistical analysis (SPSS) [8]
Call snapstateon closed sou from Oracle CDC
iNFTnews | 元宇宙技术将带来全新的购物体验
在命令行登录mysql数据库以及查看版本号
SQL 数据记录如何上下行合并
Web crawler knowledge day04