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
234d262f
Unverified
Commit
234d262f
authored
Jun 01, 2021
by
Vasilis Vryniotis
Committed by
GitHub
Jun 01, 2021
Browse files
Speed up Transformations tests (#3936)
parent
882e11db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
17 deletions
+28
-17
test/test_transforms.py
test/test_transforms.py
+3
-3
test/test_transforms_tensor.py
test/test_transforms_tensor.py
+25
-14
No files found.
test/test_transforms.py
View file @
234d262f
...
@@ -1604,7 +1604,7 @@ class Tester(unittest.TestCase):
...
@@ -1604,7 +1604,7 @@ class Tester(unittest.TestCase):
# Accept 3 wrong pixels
# Accept 3 wrong pixels
self
.
assertLess
(
n_diff_pixels
,
3
,
self
.
assertLess
(
n_diff_pixels
,
3
,
"a={}, t={}, s={}, sh={}
\n
"
.
format
(
a
,
t
,
s
,
sh
)
+
"a={}, t={}, s={}, sh={}
\n
"
.
format
(
a
,
t
,
s
,
sh
)
+
"n diff pixels={}
\n
"
.
format
(
n
p
.
sum
(
np
.
array
(
result
)[:,
:,
0
]
!=
true_result
[:,
:,
0
])
))
"n diff pixels={}
\n
"
.
format
(
n
_diff_pixels
))
# Test rotation
# Test rotation
a
=
45
a
=
45
...
@@ -1623,9 +1623,9 @@ class Tester(unittest.TestCase):
...
@@ -1623,9 +1623,9 @@ class Tester(unittest.TestCase):
_test_transformation
(
a
=
0.0
,
t
=
(
0.0
,
0.0
),
s
=
1.0
,
sh
=
sh
)
_test_transformation
(
a
=
0.0
,
t
=
(
0.0
,
0.0
),
s
=
1.0
,
sh
=
sh
)
# Test rotation, scale, translation, shear
# Test rotation, scale, translation, shear
for
a
in
range
(
-
90
,
90
,
25
):
for
a
in
range
(
-
90
,
90
,
36
):
for
t1
in
range
(
-
10
,
10
,
5
):
for
t1
in
range
(
-
10
,
10
,
5
):
for
s
in
[
0.7
5
,
0.98
,
1.0
,
1.2
,
1.4
]:
for
s
in
[
0.7
7
,
1.0
,
1.2
7
]:
for
sh
in
range
(
-
15
,
15
,
5
):
for
sh
in
range
(
-
15
,
15
,
5
):
_test_transformation
(
a
=
a
,
t
=
(
t1
,
t1
),
s
=
s
,
sh
=
(
sh
,
sh
))
_test_transformation
(
a
=
a
,
t
=
(
t1
,
t1
),
s
=
s
,
sh
=
(
sh
,
sh
))
...
...
test/test_transforms_tensor.py
View file @
234d262f
...
@@ -398,21 +398,32 @@ class Tester(TransformsTester):
...
@@ -398,21 +398,32 @@ class Tester(TransformsTester):
tensor
=
torch
.
randint
(
0
,
256
,
size
=
(
3
,
44
,
56
),
dtype
=
torch
.
uint8
,
device
=
self
.
device
)
tensor
=
torch
.
randint
(
0
,
256
,
size
=
(
3
,
44
,
56
),
dtype
=
torch
.
uint8
,
device
=
self
.
device
)
batch_tensors
=
torch
.
randint
(
0
,
256
,
size
=
(
4
,
3
,
44
,
56
),
dtype
=
torch
.
uint8
,
device
=
self
.
device
)
batch_tensors
=
torch
.
randint
(
0
,
256
,
size
=
(
4
,
3
,
44
,
56
),
dtype
=
torch
.
uint8
,
device
=
self
.
device
)
for
shear
in
[
15
,
10.0
,
(
5.0
,
10.0
),
[
-
15
,
15
],
[
-
10.0
,
10.0
,
-
11.0
,
11.0
]]:
def
_test
(
**
kwargs
):
transform
=
T
.
RandomAffine
(
**
kwargs
)
s_transform
=
torch
.
jit
.
script
(
transform
)
self
.
_test_transform_vs_scripted
(
transform
,
s_transform
,
tensor
)
self
.
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
return
s_transform
for
interpolation
in
[
NEAREST
,
BILINEAR
]:
for
shear
in
[
15
,
10.0
,
(
5.0
,
10.0
),
[
-
15
,
15
],
[
-
10.0
,
10.0
,
-
11.0
,
11.0
]]:
_test
(
degrees
=
0.0
,
interpolation
=
interpolation
,
shear
=
shear
)
for
scale
in
[(
0.7
,
1.2
),
[
0.7
,
1.2
]]:
for
scale
in
[(
0.7
,
1.2
),
[
0.7
,
1.2
]]:
for
translate
in
[(
0.1
,
0.2
),
[
0.2
,
0.1
]]:
_test
(
degrees
=
0.0
,
interpolation
=
interpolation
,
scale
=
scale
)
for
degrees
in
[
45
,
35.0
,
(
-
45
,
45
),
[
-
90.0
,
90.0
]]:
for
interpolation
in
[
NEAREST
,
BILINEAR
]:
for
translate
in
[(
0.1
,
0.2
),
[
0.2
,
0.1
]]:
for
fill
in
[
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
,
],
1
]:
_test
(
degrees
=
0.0
,
interpolation
=
interpolation
,
translate
=
translate
)
transform
=
T
.
RandomAffine
(
degrees
=
degrees
,
translate
=
translate
,
for
degrees
in
[
45
,
35.0
,
(
-
45
,
45
),
[
-
90.0
,
90.0
]]:
scale
=
scale
,
shear
=
shear
,
interpolation
=
interpolation
,
fill
=
fill
_test
(
degrees
=
degrees
,
interpolation
=
interpolation
)
)
s_transform
=
torch
.
jit
.
script
(
transform
)
for
fill
in
[
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
,
],
1
]:
_test
(
degrees
=
0.0
,
interpolation
=
interpolation
,
fill
=
fill
)
self
.
_test_transform_vs_scripted
(
transform
,
s_transform
,
tensor
)
self
.
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
s_transform
=
_test
(
degrees
=
0.0
)
with
get_tmp_dir
()
as
tmp_dir
:
with
get_tmp_dir
()
as
tmp_dir
:
s_transform
.
save
(
os
.
path
.
join
(
tmp_dir
,
"t_random_affine.pt"
))
s_transform
.
save
(
os
.
path
.
join
(
tmp_dir
,
"t_random_affine.pt"
))
...
@@ -663,7 +674,7 @@ class Tester(TransformsTester):
...
@@ -663,7 +674,7 @@ class Tester(TransformsTester):
for
fill
in
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
,
],
1
]:
for
fill
in
[
None
,
85
,
(
10
,
-
10
,
10
),
0.7
,
[
0.0
,
0.0
,
0.0
],
[
1
,
],
1
]:
transform
=
T
.
AutoAugment
(
policy
=
policy
,
fill
=
fill
)
transform
=
T
.
AutoAugment
(
policy
=
policy
,
fill
=
fill
)
s_transform
=
torch
.
jit
.
script
(
transform
)
s_transform
=
torch
.
jit
.
script
(
transform
)
for
_
in
range
(
100
):
for
_
in
range
(
25
):
self
.
_test_transform_vs_scripted
(
transform
,
s_transform
,
tensor
)
self
.
_test_transform_vs_scripted
(
transform
,
s_transform
,
tensor
)
self
.
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
self
.
_test_transform_vs_scripted_on_batch
(
transform
,
s_transform
,
batch_tensors
)
...
...
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