|
1 | 1 | from __future__ import division
|
2 | 2 | import torch
|
3 | 3 | import math
|
| 4 | +import sys |
4 | 5 | import random
|
5 | 6 | from PIL import Image, ImageOps, ImageEnhance
|
6 | 7 | try:
|
|
15 | 16 |
|
16 | 17 | from . import functional as F
|
17 | 18 |
|
| 19 | +if sys.version_info < (3, 3): |
| 20 | + Sequence = collections.Sequence |
| 21 | + Iterable = collections.Iterable |
| 22 | +else: |
| 23 | + Sequence = collections.abc.Sequence |
| 24 | + Iterable = collections.abc.Iterable |
| 25 | + |
| 26 | + |
18 | 27 | __all__ = ["Compose", "ToTensor", "ToPILImage", "Normalize", "Resize", "Scale", "CenterCrop", "Pad",
|
19 | 28 | "Lambda", "RandomApply", "RandomChoice", "RandomOrder", "RandomCrop", "RandomHorizontalFlip",
|
20 | 29 | "RandomVerticalFlip", "RandomResizedCrop", "RandomSizedCrop", "FiveCrop", "TenCrop", "LinearTransformation",
|
@@ -163,7 +172,7 @@ class Resize(object):
|
163 | 172 | """
|
164 | 173 |
|
165 | 174 | def __init__(self, size, interpolation=Image.BILINEAR):
|
166 |
| - assert isinstance(size, int) or (isinstance(size, collections.Iterable) and len(size) == 2) |
| 175 | + assert isinstance(size, int) or (isinstance(size, Iterable) and len(size) == 2) |
167 | 176 | self.size = size
|
168 | 177 | self.interpolation = interpolation
|
169 | 178 |
|
@@ -255,7 +264,7 @@ def __init__(self, padding, fill=0, padding_mode='constant'):
|
255 | 264 | assert isinstance(padding, (numbers.Number, tuple))
|
256 | 265 | assert isinstance(fill, (numbers.Number, str, tuple))
|
257 | 266 | assert padding_mode in ['constant', 'edge', 'reflect', 'symmetric']
|
258 |
| - if isinstance(padding, collections.Sequence) and len(padding) not in [2, 4]: |
| 267 | + if isinstance(padding, Sequence) and len(padding) not in [2, 4]: |
259 | 268 | raise ValueError("Padding must be an int or a 2, or 4 element tuple, not a " +
|
260 | 269 | "{} element tuple".format(len(padding)))
|
261 | 270 |
|
|
0 commit comments