diff --git a/test/test_transforms.py b/test/test_transforms.py index 04f49cb1376..b9aa16ae6bf 100644 --- a/test/test_transforms.py +++ b/test/test_transforms.py @@ -1522,10 +1522,10 @@ def test_ten_crop(should_vflip, single_dim): five_crop.__repr__() if should_vflip: - vflipped_img = img.transpose(Image.FLIP_TOP_BOTTOM) + vflipped_img = img.transpose(_pil_constants.FLIP_TOP_BOTTOM) expected_output += five_crop(vflipped_img) else: - hflipped_img = img.transpose(Image.FLIP_LEFT_RIGHT) + hflipped_img = img.transpose(_pil_constants.FLIP_LEFT_RIGHT) expected_output += five_crop(hflipped_img) assert len(results) == 10 diff --git a/torchvision/transforms/_pil_constants.py b/torchvision/transforms/_pil_constants.py index b8de5ec94f2..46f6ce5d24d 100644 --- a/torchvision/transforms/_pil_constants.py +++ b/torchvision/transforms/_pil_constants.py @@ -1,10 +1,9 @@ -import PIL from PIL import Image # See https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html#deprecations # TODO: Remove this file once PIL minimal version is >= 9.1 -if tuple(int(part) for part in PIL.__version__.split(".")) >= (9, 1): +if hasattr(Image, "Resampling"): BICUBIC = Image.Resampling.BICUBIC BILINEAR = Image.Resampling.BILINEAR LINEAR = Image.Resampling.BILINEAR