Apologies if I haven't understood how resizing works with PIL. With this the following bit of the (original) code, it seems you set aspect_ratio = width / height, but when comparing, you swap the two. Reason I have swapped the two is because in the first line you have width, height = image.size

        width, height = image.size
        max_dim = max(width, height)
        if max_dim < 512:
            im_size = (378, 378)
        else:
            aspect_ratio = width / height
            im_size = min(
                self.supported_sizes,
                key=lambda size: (
                    abs((size[1] / size[0]) - aspect_ratio),
                    abs(size[0] - width) + abs(size[1] - height),
                ),
            )

imho, still, this block seems to be working correctly. please check it more carefully
as test, width, height = 10, 1000 -> im_size = (756, 378) => return Compose( [ Resize(size=im_size, ...
o torchvision resize size argument is a sequence like (h, w)

I'll double check later but yeah, I'm pretty sure this works correctly. I spent a bunch of time in a Jupyter notebook visualizing different image resolutions to verify correctness while originally implementing this.

Confirmed that the code works correctly, although the variable names are misleading (e.g. aspect_ratio is actually the inverse of what normal people would call aspect ratio).

vikhyatk changed pull request status to closed

Sign up or log in to comment