Commit ca5d4db2 authored by vfdev's avatar vfdev Committed by Francisco Massa
Browse files

Add testing case with Pillow-SIMD, fix bug in RandomAffine if Pillow<5.0.0,...

Add testing case with Pillow-SIMD, fix bug in RandomAffine if Pillow<5.0.0, add missing docs for affine (#439)
parent 5b75a277
language: python language: python
python:
- "2.7" matrix:
- "3.5" include:
- env: LINT_CHECK
python: "2.7"
install: pip install flake8
script: flake8
- python: "2.7"
env: IMAGE_BACKEND=Pillow-SIMD
- python: "2.7"
- python: "3.5"
env: IMAGE_BACKEND=Pillow-SIMD
- python: "3.5"
install: install:
- sudo apt-get update - sudo apt-get update
...@@ -18,13 +28,9 @@ install: ...@@ -18,13 +28,9 @@ install:
- source activate test-environment - source activate test-environment
- python setup.py install - python setup.py install
- pip install --upgrade pytest - pip install --upgrade pytest
- if [[ "$IMAGE_BACKEND" == "Pillow-SIMD" ]]; then
pip uninstall -y pillow && CC="cc -march=native" pip install --force-reinstall pillow-simd;
fi
script: script:
- pytest test/ - pytest test/
matrix:
include:
- env: LINT_CHECK
python: "2.7"
install: pip install flake8
script: flake8
...@@ -40,6 +40,8 @@ Transforms on PIL Image ...@@ -40,6 +40,8 @@ Transforms on PIL Image
.. autoclass:: RandomRotation .. autoclass:: RandomRotation
.. autoclass:: RandomAffine
Transforms on torch.\*Tensor Transforms on torch.\*Tensor
---------------------------- ----------------------------
......
...@@ -2,7 +2,7 @@ from __future__ import division ...@@ -2,7 +2,7 @@ from __future__ import division
import torch import torch
import math import math
import random import random
from PIL import Image, ImageOps, ImageEnhance from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
try: try:
import accimage import accimage
except ImportError: except ImportError:
...@@ -604,7 +604,7 @@ def affine(img, angle, translate, scale, shear, resample=0, fillcolor=None): ...@@ -604,7 +604,7 @@ def affine(img, angle, translate, scale, shear, resample=0, fillcolor=None):
An optional resampling filter. An optional resampling filter.
See http://pillow.readthedocs.io/en/3.4.x/handbook/concepts.html#filters See http://pillow.readthedocs.io/en/3.4.x/handbook/concepts.html#filters
If omitted, or if the image has mode "1" or "P", it is set to PIL.Image.NEAREST. If omitted, or if the image has mode "1" or "P", it is set to PIL.Image.NEAREST.
fillcolor (int): Optional fill color for the area outside the transform in the output image. fillcolor (int): Optional fill color for the area outside the transform in the output image. (Pillow>=5.0.0)
""" """
if not _is_pil_image(img): if not _is_pil_image(img):
raise TypeError('img should be PIL Image. Got {}'.format(type(img))) 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): ...@@ -617,7 +617,8 @@ def affine(img, angle, translate, scale, shear, resample=0, fillcolor=None):
output_size = img.size output_size = img.size
center = (img.size[0] * 0.5 + 0.5, img.size[1] * 0.5 + 0.5) center = (img.size[0] * 0.5 + 0.5, img.size[1] * 0.5 + 0.5)
matrix = _get_inverse_affine_matrix(center, angle, translate, scale, shear) matrix = _get_inverse_affine_matrix(center, angle, translate, scale, shear)
return img.transform(output_size, Image.AFFINE, matrix, resample, fillcolor=fillcolor) kwargs = {"fillcolor": fillcolor} if PILLOW_VERSION[0] == '5' else {}
return img.transform(output_size, Image.AFFINE, matrix, resample, **kwargs)
def to_grayscale(img, num_output_channels=1): def to_grayscale(img, num_output_channels=1):
......
...@@ -828,7 +828,7 @@ class RandomAffine(object): ...@@ -828,7 +828,7 @@ class RandomAffine(object):
An optional resampling filter. An optional resampling filter.
See http://pillow.readthedocs.io/en/3.4.x/handbook/concepts.html#filters See http://pillow.readthedocs.io/en/3.4.x/handbook/concepts.html#filters
If omitted, or if the image has mode "1" or "P", it is set to PIL.Image.NEAREST. If omitted, or if the image has mode "1" or "P", it is set to PIL.Image.NEAREST.
fillcolor (int): Optional fill color for the area outside the transform in the output image. fillcolor (int): Optional fill color for the area outside the transform in the output image. (Pillow>=5.0.0)
""" """
def __init__(self, degrees, translate=None, scale=None, shear=None, resample=False, fillcolor=0): def __init__(self, degrees, translate=None, scale=None, shear=None, resample=False, fillcolor=0):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment