| 299 | self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size) |
| 300 | |
| 301 | def forward(self, x, mask=None, **kwargs): |
| 302 | # FIXME look at relaxing size constraints |
| 303 | # assert H == self.img_size[0] and W == self.img_size[1], \ |
| 304 | # f"Input image size ({H}*{W}) doesn't match model ({self.img_size[0]}*{self.img_size[1]})." |
| 305 | x = self.proj(x) |
| 306 | Hp, Wp = x.shape[2], x.shape[3] |
| 307 | |
| 308 | x = x.flatten(2).transpose(1, 2) |
| 309 | |
| 310 | if mask is not None: |
| 311 | mask = F.interpolate(mask[None].float(), size=(Hp, Wp)).to(torch.bool)[0] |
| 312 | |
| 313 | return x, (Hp, Wp), mask |
| 314 | |
| 315 | |
| 316 | class Norm2d(nn.Module): |