Radix Softmax module in ``SplitAttentionConv2d``. Args: radix (int): Radix of input. groups (int): Groups of input.
| 14 | |
| 15 | |
| 16 | class RSoftmax(nn.Module): |
| 17 | """Radix Softmax module in ``SplitAttentionConv2d``. |
| 18 | |
| 19 | Args: |
| 20 | radix (int): Radix of input. |
| 21 | groups (int): Groups of input. |
| 22 | """ |
| 23 | |
| 24 | def __init__(self, radix, groups): |
| 25 | super().__init__() |
| 26 | self.radix = radix |
| 27 | self.groups = groups |
| 28 | |
| 29 | def forward(self, x): |
| 30 | batch = x.size(0) |
| 31 | if self.radix > 1: |
| 32 | x = x.view(batch, self.groups, self.radix, -1).transpose(1, 2) |
| 33 | x = F.softmax(x, dim=1) |
| 34 | x = x.reshape(batch, -1) |
| 35 | else: |
| 36 | x = torch.sigmoid(x) |
| 37 | return x |
| 38 | |
| 39 | |
| 40 | class SplitAttentionConv2d(nn.Module): |