(image, patch_size)
| 41 | |
| 42 | |
| 43 | def patchify(image, patch_size): |
| 44 | p = patch_size |
| 45 | c, h, w = image.shape |
| 46 | assert h % p == 0 and w % p == 0 |
| 47 | image = image.reshape(c, h // p, p, w // p, p) |
| 48 | image = torch.einsum("chpwq->hwpqc", image) |
| 49 | image = image.reshape(-1, p**2 * c) |
| 50 | return image |
| 51 | |
| 52 | |
| 53 | def get_flattened_position_ids_extrapolate(img_h, img_w, patch_size, max_num_patches_per_side): |
no outgoing calls
no test coverage detected