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