From 0af02baf1a78d18a1a0a9694cc4862b69a8e0b78 Mon Sep 17 00:00:00 2001 From: vfdev Date: Sat, 11 Jun 2022 00:02:01 +0200 Subject: [PATCH 1/5] Update _pil_constants.py --- torchvision/transforms/_pil_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/transforms/_pil_constants.py b/torchvision/transforms/_pil_constants.py index b8de5ec94f2..4eff5c3cf31 100644 --- a/torchvision/transforms/_pil_constants.py +++ b/torchvision/transforms/_pil_constants.py @@ -4,7 +4,7 @@ # 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 tuple(int(part) if part.isdigit() else -1 for part in version.split(".")[:2]) >= (9, 1): BICUBIC = Image.Resampling.BICUBIC BILINEAR = Image.Resampling.BILINEAR LINEAR = Image.Resampling.BILINEAR From 2666a9a6bfb6dd2abb6954686303bf1f017b4a9b Mon Sep 17 00:00:00 2001 From: vfdev Date: Sat, 11 Jun 2022 00:06:58 +0200 Subject: [PATCH 2/5] Update _pil_constants.py --- torchvision/transforms/_pil_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/transforms/_pil_constants.py b/torchvision/transforms/_pil_constants.py index 4eff5c3cf31..2b9e01cc2a2 100644 --- a/torchvision/transforms/_pil_constants.py +++ b/torchvision/transforms/_pil_constants.py @@ -4,7 +4,7 @@ # 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) if part.isdigit() else -1 for part in version.split(".")[:2]) >= (9, 1): +if "Resampling" in dir(Image): BICUBIC = Image.Resampling.BICUBIC BILINEAR = Image.Resampling.BILINEAR LINEAR = Image.Resampling.BILINEAR From 5c0e3927655de4ed3f384817726465d0e80680bc Mon Sep 17 00:00:00 2001 From: vfdev Date: Sat, 11 Jun 2022 00:10:11 +0200 Subject: [PATCH 3/5] Fix flake8 --- torchvision/transforms/_pil_constants.py | 1 - 1 file changed, 1 deletion(-) diff --git a/torchvision/transforms/_pil_constants.py b/torchvision/transforms/_pil_constants.py index 2b9e01cc2a2..1afc07f5819 100644 --- a/torchvision/transforms/_pil_constants.py +++ b/torchvision/transforms/_pil_constants.py @@ -1,4 +1,3 @@ -import PIL from PIL import Image # See https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html#deprecations From 0b09feb4086bc1eeb1384e7f01b99ef451fa18c9 Mon Sep 17 00:00:00 2001 From: vfdev-5 Date: Sat, 11 Jun 2022 00:27:19 +0200 Subject: [PATCH 4/5] Fixed two related warnings in tests --- test/test_transforms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From f7b587118aa72f0a081eab81bde94e4e57ba1725 Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Sat, 11 Jun 2022 08:54:04 +0100 Subject: [PATCH 5/5] switch dir with hasattr --- torchvision/transforms/_pil_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/transforms/_pil_constants.py b/torchvision/transforms/_pil_constants.py index 1afc07f5819..46f6ce5d24d 100644 --- a/torchvision/transforms/_pil_constants.py +++ b/torchvision/transforms/_pil_constants.py @@ -3,7 +3,7 @@ # 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 "Resampling" in dir(Image): +if hasattr(Image, "Resampling"): BICUBIC = Image.Resampling.BICUBIC BILINEAR = Image.Resampling.BILINEAR LINEAR = Image.Resampling.BILINEAR