imgs: (N, chs, H, W) x: (N, L, patch_size**2 *chns)
(self, imgs)
| 375 | nn.init.constant_(m.weight, 1.0) |
| 376 | |
| 377 | def patchify(self, imgs): |
| 378 | """ |
| 379 | imgs: (N, chs, H, W) |
| 380 | x: (N, L, patch_size**2 *chns) |
| 381 | """ |
| 382 | p = self.patch_embed.patch_size[0] |
| 383 | assert imgs.shape[2] == imgs.shape[3] and imgs.shape[2] % p == 0 |
| 384 | num_chans = imgs.size(1) |
| 385 | |
| 386 | h = w = imgs.shape[2] // p |
| 387 | x = imgs.reshape(shape=(imgs.shape[0], num_chans, h, p, w, p)) |
| 388 | x = torch.einsum('nchpwq->nhwpqc', x) |
| 389 | x = x.reshape(shape=(imgs.shape[0], h * w, p**2 * num_chans)) |
| 390 | return x |
| 391 | |
| 392 | def unpatchify(self, x): |
| 393 | """ |
no outgoing calls
no test coverage detected