Skip to content

Commit ca5d4db

Browse files
vfdev-5fmassa
authored andcommitted
Add testing case with Pillow-SIMD, fix bug in RandomAffine if Pillow<5.0.0, add missing docs for affine (#439)
1 parent 5b75a27 commit ca5d4db

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

.travis.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
language: python
2-
python:
3-
- "2.7"
4-
- "3.5"
2+
3+
matrix:
4+
include:
5+
- env: LINT_CHECK
6+
python: "2.7"
7+
install: pip install flake8
8+
script: flake8
9+
- python: "2.7"
10+
env: IMAGE_BACKEND=Pillow-SIMD
11+
- python: "2.7"
12+
- python: "3.5"
13+
env: IMAGE_BACKEND=Pillow-SIMD
14+
- python: "3.5"
515

616
install:
717
- sudo apt-get update
@@ -18,13 +28,9 @@ install:
1828
- source activate test-environment
1929
- python setup.py install
2030
- pip install --upgrade pytest
21-
31+
- if [[ "$IMAGE_BACKEND" == "Pillow-SIMD" ]]; then
32+
pip uninstall -y pillow && CC="cc -march=native" pip install --force-reinstall pillow-simd;
33+
fi
2234
script:
2335
- pytest test/
2436

25-
matrix:
26-
include:
27-
- env: LINT_CHECK
28-
python: "2.7"
29-
install: pip install flake8
30-
script: flake8

docs/source/transforms.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Transforms on PIL Image
4040

4141
.. autoclass:: RandomRotation
4242

43+
.. autoclass:: RandomAffine
44+
4345
Transforms on torch.\*Tensor
4446
----------------------------
4547

torchvision/transforms/functional.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import torch
33
import math
44
import random
5-
from PIL import Image, ImageOps, ImageEnhance
5+
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
66
try:
77
import accimage
88
except ImportError:
@@ -604,7 +604,7 @@ def affine(img, angle, translate, scale, shear, resample=0, fillcolor=None):
604604
An optional resampling filter.
605605
See http://pillow.readthedocs.io/en/3.4.x/handbook/concepts.html#filters
606606
If omitted, or if the image has mode "1" or "P", it is set to PIL.Image.NEAREST.
607-
fillcolor (int): Optional fill color for the area outside the transform in the output image.
607+
fillcolor (int): Optional fill color for the area outside the transform in the output image. (Pillow>=5.0.0)
608608
"""
609609
if not _is_pil_image(img):
610610
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
@@ -617,7 +617,8 @@ def affine(img, angle, translate, scale, shear, resample=0, fillcolor=None):
617617
output_size = img.size
618618
center = (img.size[0] * 0.5 + 0.5, img.size[1] * 0.5 + 0.5)
619619
matrix = _get_inverse_affine_matrix(center, angle, translate, scale, shear)
620-
return img.transform(output_size, Image.AFFINE, matrix, resample, fillcolor=fillcolor)
620+
kwargs = {"fillcolor": fillcolor} if PILLOW_VERSION[0] == '5' else {}
621+
return img.transform(output_size, Image.AFFINE, matrix, resample, **kwargs)
621622

622623

623624
def to_grayscale(img, num_output_channels=1):

torchvision/transforms/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ class RandomAffine(object):
828828
An optional resampling filter.
829829
See http://pillow.readthedocs.io/en/3.4.x/handbook/concepts.html#filters
830830
If omitted, or if the image has mode "1" or "P", it is set to PIL.Image.NEAREST.
831-
fillcolor (int): Optional fill color for the area outside the transform in the output image.
831+
fillcolor (int): Optional fill color for the area outside the transform in the output image. (Pillow>=5.0.0)
832832
"""
833833

834834
def __init__(self, degrees, translate=None, scale=None, shear=None, resample=False, fillcolor=0):

0 commit comments

Comments
 (0)