From f692ec95e1bf30d50aeabe2fd32008cdff53ef5e Mon Sep 17 00:00:00 2001 From: Nikolaus Korfhage Date: Thu, 14 Sep 2023 13:07:44 +0200 Subject: [PATCH] Fixed padding error in ResizeMaxSize --- src/open_clip/transform.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/open_clip/transform.py b/src/open_clip/transform.py index 748884a3c..ab13a21aa 100644 --- a/src/open_clip/transform.py +++ b/src/open_clip/transform.py @@ -40,9 +40,10 @@ def forward(self, img): else: width, height = img.size scale = self.max_size / float(max(height, width)) + new_size = tuple(round(dim * scale) for dim in (height, width)) if scale != 1.0: - new_size = tuple(round(dim * scale) for dim in (height, width)) img = F.resize(img, new_size, self.interpolation) + if not width == height: pad_h = self.max_size - new_size[0] pad_w = self.max_size - new_size[1] img = F.pad(img, padding=[pad_w//2, pad_h//2, pad_w - pad_w//2, pad_h - pad_h//2], fill=self.fill)