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