From c3e616e46d2851bd1ed998c2e372152925ddde1c Mon Sep 17 00:00:00 2001 From: George Panchuk Date: Fri, 25 Sep 2026 13:33:41 +0700 Subject: [PATCH] fix: round Jina CLIP crop offsets to match Jina's reference --- fastembed/image/transform/functional.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fastembed/image/transform/functional.py b/fastembed/image/transform/functional.py index bfee639c..ed6f880a 100644 --- a/fastembed/image/transform/functional.py +++ b/fastembed/image/transform/functional.py @@ -144,14 +144,16 @@ def pad2square( left, right = 0, width top, bottom = 0, height + # Jina's reference crops with torchvision's CenterCrop, which rounds the offset half to + # even like round() instead of flooring it: a 227 px edge is cropped from 2, not 1 crop_required = False if width > size: - left = (width - size) // 2 + left = round((width - size) / 2) right = left + size crop_required = True if height > size: - top = (height - size) // 2 + top = round((height - size) / 2) bottom = top + size crop_required = True