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
9e71fdaf
Unverified
Commit
9e71fdaf
authored
Nov 27, 2020
by
Vasilis Vryniotis
Committed by
GitHub
Nov 27, 2020
Browse files
Plural to singular name change. (#3055)
parent
0c445130
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
103 deletions
+103
-103
test/test_functional_tensor.py
test/test_functional_tensor.py
+6
-6
test/test_transforms.py
test/test_transforms.py
+7
-7
test/test_transforms_tensor.py
test/test_transforms_tensor.py
+2
-2
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+53
-53
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+35
-35
No files found.
test/test_functional_tensor.py
View file @
9e71fdaf
...
@@ -9,12 +9,12 @@ import torch
...
@@ -9,12 +9,12 @@ import torch
import
torchvision.transforms.functional_tensor
as
F_t
import
torchvision.transforms.functional_tensor
as
F_t
import
torchvision.transforms.functional_pil
as
F_pil
import
torchvision.transforms.functional_pil
as
F_pil
import
torchvision.transforms.functional
as
F
import
torchvision.transforms.functional
as
F
from
torchvision.transforms
import
InterpolationMode
s
from
torchvision.transforms
import
InterpolationMode
from
common_utils
import
TransformsTester
from
common_utils
import
TransformsTester
NEAREST
,
BILINEAR
,
BICUBIC
=
InterpolationMode
s
.
NEAREST
,
InterpolationMode
s
.
BILINEAR
,
InterpolationMode
s
.
BICUBIC
NEAREST
,
BILINEAR
,
BICUBIC
=
InterpolationMode
.
NEAREST
,
InterpolationMode
.
BILINEAR
,
InterpolationMode
.
BICUBIC
class
Tester
(
TransformsTester
):
class
Tester
(
TransformsTester
):
...
@@ -419,7 +419,7 @@ class Tester(TransformsTester):
...
@@ -419,7 +419,7 @@ class Tester(TransformsTester):
)
)
# assert changed type warning
# assert changed type warning
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode
s
"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode"
):
res1
=
F
.
resize
(
tensor
,
size
=
32
,
interpolation
=
2
)
res1
=
F
.
resize
(
tensor
,
size
=
32
,
interpolation
=
2
)
res2
=
F
.
resize
(
tensor
,
size
=
32
,
interpolation
=
BILINEAR
)
res2
=
F
.
resize
(
tensor
,
size
=
32
,
interpolation
=
BILINEAR
)
self
.
assertTrue
(
res1
.
equal
(
res2
))
self
.
assertTrue
(
res1
.
equal
(
res2
))
...
@@ -626,7 +626,7 @@ class Tester(TransformsTester):
...
@@ -626,7 +626,7 @@ class Tester(TransformsTester):
self
.
assertTrue
(
res1
.
equal
(
res2
))
self
.
assertTrue
(
res1
.
equal
(
res2
))
# assert changed type warning
# assert changed type warning
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode
s
"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode"
):
res1
=
F
.
affine
(
tensor
,
45
,
translate
=
[
0
,
0
],
scale
=
1.0
,
shear
=
[
0.0
,
0.0
],
interpolation
=
2
)
res1
=
F
.
affine
(
tensor
,
45
,
translate
=
[
0
,
0
],
scale
=
1.0
,
shear
=
[
0.0
,
0.0
],
interpolation
=
2
)
res2
=
F
.
affine
(
tensor
,
45
,
translate
=
[
0
,
0
],
scale
=
1.0
,
shear
=
[
0.0
,
0.0
],
interpolation
=
BILINEAR
)
res2
=
F
.
affine
(
tensor
,
45
,
translate
=
[
0
,
0
],
scale
=
1.0
,
shear
=
[
0.0
,
0.0
],
interpolation
=
BILINEAR
)
self
.
assertTrue
(
res1
.
equal
(
res2
))
self
.
assertTrue
(
res1
.
equal
(
res2
))
...
@@ -714,7 +714,7 @@ class Tester(TransformsTester):
...
@@ -714,7 +714,7 @@ class Tester(TransformsTester):
self
.
assertTrue
(
res1
.
equal
(
res2
))
self
.
assertTrue
(
res1
.
equal
(
res2
))
# assert changed type warning
# assert changed type warning
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode
s
"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode"
):
res1
=
F
.
rotate
(
tensor
,
45
,
interpolation
=
2
)
res1
=
F
.
rotate
(
tensor
,
45
,
interpolation
=
2
)
res2
=
F
.
rotate
(
tensor
,
45
,
interpolation
=
BILINEAR
)
res2
=
F
.
rotate
(
tensor
,
45
,
interpolation
=
BILINEAR
)
self
.
assertTrue
(
res1
.
equal
(
res2
))
self
.
assertTrue
(
res1
.
equal
(
res2
))
...
@@ -788,7 +788,7 @@ class Tester(TransformsTester):
...
@@ -788,7 +788,7 @@ class Tester(TransformsTester):
# assert changed type warning
# assert changed type warning
spoints
=
[[
0
,
0
],
[
33
,
0
],
[
33
,
25
],
[
0
,
25
]]
spoints
=
[[
0
,
0
],
[
33
,
0
],
[
33
,
25
],
[
0
,
25
]]
epoints
=
[[
3
,
2
],
[
32
,
3
],
[
30
,
24
],
[
2
,
25
]]
epoints
=
[[
3
,
2
],
[
32
,
3
],
[
30
,
24
],
[
2
,
25
]]
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode
s
"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode"
):
res1
=
F
.
perspective
(
tensor
,
startpoints
=
spoints
,
endpoints
=
epoints
,
interpolation
=
2
)
res1
=
F
.
perspective
(
tensor
,
startpoints
=
spoints
,
endpoints
=
epoints
,
interpolation
=
2
)
res2
=
F
.
perspective
(
tensor
,
startpoints
=
spoints
,
endpoints
=
epoints
,
interpolation
=
BILINEAR
)
res2
=
F
.
perspective
(
tensor
,
startpoints
=
spoints
,
endpoints
=
epoints
,
interpolation
=
BILINEAR
)
self
.
assertTrue
(
res1
.
equal
(
res2
))
self
.
assertTrue
(
res1
.
equal
(
res2
))
...
...
test/test_transforms.py
View file @
9e71fdaf
...
@@ -1500,12 +1500,12 @@ class Tester(unittest.TestCase):
...
@@ -1500,12 +1500,12 @@ class Tester(unittest.TestCase):
# assert deprecation warning and non-BC
# assert deprecation warning and non-BC
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument resample is deprecated and will be removed"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument resample is deprecated and will be removed"
):
t
=
transforms
.
RandomRotation
((
-
10
,
10
),
resample
=
2
)
t
=
transforms
.
RandomRotation
((
-
10
,
10
),
resample
=
2
)
self
.
assertEqual
(
t
.
interpolation
,
transforms
.
InterpolationMode
s
.
BILINEAR
)
self
.
assertEqual
(
t
.
interpolation
,
transforms
.
InterpolationMode
.
BILINEAR
)
# assert changed type warning
# assert changed type warning
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode
s
"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode"
):
t
=
transforms
.
RandomRotation
((
-
10
,
10
),
interpolation
=
2
)
t
=
transforms
.
RandomRotation
((
-
10
,
10
),
interpolation
=
2
)
self
.
assertEqual
(
t
.
interpolation
,
transforms
.
InterpolationMode
s
.
BILINEAR
)
self
.
assertEqual
(
t
.
interpolation
,
transforms
.
InterpolationMode
.
BILINEAR
)
def
test_random_affine
(
self
):
def
test_random_affine
(
self
):
...
@@ -1547,22 +1547,22 @@ class Tester(unittest.TestCase):
...
@@ -1547,22 +1547,22 @@ class Tester(unittest.TestCase):
# Checking if RandomAffine can be printed as string
# Checking if RandomAffine can be printed as string
t
.
__repr__
()
t
.
__repr__
()
t
=
transforms
.
RandomAffine
(
10
,
interpolation
=
transforms
.
InterpolationMode
s
.
BILINEAR
)
t
=
transforms
.
RandomAffine
(
10
,
interpolation
=
transforms
.
InterpolationMode
.
BILINEAR
)
self
.
assertIn
(
"bilinear"
,
t
.
__repr__
())
self
.
assertIn
(
"bilinear"
,
t
.
__repr__
())
# assert deprecation warning and non-BC
# assert deprecation warning and non-BC
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument resample is deprecated and will be removed"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument resample is deprecated and will be removed"
):
t
=
transforms
.
RandomAffine
(
10
,
resample
=
2
)
t
=
transforms
.
RandomAffine
(
10
,
resample
=
2
)
self
.
assertEqual
(
t
.
interpolation
,
transforms
.
InterpolationMode
s
.
BILINEAR
)
self
.
assertEqual
(
t
.
interpolation
,
transforms
.
InterpolationMode
.
BILINEAR
)
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument fillcolor is deprecated and will be removed"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument fillcolor is deprecated and will be removed"
):
t
=
transforms
.
RandomAffine
(
10
,
fillcolor
=
10
)
t
=
transforms
.
RandomAffine
(
10
,
fillcolor
=
10
)
self
.
assertEqual
(
t
.
fill
,
10
)
self
.
assertEqual
(
t
.
fill
,
10
)
# assert changed type warning
# assert changed type warning
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode
s
"
):
with
self
.
assertWarnsRegex
(
UserWarning
,
r
"Argument interpolation should be of type InterpolationMode"
):
t
=
transforms
.
RandomAffine
(
10
,
interpolation
=
2
)
t
=
transforms
.
RandomAffine
(
10
,
interpolation
=
2
)
self
.
assertEqual
(
t
.
interpolation
,
transforms
.
InterpolationMode
s
.
BILINEAR
)
self
.
assertEqual
(
t
.
interpolation
,
transforms
.
InterpolationMode
.
BILINEAR
)
def
test_to_grayscale
(
self
):
def
test_to_grayscale
(
self
):
"""Unit tests for grayscale transform"""
"""Unit tests for grayscale transform"""
...
...
test/test_transforms_tensor.py
View file @
9e71fdaf
...
@@ -2,7 +2,7 @@ import os
...
@@ -2,7 +2,7 @@ import os
import
torch
import
torch
from
torchvision
import
transforms
as
T
from
torchvision
import
transforms
as
T
from
torchvision.transforms
import
functional
as
F
from
torchvision.transforms
import
functional
as
F
from
torchvision.transforms
import
InterpolationMode
s
from
torchvision.transforms
import
InterpolationMode
import
numpy
as
np
import
numpy
as
np
...
@@ -11,7 +11,7 @@ import unittest
...
@@ -11,7 +11,7 @@ import unittest
from
common_utils
import
TransformsTester
,
get_tmp_dir
,
int_dtypes
,
float_dtypes
from
common_utils
import
TransformsTester
,
get_tmp_dir
,
int_dtypes
,
float_dtypes
NEAREST
,
BILINEAR
,
BICUBIC
=
InterpolationMode
s
.
NEAREST
,
InterpolationMode
s
.
BILINEAR
,
InterpolationMode
s
.
BICUBIC
NEAREST
,
BILINEAR
,
BICUBIC
=
InterpolationMode
.
NEAREST
,
InterpolationMode
.
BILINEAR
,
InterpolationMode
.
BICUBIC
class
Tester
(
TransformsTester
):
class
Tester
(
TransformsTester
):
...
...
torchvision/transforms/functional.py
View file @
9e71fdaf
...
@@ -20,7 +20,7 @@ from . import functional_pil as F_pil
...
@@ -20,7 +20,7 @@ from . import functional_pil as F_pil
from
.
import
functional_tensor
as
F_t
from
.
import
functional_tensor
as
F_t
class
InterpolationMode
s
(
Enum
):
class
InterpolationMode
(
Enum
):
"""Interpolation modes
"""Interpolation modes
"""
"""
NEAREST
=
"nearest"
NEAREST
=
"nearest"
...
@@ -33,26 +33,26 @@ class InterpolationModes(Enum):
...
@@ -33,26 +33,26 @@ class InterpolationModes(Enum):
# TODO: Once torchscript supports Enums with staticmethod
# TODO: Once torchscript supports Enums with staticmethod
# this can be put into InterpolationMode
s
as staticmethod
# this can be put into InterpolationMode as staticmethod
def
_interpolation_modes_from_int
(
i
:
int
)
->
InterpolationMode
s
:
def
_interpolation_modes_from_int
(
i
:
int
)
->
InterpolationMode
:
inverse_modes_mapping
=
{
inverse_modes_mapping
=
{
0
:
InterpolationMode
s
.
NEAREST
,
0
:
InterpolationMode
.
NEAREST
,
2
:
InterpolationMode
s
.
BILINEAR
,
2
:
InterpolationMode
.
BILINEAR
,
3
:
InterpolationMode
s
.
BICUBIC
,
3
:
InterpolationMode
.
BICUBIC
,
4
:
InterpolationMode
s
.
BOX
,
4
:
InterpolationMode
.
BOX
,
5
:
InterpolationMode
s
.
HAMMING
,
5
:
InterpolationMode
.
HAMMING
,
1
:
InterpolationMode
s
.
LANCZOS
,
1
:
InterpolationMode
.
LANCZOS
,
}
}
return
inverse_modes_mapping
[
i
]
return
inverse_modes_mapping
[
i
]
pil_modes_mapping
=
{
pil_modes_mapping
=
{
InterpolationMode
s
.
NEAREST
:
0
,
InterpolationMode
.
NEAREST
:
0
,
InterpolationMode
s
.
BILINEAR
:
2
,
InterpolationMode
.
BILINEAR
:
2
,
InterpolationMode
s
.
BICUBIC
:
3
,
InterpolationMode
.
BICUBIC
:
3
,
InterpolationMode
s
.
BOX
:
4
,
InterpolationMode
.
BOX
:
4
,
InterpolationMode
s
.
HAMMING
:
5
,
InterpolationMode
.
HAMMING
:
5
,
InterpolationMode
s
.
LANCZOS
:
1
,
InterpolationMode
.
LANCZOS
:
1
,
}
}
_is_pil_image
=
F_pil
.
_is_pil_image
_is_pil_image
=
F_pil
.
_is_pil_image
...
@@ -329,7 +329,7 @@ def normalize(tensor: Tensor, mean: List[float], std: List[float], inplace: bool
...
@@ -329,7 +329,7 @@ def normalize(tensor: Tensor, mean: List[float], std: List[float], inplace: bool
return
tensor
return
tensor
def
resize
(
img
:
Tensor
,
size
:
List
[
int
],
interpolation
:
InterpolationMode
s
=
InterpolationMode
s
.
BILINEAR
)
->
Tensor
:
def
resize
(
img
:
Tensor
,
size
:
List
[
int
],
interpolation
:
InterpolationMode
=
InterpolationMode
.
BILINEAR
)
->
Tensor
:
r
"""Resize the input image to the given size.
r
"""Resize the input image to the given size.
The image can be a PIL Image or a torch Tensor, in which case it is expected
The image can be a PIL Image or a torch Tensor, in which case it is expected
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
...
@@ -343,10 +343,10 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int
...
@@ -343,10 +343,10 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int
:math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`.
:math:`\left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right)`.
In torchscript mode size as single int is not supported, use a tuple or
In torchscript mode size as single int is not supported, use a tuple or
list of length 1: ``[size, ]``.
list of length 1: ``[size, ]``.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`.
:class:`torchvision.transforms.InterpolationMode`.
Default is ``InterpolationMode
s
.BILINEAR``. If input is Tensor, only ``InterpolationMode
s
.NEAREST``,
Default is ``InterpolationMode.BILINEAR``. If input is Tensor, only ``InterpolationMode.NEAREST``,
``InterpolationMode
s
.BILINEAR`` and ``InterpolationMode
s
.BICUBIC`` are supported.
``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
Returns:
Returns:
...
@@ -355,13 +355,13 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int
...
@@ -355,13 +355,13 @@ def resize(img: Tensor, size: List[int], interpolation: InterpolationModes = Int
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
if
not
isinstance
(
interpolation
,
InterpolationMode
s
):
if
not
isinstance
(
interpolation
,
InterpolationMode
):
raise
TypeError
(
"Argument interpolation should be a InterpolationMode
s
"
)
raise
TypeError
(
"Argument interpolation should be a InterpolationMode"
)
if
not
isinstance
(
img
,
torch
.
Tensor
):
if
not
isinstance
(
img
,
torch
.
Tensor
):
pil_interpolation
=
pil_modes_mapping
[
interpolation
]
pil_interpolation
=
pil_modes_mapping
[
interpolation
]
...
@@ -475,7 +475,7 @@ def center_crop(img: Tensor, output_size: List[int]) -> Tensor:
...
@@ -475,7 +475,7 @@ def center_crop(img: Tensor, output_size: List[int]) -> Tensor:
def
resized_crop
(
def
resized_crop
(
img
:
Tensor
,
top
:
int
,
left
:
int
,
height
:
int
,
width
:
int
,
size
:
List
[
int
],
img
:
Tensor
,
top
:
int
,
left
:
int
,
height
:
int
,
width
:
int
,
size
:
List
[
int
],
interpolation
:
InterpolationMode
s
=
InterpolationMode
s
.
BILINEAR
interpolation
:
InterpolationMode
=
InterpolationMode
.
BILINEAR
)
->
Tensor
:
)
->
Tensor
:
"""Crop the given image and resize it to desired size.
"""Crop the given image and resize it to desired size.
The image can be a PIL Image or a Tensor, in which case it is expected
The image can be a PIL Image or a Tensor, in which case it is expected
...
@@ -490,10 +490,10 @@ def resized_crop(
...
@@ -490,10 +490,10 @@ def resized_crop(
height (int): Height of the crop box.
height (int): Height of the crop box.
width (int): Width of the crop box.
width (int): Width of the crop box.
size (sequence or int): Desired output size. Same semantics as ``resize``.
size (sequence or int): Desired output size. Same semantics as ``resize``.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`.
:class:`torchvision.transforms.InterpolationMode`.
Default is ``InterpolationMode
s
.BILINEAR``. If input is Tensor, only ``InterpolationMode
s
.NEAREST``,
Default is ``InterpolationMode.BILINEAR``. If input is Tensor, only ``InterpolationMode.NEAREST``,
``InterpolationMode
s
.BILINEAR`` and ``InterpolationMode
s
.BICUBIC`` are supported.
``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
Returns:
Returns:
...
@@ -556,7 +556,7 @@ def perspective(
...
@@ -556,7 +556,7 @@ def perspective(
img
:
Tensor
,
img
:
Tensor
,
startpoints
:
List
[
List
[
int
]],
startpoints
:
List
[
List
[
int
]],
endpoints
:
List
[
List
[
int
]],
endpoints
:
List
[
List
[
int
]],
interpolation
:
InterpolationMode
s
=
InterpolationMode
s
.
BILINEAR
,
interpolation
:
InterpolationMode
=
InterpolationMode
.
BILINEAR
,
fill
:
Optional
[
int
]
=
None
fill
:
Optional
[
int
]
=
None
)
->
Tensor
:
)
->
Tensor
:
"""Perform perspective transform of the given image.
"""Perform perspective transform of the given image.
...
@@ -569,9 +569,9 @@ def perspective(
...
@@ -569,9 +569,9 @@ def perspective(
``[top-left, top-right, bottom-right, bottom-left]`` of the original image.
``[top-left, top-right, bottom-right, bottom-left]`` of the original image.
endpoints (list of list of ints): List containing four lists of two integers corresponding to four corners
endpoints (list of list of ints): List containing four lists of two integers corresponding to four corners
``[top-left, top-right, bottom-right, bottom-left]`` of the transformed image.
``[top-left, top-right, bottom-right, bottom-left]`` of the transformed image.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`. Default is ``InterpolationMode
s
.BILINEAR``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
If input is Tensor, only ``InterpolationMode
s
.NEAREST``, ``InterpolationMode
s
.BILINEAR`` are supported.
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
fill (n-tuple or int or float): Pixel fill value for area outside the rotated
fill (n-tuple or int or float): Pixel fill value for area outside the rotated
image. If int or float, the value is used for all bands respectively.
image. If int or float, the value is used for all bands respectively.
...
@@ -587,13 +587,13 @@ def perspective(
...
@@ -587,13 +587,13 @@ def perspective(
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
if
not
isinstance
(
interpolation
,
InterpolationMode
s
):
if
not
isinstance
(
interpolation
,
InterpolationMode
):
raise
TypeError
(
"Argument interpolation should be a InterpolationMode
s
"
)
raise
TypeError
(
"Argument interpolation should be a InterpolationMode"
)
if
not
isinstance
(
img
,
torch
.
Tensor
):
if
not
isinstance
(
img
,
torch
.
Tensor
):
pil_interpolation
=
pil_modes_mapping
[
interpolation
]
pil_interpolation
=
pil_modes_mapping
[
interpolation
]
...
@@ -869,7 +869,7 @@ def _get_inverse_affine_matrix(
...
@@ -869,7 +869,7 @@ def _get_inverse_affine_matrix(
def
rotate
(
def
rotate
(
img
:
Tensor
,
angle
:
float
,
interpolation
:
InterpolationMode
s
=
InterpolationMode
s
.
NEAREST
,
img
:
Tensor
,
angle
:
float
,
interpolation
:
InterpolationMode
=
InterpolationMode
.
NEAREST
,
expand
:
bool
=
False
,
center
:
Optional
[
List
[
int
]]
=
None
,
expand
:
bool
=
False
,
center
:
Optional
[
List
[
int
]]
=
None
,
fill
:
Optional
[
int
]
=
None
,
resample
:
Optional
[
int
]
=
None
fill
:
Optional
[
int
]
=
None
,
resample
:
Optional
[
int
]
=
None
)
->
Tensor
:
)
->
Tensor
:
...
@@ -880,9 +880,9 @@ def rotate(
...
@@ -880,9 +880,9 @@ def rotate(
Args:
Args:
img (PIL Image or Tensor): image to be rotated.
img (PIL Image or Tensor): image to be rotated.
angle (float or int): rotation angle value in degrees, counter-clockwise.
angle (float or int): rotation angle value in degrees, counter-clockwise.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`. Default is ``InterpolationMode
s
.NEAREST``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationMode
s
.NEAREST``, ``InterpolationMode
s
.BILINEAR`` are supported.
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
expand (bool, optional): Optional expansion flag.
expand (bool, optional): Optional expansion flag.
If true, expands the output image to make it large enough to hold the entire rotated image.
If true, expands the output image to make it large enough to hold the entire rotated image.
...
@@ -913,8 +913,8 @@ def rotate(
...
@@ -913,8 +913,8 @@ def rotate(
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
...
@@ -924,8 +924,8 @@ def rotate(
...
@@ -924,8 +924,8 @@ def rotate(
if
center
is
not
None
and
not
isinstance
(
center
,
(
list
,
tuple
)):
if
center
is
not
None
and
not
isinstance
(
center
,
(
list
,
tuple
)):
raise
TypeError
(
"Argument center should be a sequence"
)
raise
TypeError
(
"Argument center should be a sequence"
)
if
not
isinstance
(
interpolation
,
InterpolationMode
s
):
if
not
isinstance
(
interpolation
,
InterpolationMode
):
raise
TypeError
(
"Argument interpolation should be a InterpolationMode
s
"
)
raise
TypeError
(
"Argument interpolation should be a InterpolationMode"
)
if
not
isinstance
(
img
,
torch
.
Tensor
):
if
not
isinstance
(
img
,
torch
.
Tensor
):
pil_interpolation
=
pil_modes_mapping
[
interpolation
]
pil_interpolation
=
pil_modes_mapping
[
interpolation
]
...
@@ -945,7 +945,7 @@ def rotate(
...
@@ -945,7 +945,7 @@ def rotate(
def
affine
(
def
affine
(
img
:
Tensor
,
angle
:
float
,
translate
:
List
[
int
],
scale
:
float
,
shear
:
List
[
float
],
img
:
Tensor
,
angle
:
float
,
translate
:
List
[
int
],
scale
:
float
,
shear
:
List
[
float
],
interpolation
:
InterpolationMode
s
=
InterpolationMode
s
.
NEAREST
,
fill
:
Optional
[
int
]
=
None
,
interpolation
:
InterpolationMode
=
InterpolationMode
.
NEAREST
,
fill
:
Optional
[
int
]
=
None
,
resample
:
Optional
[
int
]
=
None
,
fillcolor
:
Optional
[
int
]
=
None
resample
:
Optional
[
int
]
=
None
,
fillcolor
:
Optional
[
int
]
=
None
)
->
Tensor
:
)
->
Tensor
:
"""Apply affine transformation on the image keeping image center invariant.
"""Apply affine transformation on the image keeping image center invariant.
...
@@ -960,9 +960,9 @@ def affine(
...
@@ -960,9 +960,9 @@ def affine(
shear (float or tuple or list): shear angle value in degrees between -180 to 180, clockwise direction.
shear (float or tuple or list): shear angle value in degrees between -180 to 180, clockwise direction.
If a tuple of list is specified, the first value corresponds to a shear parallel to the x axis, while
If a tuple of list is specified, the first value corresponds to a shear parallel to the x axis, while
the second value corresponds to a shear parallel to the y axis.
the second value corresponds to a shear parallel to the y axis.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`. Default is ``InterpolationMode
s
.NEAREST``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationMode
s
.NEAREST``, ``InterpolationMode
s
.BILINEAR`` are supported.
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
fill (int): Optional fill color for the area outside the transform in the output image (Pillow>=5.0.0).
fill (int): Optional fill color for the area outside the transform in the output image (Pillow>=5.0.0).
This option is not supported for Tensor input. Fill value for the area outside the transform in the output
This option is not supported for Tensor input. Fill value for the area outside the transform in the output
...
@@ -984,8 +984,8 @@ def affine(
...
@@ -984,8 +984,8 @@ def affine(
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
...
@@ -1010,8 +1010,8 @@ def affine(
...
@@ -1010,8 +1010,8 @@ def affine(
if
not
isinstance
(
shear
,
(
numbers
.
Number
,
(
list
,
tuple
))):
if
not
isinstance
(
shear
,
(
numbers
.
Number
,
(
list
,
tuple
))):
raise
TypeError
(
"Shear should be either a single value or a sequence of two values"
)
raise
TypeError
(
"Shear should be either a single value or a sequence of two values"
)
if
not
isinstance
(
interpolation
,
InterpolationMode
s
):
if
not
isinstance
(
interpolation
,
InterpolationMode
):
raise
TypeError
(
"Argument interpolation should be a InterpolationMode
s
"
)
raise
TypeError
(
"Argument interpolation should be a InterpolationMode"
)
if
isinstance
(
angle
,
int
):
if
isinstance
(
angle
,
int
):
angle
=
float
(
angle
)
angle
=
float
(
angle
)
...
...
torchvision/transforms/transforms.py
View file @
9e71fdaf
...
@@ -14,14 +14,14 @@ except ImportError:
...
@@ -14,14 +14,14 @@ except ImportError:
accimage
=
None
accimage
=
None
from
.
import
functional
as
F
from
.
import
functional
as
F
from
.functional
import
InterpolationMode
s
,
_interpolation_modes_from_int
from
.functional
import
InterpolationMode
,
_interpolation_modes_from_int
__all__
=
[
"Compose"
,
"ToTensor"
,
"PILToTensor"
,
"ConvertImageDtype"
,
"ToPILImage"
,
"Normalize"
,
"Resize"
,
"Scale"
,
__all__
=
[
"Compose"
,
"ToTensor"
,
"PILToTensor"
,
"ConvertImageDtype"
,
"ToPILImage"
,
"Normalize"
,
"Resize"
,
"Scale"
,
"CenterCrop"
,
"Pad"
,
"Lambda"
,
"RandomApply"
,
"RandomChoice"
,
"RandomOrder"
,
"RandomCrop"
,
"CenterCrop"
,
"Pad"
,
"Lambda"
,
"RandomApply"
,
"RandomChoice"
,
"RandomOrder"
,
"RandomCrop"
,
"RandomHorizontalFlip"
,
"RandomVerticalFlip"
,
"RandomResizedCrop"
,
"RandomSizedCrop"
,
"FiveCrop"
,
"TenCrop"
,
"RandomHorizontalFlip"
,
"RandomVerticalFlip"
,
"RandomResizedCrop"
,
"RandomSizedCrop"
,
"FiveCrop"
,
"TenCrop"
,
"LinearTransformation"
,
"ColorJitter"
,
"RandomRotation"
,
"RandomAffine"
,
"Grayscale"
,
"RandomGrayscale"
,
"LinearTransformation"
,
"ColorJitter"
,
"RandomRotation"
,
"RandomAffine"
,
"Grayscale"
,
"RandomGrayscale"
,
"RandomPerspective"
,
"RandomErasing"
,
"GaussianBlur"
,
"InterpolationMode
s
"
]
"RandomPerspective"
,
"RandomErasing"
,
"GaussianBlur"
,
"InterpolationMode"
]
class
Compose
:
class
Compose
:
...
@@ -234,15 +234,15 @@ class Resize(torch.nn.Module):
...
@@ -234,15 +234,15 @@ class Resize(torch.nn.Module):
(size * height / width, size).
(size * height / width, size).
In torchscript mode padding as single int is not supported, use a tuple or
In torchscript mode padding as single int is not supported, use a tuple or
list of length 1: ``[size, ]``.
list of length 1: ``[size, ]``.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`. Default is ``InterpolationMode
s
.BILINEAR``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
If input is Tensor, only ``InterpolationMode
s
.NEAREST``, ``InterpolationMode
s
.BILINEAR`` and
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` and
``InterpolationMode
s
.BICUBIC`` are supported.
``InterpolationMode.BICUBIC`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
"""
"""
def
__init__
(
self
,
size
,
interpolation
=
InterpolationMode
s
.
BILINEAR
):
def
__init__
(
self
,
size
,
interpolation
=
InterpolationMode
.
BILINEAR
):
super
().
__init__
()
super
().
__init__
()
if
not
isinstance
(
size
,
(
int
,
Sequence
)):
if
not
isinstance
(
size
,
(
int
,
Sequence
)):
raise
TypeError
(
"Size should be int or sequence. Got {}"
.
format
(
type
(
size
)))
raise
TypeError
(
"Size should be int or sequence. Got {}"
.
format
(
type
(
size
)))
...
@@ -253,8 +253,8 @@ class Resize(torch.nn.Module):
...
@@ -253,8 +253,8 @@ class Resize(torch.nn.Module):
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
...
@@ -663,9 +663,9 @@ class RandomPerspective(torch.nn.Module):
...
@@ -663,9 +663,9 @@ class RandomPerspective(torch.nn.Module):
distortion_scale (float): argument to control the degree of distortion and ranges from 0 to 1.
distortion_scale (float): argument to control the degree of distortion and ranges from 0 to 1.
Default is 0.5.
Default is 0.5.
p (float): probability of the image being transformed. Default is 0.5.
p (float): probability of the image being transformed. Default is 0.5.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`. Default is ``InterpolationMode
s
.BILINEAR``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
If input is Tensor, only ``InterpolationMode
s
.NEAREST``, ``InterpolationMode
s
.BILINEAR`` are supported.
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
fill (n-tuple or int or float): Pixel fill value for area outside the rotated
fill (n-tuple or int or float): Pixel fill value for area outside the rotated
image. If int or float, the value is used for all bands respectively. Default is 0.
image. If int or float, the value is used for all bands respectively. Default is 0.
...
@@ -673,15 +673,15 @@ class RandomPerspective(torch.nn.Module):
...
@@ -673,15 +673,15 @@ class RandomPerspective(torch.nn.Module):
input. Fill value for the area outside the transform in the output image is always 0.
input. Fill value for the area outside the transform in the output image is always 0.
"""
"""
def
__init__
(
self
,
distortion_scale
=
0.5
,
p
=
0.5
,
interpolation
=
InterpolationMode
s
.
BILINEAR
,
fill
=
0
):
def
__init__
(
self
,
distortion_scale
=
0.5
,
p
=
0.5
,
interpolation
=
InterpolationMode
.
BILINEAR
,
fill
=
0
):
super
().
__init__
()
super
().
__init__
()
self
.
p
=
p
self
.
p
=
p
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
...
@@ -758,15 +758,15 @@ class RandomResizedCrop(torch.nn.Module):
...
@@ -758,15 +758,15 @@ class RandomResizedCrop(torch.nn.Module):
made. If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]).
made. If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]).
scale (tuple of float): scale range of the cropped image before resizing, relatively to the origin image.
scale (tuple of float): scale range of the cropped image before resizing, relatively to the origin image.
ratio (tuple of float): aspect ratio range of the cropped image before resizing.
ratio (tuple of float): aspect ratio range of the cropped image before resizing.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`. Default is ``InterpolationMode
s
.BILINEAR``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.BILINEAR``.
If input is Tensor, only ``InterpolationMode
s
.NEAREST``, ``InterpolationMode
s
.BILINEAR`` and
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` and
``InterpolationMode
s
.BICUBIC`` are supported.
``InterpolationMode.BICUBIC`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
"""
"""
def
__init__
(
self
,
size
,
scale
=
(
0.08
,
1.0
),
ratio
=
(
3.
/
4.
,
4.
/
3.
),
interpolation
=
InterpolationMode
s
.
BILINEAR
):
def
__init__
(
self
,
size
,
scale
=
(
0.08
,
1.0
),
ratio
=
(
3.
/
4.
,
4.
/
3.
),
interpolation
=
InterpolationMode
.
BILINEAR
):
super
().
__init__
()
super
().
__init__
()
self
.
size
=
_setup_size
(
size
,
error_msg
=
"Please provide only two dimensions (h, w) for size."
)
self
.
size
=
_setup_size
(
size
,
error_msg
=
"Please provide only two dimensions (h, w) for size."
)
...
@@ -780,8 +780,8 @@ class RandomResizedCrop(torch.nn.Module):
...
@@ -780,8 +780,8 @@ class RandomResizedCrop(torch.nn.Module):
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
...
@@ -1147,9 +1147,9 @@ class RandomRotation(torch.nn.Module):
...
@@ -1147,9 +1147,9 @@ class RandomRotation(torch.nn.Module):
degrees (sequence or float or int): Range of degrees to select from.
degrees (sequence or float or int): Range of degrees to select from.
If degrees is a number instead of sequence like (min, max), the range of degrees
If degrees is a number instead of sequence like (min, max), the range of degrees
will be (-degrees, +degrees).
will be (-degrees, +degrees).
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`. Default is ``InterpolationMode
s
.NEAREST``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationMode
s
.NEAREST``, ``InterpolationMode
s
.BILINEAR`` are supported.
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
expand (bool, optional): Optional expansion flag.
expand (bool, optional): Optional expansion flag.
If true, expands the output to make it large enough to hold the entire rotated image.
If true, expands the output to make it large enough to hold the entire rotated image.
...
@@ -1170,7 +1170,7 @@ class RandomRotation(torch.nn.Module):
...
@@ -1170,7 +1170,7 @@ class RandomRotation(torch.nn.Module):
"""
"""
def
__init__
(
def
__init__
(
self
,
degrees
,
interpolation
=
InterpolationMode
s
.
NEAREST
,
expand
=
False
,
center
=
None
,
fill
=
None
,
resample
=
None
self
,
degrees
,
interpolation
=
InterpolationMode
.
NEAREST
,
expand
=
False
,
center
=
None
,
fill
=
None
,
resample
=
None
):
):
super
().
__init__
()
super
().
__init__
()
if
resample
is
not
None
:
if
resample
is
not
None
:
...
@@ -1182,8 +1182,8 @@ class RandomRotation(torch.nn.Module):
...
@@ -1182,8 +1182,8 @@ class RandomRotation(torch.nn.Module):
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
...
@@ -1253,9 +1253,9 @@ class RandomAffine(torch.nn.Module):
...
@@ -1253,9 +1253,9 @@ class RandomAffine(torch.nn.Module):
range (shear[0], shear[1]) will be applied. Else if shear is a tuple or list of 4 values,
range (shear[0], shear[1]) will be applied. Else if shear is a tuple or list of 4 values,
a x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3]) will be applied.
a x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3]) will be applied.
Will not apply shear by default.
Will not apply shear by default.
interpolation (InterpolationMode
s
): Desired interpolation enum defined by
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode
s
`. Default is ``InterpolationMode
s
.NEAREST``.
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationMode
s
.NEAREST``, ``InterpolationMode
s
.BILINEAR`` are supported.
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
For backward compatibility integer values (e.g. ``PIL.Image.NEAREST``) are still acceptable.
fill (tuple or int): Optional fill color (Tuple for RGB Image and int for grayscale) for the area
fill (tuple or int): Optional fill color (Tuple for RGB Image and int for grayscale) for the area
outside the transform in the output image (Pillow>=5.0.0). This option is not supported for Tensor
outside the transform in the output image (Pillow>=5.0.0). This option is not supported for Tensor
...
@@ -1270,7 +1270,7 @@ class RandomAffine(torch.nn.Module):
...
@@ -1270,7 +1270,7 @@ class RandomAffine(torch.nn.Module):
"""
"""
def
__init__
(
def
__init__
(
self
,
degrees
,
translate
=
None
,
scale
=
None
,
shear
=
None
,
interpolation
=
InterpolationMode
s
.
NEAREST
,
fill
=
0
,
self
,
degrees
,
translate
=
None
,
scale
=
None
,
shear
=
None
,
interpolation
=
InterpolationMode
.
NEAREST
,
fill
=
0
,
fillcolor
=
None
,
resample
=
None
fillcolor
=
None
,
resample
=
None
):
):
super
().
__init__
()
super
().
__init__
()
...
@@ -1283,8 +1283,8 @@ class RandomAffine(torch.nn.Module):
...
@@ -1283,8 +1283,8 @@ class RandomAffine(torch.nn.Module):
# Backward compatibility with integer value
# Backward compatibility with integer value
if
isinstance
(
interpolation
,
int
):
if
isinstance
(
interpolation
,
int
):
warnings
.
warn
(
warnings
.
warn
(
"Argument interpolation should be of type InterpolationMode
s
instead of int. "
"Argument interpolation should be of type InterpolationMode instead of int. "
"Please, use InterpolationMode
s
enum."
"Please, use InterpolationMode enum."
)
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
interpolation
=
_interpolation_modes_from_int
(
interpolation
)
...
@@ -1377,7 +1377,7 @@ class RandomAffine(torch.nn.Module):
...
@@ -1377,7 +1377,7 @@ class RandomAffine(torch.nn.Module):
s
+=
', scale={scale}'
s
+=
', scale={scale}'
if
self
.
shear
is
not
None
:
if
self
.
shear
is
not
None
:
s
+=
', shear={shear}'
s
+=
', shear={shear}'
if
self
.
interpolation
!=
InterpolationMode
s
.
NEAREST
:
if
self
.
interpolation
!=
InterpolationMode
.
NEAREST
:
s
+=
', interpolation={interpolation}'
s
+=
', interpolation={interpolation}'
if
self
.
fill
!=
0
:
if
self
.
fill
!=
0
:
s
+=
', fill={fill}'
s
+=
', fill={fill}'
...
...
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