Skip to content

Fix py37 warning #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions torchvision/transforms/functional.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division
import torch
import sys
import math
import random
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
Expand All @@ -13,6 +14,13 @@
import collections
import warnings

if sys.version_info < (3, 3):
Sequence = collections.Sequence
Iterable = collections.Iterable
else:
Sequence = collections.abc.Sequence
Iterable = collections.abc.Iterable


def _is_pil_image(img):
if accimage is not None:
Expand Down Expand Up @@ -191,7 +199,7 @@ def resize(img, size, interpolation=Image.BILINEAR):
"""
if not _is_pil_image(img):
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
if not (isinstance(size, int) or (isinstance(size, collections.Iterable) and len(size) == 2)):
if not (isinstance(size, int) or (isinstance(size, Iterable) and len(size) == 2)):
raise TypeError('Got inappropriate size arg: {}'.format(size))

if isinstance(size, int):
Expand Down Expand Up @@ -258,7 +266,7 @@ def pad(img, padding, fill=0, padding_mode='constant'):
if not isinstance(padding_mode, str):
raise TypeError('Got inappropriate padding_mode arg')

if isinstance(padding, collections.Sequence) and len(padding) not in [2, 4]:
if isinstance(padding, Sequence) and len(padding) not in [2, 4]:
raise ValueError("Padding must be an int or a 2, or 4 element tuple, not a " +
"{} element tuple".format(len(padding)))

Expand All @@ -270,10 +278,10 @@ def pad(img, padding, fill=0, padding_mode='constant'):
else:
if isinstance(padding, int):
pad_left = pad_right = pad_top = pad_bottom = padding
if isinstance(padding, collections.Sequence) and len(padding) == 2:
if isinstance(padding, Sequence) and len(padding) == 2:
pad_left = pad_right = padding[0]
pad_top = pad_bottom = padding[1]
if isinstance(padding, collections.Sequence) and len(padding) == 4:
if isinstance(padding, Sequence) and len(padding) == 4:
pad_left = padding[0]
pad_top = padding[1]
pad_right = padding[2]
Expand Down
13 changes: 11 additions & 2 deletions torchvision/transforms/transforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import division
import torch
import math
import sys
import random
from PIL import Image, ImageOps, ImageEnhance
try:
Expand All @@ -15,6 +16,14 @@

from . import functional as F

if sys.version_info < (3, 3):
Sequence = collections.Sequence
Iterable = collections.Iterable
else:
Sequence = collections.abc.Sequence
Iterable = collections.abc.Iterable


__all__ = ["Compose", "ToTensor", "ToPILImage", "Normalize", "Resize", "Scale", "CenterCrop", "Pad",
"Lambda", "RandomApply", "RandomChoice", "RandomOrder", "RandomCrop", "RandomHorizontalFlip",
"RandomVerticalFlip", "RandomResizedCrop", "RandomSizedCrop", "FiveCrop", "TenCrop", "LinearTransformation",
Expand Down Expand Up @@ -163,7 +172,7 @@ class Resize(object):
"""

def __init__(self, size, interpolation=Image.BILINEAR):
assert isinstance(size, int) or (isinstance(size, collections.Iterable) and len(size) == 2)
assert isinstance(size, int) or (isinstance(size, Iterable) and len(size) == 2)
self.size = size
self.interpolation = interpolation

Expand Down Expand Up @@ -255,7 +264,7 @@ def __init__(self, padding, fill=0, padding_mode='constant'):
assert isinstance(padding, (numbers.Number, tuple))
assert isinstance(fill, (numbers.Number, str, tuple))
assert padding_mode in ['constant', 'edge', 'reflect', 'symmetric']
if isinstance(padding, collections.Sequence) and len(padding) not in [2, 4]:
if isinstance(padding, Sequence) and len(padding) not in [2, 4]:
raise ValueError("Padding must be an int or a 2, or 4 element tuple, not a " +
"{} element tuple".format(len(padding)))

Expand Down