SE Block Proposed in https://arxiv.org/pdf/1709.01507.pdf
| 56 | |
| 57 | |
| 58 | class SEBlock(nn.Module): |
| 59 | """ SE Block Proposed in https://arxiv.org/pdf/1709.01507.pdf |
| 60 | """ |
| 61 | |
| 62 | def __init__(self, in_channels, out_channels, reduction=1): |
| 63 | super(SEBlock, self).__init__() |
| 64 | self.pool = nn.AdaptiveAvgPool2d(1) |
| 65 | self.fc = nn.Sequential( |
| 66 | nn.Linear(in_channels, int(in_channels // reduction), bias=False), |
| 67 | nn.ReLU(inplace=True), |
| 68 | nn.Linear(int(in_channels // reduction), out_channels, bias=False), |
| 69 | nn.Sigmoid() |
| 70 | ) |
| 71 | |
| 72 | def forward(self, x): |
| 73 | b, c, _, _ = x.size() |
| 74 | w = self.pool(x).view(b, c) |
| 75 | w = self.fc(w).view(b, c, 1, 1) |
| 76 | |
| 77 | return x * w.expand_as(x) |
| 78 | |
| 79 | |
| 80 | #------------------------------------------------------------------------------ |