| 53 | |
| 54 | |
| 55 | class SE_Block(nn.Module): |
| 56 | def __init__(self, c, r=16): |
| 57 | super().__init__() |
| 58 | self.squeeze = GAP() |
| 59 | self.excitation = nn.Sequential( |
| 60 | nn.Linear(c, c // r, bias=False), |
| 61 | nn.ReLU(inplace=True), |
| 62 | nn.Linear(c // r, c, bias=False), |
| 63 | nn.Sigmoid() |
| 64 | ) |
| 65 | |
| 66 | def forward(self, x): |
| 67 | b, c, f = x.shape |
| 68 | y = self.squeeze(x).view(b, c) |
| 69 | y = self.excitation(y).view(b, c, 1) |
| 70 | return x * y.expand_as(x) |
| 71 | |
| 72 | |
| 73 | class FeatureProjector(nn.Module): |