Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
f91a1823
Commit
f91a1823
authored
Sep 11, 2018
by
Tongzhou Wang
Committed by
Soumith Chintala
Sep 11, 2018
Browse files
fix py37 warning (#600)
parent
fc7911c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
6 deletions
+23
-6
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+12
-4
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+11
-2
No files found.
torchvision/transforms/functional.py
View file @
f91a1823
from
__future__
import
division
from
__future__
import
division
import
torch
import
torch
import
sys
import
math
import
math
import
random
import
random
from
PIL
import
Image
,
ImageOps
,
ImageEnhance
,
PILLOW_VERSION
from
PIL
import
Image
,
ImageOps
,
ImageEnhance
,
PILLOW_VERSION
...
@@ -13,6 +14,13 @@ import types
...
@@ -13,6 +14,13 @@ import types
import
collections
import
collections
import
warnings
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
):
def
_is_pil_image
(
img
):
if
accimage
is
not
None
:
if
accimage
is
not
None
:
...
@@ -191,7 +199,7 @@ def resize(img, size, interpolation=Image.BILINEAR):
...
@@ -191,7 +199,7 @@ def resize(img, size, interpolation=Image.BILINEAR):
"""
"""
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
)))
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
))
raise
TypeError
(
'Got inappropriate size arg: {}'
.
format
(
size
))
if
isinstance
(
size
,
int
):
if
isinstance
(
size
,
int
):
...
@@ -258,7 +266,7 @@ def pad(img, padding, fill=0, padding_mode='constant'):
...
@@ -258,7 +266,7 @@ def pad(img, padding, fill=0, padding_mode='constant'):
if
not
isinstance
(
padding_mode
,
str
):
if
not
isinstance
(
padding_mode
,
str
):
raise
TypeError
(
'Got inappropriate padding_mode arg'
)
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 "
+
raise
ValueError
(
"Padding must be an int or a 2, or 4 element tuple, not a "
+
"{} element tuple"
.
format
(
len
(
padding
)))
"{} element tuple"
.
format
(
len
(
padding
)))
...
@@ -270,10 +278,10 @@ def pad(img, padding, fill=0, padding_mode='constant'):
...
@@ -270,10 +278,10 @@ def pad(img, padding, fill=0, padding_mode='constant'):
else
:
else
:
if
isinstance
(
padding
,
int
):
if
isinstance
(
padding
,
int
):
pad_left
=
pad_right
=
pad_top
=
pad_bottom
=
padding
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_left
=
pad_right
=
padding
[
0
]
pad_top
=
pad_bottom
=
padding
[
1
]
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_left
=
padding
[
0
]
pad_top
=
padding
[
1
]
pad_top
=
padding
[
1
]
pad_right
=
padding
[
2
]
pad_right
=
padding
[
2
]
...
...
torchvision/transforms/transforms.py
View file @
f91a1823
from
__future__
import
division
from
__future__
import
division
import
torch
import
torch
import
math
import
math
import
sys
import
random
import
random
from
PIL
import
Image
,
ImageOps
,
ImageEnhance
from
PIL
import
Image
,
ImageOps
,
ImageEnhance
try
:
try
:
...
@@ -15,6 +16,14 @@ import warnings
...
@@ -15,6 +16,14 @@ import warnings
from
.
import
functional
as
F
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"
,
__all__
=
[
"Compose"
,
"ToTensor"
,
"ToPILImage"
,
"Normalize"
,
"Resize"
,
"Scale"
,
"CenterCrop"
,
"Pad"
,
"Lambda"
,
"RandomApply"
,
"RandomChoice"
,
"RandomOrder"
,
"RandomCrop"
,
"RandomHorizontalFlip"
,
"Lambda"
,
"RandomApply"
,
"RandomChoice"
,
"RandomOrder"
,
"RandomCrop"
,
"RandomHorizontalFlip"
,
"RandomVerticalFlip"
,
"RandomResizedCrop"
,
"RandomSizedCrop"
,
"FiveCrop"
,
"TenCrop"
,
"LinearTransformation"
,
"RandomVerticalFlip"
,
"RandomResizedCrop"
,
"RandomSizedCrop"
,
"FiveCrop"
,
"TenCrop"
,
"LinearTransformation"
,
...
@@ -163,7 +172,7 @@ class Resize(object):
...
@@ -163,7 +172,7 @@ class Resize(object):
"""
"""
def
__init__
(
self
,
size
,
interpolation
=
Image
.
BILINEAR
):
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
.
size
=
size
self
.
interpolation
=
interpolation
self
.
interpolation
=
interpolation
...
@@ -255,7 +264,7 @@ class Pad(object):
...
@@ -255,7 +264,7 @@ class Pad(object):
assert
isinstance
(
padding
,
(
numbers
.
Number
,
tuple
))
assert
isinstance
(
padding
,
(
numbers
.
Number
,
tuple
))
assert
isinstance
(
fill
,
(
numbers
.
Number
,
str
,
tuple
))
assert
isinstance
(
fill
,
(
numbers
.
Number
,
str
,
tuple
))
assert
padding_mode
in
[
'constant'
,
'edge'
,
'reflect'
,
'symmetric'
]
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 "
+
raise
ValueError
(
"Padding must be an int or a 2, or 4 element tuple, not a "
+
"{} element tuple"
.
format
(
len
(
padding
)))
"{} element tuple"
.
format
(
len
(
padding
)))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment