当前位置:网站首页>Mécanisme d'attention du canal de fixation
Mécanisme d'attention du canal de fixation
2022-06-29 04:06:00 【Viatorsun】

Mécanisme d'attention basé sur les canaux De CVPR2018: Squeeze-and-Excitation Networks
Code officiel: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)
边栏推荐
- Qtableview gets all currently selected cells
- yolox出现 RuntimeError: DataLoader worker (pid(s) 17724, 1364, 18928) exited unexpectedly
- Ansible best practices playbook different context rights raising demo
- Data collection and management [2]
- The five levels of making money, which level are you on?
- moudo网络库剖析
- Tech Cloud Report: Mixed Office B side: How Safety and Efficiency can be combined?
- 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
- 中小型企业网络的组建
- The great gods take connections from the MySQL connection pool in the open of the rich function. The initialization of the connection pool is 20. If the parallelism of the rich function is 1
猜你喜欢

基于xlsx的B+树索引实现

SQL 数据记录如何上下行合并

Technology cloud report: side B of mixed office: how to have both security and efficiency?

Baidu AI Cloud service grid product CSM release 𞓜 hot public beta

【C语言】解决 “address of stack memory associated with local variable ‘num‘ returned”

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

leetcode:304. 2D area and retrieval - matrix immutable

How sqlserver queries and removes results with null fields in the whole column

Implementation of b+ tree index based on xlsx

Microsecond TCP timestamp
随机推荐
Data collection and management [13]
Baidu AI Cloud service grid product CSM release 𞓜 hot public beta
【新功能】Ambire 钱包集成了 Metis 网络
Why is the test post a giant pit? The 8-year-old tester told you not to be fooled
云原生周报 | Grafana 9正式发布;云原生词汇表中文版现已上线
SQL two columns become multi row filter display
MobileOne: 移动端仅需1ms的高性能骨干
logstash启动过慢甚至卡死
[MCU framework][dfu] DFU upgrade example with CRC verification + timeout mechanism +led indicator + chip locking + chip self erasure
Why are you a test / development programmer? Can you recall
The second meeting of the Second Council of Euler open source community was held, and Xinhua III, hyperfusion and Godson Zhongke became members of the Council
Web crawler knowledge day04
技术:如何设计zkVM电路
Binary tree serialization and deserialization (leetcode (difficult))
Black screen and error reporting when loading custom models for gazebo with roslaunch
Is the sink usually the JDBC insert update delete?
谁家的加密密钥,写死在代码里?(说的就是你)
Data collection and management [2]
多机局域网办公神器 rustdesk 使用强推!!!
【C语言】详解线程回收函数 pthread_join