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
016804ee
Unverified
Commit
016804ee
authored
Jun 21, 2023
by
Nicolas Hug
Committed by
GitHub
Jun 21, 2023
Browse files
Rename cpu_and_gpu into cpu_and_cuda (#7687)
parent
fc83b280
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
135 additions
and
135 deletions
+135
-135
test/common_utils.py
test/common_utils.py
+1
-1
test/conftest.py
test/conftest.py
+1
-1
test/test_functional_tensor.py
test/test_functional_tensor.py
+45
-45
test/test_models.py
test/test_models.py
+6
-6
test/test_ops.py
test/test_ops.py
+21
-21
test/test_prototype_models.py
test/test_prototype_models.py
+3
-3
test/test_transforms_tensor.py
test/test_transforms_tensor.py
+30
-30
test/test_transforms_v2.py
test/test_transforms_v2.py
+3
-3
test/test_transforms_v2_functional.py
test/test_transforms_v2_functional.py
+25
-25
No files found.
test/common_utils.py
View file @
016804ee
...
@@ -122,7 +122,7 @@ def disable_console_output():
...
@@ -122,7 +122,7 @@ def disable_console_output():
yield
yield
def
cpu_and_
gpu
():
def
cpu_and_
cuda
():
import
pytest
# noqa
import
pytest
# noqa
return
(
"cpu"
,
pytest
.
param
(
"cuda"
,
marks
=
pytest
.
mark
.
needs_cuda
))
return
(
"cpu"
,
pytest
.
param
(
"cuda"
,
marks
=
pytest
.
mark
.
needs_cuda
))
...
...
test/conftest.py
View file @
016804ee
...
@@ -33,7 +33,7 @@ def pytest_collection_modifyitems(items):
...
@@ -33,7 +33,7 @@ def pytest_collection_modifyitems(items):
# The needs_cuda mark will exist if the test was explicitly decorated with
# The needs_cuda mark will exist if the test was explicitly decorated with
# the @needs_cuda decorator. It will also exist if it was parametrized with a
# the @needs_cuda decorator. It will also exist if it was parametrized with a
# parameter that has the mark: for example if a test is parametrized with
# parameter that has the mark: for example if a test is parametrized with
# @pytest.mark.parametrize('device', cpu_and_
gpu
())
# @pytest.mark.parametrize('device', cpu_and_
cuda
())
# the "instances" of the tests where device == 'cuda' will have the 'needs_cuda' mark,
# the "instances" of the tests where device == 'cuda' will have the 'needs_cuda' mark,
# and the ones with device == 'cpu' won't have the mark.
# and the ones with device == 'cpu' won't have the mark.
needs_cuda
=
item
.
get_closest_marker
(
"needs_cuda"
)
is
not
None
needs_cuda
=
item
.
get_closest_marker
(
"needs_cuda"
)
is
not
None
...
...
test/test_functional_tensor.py
View file @
016804ee
...
@@ -21,7 +21,7 @@ from common_utils import (
...
@@ -21,7 +21,7 @@ from common_utils import (
_create_data_batch
,
_create_data_batch
,
_test_fn_on_batch
,
_test_fn_on_batch
,
assert_equal
,
assert_equal
,
cpu_and_
gpu
,
cpu_and_
cuda
,
needs_cuda
,
needs_cuda
,
)
)
from
torchvision.transforms
import
InterpolationMode
from
torchvision.transforms
import
InterpolationMode
...
@@ -34,7 +34,7 @@ NEAREST, NEAREST_EXACT, BILINEAR, BICUBIC = (
...
@@ -34,7 +34,7 @@ NEAREST, NEAREST_EXACT, BILINEAR, BICUBIC = (
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"fn"
,
[
F
.
get_image_size
,
F
.
get_image_num_channels
,
F
.
get_dimensions
])
@
pytest
.
mark
.
parametrize
(
"fn"
,
[
F
.
get_image_size
,
F
.
get_image_num_channels
,
F
.
get_dimensions
])
def
test_image_sizes
(
device
,
fn
):
def
test_image_sizes
(
device
,
fn
):
script_F
=
torch
.
jit
.
script
(
fn
)
script_F
=
torch
.
jit
.
script
(
fn
)
...
@@ -72,7 +72,7 @@ class TestRotate:
...
@@ -72,7 +72,7 @@ class TestRotate:
scripted_rotate
=
torch
.
jit
.
script
(
F
.
rotate
)
scripted_rotate
=
torch
.
jit
.
script
(
F
.
rotate
)
IMG_W
=
26
IMG_W
=
26
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
7
,
33
),
(
26
,
IMG_W
),
(
32
,
IMG_W
)])
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
7
,
33
),
(
26
,
IMG_W
),
(
32
,
IMG_W
)])
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"center"
,
"center"
,
...
@@ -131,7 +131,7 @@ class TestRotate:
...
@@ -131,7 +131,7 @@ class TestRotate:
f
"
{
out_pil_tensor
[
0
,
:
7
,
:
7
]
}
"
f
"
{
out_pil_tensor
[
0
,
:
7
,
:
7
]
}
"
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
def
test_rotate_batch
(
self
,
device
,
dt
):
def
test_rotate_batch
(
self
,
device
,
dt
):
if
dt
==
torch
.
float16
and
device
==
"cpu"
:
if
dt
==
torch
.
float16
and
device
==
"cpu"
:
...
@@ -157,7 +157,7 @@ class TestAffine:
...
@@ -157,7 +157,7 @@ class TestAffine:
ALL_DTYPES
=
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
]
ALL_DTYPES
=
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
]
scripted_affine
=
torch
.
jit
.
script
(
F
.
affine
)
scripted_affine
=
torch
.
jit
.
script
(
F
.
affine
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
26
,
26
),
(
32
,
26
)])
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
26
,
26
),
(
32
,
26
)])
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
def
test_identity_map
(
self
,
device
,
height
,
width
,
dt
):
def
test_identity_map
(
self
,
device
,
height
,
width
,
dt
):
...
@@ -180,7 +180,7 @@ class TestAffine:
...
@@ -180,7 +180,7 @@ class TestAffine:
)
)
assert_equal
(
tensor
,
out_tensor
,
msg
=
f
"
{
out_tensor
[
0
,
:
5
,
:
5
]
}
vs
{
tensor
[
0
,
:
5
,
:
5
]
}
"
)
assert_equal
(
tensor
,
out_tensor
,
msg
=
f
"
{
out_tensor
[
0
,
:
5
,
:
5
]
}
vs
{
tensor
[
0
,
:
5
,
:
5
]
}
"
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
26
,
26
)])
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
26
,
26
)])
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
...
@@ -224,7 +224,7 @@ class TestAffine:
...
@@ -224,7 +224,7 @@ class TestAffine:
# Tolerance : less than 6% of different pixels
# Tolerance : less than 6% of different pixels
assert
ratio_diff_pixels
<
0.06
assert
ratio_diff_pixels
<
0.06
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
32
,
26
)])
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
32
,
26
)])
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"angle"
,
[
90
,
45
,
15
,
-
30
,
-
60
,
-
120
])
@
pytest
.
mark
.
parametrize
(
"angle"
,
[
90
,
45
,
15
,
-
30
,
-
60
,
-
120
])
...
@@ -258,7 +258,7 @@ class TestAffine:
...
@@ -258,7 +258,7 @@ class TestAffine:
# Tolerance : less than 3% of different pixels
# Tolerance : less than 3% of different pixels
assert
ratio_diff_pixels
<
0.03
assert
ratio_diff_pixels
<
0.03
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
26
,
26
),
(
32
,
26
)])
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
26
,
26
),
(
32
,
26
)])
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"t"
,
[[
10
,
12
],
(
-
12
,
-
13
)])
@
pytest
.
mark
.
parametrize
(
"t"
,
[[
10
,
12
],
(
-
12
,
-
13
)])
...
@@ -283,7 +283,7 @@ class TestAffine:
...
@@ -283,7 +283,7 @@ class TestAffine:
_assert_equal_tensor_to_pil
(
out_tensor
,
out_pil_img
)
_assert_equal_tensor_to_pil
(
out_tensor
,
out_pil_img
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
26
,
26
),
(
32
,
26
)])
@
pytest
.
mark
.
parametrize
(
"height, width"
,
[(
26
,
26
),
(
32
,
26
)])
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
...
@@ -344,7 +344,7 @@ class TestAffine:
...
@@ -344,7 +344,7 @@ class TestAffine:
tol
=
0.06
if
device
==
"cuda"
else
0.05
tol
=
0.06
if
device
==
"cuda"
else
0.05
assert
ratio_diff_pixels
<
tol
assert
ratio_diff_pixels
<
tol
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
@
pytest
.
mark
.
parametrize
(
"dt"
,
ALL_DTYPES
)
def
test_batches
(
self
,
device
,
dt
):
def
test_batches
(
self
,
device
,
dt
):
if
dt
==
torch
.
float16
and
device
==
"cpu"
:
if
dt
==
torch
.
float16
and
device
==
"cpu"
:
...
@@ -357,7 +357,7 @@ class TestAffine:
...
@@ -357,7 +357,7 @@ class TestAffine:
_test_fn_on_batch
(
batch_tensors
,
F
.
affine
,
angle
=-
43
,
translate
=
[
-
3
,
4
],
scale
=
1.2
,
shear
=
[
4.0
,
5.0
])
_test_fn_on_batch
(
batch_tensors
,
F
.
affine
,
angle
=-
43
,
translate
=
[
-
3
,
4
],
scale
=
1.2
,
shear
=
[
4.0
,
5.0
])
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_interpolation_type
(
self
,
device
):
def
test_interpolation_type
(
self
,
device
):
tensor
,
pil_img
=
_create_data
(
26
,
26
,
device
=
device
)
tensor
,
pil_img
=
_create_data
(
26
,
26
,
device
=
device
)
...
@@ -389,7 +389,7 @@ def _get_data_dims_and_points_for_perspective():
...
@@ -389,7 +389,7 @@ def _get_data_dims_and_points_for_perspective():
return
dims_and_points
return
dims_and_points
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dims_and_points"
,
_get_data_dims_and_points_for_perspective
())
@
pytest
.
mark
.
parametrize
(
"dims_and_points"
,
_get_data_dims_and_points_for_perspective
())
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
...
@@ -435,7 +435,7 @@ def test_perspective_pil_vs_tensor(device, dims_and_points, dt, fill, fn):
...
@@ -435,7 +435,7 @@ def test_perspective_pil_vs_tensor(device, dims_and_points, dt, fill, fn):
assert
ratio_diff_pixels
<
0.05
assert
ratio_diff_pixels
<
0.05
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dims_and_points"
,
_get_data_dims_and_points_for_perspective
())
@
pytest
.
mark
.
parametrize
(
"dims_and_points"
,
_get_data_dims_and_points_for_perspective
())
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
def
test_perspective_batch
(
device
,
dims_and_points
,
dt
):
def
test_perspective_batch
(
device
,
dims_and_points
,
dt
):
...
@@ -473,7 +473,7 @@ def test_perspective_interpolation_type():
...
@@ -473,7 +473,7 @@ def test_perspective_interpolation_type():
assert_equal
(
res1
,
res2
)
assert_equal
(
res1
,
res2
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"size"
,
"size"
,
...
@@ -539,7 +539,7 @@ def test_resize(device, dt, size, max_size, interpolation):
...
@@ -539,7 +539,7 @@ def test_resize(device, dt, size, max_size, interpolation):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_resize_asserts
(
device
):
def
test_resize_asserts
(
device
):
tensor
,
pil_img
=
_create_data
(
26
,
36
,
device
=
device
)
tensor
,
pil_img
=
_create_data
(
26
,
36
,
device
=
device
)
...
@@ -556,7 +556,7 @@ def test_resize_asserts(device):
...
@@ -556,7 +556,7 @@ def test_resize_asserts(device):
F
.
resize
(
img
,
size
=
32
,
max_size
=
32
)
F
.
resize
(
img
,
size
=
32
,
max_size
=
32
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"size"
,
[[
96
,
72
],
[
96
,
420
],
[
420
,
72
]])
@
pytest
.
mark
.
parametrize
(
"size"
,
[[
96
,
72
],
[
96
,
420
],
[
420
,
72
]])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
BILINEAR
,
BICUBIC
])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
BILINEAR
,
BICUBIC
])
...
@@ -663,7 +663,7 @@ def check_functional_vs_PIL_vs_scripted(
...
@@ -663,7 +663,7 @@ def check_functional_vs_PIL_vs_scripted(
_test_fn_on_batch
(
batch_tensors
,
fn
,
scripted_fn_atol
=
atol
,
**
config
)
_test_fn_on_batch
(
batch_tensors
,
fn
,
scripted_fn_atol
=
atol
,
**
config
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"brightness_factor"
:
f
}
for
f
in
(
0.1
,
0.5
,
1.0
,
1.34
,
2.5
)])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"brightness_factor"
:
f
}
for
f
in
(
0.1
,
0.5
,
1.0
,
1.34
,
2.5
)])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
...
@@ -679,7 +679,7 @@ def test_adjust_brightness(device, dtype, config, channels):
...
@@ -679,7 +679,7 @@ def test_adjust_brightness(device, dtype, config, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
def
test_invert
(
device
,
dtype
,
channels
):
def
test_invert
(
device
,
dtype
,
channels
):
...
@@ -688,7 +688,7 @@ def test_invert(device, dtype, channels):
...
@@ -688,7 +688,7 @@ def test_invert(device, dtype, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"bits"
:
bits
}
for
bits
in
range
(
0
,
8
)])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"bits"
:
bits
}
for
bits
in
range
(
0
,
8
)])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
def
test_posterize
(
device
,
config
,
channels
):
def
test_posterize
(
device
,
config
,
channels
):
...
@@ -705,7 +705,7 @@ def test_posterize(device, config, channels):
...
@@ -705,7 +705,7 @@ def test_posterize(device, config, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"threshold"
:
threshold
}
for
threshold
in
[
0
,
64
,
128
,
192
,
255
]])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"threshold"
:
threshold
}
for
threshold
in
[
0
,
64
,
128
,
192
,
255
]])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
def
test_solarize1
(
device
,
config
,
channels
):
def
test_solarize1
(
device
,
config
,
channels
):
...
@@ -722,7 +722,7 @@ def test_solarize1(device, config, channels):
...
@@ -722,7 +722,7 @@ def test_solarize1(device, config, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"threshold"
:
threshold
}
for
threshold
in
[
0.0
,
0.25
,
0.5
,
0.75
,
1.0
]])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"threshold"
:
threshold
}
for
threshold
in
[
0.0
,
0.25
,
0.5
,
0.75
,
1.0
]])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
...
@@ -754,7 +754,7 @@ def test_solarize2(device, dtype, config, channels):
...
@@ -754,7 +754,7 @@ def test_solarize2(device, dtype, config, channels):
*
[(
torch
.
int64
,
threshold
)
for
threshold
in
[
0
,
2
**
32
,
2
**
63
-
1
]],
*
[(
torch
.
int64
,
threshold
)
for
threshold
in
[
0
,
2
**
32
,
2
**
63
-
1
]],
],
],
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_solarize_threshold_within_bound
(
threshold
,
dtype
,
device
):
def
test_solarize_threshold_within_bound
(
threshold
,
dtype
,
device
):
make_img
=
torch
.
rand
if
dtype
.
is_floating_point
else
partial
(
torch
.
randint
,
0
,
torch
.
iinfo
(
dtype
).
max
)
make_img
=
torch
.
rand
if
dtype
.
is_floating_point
else
partial
(
torch
.
randint
,
0
,
torch
.
iinfo
(
dtype
).
max
)
img
=
make_img
((
3
,
12
,
23
),
dtype
=
dtype
,
device
=
device
)
img
=
make_img
((
3
,
12
,
23
),
dtype
=
dtype
,
device
=
device
)
...
@@ -770,7 +770,7 @@ def test_solarize_threshold_within_bound(threshold, dtype, device):
...
@@ -770,7 +770,7 @@ def test_solarize_threshold_within_bound(threshold, dtype, device):
(
torch
.
int64
,
2
**
64
),
(
torch
.
int64
,
2
**
64
),
],
],
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_solarize_threshold_above_bound
(
threshold
,
dtype
,
device
):
def
test_solarize_threshold_above_bound
(
threshold
,
dtype
,
device
):
make_img
=
torch
.
rand
if
dtype
.
is_floating_point
else
partial
(
torch
.
randint
,
0
,
torch
.
iinfo
(
dtype
).
max
)
make_img
=
torch
.
rand
if
dtype
.
is_floating_point
else
partial
(
torch
.
randint
,
0
,
torch
.
iinfo
(
dtype
).
max
)
img
=
make_img
((
3
,
12
,
23
),
dtype
=
dtype
,
device
=
device
)
img
=
make_img
((
3
,
12
,
23
),
dtype
=
dtype
,
device
=
device
)
...
@@ -778,7 +778,7 @@ def test_solarize_threshold_above_bound(threshold, dtype, device):
...
@@ -778,7 +778,7 @@ def test_solarize_threshold_above_bound(threshold, dtype, device):
F_t
.
solarize
(
img
,
threshold
)
F_t
.
solarize
(
img
,
threshold
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"sharpness_factor"
:
f
}
for
f
in
[
0.2
,
0.5
,
1.0
,
1.5
,
2.0
]])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"sharpness_factor"
:
f
}
for
f
in
[
0.2
,
0.5
,
1.0
,
1.5
,
2.0
]])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
...
@@ -794,7 +794,7 @@ def test_adjust_sharpness(device, dtype, config, channels):
...
@@ -794,7 +794,7 @@ def test_adjust_sharpness(device, dtype, config, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
def
test_autocontrast
(
device
,
dtype
,
channels
):
def
test_autocontrast
(
device
,
dtype
,
channels
):
...
@@ -803,7 +803,7 @@ def test_autocontrast(device, dtype, channels):
...
@@ -803,7 +803,7 @@ def test_autocontrast(device, dtype, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
def
test_autocontrast_equal_minmax
(
device
,
dtype
,
channels
):
def
test_autocontrast_equal_minmax
(
device
,
dtype
,
channels
):
...
@@ -815,7 +815,7 @@ def test_autocontrast_equal_minmax(device, dtype, channels):
...
@@ -815,7 +815,7 @@ def test_autocontrast_equal_minmax(device, dtype, channels):
assert
(
F
.
autocontrast
(
a
)[
0
]
==
F
.
autocontrast
(
a
[
0
])).
all
()
assert
(
F
.
autocontrast
(
a
)[
0
]
==
F
.
autocontrast
(
a
[
0
])).
all
()
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
def
test_equalize
(
device
,
channels
):
def
test_equalize
(
device
,
channels
):
torch
.
use_deterministic_algorithms
(
False
)
torch
.
use_deterministic_algorithms
(
False
)
...
@@ -832,7 +832,7 @@ def test_equalize(device, channels):
...
@@ -832,7 +832,7 @@ def test_equalize(device, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"contrast_factor"
:
f
}
for
f
in
[
0.2
,
0.5
,
1.0
,
1.5
,
2.0
]])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"contrast_factor"
:
f
}
for
f
in
[
0.2
,
0.5
,
1.0
,
1.5
,
2.0
]])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
...
@@ -842,7 +842,7 @@ def test_adjust_contrast(device, dtype, config, channels):
...
@@ -842,7 +842,7 @@ def test_adjust_contrast(device, dtype, config, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"saturation_factor"
:
f
}
for
f
in
[
0.5
,
0.75
,
1.0
,
1.5
,
2.0
]])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"saturation_factor"
:
f
}
for
f
in
[
0.5
,
0.75
,
1.0
,
1.5
,
2.0
]])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
...
@@ -852,7 +852,7 @@ def test_adjust_saturation(device, dtype, config, channels):
...
@@ -852,7 +852,7 @@ def test_adjust_saturation(device, dtype, config, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"hue_factor"
:
f
}
for
f
in
[
-
0.45
,
-
0.25
,
0.0
,
0.25
,
0.45
]])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"hue_factor"
:
f
}
for
f
in
[
-
0.45
,
-
0.25
,
0.0
,
0.25
,
0.45
]])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
...
@@ -862,7 +862,7 @@ def test_adjust_hue(device, dtype, config, channels):
...
@@ -862,7 +862,7 @@ def test_adjust_hue(device, dtype, config, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"dtype"
,
(
None
,
torch
.
float32
,
torch
.
float64
))
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"gamma"
:
g1
,
"gain"
:
g2
}
for
g1
,
g2
in
zip
([
0.8
,
1.0
,
1.2
],
[
0.7
,
1.0
,
1.3
])])
@
pytest
.
mark
.
parametrize
(
"config"
,
[{
"gamma"
:
g1
,
"gain"
:
g2
}
for
g1
,
g2
in
zip
([
0.8
,
1.0
,
1.2
],
[
0.7
,
1.0
,
1.3
])])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
...
@@ -878,7 +878,7 @@ def test_adjust_gamma(device, dtype, config, channels):
...
@@ -878,7 +878,7 @@ def test_adjust_gamma(device, dtype, config, channels):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"pad"
,
[
2
,
[
3
],
[
0
,
3
],
(
3
,
3
),
[
4
,
2
,
4
,
3
]])
@
pytest
.
mark
.
parametrize
(
"pad"
,
[
2
,
[
3
],
[
0
,
3
],
(
3
,
3
),
[
4
,
2
,
4
,
3
]])
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
...
@@ -928,7 +928,7 @@ def test_pad(device, dt, pad, config):
...
@@ -928,7 +928,7 @@ def test_pad(device, dt, pad, config):
_test_fn_on_batch
(
batch_tensors
,
F
.
pad
,
padding
=
script_pad
,
**
config
)
_test_fn_on_batch
(
batch_tensors
,
F
.
pad
,
padding
=
script_pad
,
**
config
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"mode"
,
[
NEAREST
,
NEAREST_EXACT
,
BILINEAR
,
BICUBIC
])
@
pytest
.
mark
.
parametrize
(
"mode"
,
[
NEAREST
,
NEAREST_EXACT
,
BILINEAR
,
BICUBIC
])
def
test_resized_crop
(
device
,
mode
):
def
test_resized_crop
(
device
,
mode
):
# test values of F.resized_crop in several cases:
# test values of F.resized_crop in several cases:
...
@@ -963,7 +963,7 @@ def test_resized_crop(device, mode):
...
@@ -963,7 +963,7 @@ def test_resized_crop(device, mode):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"func, args"
,
"func, args"
,
[
[
...
@@ -996,7 +996,7 @@ def test_assert_image_tensor(device, func, args):
...
@@ -996,7 +996,7 @@ def test_assert_image_tensor(device, func, args):
func
(
tensor
,
*
args
)
func
(
tensor
,
*
args
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_vflip
(
device
):
def
test_vflip
(
device
):
script_vflip
=
torch
.
jit
.
script
(
F
.
vflip
)
script_vflip
=
torch
.
jit
.
script
(
F
.
vflip
)
...
@@ -1013,7 +1013,7 @@ def test_vflip(device):
...
@@ -1013,7 +1013,7 @@ def test_vflip(device):
_test_fn_on_batch
(
batch_tensors
,
F
.
vflip
)
_test_fn_on_batch
(
batch_tensors
,
F
.
vflip
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_hflip
(
device
):
def
test_hflip
(
device
):
script_hflip
=
torch
.
jit
.
script
(
F
.
hflip
)
script_hflip
=
torch
.
jit
.
script
(
F
.
hflip
)
...
@@ -1030,7 +1030,7 @@ def test_hflip(device):
...
@@ -1030,7 +1030,7 @@ def test_hflip(device):
_test_fn_on_batch
(
batch_tensors
,
F
.
hflip
)
_test_fn_on_batch
(
batch_tensors
,
F
.
hflip
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"top, left, height, width"
,
"top, left, height, width"
,
[
[
...
@@ -1059,7 +1059,7 @@ def test_crop(device, top, left, height, width):
...
@@ -1059,7 +1059,7 @@ def test_crop(device, top, left, height, width):
_test_fn_on_batch
(
batch_tensors
,
F
.
crop
,
top
=
top
,
left
=
left
,
height
=
height
,
width
=
width
)
_test_fn_on_batch
(
batch_tensors
,
F
.
crop
,
top
=
top
,
left
=
left
,
height
=
height
,
width
=
width
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"image_size"
,
(
"small"
,
"large"
))
@
pytest
.
mark
.
parametrize
(
"image_size"
,
(
"small"
,
"large"
))
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"ksize"
,
[(
3
,
3
),
[
3
,
5
],
(
23
,
23
)])
@
pytest
.
mark
.
parametrize
(
"ksize"
,
[(
3
,
3
),
[
3
,
5
],
(
23
,
23
)])
...
@@ -1113,7 +1113,7 @@ def test_gaussian_blur(device, image_size, dt, ksize, sigma, fn):
...
@@ -1113,7 +1113,7 @@ def test_gaussian_blur(device, image_size, dt, ksize, sigma, fn):
torch
.
testing
.
assert_close
(
out
,
true_out
,
rtol
=
0.0
,
atol
=
1.0
,
msg
=
f
"
{
ksize
}
,
{
sigma
}
"
)
torch
.
testing
.
assert_close
(
out
,
true_out
,
rtol
=
0.0
,
atol
=
1.0
,
msg
=
f
"
{
ksize
}
,
{
sigma
}
"
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_hsv2rgb
(
device
):
def
test_hsv2rgb
(
device
):
scripted_fn
=
torch
.
jit
.
script
(
F_t
.
_hsv2rgb
)
scripted_fn
=
torch
.
jit
.
script
(
F_t
.
_hsv2rgb
)
shape
=
(
3
,
100
,
150
)
shape
=
(
3
,
100
,
150
)
...
@@ -1144,7 +1144,7 @@ def test_hsv2rgb(device):
...
@@ -1144,7 +1144,7 @@ def test_hsv2rgb(device):
_test_fn_on_batch
(
batch_tensors
,
F_t
.
_hsv2rgb
)
_test_fn_on_batch
(
batch_tensors
,
F_t
.
_hsv2rgb
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_rgb2hsv
(
device
):
def
test_rgb2hsv
(
device
):
scripted_fn
=
torch
.
jit
.
script
(
F_t
.
_rgb2hsv
)
scripted_fn
=
torch
.
jit
.
script
(
F_t
.
_rgb2hsv
)
shape
=
(
3
,
150
,
100
)
shape
=
(
3
,
150
,
100
)
...
@@ -1183,7 +1183,7 @@ def test_rgb2hsv(device):
...
@@ -1183,7 +1183,7 @@ def test_rgb2hsv(device):
_test_fn_on_batch
(
batch_tensors
,
F_t
.
_rgb2hsv
)
_test_fn_on_batch
(
batch_tensors
,
F_t
.
_rgb2hsv
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"num_output_channels"
,
(
3
,
1
))
@
pytest
.
mark
.
parametrize
(
"num_output_channels"
,
(
3
,
1
))
def
test_rgb_to_grayscale
(
device
,
num_output_channels
):
def
test_rgb_to_grayscale
(
device
,
num_output_channels
):
script_rgb_to_grayscale
=
torch
.
jit
.
script
(
F
.
rgb_to_grayscale
)
script_rgb_to_grayscale
=
torch
.
jit
.
script
(
F
.
rgb_to_grayscale
)
...
@@ -1202,7 +1202,7 @@ def test_rgb_to_grayscale(device, num_output_channels):
...
@@ -1202,7 +1202,7 @@ def test_rgb_to_grayscale(device, num_output_channels):
_test_fn_on_batch
(
batch_tensors
,
F
.
rgb_to_grayscale
,
num_output_channels
=
num_output_channels
)
_test_fn_on_batch
(
batch_tensors
,
F
.
rgb_to_grayscale
,
num_output_channels
=
num_output_channels
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_center_crop
(
device
):
def
test_center_crop
(
device
):
script_center_crop
=
torch
.
jit
.
script
(
F
.
center_crop
)
script_center_crop
=
torch
.
jit
.
script
(
F
.
center_crop
)
...
@@ -1220,7 +1220,7 @@ def test_center_crop(device):
...
@@ -1220,7 +1220,7 @@ def test_center_crop(device):
_test_fn_on_batch
(
batch_tensors
,
F
.
center_crop
,
output_size
=
[
10
,
11
])
_test_fn_on_batch
(
batch_tensors
,
F
.
center_crop
,
output_size
=
[
10
,
11
])
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_five_crop
(
device
):
def
test_five_crop
(
device
):
script_five_crop
=
torch
.
jit
.
script
(
F
.
five_crop
)
script_five_crop
=
torch
.
jit
.
script
(
F
.
five_crop
)
...
@@ -1254,7 +1254,7 @@ def test_five_crop(device):
...
@@ -1254,7 +1254,7 @@ def test_five_crop(device):
assert_equal
(
transformed_batch
,
s_transformed_batch
)
assert_equal
(
transformed_batch
,
s_transformed_batch
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_ten_crop
(
device
):
def
test_ten_crop
(
device
):
script_ten_crop
=
torch
.
jit
.
script
(
F
.
ten_crop
)
script_ten_crop
=
torch
.
jit
.
script
(
F
.
ten_crop
)
...
@@ -1300,7 +1300,7 @@ def test_elastic_transform_asserts():
...
@@ -1300,7 +1300,7 @@ def test_elastic_transform_asserts():
_
=
F
.
elastic_transform
(
img_tensor
,
displacement
=
torch
.
rand
(
1
,
2
))
_
=
F
.
elastic_transform
(
img_tensor
,
displacement
=
torch
.
rand
(
1
,
2
))
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
,
BICUBIC
])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
,
BICUBIC
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
...
...
test/test_models.py
View file @
016804ee
...
@@ -15,7 +15,7 @@ import torch
...
@@ -15,7 +15,7 @@ import torch
import
torch.fx
import
torch.fx
import
torch.nn
as
nn
import
torch.nn
as
nn
from
_utils_internal
import
get_relative_path
from
_utils_internal
import
get_relative_path
from
common_utils
import
cpu_and_
gpu
,
freeze_rng_state
,
map_nested_tensor_object
,
needs_cuda
,
set_rng_seed
from
common_utils
import
cpu_and_
cuda
,
freeze_rng_state
,
map_nested_tensor_object
,
needs_cuda
,
set_rng_seed
from
PIL
import
Image
from
PIL
import
Image
from
torchvision
import
models
,
transforms
from
torchvision
import
models
,
transforms
from
torchvision.models
import
get_model_builder
,
list_models
from
torchvision.models
import
get_model_builder
,
list_models
...
@@ -676,14 +676,14 @@ def vitc_b_16(**kwargs: Any):
...
@@ -676,14 +676,14 @@ def vitc_b_16(**kwargs: Any):
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
[
vitc_b_16
])
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
[
vitc_b_16
])
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
cuda
())
def
test_vitc_models
(
model_fn
,
dev
):
def
test_vitc_models
(
model_fn
,
dev
):
test_classification_model
(
model_fn
,
dev
)
test_classification_model
(
model_fn
,
dev
)
@
disable_tf32
()
# see: https://github.com/pytorch/vision/issues/7618
@
disable_tf32
()
# see: https://github.com/pytorch/vision/issues/7618
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
list_model_fns
(
models
))
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
list_model_fns
(
models
))
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
cuda
())
def
test_classification_model
(
model_fn
,
dev
):
def
test_classification_model
(
model_fn
,
dev
):
set_rng_seed
(
0
)
set_rng_seed
(
0
)
defaults
=
{
defaults
=
{
...
@@ -726,7 +726,7 @@ def test_classification_model(model_fn, dev):
...
@@ -726,7 +726,7 @@ def test_classification_model(model_fn, dev):
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
list_model_fns
(
models
.
segmentation
))
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
list_model_fns
(
models
.
segmentation
))
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
cuda
())
def
test_segmentation_model
(
model_fn
,
dev
):
def
test_segmentation_model
(
model_fn
,
dev
):
set_rng_seed
(
0
)
set_rng_seed
(
0
)
defaults
=
{
defaults
=
{
...
@@ -791,7 +791,7 @@ def test_segmentation_model(model_fn, dev):
...
@@ -791,7 +791,7 @@ def test_segmentation_model(model_fn, dev):
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
list_model_fns
(
models
.
detection
))
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
list_model_fns
(
models
.
detection
))
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
cuda
())
def
test_detection_model
(
model_fn
,
dev
):
def
test_detection_model
(
model_fn
,
dev
):
set_rng_seed
(
0
)
set_rng_seed
(
0
)
defaults
=
{
defaults
=
{
...
@@ -923,7 +923,7 @@ def test_detection_model_validation(model_fn):
...
@@ -923,7 +923,7 @@ def test_detection_model_validation(model_fn):
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
list_model_fns
(
models
.
video
))
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
list_model_fns
(
models
.
video
))
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
cuda
())
def
test_video_model
(
model_fn
,
dev
):
def
test_video_model
(
model_fn
,
dev
):
set_rng_seed
(
0
)
set_rng_seed
(
0
)
# the default input shape is
# the default input shape is
...
...
test/test_ops.py
View file @
016804ee
...
@@ -10,7 +10,7 @@ import pytest
...
@@ -10,7 +10,7 @@ import pytest
import
torch
import
torch
import
torch.fx
import
torch.fx
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
from
common_utils
import
assert_equal
,
cpu_and_
gpu
,
needs_cuda
from
common_utils
import
assert_equal
,
cpu_and_
cuda
,
needs_cuda
from
PIL
import
Image
from
PIL
import
Image
from
torch
import
nn
,
Tensor
from
torch
import
nn
,
Tensor
from
torch.autograd
import
gradcheck
from
torch.autograd
import
gradcheck
...
@@ -97,7 +97,7 @@ class PoolWrapper(nn.Module):
...
@@ -97,7 +97,7 @@ class PoolWrapper(nn.Module):
class
RoIOpTester
(
ABC
):
class
RoIOpTester
(
ABC
):
dtype
=
torch
.
float64
dtype
=
torch
.
float64
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
def
test_forward
(
self
,
device
,
contiguous
,
x_dtype
=
None
,
rois_dtype
=
None
,
deterministic
=
False
,
**
kwargs
):
def
test_forward
(
self
,
device
,
contiguous
,
x_dtype
=
None
,
rois_dtype
=
None
,
deterministic
=
False
,
**
kwargs
):
x_dtype
=
self
.
dtype
if
x_dtype
is
None
else
x_dtype
x_dtype
=
self
.
dtype
if
x_dtype
is
None
else
x_dtype
...
@@ -126,7 +126,7 @@ class RoIOpTester(ABC):
...
@@ -126,7 +126,7 @@ class RoIOpTester(ABC):
tol
=
1e-3
if
(
x_dtype
is
torch
.
half
or
rois_dtype
is
torch
.
half
)
else
1e-5
tol
=
1e-3
if
(
x_dtype
is
torch
.
half
or
rois_dtype
is
torch
.
half
)
else
1e-5
torch
.
testing
.
assert_close
(
gt_y
.
to
(
y
),
y
,
rtol
=
tol
,
atol
=
tol
)
torch
.
testing
.
assert_close
(
gt_y
.
to
(
y
),
y
,
rtol
=
tol
,
atol
=
tol
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_is_leaf_node
(
self
,
device
):
def
test_is_leaf_node
(
self
,
device
):
op_obj
=
self
.
make_obj
(
wrap
=
True
).
to
(
device
=
device
)
op_obj
=
self
.
make_obj
(
wrap
=
True
).
to
(
device
=
device
)
graph_node_names
=
get_graph_node_names
(
op_obj
)
graph_node_names
=
get_graph_node_names
(
op_obj
)
...
@@ -135,7 +135,7 @@ class RoIOpTester(ABC):
...
@@ -135,7 +135,7 @@ class RoIOpTester(ABC):
assert
len
(
graph_node_names
[
0
])
==
len
(
graph_node_names
[
1
])
assert
len
(
graph_node_names
[
0
])
==
len
(
graph_node_names
[
1
])
assert
len
(
graph_node_names
[
0
])
==
1
+
op_obj
.
n_inputs
assert
len
(
graph_node_names
[
0
])
==
1
+
op_obj
.
n_inputs
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_torch_fx_trace
(
self
,
device
,
x_dtype
=
torch
.
float
,
rois_dtype
=
torch
.
float
):
def
test_torch_fx_trace
(
self
,
device
,
x_dtype
=
torch
.
float
,
rois_dtype
=
torch
.
float
):
op_obj
=
self
.
make_obj
().
to
(
device
=
device
)
op_obj
=
self
.
make_obj
().
to
(
device
=
device
)
graph_module
=
torch
.
fx
.
symbolic_trace
(
op_obj
)
graph_module
=
torch
.
fx
.
symbolic_trace
(
op_obj
)
...
@@ -155,7 +155,7 @@ class RoIOpTester(ABC):
...
@@ -155,7 +155,7 @@ class RoIOpTester(ABC):
torch
.
testing
.
assert_close
(
output_gt
,
output_fx
,
rtol
=
tol
,
atol
=
tol
)
torch
.
testing
.
assert_close
(
output_gt
,
output_fx
,
rtol
=
tol
,
atol
=
tol
)
@
pytest
.
mark
.
parametrize
(
"seed"
,
range
(
10
))
@
pytest
.
mark
.
parametrize
(
"seed"
,
range
(
10
))
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
def
test_backward
(
self
,
seed
,
device
,
contiguous
,
deterministic
=
False
):
def
test_backward
(
self
,
seed
,
device
,
contiguous
,
deterministic
=
False
):
torch
.
random
.
manual_seed
(
seed
)
torch
.
random
.
manual_seed
(
seed
)
...
@@ -418,7 +418,7 @@ class TestRoIAlign(RoIOpTester):
...
@@ -418,7 +418,7 @@ class TestRoIAlign(RoIOpTester):
self
.
_helper_boxes_shape
(
ops
.
roi_align
)
self
.
_helper_boxes_shape
(
ops
.
roi_align
)
@
pytest
.
mark
.
parametrize
(
"aligned"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"aligned"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"deterministic"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"deterministic"
,
(
True
,
False
))
def
test_forward
(
self
,
device
,
contiguous
,
deterministic
,
aligned
,
x_dtype
=
None
,
rois_dtype
=
None
):
def
test_forward
(
self
,
device
,
contiguous
,
deterministic
,
aligned
,
x_dtype
=
None
,
rois_dtype
=
None
):
...
@@ -450,7 +450,7 @@ class TestRoIAlign(RoIOpTester):
...
@@ -450,7 +450,7 @@ class TestRoIAlign(RoIOpTester):
)
)
@
pytest
.
mark
.
parametrize
(
"seed"
,
range
(
10
))
@
pytest
.
mark
.
parametrize
(
"seed"
,
range
(
10
))
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"deterministic"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"deterministic"
,
(
True
,
False
))
def
test_backward
(
self
,
seed
,
device
,
contiguous
,
deterministic
):
def
test_backward
(
self
,
seed
,
device
,
contiguous
,
deterministic
):
...
@@ -612,7 +612,7 @@ class TestMultiScaleRoIAlign:
...
@@ -612,7 +612,7 @@ class TestMultiScaleRoIAlign:
)
)
assert
repr
(
t
)
==
expected_string
assert
repr
(
t
)
==
expected_string
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_is_leaf_node
(
self
,
device
):
def
test_is_leaf_node
(
self
,
device
):
op_obj
=
self
.
make_obj
(
wrap
=
True
).
to
(
device
=
device
)
op_obj
=
self
.
make_obj
(
wrap
=
True
).
to
(
device
=
device
)
graph_node_names
=
get_graph_node_names
(
op_obj
)
graph_node_names
=
get_graph_node_names
(
op_obj
)
...
@@ -885,7 +885,7 @@ class TestDeformConv:
...
@@ -885,7 +885,7 @@ class TestDeformConv:
)
)
return
DeformConvModuleWrapper
(
obj
)
if
wrap
else
obj
return
DeformConvModuleWrapper
(
obj
)
if
wrap
else
obj
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_is_leaf_node
(
self
,
device
):
def
test_is_leaf_node
(
self
,
device
):
op_obj
=
self
.
make_obj
(
wrap
=
True
).
to
(
device
=
device
)
op_obj
=
self
.
make_obj
(
wrap
=
True
).
to
(
device
=
device
)
graph_node_names
=
get_graph_node_names
(
op_obj
)
graph_node_names
=
get_graph_node_names
(
op_obj
)
...
@@ -894,7 +894,7 @@ class TestDeformConv:
...
@@ -894,7 +894,7 @@ class TestDeformConv:
assert
len
(
graph_node_names
[
0
])
==
len
(
graph_node_names
[
1
])
assert
len
(
graph_node_names
[
0
])
==
len
(
graph_node_names
[
1
])
assert
len
(
graph_node_names
[
0
])
==
1
+
op_obj
.
n_inputs
assert
len
(
graph_node_names
[
0
])
==
1
+
op_obj
.
n_inputs
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"batch_sz"
,
(
0
,
33
))
@
pytest
.
mark
.
parametrize
(
"batch_sz"
,
(
0
,
33
))
def
test_forward
(
self
,
device
,
contiguous
,
batch_sz
,
dtype
=
None
):
def
test_forward
(
self
,
device
,
contiguous
,
batch_sz
,
dtype
=
None
):
...
@@ -946,7 +946,7 @@ class TestDeformConv:
...
@@ -946,7 +946,7 @@ class TestDeformConv:
wrong_mask
=
torch
.
rand_like
(
mask
[:,
:
2
])
wrong_mask
=
torch
.
rand_like
(
mask
[:,
:
2
])
layer
(
x
,
offset
,
wrong_mask
)
layer
(
x
,
offset
,
wrong_mask
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"contiguous"
,
(
True
,
False
))
@
pytest
.
mark
.
parametrize
(
"batch_sz"
,
(
0
,
33
))
@
pytest
.
mark
.
parametrize
(
"batch_sz"
,
(
0
,
33
))
def
test_backward
(
self
,
device
,
contiguous
,
batch_sz
):
def
test_backward
(
self
,
device
,
contiguous
,
batch_sz
):
...
@@ -1411,7 +1411,7 @@ def assert_empty_loss(iou_fn, dtype, device):
...
@@ -1411,7 +1411,7 @@ def assert_empty_loss(iou_fn, dtype, device):
class
TestGeneralizedBoxIouLoss
:
class
TestGeneralizedBoxIouLoss
:
# We refer to original test: https://github.com/facebookresearch/fvcore/blob/main/tests/test_giou_loss.py
# We refer to original test: https://github.com/facebookresearch/fvcore/blob/main/tests/test_giou_loss.py
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
def
test_giou_loss
(
self
,
dtype
,
device
):
def
test_giou_loss
(
self
,
dtype
,
device
):
box1
,
box2
,
box3
,
box4
,
box1s
,
box2s
=
get_boxes
(
dtype
,
device
)
box1
,
box2
,
box3
,
box4
,
box1s
,
box2s
=
get_boxes
(
dtype
,
device
)
...
@@ -1439,7 +1439,7 @@ class TestGeneralizedBoxIouLoss:
...
@@ -1439,7 +1439,7 @@ class TestGeneralizedBoxIouLoss:
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid"
):
ops
.
generalized_box_iou_loss
(
box1s
,
box2s
,
reduction
=
"xyz"
)
ops
.
generalized_box_iou_loss
(
box1s
,
box2s
,
reduction
=
"xyz"
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
def
test_empty_inputs
(
self
,
dtype
,
device
):
def
test_empty_inputs
(
self
,
dtype
,
device
):
assert_empty_loss
(
ops
.
generalized_box_iou_loss
,
dtype
,
device
)
assert_empty_loss
(
ops
.
generalized_box_iou_loss
,
dtype
,
device
)
...
@@ -1447,7 +1447,7 @@ class TestGeneralizedBoxIouLoss:
...
@@ -1447,7 +1447,7 @@ class TestGeneralizedBoxIouLoss:
class
TestCompleteBoxIouLoss
:
class
TestCompleteBoxIouLoss
:
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_ciou_loss
(
self
,
dtype
,
device
):
def
test_ciou_loss
(
self
,
dtype
,
device
):
box1
,
box2
,
box3
,
box4
,
box1s
,
box2s
=
get_boxes
(
dtype
,
device
)
box1
,
box2
,
box3
,
box4
,
box1s
,
box2s
=
get_boxes
(
dtype
,
device
)
...
@@ -1461,14 +1461,14 @@ class TestCompleteBoxIouLoss:
...
@@ -1461,14 +1461,14 @@ class TestCompleteBoxIouLoss:
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid"
):
ops
.
complete_box_iou_loss
(
box1s
,
box2s
,
reduction
=
"xyz"
)
ops
.
complete_box_iou_loss
(
box1s
,
box2s
,
reduction
=
"xyz"
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
def
test_empty_inputs
(
self
,
dtype
,
device
):
def
test_empty_inputs
(
self
,
dtype
,
device
):
assert_empty_loss
(
ops
.
complete_box_iou_loss
,
dtype
,
device
)
assert_empty_loss
(
ops
.
complete_box_iou_loss
,
dtype
,
device
)
class
TestDistanceBoxIouLoss
:
class
TestDistanceBoxIouLoss
:
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
def
test_distance_iou_loss
(
self
,
dtype
,
device
):
def
test_distance_iou_loss
(
self
,
dtype
,
device
):
box1
,
box2
,
box3
,
box4
,
box1s
,
box2s
=
get_boxes
(
dtype
,
device
)
box1
,
box2
,
box3
,
box4
,
box1s
,
box2s
=
get_boxes
(
dtype
,
device
)
...
@@ -1483,7 +1483,7 @@ class TestDistanceBoxIouLoss:
...
@@ -1483,7 +1483,7 @@ class TestDistanceBoxIouLoss:
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid"
):
ops
.
distance_box_iou_loss
(
box1s
,
box2s
,
reduction
=
"xyz"
)
ops
.
distance_box_iou_loss
(
box1s
,
box2s
,
reduction
=
"xyz"
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
def
test_empty_distance_iou_inputs
(
self
,
dtype
,
device
):
def
test_empty_distance_iou_inputs
(
self
,
dtype
,
device
):
assert_empty_loss
(
ops
.
distance_box_iou_loss
,
dtype
,
device
)
assert_empty_loss
(
ops
.
distance_box_iou_loss
,
dtype
,
device
)
...
@@ -1528,7 +1528,7 @@ class TestFocalLoss:
...
@@ -1528,7 +1528,7 @@ class TestFocalLoss:
@
pytest
.
mark
.
parametrize
(
"alpha"
,
[
-
1.0
,
0.0
,
0.58
,
1.0
])
@
pytest
.
mark
.
parametrize
(
"alpha"
,
[
-
1.0
,
0.0
,
0.58
,
1.0
])
@
pytest
.
mark
.
parametrize
(
"gamma"
,
[
0
,
2
])
@
pytest
.
mark
.
parametrize
(
"gamma"
,
[
0
,
2
])
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"seed"
,
[
0
,
1
])
@
pytest
.
mark
.
parametrize
(
"seed"
,
[
0
,
1
])
def
test_correct_ratio
(
self
,
alpha
,
gamma
,
device
,
dtype
,
seed
):
def
test_correct_ratio
(
self
,
alpha
,
gamma
,
device
,
dtype
,
seed
):
...
@@ -1557,7 +1557,7 @@ class TestFocalLoss:
...
@@ -1557,7 +1557,7 @@ class TestFocalLoss:
torch
.
testing
.
assert_close
(
correct_ratio
,
loss_ratio
,
atol
=
tol
,
rtol
=
tol
)
torch
.
testing
.
assert_close
(
correct_ratio
,
loss_ratio
,
atol
=
tol
,
rtol
=
tol
)
@
pytest
.
mark
.
parametrize
(
"reduction"
,
[
"mean"
,
"sum"
])
@
pytest
.
mark
.
parametrize
(
"reduction"
,
[
"mean"
,
"sum"
])
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"seed"
,
[
2
,
3
])
@
pytest
.
mark
.
parametrize
(
"seed"
,
[
2
,
3
])
def
test_equal_ce_loss
(
self
,
reduction
,
device
,
dtype
,
seed
):
def
test_equal_ce_loss
(
self
,
reduction
,
device
,
dtype
,
seed
):
...
@@ -1584,7 +1584,7 @@ class TestFocalLoss:
...
@@ -1584,7 +1584,7 @@ class TestFocalLoss:
@
pytest
.
mark
.
parametrize
(
"alpha"
,
[
-
1.0
,
0.0
,
0.58
,
1.0
])
@
pytest
.
mark
.
parametrize
(
"alpha"
,
[
-
1.0
,
0.0
,
0.58
,
1.0
])
@
pytest
.
mark
.
parametrize
(
"gamma"
,
[
0
,
2
])
@
pytest
.
mark
.
parametrize
(
"gamma"
,
[
0
,
2
])
@
pytest
.
mark
.
parametrize
(
"reduction"
,
[
"none"
,
"mean"
,
"sum"
])
@
pytest
.
mark
.
parametrize
(
"reduction"
,
[
"none"
,
"mean"
,
"sum"
])
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"seed"
,
[
4
,
5
])
@
pytest
.
mark
.
parametrize
(
"seed"
,
[
4
,
5
])
def
test_jit
(
self
,
alpha
,
gamma
,
reduction
,
device
,
dtype
,
seed
):
def
test_jit
(
self
,
alpha
,
gamma
,
reduction
,
device
,
dtype
,
seed
):
...
@@ -1600,7 +1600,7 @@ class TestFocalLoss:
...
@@ -1600,7 +1600,7 @@ class TestFocalLoss:
torch
.
testing
.
assert_close
(
focal_loss
,
scripted_focal_loss
,
rtol
=
tol
,
atol
=
tol
)
torch
.
testing
.
assert_close
(
focal_loss
,
scripted_focal_loss
,
rtol
=
tol
,
atol
=
tol
)
# Raise ValueError for anonymous reduction mode
# Raise ValueError for anonymous reduction mode
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
@
pytest
.
mark
.
parametrize
(
"dtype"
,
[
torch
.
float32
,
torch
.
half
])
def
test_reduction_mode
(
self
,
device
,
dtype
,
reduction
=
"xyz"
):
def
test_reduction_mode
(
self
,
device
,
dtype
,
reduction
=
"xyz"
):
if
device
==
"cpu"
and
dtype
is
torch
.
half
:
if
device
==
"cpu"
and
dtype
is
torch
.
half
:
...
...
test/test_prototype_models.py
View file @
016804ee
import
pytest
import
pytest
import
test_models
as
TM
import
test_models
as
TM
import
torch
import
torch
from
common_utils
import
cpu_and_
gpu
,
set_rng_seed
from
common_utils
import
cpu_and_
cuda
,
set_rng_seed
from
torchvision.prototype
import
models
from
torchvision.prototype
import
models
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
(
models
.
depth
.
stereo
.
raft_stereo_base
,))
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
(
models
.
depth
.
stereo
.
raft_stereo_base
,))
@
pytest
.
mark
.
parametrize
(
"model_mode"
,
(
"standard"
,
"scripted"
))
@
pytest
.
mark
.
parametrize
(
"model_mode"
,
(
"standard"
,
"scripted"
))
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
cuda
())
def
test_raft_stereo
(
model_fn
,
model_mode
,
dev
):
def
test_raft_stereo
(
model_fn
,
model_mode
,
dev
):
# A simple test to make sure the model can do forward pass and jit scriptable
# A simple test to make sure the model can do forward pass and jit scriptable
set_rng_seed
(
0
)
set_rng_seed
(
0
)
...
@@ -40,7 +40,7 @@ def test_raft_stereo(model_fn, model_mode, dev):
...
@@ -40,7 +40,7 @@ def test_raft_stereo(model_fn, model_mode, dev):
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
(
models
.
depth
.
stereo
.
crestereo_base
,))
@
pytest
.
mark
.
parametrize
(
"model_fn"
,
(
models
.
depth
.
stereo
.
crestereo_base
,))
@
pytest
.
mark
.
parametrize
(
"model_mode"
,
(
"standard"
,
"scripted"
))
@
pytest
.
mark
.
parametrize
(
"model_mode"
,
(
"standard"
,
"scripted"
))
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"dev"
,
cpu_and_
cuda
())
def
test_crestereo
(
model_fn
,
model_mode
,
dev
):
def
test_crestereo
(
model_fn
,
model_mode
,
dev
):
set_rng_seed
(
0
)
set_rng_seed
(
0
)
...
...
test/test_transforms_tensor.py
View file @
016804ee
...
@@ -12,7 +12,7 @@ from common_utils import (
...
@@ -12,7 +12,7 @@ from common_utils import (
_create_data
,
_create_data
,
_create_data_batch
,
_create_data_batch
,
assert_equal
,
assert_equal
,
cpu_and_
gpu
,
cpu_and_
cuda
,
float_dtypes
,
float_dtypes
,
get_tmp_dir
,
get_tmp_dir
,
int_dtypes
,
int_dtypes
,
...
@@ -105,7 +105,7 @@ def _test_fn_save_load(fn, tmpdir):
...
@@ -105,7 +105,7 @@ def _test_fn_save_load(fn, tmpdir):
_
=
torch
.
jit
.
load
(
p
)
_
=
torch
.
jit
.
load
(
p
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"func,method,fn_kwargs,match_kwargs"
,
"func,method,fn_kwargs,match_kwargs"
,
[
[
...
@@ -130,7 +130,7 @@ def test_random(func, method, device, channels, fn_kwargs, match_kwargs):
...
@@ -130,7 +130,7 @@ def test_random(func, method, device, channels, fn_kwargs, match_kwargs):
@
pytest
.
mark
.
parametrize
(
"seed"
,
range
(
10
))
@
pytest
.
mark
.
parametrize
(
"seed"
,
range
(
10
))
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"channels"
,
[
1
,
3
])
class
TestColorJitter
:
class
TestColorJitter
:
@
pytest
.
fixture
(
autouse
=
True
)
@
pytest
.
fixture
(
autouse
=
True
)
...
@@ -206,7 +206,7 @@ class TestColorJitter:
...
@@ -206,7 +206,7 @@ class TestColorJitter:
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"m"
,
[
"constant"
,
"edge"
,
"reflect"
,
"symmetric"
])
@
pytest
.
mark
.
parametrize
(
"m"
,
[
"constant"
,
"edge"
,
"reflect"
,
"symmetric"
])
@
pytest
.
mark
.
parametrize
(
"mul"
,
[
1
,
-
1
])
@
pytest
.
mark
.
parametrize
(
"mul"
,
[
1
,
-
1
])
def
test_pad
(
m
,
mul
,
device
):
def
test_pad
(
m
,
mul
,
device
):
...
@@ -229,7 +229,7 @@ def test_pad(m, mul, device):
...
@@ -229,7 +229,7 @@ def test_pad(m, mul, device):
_test_op
(
F
.
pad
,
T
.
Pad
,
device
=
device
,
fn_kwargs
=
fn_kwargs
,
meth_kwargs
=
meth_kwargs
)
_test_op
(
F
.
pad
,
T
.
Pad
,
device
=
device
,
fn_kwargs
=
fn_kwargs
,
meth_kwargs
=
meth_kwargs
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_crop
(
device
):
def
test_crop
(
device
):
fn_kwargs
=
{
"top"
:
2
,
"left"
:
3
,
"height"
:
4
,
"width"
:
5
}
fn_kwargs
=
{
"top"
:
2
,
"left"
:
3
,
"height"
:
4
,
"width"
:
5
}
# Test transforms.RandomCrop with size and padding as tuple
# Test transforms.RandomCrop with size and padding as tuple
...
@@ -257,7 +257,7 @@ def test_crop(device):
...
@@ -257,7 +257,7 @@ def test_crop(device):
_test_functional_op
(
F
.
crop
,
fn_kwargs
=
fn_kwargs
,
device
=
device
)
_test_functional_op
(
F
.
crop
,
fn_kwargs
=
fn_kwargs
,
device
=
device
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"padding_config"
,
"padding_config"
,
[
[
...
@@ -283,7 +283,7 @@ def test_random_crop_save_load(tmpdir):
...
@@ -283,7 +283,7 @@ def test_random_crop_save_load(tmpdir):
_test_fn_save_load
(
fn
,
tmpdir
)
_test_fn_save_load
(
fn
,
tmpdir
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_center_crop
(
device
,
tmpdir
):
def
test_center_crop
(
device
,
tmpdir
):
fn_kwargs
=
{
"output_size"
:
(
4
,
5
)}
fn_kwargs
=
{
"output_size"
:
(
4
,
5
)}
meth_kwargs
=
{
"size"
:
(
4
,
5
)}
meth_kwargs
=
{
"size"
:
(
4
,
5
)}
...
@@ -313,7 +313,7 @@ def test_center_crop_save_load(tmpdir):
...
@@ -313,7 +313,7 @@ def test_center_crop_save_load(tmpdir):
_test_fn_save_load
(
fn
,
tmpdir
)
_test_fn_save_load
(
fn
,
tmpdir
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"fn, method, out_length"
,
"fn, method, out_length"
,
[
[
...
@@ -380,7 +380,7 @@ class TestResize:
...
@@ -380,7 +380,7 @@ class TestResize:
assert
y
.
shape
[
1
]
==
size
assert
y
.
shape
[
1
]
==
size
assert
y
.
shape
[
2
]
==
int
(
size
*
46
/
32
)
assert
y
.
shape
[
2
]
==
int
(
size
*
46
/
32
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
])
@
pytest
.
mark
.
parametrize
(
"size"
,
[[
32
],
[
32
,
32
],
(
32
,
32
),
[
34
,
35
]])
@
pytest
.
mark
.
parametrize
(
"size"
,
[[
32
],
[
32
,
32
],
(
32
,
32
),
[
34
,
35
]])
@
pytest
.
mark
.
parametrize
(
"max_size"
,
[
None
,
35
,
1000
])
@
pytest
.
mark
.
parametrize
(
"max_size"
,
[
None
,
35
,
1000
])
...
@@ -404,7 +404,7 @@ class TestResize:
...
@@ -404,7 +404,7 @@ class TestResize:
fn
=
T
.
Resize
(
size
=
[
32
],
antialias
=
True
)
fn
=
T
.
Resize
(
size
=
[
32
],
antialias
=
True
)
_test_fn_save_load
(
fn
,
tmpdir
)
_test_fn_save_load
(
fn
,
tmpdir
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"scale"
,
[(
0.7
,
1.2
),
[
0.7
,
1.2
]])
@
pytest
.
mark
.
parametrize
(
"scale"
,
[(
0.7
,
1.2
),
[
0.7
,
1.2
]])
@
pytest
.
mark
.
parametrize
(
"ratio"
,
[(
0.75
,
1.333
),
[
0.75
,
1.333
]])
@
pytest
.
mark
.
parametrize
(
"ratio"
,
[(
0.75
,
1.333
),
[
0.75
,
1.333
]])
@
pytest
.
mark
.
parametrize
(
"size"
,
[(
32
,),
[
44
],
[
32
],
[
32
,
32
],
(
32
,
32
),
[
44
,
55
]])
@
pytest
.
mark
.
parametrize
(
"size"
,
[(
32
,),
[
44
],
[
32
],
[
32
,
32
],
(
32
,
32
),
[
44
,
55
]])
...
@@ -460,42 +460,42 @@ def test_random_affine_save_load(tmpdir):
...
@@ -460,42 +460,42 @@ def test_random_affine_save_load(tmpdir):
_test_fn_save_load
(
fn
,
tmpdir
)
_test_fn_save_load
(
fn
,
tmpdir
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"shear"
,
[
15
,
10.0
,
(
5.0
,
10.0
),
[
-
15
,
15
],
[
-
10.0
,
10.0
,
-
11.0
,
11.0
]])
@
pytest
.
mark
.
parametrize
(
"shear"
,
[
15
,
10.0
,
(
5.0
,
10.0
),
[
-
15
,
15
],
[
-
10.0
,
10.0
,
-
11.0
,
11.0
]])
def
test_random_affine_shear
(
device
,
interpolation
,
shear
):
def
test_random_affine_shear
(
device
,
interpolation
,
shear
):
_test_random_affine_helper
(
device
,
degrees
=
0.0
,
interpolation
=
interpolation
,
shear
=
shear
)
_test_random_affine_helper
(
device
,
degrees
=
0.0
,
interpolation
=
interpolation
,
shear
=
shear
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"scale"
,
[(
0.7
,
1.2
),
[
0.7
,
1.2
]])
@
pytest
.
mark
.
parametrize
(
"scale"
,
[(
0.7
,
1.2
),
[
0.7
,
1.2
]])
def
test_random_affine_scale
(
device
,
interpolation
,
scale
):
def
test_random_affine_scale
(
device
,
interpolation
,
scale
):
_test_random_affine_helper
(
device
,
degrees
=
0.0
,
interpolation
=
interpolation
,
scale
=
scale
)
_test_random_affine_helper
(
device
,
degrees
=
0.0
,
interpolation
=
interpolation
,
scale
=
scale
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"translate"
,
[(
0.1
,
0.2
),
[
0.2
,
0.1
]])
@
pytest
.
mark
.
parametrize
(
"translate"
,
[(
0.1
,
0.2
),
[
0.2
,
0.1
]])
def
test_random_affine_translate
(
device
,
interpolation
,
translate
):
def
test_random_affine_translate
(
device
,
interpolation
,
translate
):
_test_random_affine_helper
(
device
,
degrees
=
0.0
,
interpolation
=
interpolation
,
translate
=
translate
)
_test_random_affine_helper
(
device
,
degrees
=
0.0
,
interpolation
=
interpolation
,
translate
=
translate
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"degrees"
,
[
45
,
35.0
,
(
-
45
,
45
),
[
-
90.0
,
90.0
]])
@
pytest
.
mark
.
parametrize
(
"degrees"
,
[
45
,
35.0
,
(
-
45
,
45
),
[
-
90.0
,
90.0
]])
def
test_random_affine_degrees
(
device
,
interpolation
,
degrees
):
def
test_random_affine_degrees
(
device
,
interpolation
,
degrees
):
_test_random_affine_helper
(
device
,
degrees
=
degrees
,
interpolation
=
interpolation
)
_test_random_affine_helper
(
device
,
degrees
=
degrees
,
interpolation
=
interpolation
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
def
test_random_affine_fill
(
device
,
interpolation
,
fill
):
def
test_random_affine_fill
(
device
,
interpolation
,
fill
):
_test_random_affine_helper
(
device
,
degrees
=
0.0
,
interpolation
=
interpolation
,
fill
=
fill
)
_test_random_affine_helper
(
device
,
degrees
=
0.0
,
interpolation
=
interpolation
,
fill
=
fill
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"center"
,
[(
0
,
0
),
[
10
,
10
],
None
,
(
56
,
44
)])
@
pytest
.
mark
.
parametrize
(
"center"
,
[(
0
,
0
),
[
10
,
10
],
None
,
(
56
,
44
)])
@
pytest
.
mark
.
parametrize
(
"expand"
,
[
True
,
False
])
@
pytest
.
mark
.
parametrize
(
"expand"
,
[
True
,
False
])
@
pytest
.
mark
.
parametrize
(
"degrees"
,
[
45
,
35.0
,
(
-
45
,
45
),
[
-
90.0
,
90.0
]])
@
pytest
.
mark
.
parametrize
(
"degrees"
,
[
45
,
35.0
,
(
-
45
,
45
),
[
-
90.0
,
90.0
]])
...
@@ -517,7 +517,7 @@ def test_random_rotate_save_load(tmpdir):
...
@@ -517,7 +517,7 @@ def test_random_rotate_save_load(tmpdir):
_test_fn_save_load
(
fn
,
tmpdir
)
_test_fn_save_load
(
fn
,
tmpdir
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"distortion_scale"
,
np
.
linspace
(
0.1
,
1.0
,
num
=
20
))
@
pytest
.
mark
.
parametrize
(
"distortion_scale"
,
np
.
linspace
(
0.1
,
1.0
,
num
=
20
))
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"interpolation"
,
[
NEAREST
,
BILINEAR
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
...
@@ -537,7 +537,7 @@ def test_random_perspective_save_load(tmpdir):
...
@@ -537,7 +537,7 @@ def test_random_perspective_save_load(tmpdir):
_test_fn_save_load
(
fn
,
tmpdir
)
_test_fn_save_load
(
fn
,
tmpdir
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"Klass, meth_kwargs"
,
"Klass, meth_kwargs"
,
[(
T
.
Grayscale
,
{
"num_output_channels"
:
1
}),
(
T
.
Grayscale
,
{
"num_output_channels"
:
3
}),
(
T
.
RandomGrayscale
,
{})],
[(
T
.
Grayscale
,
{
"num_output_channels"
:
1
}),
(
T
.
Grayscale
,
{
"num_output_channels"
:
3
}),
(
T
.
RandomGrayscale
,
{})],
...
@@ -547,7 +547,7 @@ def test_to_grayscale(device, Klass, meth_kwargs):
...
@@ -547,7 +547,7 @@ def test_to_grayscale(device, Klass, meth_kwargs):
_test_class_op
(
Klass
,
meth_kwargs
=
meth_kwargs
,
test_exact_match
=
False
,
device
=
device
,
tol
=
tol
,
agg_method
=
"max"
)
_test_class_op
(
Klass
,
meth_kwargs
=
meth_kwargs
,
test_exact_match
=
False
,
device
=
device
,
tol
=
tol
,
agg_method
=
"max"
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"in_dtype"
,
int_dtypes
()
+
float_dtypes
())
@
pytest
.
mark
.
parametrize
(
"in_dtype"
,
int_dtypes
()
+
float_dtypes
())
@
pytest
.
mark
.
parametrize
(
"out_dtype"
,
int_dtypes
()
+
float_dtypes
())
@
pytest
.
mark
.
parametrize
(
"out_dtype"
,
int_dtypes
()
+
float_dtypes
())
def
test_convert_image_dtype
(
device
,
in_dtype
,
out_dtype
):
def
test_convert_image_dtype
(
device
,
in_dtype
,
out_dtype
):
...
@@ -578,7 +578,7 @@ def test_convert_image_dtype_save_load(tmpdir):
...
@@ -578,7 +578,7 @@ def test_convert_image_dtype_save_load(tmpdir):
_test_fn_save_load
(
fn
,
tmpdir
)
_test_fn_save_load
(
fn
,
tmpdir
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"policy"
,
[
policy
for
policy
in
T
.
AutoAugmentPolicy
])
@
pytest
.
mark
.
parametrize
(
"policy"
,
[
policy
for
policy
in
T
.
AutoAugmentPolicy
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
def
test_autoaugment
(
device
,
policy
,
fill
):
def
test_autoaugment
(
device
,
policy
,
fill
):
...
@@ -592,7 +592,7 @@ def test_autoaugment(device, policy, fill):
...
@@ -592,7 +592,7 @@ def test_autoaugment(device, policy, fill):
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"num_ops"
,
[
1
,
2
,
3
])
@
pytest
.
mark
.
parametrize
(
"num_ops"
,
[
1
,
2
,
3
])
@
pytest
.
mark
.
parametrize
(
"magnitude"
,
[
7
,
9
,
11
])
@
pytest
.
mark
.
parametrize
(
"magnitude"
,
[
7
,
9
,
11
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
...
@@ -607,7 +607,7 @@ def test_randaugment(device, num_ops, magnitude, fill):
...
@@ -607,7 +607,7 @@ def test_randaugment(device, num_ops, magnitude, fill):
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
def
test_trivialaugmentwide
(
device
,
fill
):
def
test_trivialaugmentwide
(
device
,
fill
):
tensor
=
torch
.
randint
(
0
,
256
,
size
=
(
3
,
44
,
56
),
dtype
=
torch
.
uint8
,
device
=
device
)
tensor
=
torch
.
randint
(
0
,
256
,
size
=
(
3
,
44
,
56
),
dtype
=
torch
.
uint8
,
device
=
device
)
...
@@ -620,7 +620,7 @@ def test_trivialaugmentwide(device, fill):
...
@@ -620,7 +620,7 @@ def test_trivialaugmentwide(device, fill):
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
@
pytest
.
mark
.
parametrize
(
"fill"
,
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
],
1
])
def
test_augmix
(
device
,
fill
):
def
test_augmix
(
device
,
fill
):
tensor
=
torch
.
randint
(
0
,
256
,
size
=
(
3
,
44
,
56
),
dtype
=
torch
.
uint8
,
device
=
device
)
tensor
=
torch
.
randint
(
0
,
256
,
size
=
(
3
,
44
,
56
),
dtype
=
torch
.
uint8
,
device
=
device
)
...
@@ -686,7 +686,7 @@ def test_autoaugment__op_apply_shear(interpolation, mode):
...
@@ -686,7 +686,7 @@ def test_autoaugment__op_apply_shear(interpolation, mode):
_assert_approx_equal_tensor_to_pil
(
out
,
expected_out
)
_assert_approx_equal_tensor_to_pil
(
out
,
expected_out
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"config"
,
"config"
,
[
[
...
@@ -724,7 +724,7 @@ def test_random_erasing_with_invalid_data():
...
@@ -724,7 +724,7 @@ def test_random_erasing_with_invalid_data():
random_erasing
(
img
)
random_erasing
(
img
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_normalize
(
device
,
tmpdir
):
def
test_normalize
(
device
,
tmpdir
):
fn
=
T
.
Normalize
((
0.5
,
0.5
,
0.5
),
(
0.5
,
0.5
,
0.5
))
fn
=
T
.
Normalize
((
0.5
,
0.5
,
0.5
),
(
0.5
,
0.5
,
0.5
))
tensor
,
_
=
_create_data
(
26
,
34
,
device
=
device
)
tensor
,
_
=
_create_data
(
26
,
34
,
device
=
device
)
...
@@ -743,7 +743,7 @@ def test_normalize(device, tmpdir):
...
@@ -743,7 +743,7 @@ def test_normalize(device, tmpdir):
scripted_fn
.
save
(
os
.
path
.
join
(
tmpdir
,
"t_norm.pt"
))
scripted_fn
.
save
(
os
.
path
.
join
(
tmpdir
,
"t_norm.pt"
))
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_linear_transformation
(
device
,
tmpdir
):
def
test_linear_transformation
(
device
,
tmpdir
):
c
,
h
,
w
=
3
,
24
,
32
c
,
h
,
w
=
3
,
24
,
32
...
@@ -769,7 +769,7 @@ def test_linear_transformation(device, tmpdir):
...
@@ -769,7 +769,7 @@ def test_linear_transformation(device, tmpdir):
scripted_fn
.
save
(
os
.
path
.
join
(
tmpdir
,
"t_norm.pt"
))
scripted_fn
.
save
(
os
.
path
.
join
(
tmpdir
,
"t_norm.pt"
))
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_compose
(
device
):
def
test_compose
(
device
):
tensor
,
_
=
_create_data
(
26
,
34
,
device
=
device
)
tensor
,
_
=
_create_data
(
26
,
34
,
device
=
device
)
tensor
=
tensor
.
to
(
dtype
=
torch
.
float32
)
/
255.0
tensor
=
tensor
.
to
(
dtype
=
torch
.
float32
)
/
255.0
...
@@ -797,7 +797,7 @@ def test_compose(device):
...
@@ -797,7 +797,7 @@ def test_compose(device):
torch
.
jit
.
script
(
t
)
torch
.
jit
.
script
(
t
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_random_apply
(
device
):
def
test_random_apply
(
device
):
tensor
,
_
=
_create_data
(
26
,
34
,
device
=
device
)
tensor
,
_
=
_create_data
(
26
,
34
,
device
=
device
)
tensor
=
tensor
.
to
(
dtype
=
torch
.
float32
)
/
255.0
tensor
=
tensor
.
to
(
dtype
=
torch
.
float32
)
/
255.0
...
@@ -839,7 +839,7 @@ def test_random_apply(device):
...
@@ -839,7 +839,7 @@ def test_random_apply(device):
torch
.
jit
.
script
(
transforms
)
torch
.
jit
.
script
(
transforms
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"meth_kwargs"
,
"meth_kwargs"
,
[
[
...
@@ -877,7 +877,7 @@ def test_gaussian_blur(device, channels, meth_kwargs):
...
@@ -877,7 +877,7 @@ def test_gaussian_blur(device, channels, meth_kwargs):
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"fill"
,
"fill"
,
[
[
...
...
test/test_transforms_v2.py
View file @
016804ee
...
@@ -16,7 +16,7 @@ import torchvision.transforms.v2 as transforms
...
@@ -16,7 +16,7 @@ import torchvision.transforms.v2 as transforms
from
common_utils
import
(
from
common_utils
import
(
assert_equal
,
assert_equal
,
assert_run_python_script
,
assert_run_python_script
,
cpu_and_
gpu
,
cpu_and_
cuda
,
make_bounding_box
,
make_bounding_box
,
make_bounding_boxes
,
make_bounding_boxes
,
make_detection_mask
,
make_detection_mask
,
...
@@ -173,7 +173,7 @@ class TestSmoke:
...
@@ -173,7 +173,7 @@ class TestSmoke:
next
(
make_vanilla_tensor_images
()),
next
(
make_vanilla_tensor_images
()),
],
],
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_common
(
self
,
transform
,
adapter
,
container_type
,
image_or_video
,
device
):
def
test_common
(
self
,
transform
,
adapter
,
container_type
,
image_or_video
,
device
):
spatial_size
=
F
.
get_spatial_size
(
image_or_video
)
spatial_size
=
F
.
get_spatial_size
(
image_or_video
)
input
=
dict
(
input
=
dict
(
...
@@ -1364,7 +1364,7 @@ class TestRandomChoice:
...
@@ -1364,7 +1364,7 @@ class TestRandomChoice:
class
TestRandomIoUCrop
:
class
TestRandomIoUCrop
:
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"options"
,
[[
0.5
,
0.9
],
[
2.0
]])
@
pytest
.
mark
.
parametrize
(
"options"
,
[[
0.5
,
0.9
],
[
2.0
]])
def
test__get_params
(
self
,
device
,
options
,
mocker
):
def
test__get_params
(
self
,
device
,
options
,
mocker
):
image
=
mocker
.
MagicMock
(
spec
=
datapoints
.
Image
)
image
=
mocker
.
MagicMock
(
spec
=
datapoints
.
Image
)
...
...
test/test_transforms_v2_functional.py
View file @
016804ee
...
@@ -14,7 +14,7 @@ import torch
...
@@ -14,7 +14,7 @@ import torch
from
common_utils
import
(
from
common_utils
import
(
assert_close
,
assert_close
,
cache
,
cache
,
cpu_and_
gpu
,
cpu_and_
cuda
,
DEFAULT_SQUARE_SPATIAL_SIZE
,
DEFAULT_SQUARE_SPATIAL_SIZE
,
make_bounding_boxes
,
make_bounding_boxes
,
needs_cuda
,
needs_cuda
,
...
@@ -120,7 +120,7 @@ class TestKernels:
...
@@ -120,7 +120,7 @@ class TestKernels:
[
info
for
info
in
KERNEL_INFOS
if
info
.
logs_usage
],
[
info
for
info
in
KERNEL_INFOS
if
info
.
logs_usage
],
args_kwargs_fn
=
lambda
info
:
info
.
sample_inputs_fn
(),
args_kwargs_fn
=
lambda
info
:
info
.
sample_inputs_fn
(),
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_logging
(
self
,
spy_on
,
info
,
args_kwargs
,
device
):
def
test_logging
(
self
,
spy_on
,
info
,
args_kwargs
,
device
):
spy
=
spy_on
(
torch
.
_C
.
_log_api_usage_once
)
spy
=
spy_on
(
torch
.
_C
.
_log_api_usage_once
)
...
@@ -131,7 +131,7 @@ class TestKernels:
...
@@ -131,7 +131,7 @@ class TestKernels:
@
ignore_jit_warning_no_profile
@
ignore_jit_warning_no_profile
@
sample_inputs
@
sample_inputs
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_scripted_vs_eager
(
self
,
test_id
,
info
,
args_kwargs
,
device
):
def
test_scripted_vs_eager
(
self
,
test_id
,
info
,
args_kwargs
,
device
):
kernel_eager
=
info
.
kernel
kernel_eager
=
info
.
kernel
kernel_scripted
=
script
(
kernel_eager
)
kernel_scripted
=
script
(
kernel_eager
)
...
@@ -167,7 +167,7 @@ class TestKernels:
...
@@ -167,7 +167,7 @@ class TestKernels:
]
]
@
sample_inputs
@
sample_inputs
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_batched_vs_single
(
self
,
test_id
,
info
,
args_kwargs
,
device
):
def
test_batched_vs_single
(
self
,
test_id
,
info
,
args_kwargs
,
device
):
(
batched_input
,
*
other_args
),
kwargs
=
args_kwargs
.
load
(
device
)
(
batched_input
,
*
other_args
),
kwargs
=
args_kwargs
.
load
(
device
)
...
@@ -208,7 +208,7 @@ class TestKernels:
...
@@ -208,7 +208,7 @@ class TestKernels:
)
)
@
sample_inputs
@
sample_inputs
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_no_inplace
(
self
,
info
,
args_kwargs
,
device
):
def
test_no_inplace
(
self
,
info
,
args_kwargs
,
device
):
(
input
,
*
other_args
),
kwargs
=
args_kwargs
.
load
(
device
)
(
input
,
*
other_args
),
kwargs
=
args_kwargs
.
load
(
device
)
input
=
input
.
as_subclass
(
torch
.
Tensor
)
input
=
input
.
as_subclass
(
torch
.
Tensor
)
...
@@ -240,7 +240,7 @@ class TestKernels:
...
@@ -240,7 +240,7 @@ class TestKernels:
)
)
@
sample_inputs
@
sample_inputs
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_dtype_and_device_consistency
(
self
,
info
,
args_kwargs
,
device
):
def
test_dtype_and_device_consistency
(
self
,
info
,
args_kwargs
,
device
):
(
input
,
*
other_args
),
kwargs
=
args_kwargs
.
load
(
device
)
(
input
,
*
other_args
),
kwargs
=
args_kwargs
.
load
(
device
)
input
=
input
.
as_subclass
(
torch
.
Tensor
)
input
=
input
.
as_subclass
(
torch
.
Tensor
)
...
@@ -320,7 +320,7 @@ class TestDispatchers:
...
@@ -320,7 +320,7 @@ class TestDispatchers:
DISPATCHER_INFOS
,
DISPATCHER_INFOS
,
args_kwargs_fn
=
lambda
info
:
info
.
sample_inputs
(),
args_kwargs_fn
=
lambda
info
:
info
.
sample_inputs
(),
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_logging
(
self
,
spy_on
,
info
,
args_kwargs
,
device
):
def
test_logging
(
self
,
spy_on
,
info
,
args_kwargs
,
device
):
spy
=
spy_on
(
torch
.
_C
.
_log_api_usage_once
)
spy
=
spy_on
(
torch
.
_C
.
_log_api_usage_once
)
...
@@ -331,7 +331,7 @@ class TestDispatchers:
...
@@ -331,7 +331,7 @@ class TestDispatchers:
@
ignore_jit_warning_no_profile
@
ignore_jit_warning_no_profile
@
image_sample_inputs
@
image_sample_inputs
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_scripted_smoke
(
self
,
info
,
args_kwargs
,
device
):
def
test_scripted_smoke
(
self
,
info
,
args_kwargs
,
device
):
dispatcher
=
script
(
info
.
dispatcher
)
dispatcher
=
script
(
info
.
dispatcher
)
...
@@ -553,7 +553,7 @@ def test_alias(alias, target):
...
@@ -553,7 +553,7 @@ def test_alias(alias, target):
args_kwargs_fn
=
lambda
info
:
info
.
sample_inputs_fn
(),
args_kwargs_fn
=
lambda
info
:
info
.
sample_inputs_fn
(),
),
),
)
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_convert_dtype_image_tensor_dtype_and_device
(
info
,
args_kwargs
,
device
):
def
test_convert_dtype_image_tensor_dtype_and_device
(
info
,
args_kwargs
,
device
):
(
input
,
*
other_args
),
kwargs
=
args_kwargs
.
load
(
device
)
(
input
,
*
other_args
),
kwargs
=
args_kwargs
.
load
(
device
)
dtype
=
other_args
[
0
]
if
other_args
else
kwargs
.
get
(
"dtype"
,
torch
.
float32
)
dtype
=
other_args
[
0
]
if
other_args
else
kwargs
.
get
(
"dtype"
,
torch
.
float32
)
...
@@ -564,7 +564,7 @@ def test_convert_dtype_image_tensor_dtype_and_device(info, args_kwargs, device):
...
@@ -564,7 +564,7 @@ def test_convert_dtype_image_tensor_dtype_and_device(info, args_kwargs, device):
assert
output
.
device
==
input
.
device
assert
output
.
device
==
input
.
device
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"num_channels"
,
[
1
,
3
])
@
pytest
.
mark
.
parametrize
(
"num_channels"
,
[
1
,
3
])
def
test_normalize_image_tensor_stats
(
device
,
num_channels
):
def
test_normalize_image_tensor_stats
(
device
,
num_channels
):
stats
=
pytest
.
importorskip
(
"scipy.stats"
,
reason
=
"SciPy is not available"
)
stats
=
pytest
.
importorskip
(
"scipy.stats"
,
reason
=
"SciPy is not available"
)
...
@@ -664,7 +664,7 @@ def _compute_affine_matrix(angle_, translate_, scale_, shear_, center_):
...
@@ -664,7 +664,7 @@ def _compute_affine_matrix(angle_, translate_, scale_, shear_, center_):
return
true_matrix
return
true_matrix
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_correctness_affine_bounding_box_on_fixed_input
(
device
):
def
test_correctness_affine_bounding_box_on_fixed_input
(
device
):
# Check transformation against known expected output
# Check transformation against known expected output
format
=
datapoints
.
BoundingBoxFormat
.
XYXY
format
=
datapoints
.
BoundingBoxFormat
.
XYXY
...
@@ -715,7 +715,7 @@ def test_correctness_affine_bounding_box_on_fixed_input(device):
...
@@ -715,7 +715,7 @@ def test_correctness_affine_bounding_box_on_fixed_input(device):
torch
.
testing
.
assert_close
(
output_boxes
.
tolist
(),
expected_bboxes
)
torch
.
testing
.
assert_close
(
output_boxes
.
tolist
(),
expected_bboxes
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_correctness_affine_segmentation_mask_on_fixed_input
(
device
):
def
test_correctness_affine_segmentation_mask_on_fixed_input
(
device
):
# Check transformation against known expected output and CPU/CUDA devices
# Check transformation against known expected output and CPU/CUDA devices
...
@@ -820,7 +820,7 @@ def test_correctness_rotate_bounding_box(angle, expand, center):
...
@@ -820,7 +820,7 @@ def test_correctness_rotate_bounding_box(angle, expand, center):
torch
.
testing
.
assert_close
(
output_spatial_size
,
expected_spatial_size
,
atol
=
1
,
rtol
=
0
)
torch
.
testing
.
assert_close
(
output_spatial_size
,
expected_spatial_size
,
atol
=
1
,
rtol
=
0
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"expand"
,
[
False
])
# expand=True does not match D2
@
pytest
.
mark
.
parametrize
(
"expand"
,
[
False
])
# expand=True does not match D2
def
test_correctness_rotate_bounding_box_on_fixed_input
(
device
,
expand
):
def
test_correctness_rotate_bounding_box_on_fixed_input
(
device
,
expand
):
# Check transformation against known expected output
# Check transformation against known expected output
...
@@ -876,7 +876,7 @@ def test_correctness_rotate_bounding_box_on_fixed_input(device, expand):
...
@@ -876,7 +876,7 @@ def test_correctness_rotate_bounding_box_on_fixed_input(device, expand):
torch
.
testing
.
assert_close
(
output_boxes
.
tolist
(),
expected_bboxes
)
torch
.
testing
.
assert_close
(
output_boxes
.
tolist
(),
expected_bboxes
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_correctness_rotate_segmentation_mask_on_fixed_input
(
device
):
def
test_correctness_rotate_segmentation_mask_on_fixed_input
(
device
):
# Check transformation against known expected output and CPU/CUDA devices
# Check transformation against known expected output and CPU/CUDA devices
...
@@ -892,7 +892,7 @@ def test_correctness_rotate_segmentation_mask_on_fixed_input(device):
...
@@ -892,7 +892,7 @@ def test_correctness_rotate_segmentation_mask_on_fixed_input(device):
torch
.
testing
.
assert_close
(
out_mask
,
expected_mask
)
torch
.
testing
.
assert_close
(
out_mask
,
expected_mask
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"format"
,
"format"
,
[
datapoints
.
BoundingBoxFormat
.
XYXY
,
datapoints
.
BoundingBoxFormat
.
XYWH
,
datapoints
.
BoundingBoxFormat
.
CXCYWH
],
[
datapoints
.
BoundingBoxFormat
.
XYXY
,
datapoints
.
BoundingBoxFormat
.
XYWH
,
datapoints
.
BoundingBoxFormat
.
CXCYWH
],
...
@@ -949,7 +949,7 @@ def test_correctness_crop_bounding_box(device, format, top, left, height, width,
...
@@ -949,7 +949,7 @@ def test_correctness_crop_bounding_box(device, format, top, left, height, width,
torch
.
testing
.
assert_close
(
output_spatial_size
,
spatial_size
)
torch
.
testing
.
assert_close
(
output_spatial_size
,
spatial_size
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_correctness_horizontal_flip_segmentation_mask_on_fixed_input
(
device
):
def
test_correctness_horizontal_flip_segmentation_mask_on_fixed_input
(
device
):
mask
=
torch
.
zeros
((
3
,
3
,
3
),
dtype
=
torch
.
long
,
device
=
device
)
mask
=
torch
.
zeros
((
3
,
3
,
3
),
dtype
=
torch
.
long
,
device
=
device
)
mask
[:,
:,
0
]
=
1
mask
[:,
:,
0
]
=
1
...
@@ -961,7 +961,7 @@ def test_correctness_horizontal_flip_segmentation_mask_on_fixed_input(device):
...
@@ -961,7 +961,7 @@ def test_correctness_horizontal_flip_segmentation_mask_on_fixed_input(device):
torch
.
testing
.
assert_close
(
out_mask
,
expected_mask
)
torch
.
testing
.
assert_close
(
out_mask
,
expected_mask
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_correctness_vertical_flip_segmentation_mask_on_fixed_input
(
device
):
def
test_correctness_vertical_flip_segmentation_mask_on_fixed_input
(
device
):
mask
=
torch
.
zeros
((
3
,
3
,
3
),
dtype
=
torch
.
long
,
device
=
device
)
mask
=
torch
.
zeros
((
3
,
3
,
3
),
dtype
=
torch
.
long
,
device
=
device
)
mask
[:,
0
,
:]
=
1
mask
[:,
0
,
:]
=
1
...
@@ -973,7 +973,7 @@ def test_correctness_vertical_flip_segmentation_mask_on_fixed_input(device):
...
@@ -973,7 +973,7 @@ def test_correctness_vertical_flip_segmentation_mask_on_fixed_input(device):
torch
.
testing
.
assert_close
(
out_mask
,
expected_mask
)
torch
.
testing
.
assert_close
(
out_mask
,
expected_mask
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"format"
,
"format"
,
[
datapoints
.
BoundingBoxFormat
.
XYXY
,
datapoints
.
BoundingBoxFormat
.
XYWH
,
datapoints
.
BoundingBoxFormat
.
CXCYWH
],
[
datapoints
.
BoundingBoxFormat
.
XYXY
,
datapoints
.
BoundingBoxFormat
.
XYWH
,
datapoints
.
BoundingBoxFormat
.
CXCYWH
],
...
@@ -1032,7 +1032,7 @@ def _parse_padding(padding):
...
@@ -1032,7 +1032,7 @@ def _parse_padding(padding):
return
padding
return
padding
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"padding"
,
[[
1
],
[
1
,
1
],
[
1
,
1
,
2
,
2
]])
@
pytest
.
mark
.
parametrize
(
"padding"
,
[[
1
],
[
1
,
1
],
[
1
,
1
,
2
,
2
]])
def
test_correctness_pad_bounding_box
(
device
,
padding
):
def
test_correctness_pad_bounding_box
(
device
,
padding
):
def
_compute_expected_bbox
(
bbox
,
padding_
):
def
_compute_expected_bbox
(
bbox
,
padding_
):
...
@@ -1087,7 +1087,7 @@ def test_correctness_pad_bounding_box(device, padding):
...
@@ -1087,7 +1087,7 @@ def test_correctness_pad_bounding_box(device, padding):
torch
.
testing
.
assert_close
(
output_boxes
,
expected_bboxes
,
atol
=
1
,
rtol
=
0
)
torch
.
testing
.
assert_close
(
output_boxes
,
expected_bboxes
,
atol
=
1
,
rtol
=
0
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_correctness_pad_segmentation_mask_on_fixed_input
(
device
):
def
test_correctness_pad_segmentation_mask_on_fixed_input
(
device
):
mask
=
torch
.
ones
((
1
,
3
,
3
),
dtype
=
torch
.
long
,
device
=
device
)
mask
=
torch
.
ones
((
1
,
3
,
3
),
dtype
=
torch
.
long
,
device
=
device
)
...
@@ -1098,7 +1098,7 @@ def test_correctness_pad_segmentation_mask_on_fixed_input(device):
...
@@ -1098,7 +1098,7 @@ def test_correctness_pad_segmentation_mask_on_fixed_input(device):
torch
.
testing
.
assert_close
(
out_mask
,
expected_mask
)
torch
.
testing
.
assert_close
(
out_mask
,
expected_mask
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"startpoints, endpoints"
,
"startpoints, endpoints"
,
[
[
...
@@ -1182,7 +1182,7 @@ def test_correctness_perspective_bounding_box(device, startpoints, endpoints):
...
@@ -1182,7 +1182,7 @@ def test_correctness_perspective_bounding_box(device, startpoints, endpoints):
torch
.
testing
.
assert_close
(
output_bboxes
,
expected_bboxes
,
rtol
=
0
,
atol
=
1
)
torch
.
testing
.
assert_close
(
output_bboxes
,
expected_bboxes
,
rtol
=
0
,
atol
=
1
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"output_size"
,
"output_size"
,
[(
18
,
18
),
[
18
,
15
],
(
16
,
19
),
[
12
],
[
46
,
48
]],
[(
18
,
18
),
[
18
,
15
],
(
16
,
19
),
[
12
],
[
46
,
48
]],
...
@@ -1236,7 +1236,7 @@ def test_correctness_center_crop_bounding_box(device, output_size):
...
@@ -1236,7 +1236,7 @@ def test_correctness_center_crop_bounding_box(device, output_size):
torch
.
testing
.
assert_close
(
output_spatial_size
,
output_size
)
torch
.
testing
.
assert_close
(
output_spatial_size
,
output_size
)
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"output_size"
,
[[
4
,
2
],
[
4
],
[
7
,
6
]])
@
pytest
.
mark
.
parametrize
(
"output_size"
,
[[
4
,
2
],
[
4
],
[
7
,
6
]])
def
test_correctness_center_crop_mask
(
device
,
output_size
):
def
test_correctness_center_crop_mask
(
device
,
output_size
):
def
_compute_expected_mask
(
mask
,
output_size
):
def
_compute_expected_mask
(
mask
,
output_size
):
...
@@ -1260,7 +1260,7 @@ def test_correctness_center_crop_mask(device, output_size):
...
@@ -1260,7 +1260,7 @@ def test_correctness_center_crop_mask(device, output_size):
# Copied from test/test_functional_tensor.py
# Copied from test/test_functional_tensor.py
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
@
pytest
.
mark
.
parametrize
(
"spatial_size"
,
(
"small"
,
"large"
))
@
pytest
.
mark
.
parametrize
(
"spatial_size"
,
(
"small"
,
"large"
))
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"dt"
,
[
None
,
torch
.
float32
,
torch
.
float64
,
torch
.
float16
])
@
pytest
.
mark
.
parametrize
(
"ksize"
,
[(
3
,
3
),
[
3
,
5
],
(
23
,
23
)])
@
pytest
.
mark
.
parametrize
(
"ksize"
,
[(
3
,
3
),
[
3
,
5
],
(
23
,
23
)])
...
@@ -1357,7 +1357,7 @@ def test_equalize_image_tensor_edge_cases():
...
@@ -1357,7 +1357,7 @@ def test_equalize_image_tensor_edge_cases():
assert
output
.
unique
().
tolist
()
==
[
0
,
255
]
assert
output
.
unique
().
tolist
()
==
[
0
,
255
]
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_
cuda
())
def
test_correctness_uniform_temporal_subsample
(
device
):
def
test_correctness_uniform_temporal_subsample
(
device
):
video
=
torch
.
arange
(
10
,
device
=
device
)[:,
None
,
None
,
None
].
expand
(
-
1
,
3
,
8
,
8
)
video
=
torch
.
arange
(
10
,
device
=
device
)[:,
None
,
None
,
None
].
expand
(
-
1
,
3
,
8
,
8
)
out_video
=
F
.
uniform_temporal_subsample
(
video
,
5
)
out_video
=
F
.
uniform_temporal_subsample
(
video
,
5
)
...
...
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