| 180 | |
| 181 | |
| 182 | class SELayer(nn.Module): |
| 183 | def __init__(self, channel, reduction=16): |
| 184 | super(SELayer, self).__init__() |
| 185 | self.avg_pool = nn.AdaptiveAvgPool2d(1) |
| 186 | self.fc = nn.Sequential( |
| 187 | nn.Linear(channel, channel // reduction, bias=False), |
| 188 | nn.ReLU(inplace=True), |
| 189 | nn.Linear(channel // reduction, channel, bias=False), |
| 190 | nn.Sigmoid() |
| 191 | ) |
| 192 | |
| 193 | def forward(self, x): |
| 194 | b, c, _, _ = x.size() |
| 195 | y = self.avg_pool(x).view(b, c) |
| 196 | y = self.fc(y).view(b, c, 1, 1) |
| 197 | return x * y.expand_as(x) |
| 198 | |
| 199 | |
| 200 | class SEBasicBlock(nn.Module): |