Multilayer perceptron.
| 24 | |
| 25 | |
| 26 | class Mlp(nn.Module): |
| 27 | """Multilayer perceptron.""" |
| 28 | |
| 29 | def __init__( |
| 30 | self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0 |
| 31 | ): |
| 32 | super().__init__() |
| 33 | out_features = out_features or in_features |
| 34 | hidden_features = hidden_features or in_features |
| 35 | self.fc1 = nn.Linear(in_features, hidden_features) |
| 36 | self.act = act_layer() |
| 37 | self.fc2 = nn.Linear(hidden_features, out_features) |
| 38 | self.drop = nn.Dropout(drop) |
| 39 | |
| 40 | def forward(self, x): |
| 41 | x = self.fc1(x) |
| 42 | x = self.act(x) |
| 43 | x = self.drop(x) |
| 44 | x = self.fc2(x) |
| 45 | x = self.drop(x) |
| 46 | return x |
| 47 | |
| 48 | |
| 49 | def window_partition(x, window_size): |