From 5e240049aec6541050c75c5f3907d5a12206fd88 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Fri, 17 Jun 2022 02:46:20 -0700 Subject: [PATCH] [fbsync] Update _pil_constants.py (#6154) Summary: * Update _pil_constants.py * Update _pil_constants.py * Fix flake8 * Fixed two related warnings in tests * switch dir with hasattr Reviewed By: datumbox Differential Revision: D37212661 fbshipit-source-id: de82b320b5d8d1a76f56dfe531678f2e81c5c3e0 Co-authored-by: Vasilis Vryniotis --- test/test_transforms.py | 4 ++-- torchvision/transforms/_pil_constants.py | 3 +-- 2 files changed, 3 insertions(+), 4 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 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