Safemotion Lib
Loading...
Searching...
No Matches
se_layer.py
Go to the documentation of this file.
1# encoding: utf-8
2"""
3@author: liaoxingyu
4@contact: sherlockliao01@gmail.com
5"""
6
7from torch import nn
8
9
10class SELayer(nn.Module):
11 def __init__(self, channel, reduction=16):
12 super(SELayer, self).__init__()
13 self.avg_pool = nn.AdaptiveAvgPool2d(1)
14 self.fc = nn.Sequential(
15 nn.Linear(channel, int(channel / reduction), bias=False),
16 nn.ReLU(inplace=True),
17 nn.Linear(int(channel / reduction), channel, bias=False),
18 nn.Sigmoid()
19 )
20
21 def forward(self, x):
22 b, c, _, _ = x.size()
23 y = self.avg_pool(x).view(b, c)
24 y = self.fc(y).view(b, c, 1, 1)
25 return x * y.expand_as(x)
__init__(self, channel, reduction=16)
Definition se_layer.py:11