MCPcopy Create free account
hub / github.com/ByteDance-Seed/Bagel / patchify

Function patchify

data/data_utils.py:43–50  ·  view source on GitHub ↗
(image, patch_size)

Source from the content-addressed store, hash-verified

41
42
43def 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
53def get_flattened_position_ids_extrapolate(img_h, img_w, patch_size, max_num_patches_per_side):

Callers 2

prepare_vit_imagesMethod · 0.90
pack_sequenceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected