x: (N, L, patch_size**2 *chans) imgs: (N, chans, H, W)
(self, x)
| 390 | return x |
| 391 | |
| 392 | def unpatchify(self, x): |
| 393 | """ |
| 394 | x: (N, L, patch_size**2 *chans) |
| 395 | imgs: (N, chans, H, W) |
| 396 | """ |
| 397 | p = self.patch_embed.patch_size[0] |
| 398 | h = w = int(x.shape[1]**.5) |
| 399 | assert h * w == x.shape[1] |
| 400 | num_chans = x.size(-1)//(p**2) |
| 401 | assert p**2 * num_chans == x.size(-1) |
| 402 | |
| 403 | x = x.reshape(shape=(x.shape[0], h, w, p, p, num_chans)) |
| 404 | x = torch.einsum('nhwpqc->nchpwq', x) |
| 405 | imgs = x.reshape(shape=(x.shape[0], num_chans, h * p, h * p)) |
| 406 | return imgs |
| 407 | |
| 408 | def random_masking(self, x, mask_ratio): |
| 409 | """ |
no outgoing calls
no test coverage detected