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
3f556e20
Unverified
Commit
3f556e20
authored
May 22, 2021
by
Nicolas Hug
Committed by
GitHub
May 22, 2021
Browse files
Use torch.testing.assert_close in common_utils.py (#3873)
Co-authored-by:
Philip Meier
<
github.pmeier@posteo.de
>
parent
0bb9b914
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
2 deletions
+5
-2
test/common_utils.py
test/common_utils.py
+5
-2
No files found.
test/common_utils.py
View file @
3f556e20
...
...
@@ -20,6 +20,8 @@ from _utils_internal import get_relative_path
import
numpy
as
np
from
PIL
import
Image
from
_assert_utils
import
assert_equal
IS_PY39
=
sys
.
version_info
.
major
==
3
and
sys
.
version_info
.
minor
==
9
PY39_SEGFAULT_SKIP_MSG
=
"Segmentation fault with Python 3.9, see https://github.com/pytorch/vision/issues/3367"
PY39_SKIP
=
unittest
.
skipIf
(
IS_PY39
,
PY39_SEGFAULT_SKIP_MSG
)
...
...
@@ -139,7 +141,8 @@ class TestCase(unittest.TestCase):
raise
RuntimeError
(
"The output for {}, is larger than 50kb"
.
format
(
filename
))
else
:
expected
=
torch
.
load
(
expected_file
)
self
.
assertEqual
(
output
,
expected
,
prec
=
prec
)
rtol
=
atol
=
prec
or
self
.
precision
torch
.
testing
.
assert_close
(
output
,
expected
,
rtol
=
rtol
,
atol
=
atol
,
check_dtype
=
False
)
def
assertEqual
(
self
,
x
,
y
,
prec
=
None
,
message
=
''
,
allow_inf
=
False
):
"""
...
...
@@ -345,7 +348,7 @@ class TransformsTester(unittest.TestCase):
pil_tensor
=
torch
.
as_tensor
(
np_pil_image
.
transpose
((
2
,
0
,
1
)))
if
msg
is
None
:
msg
=
"tensor:
\n
{}
\n
did not equal PIL tensor:
\n
{}"
.
format
(
tensor
,
pil_tensor
)
self
.
assert
True
(
tensor
.
cpu
()
.
equal
(
pil_tensor
)
,
msg
)
assert
_equal
(
tensor
.
cpu
()
,
pil_tensor
,
check_stride
=
False
,
msg
=
msg
)
def
approxEqualTensorToPIL
(
self
,
tensor
,
pil_image
,
tol
=
1e-5
,
msg
=
None
,
agg_method
=
"mean"
,
allowed_percentage_diff
=
None
):
...
...
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