Skip to content

Commit 7fdcae5

Browse files
fmassafacebook-github-bot
authored andcommitted
[fbsync] Bump PIL dependency to >=5.3.0 and run 5.3.0 on some CI runs (#3641)
Summary: * bump to 5.3.0 * Also make 3.6 CI runs rely on 5.3.0 Reviewed By: NicolasHug Differential Revision: D27706951 fbshipit-source-id: 93f598655a26ad9935f4ba910ab35b758970e2c4
1 parent c1ec02e commit 7fdcae5

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

.circleci/unittest/linux/scripts/install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,11 @@ fi
2626
printf "Installing PyTorch with %s\n" "${cudatoolkit}"
2727
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}"
2828

29+
if [ $PYTHON_VERSION == "3.6" ]; then
30+
printf "Installing minimal PILLOW version\n"
31+
# Install the minimal PILLOW version. Otherwise, let setup.py install the latest
32+
pip install pillow==5.3.0
33+
fi
34+
2935
printf "* Installing torchvision\n"
3036
python setup.py develop

.circleci/unittest/windows/scripts/install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,11 @@ fi
2828
printf "Installing PyTorch with %s\n" "${cudatoolkit}"
2929
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c conda-forge "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}"
3030

31+
if [ $PYTHON_VERSION == "3.6" ]; then
32+
printf "Installing minimal PILLOW version\n"
33+
# Install the minimal PILLOW version. Otherwise, let setup.py install the latest
34+
pip install pillow==5.3.0
35+
fi
36+
3137
printf "* Installing torchvision\n"
3238
"$this_dir/vc_env_helper.bat" python setup.py develop

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def write_version_file():
6767
pytorch_dep,
6868
]
6969

70-
pillow_ver = ' >= 4.1.1'
70+
pillow_ver = ' >= 5.3.0'
7171
pillow_req = 'pillow-simd' if get_dist('pillow-simd') is not None else 'pillow'
7272
requirements.append(pillow_req + pillow_ver)
7373

torchvision/transforms/functional.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def _interpolation_modes_from_int(i: int) -> InterpolationMode:
5555
}
5656

5757
_is_pil_image = F_pil._is_pil_image
58-
_parse_fill = F_pil._parse_fill
5958

6059

6160
def _get_image_size(img: Tensor) -> List[int]:

torchvision/transforms/functional_pil.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import numpy as np
55
import torch
6-
from PIL import Image, ImageOps, ImageEnhance, __version__ as PILLOW_VERSION
6+
from PIL import Image, ImageOps, ImageEnhance
77

88
try:
99
import accimage
@@ -147,7 +147,7 @@ def pad(img, padding, fill=0, padding_mode="constant"):
147147
raise ValueError("Padding mode should be either constant, edge, reflect or symmetric")
148148

149149
if padding_mode == "constant":
150-
opts = _parse_fill(fill, img, "2.3.0", name="fill")
150+
opts = _parse_fill(fill, img, name="fill")
151151
if img.mode == "P":
152152
palette = img.getpalette()
153153
image = ImageOps.expand(img, border=padding, **opts)
@@ -242,18 +242,8 @@ def resize(img, size, interpolation=Image.BILINEAR, max_size=None):
242242

243243

244244
@torch.jit.unused
245-
def _parse_fill(fill, img, min_pil_version, name="fillcolor"):
245+
def _parse_fill(fill, img, name="fillcolor"):
246246
# Process fill color for affine transforms
247-
major_found, minor_found = (int(v) for v in PILLOW_VERSION.split('.')[:2])
248-
major_required, minor_required = (int(v) for v in min_pil_version.split('.')[:2])
249-
if major_found < major_required or (major_found == major_required and minor_found < minor_required):
250-
if fill is None:
251-
return {}
252-
else:
253-
msg = ("The option to fill background area of the transformed image, "
254-
"requires pillow>={}")
255-
raise RuntimeError(msg.format(min_pil_version))
256-
257247
num_bands = len(img.getbands())
258248
if fill is None:
259249
fill = 0
@@ -276,7 +266,7 @@ def affine(img, matrix, interpolation=0, fill=None):
276266
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
277267

278268
output_size = img.size
279-
opts = _parse_fill(fill, img, '5.0.0')
269+
opts = _parse_fill(fill, img)
280270
return img.transform(output_size, Image.AFFINE, matrix, interpolation, **opts)
281271

282272

@@ -285,7 +275,7 @@ def rotate(img, angle, interpolation=0, expand=False, center=None, fill=None):
285275
if not _is_pil_image(img):
286276
raise TypeError("img should be PIL Image. Got {}".format(type(img)))
287277

288-
opts = _parse_fill(fill, img, '5.2.0')
278+
opts = _parse_fill(fill, img)
289279
return img.rotate(angle, interpolation, expand, center, **opts)
290280

291281

@@ -294,7 +284,7 @@ def perspective(img, perspective_coeffs, interpolation=Image.BICUBIC, fill=None)
294284
if not _is_pil_image(img):
295285
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
296286

297-
opts = _parse_fill(fill, img, '5.0.0')
287+
opts = _parse_fill(fill, img)
298288

299289
return img.transform(img.size, Image.PERSPECTIVE, perspective_coeffs, interpolation, **opts)
300290

0 commit comments

Comments
 (0)