Skip to content

Commit 72858c1

Browse files
committed
Add siglip2 compatible naflex encoders. Add support to factorized pos embeds and 'aspect preserving mode' to Flex Embeds. Some more docstrings and typing.
1 parent b7ced7c commit 72858c1

File tree

2 files changed

+329
-112
lines changed

2 files changed

+329
-112
lines changed

timm/data/naflex_transforms.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,9 @@ def patchify_image(
749749

750750
# Ensure the image is divisible by patch size
751751
if pad and (h % ph != 0 or w % pw != 0):
752-
new_h = math.ceil(h / ph) * ph
753-
new_w = math.ceil(w / pw) * pw
754-
padded_img = torch.zeros(c, new_h, new_w, dtype=img.dtype)
755-
padded_img[:, :h, :w] = img
756-
img = padded_img
752+
pad_h = (ph - h % ph) % ph # amount to add on bottom
753+
pad_w = (pw - w % pw) % pw # amount to add on right
754+
img = torch.nn.functional.pad(img, (0, pad_w, 0, pad_h))
757755
c, h, w = img.shape
758756

759757
# Calculate number of patches in each dimension

0 commit comments

Comments
 (0)