Multilayer perceptron.
| 8 | |
| 9 | |
| 10 | class Mlp(nn.Module): |
| 11 | """Multilayer perceptron.""" |
| 12 | def __init__(self, |
| 13 | in_features, |
| 14 | hidden_features=None, |
| 15 | out_features=None, |
| 16 | act_layer=nn.GELU, |
| 17 | drop=0.): |
| 18 | super().__init__() |
| 19 | out_features = out_features or in_features |
| 20 | hidden_features = hidden_features or in_features |
| 21 | self.fc1 = nn.Linear(in_features, hidden_features) |
| 22 | self.act = act_layer() |
| 23 | self.fc2 = nn.Linear(hidden_features, out_features) |
| 24 | self.drop = nn.Dropout(drop) |
| 25 | |
| 26 | def forward(self, x): |
| 27 | x = self.fc1(x) |
| 28 | x = self.act(x) |
| 29 | x = self.drop(x) |
| 30 | x = self.fc2(x) |
| 31 | x = self.drop(x) |
| 32 | return x |
| 33 | |
| 34 | |
| 35 | def window_partition(x, window_size): |