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
27bdb8cf
Unverified
Commit
27bdb8cf
authored
Jun 08, 2021
by
Anirudh
Committed by
GitHub
Jun 08, 2021
Browse files
port test_accimage_xxx in test_transforms to pytest (#3985)
parent
0013d931
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
54 deletions
+54
-54
test/test_transforms.py
test/test_transforms.py
+54
-54
No files found.
test/test_transforms.py
View file @
27bdb8cf
...
@@ -330,60 +330,6 @@ class Tester(unittest.TestCase):
...
@@ -330,60 +330,6 @@ class Tester(unittest.TestCase):
self
.
assertEqual
(
actual_min
,
desired_min
)
self
.
assertEqual
(
actual_min
,
desired_min
)
self
.
assertEqual
(
actual_max
,
desired_max
)
self
.
assertEqual
(
actual_max
,
desired_max
)
@
unittest
.
skipIf
(
accimage
is
None
,
'accimage not available'
)
def
test_accimage_to_tensor
(
self
):
trans
=
transforms
.
ToTensor
()
expected_output
=
trans
(
Image
.
open
(
GRACE_HOPPER
).
convert
(
'RGB'
))
output
=
trans
(
accimage
.
Image
(
GRACE_HOPPER
))
torch
.
testing
.
assert_close
(
output
,
expected_output
)
@
unittest
.
skipIf
(
accimage
is
None
,
'accimage not available'
)
def
test_accimage_pil_to_tensor
(
self
):
trans
=
transforms
.
PILToTensor
()
expected_output
=
trans
(
Image
.
open
(
GRACE_HOPPER
).
convert
(
'RGB'
))
output
=
trans
(
accimage
.
Image
(
GRACE_HOPPER
))
self
.
assertEqual
(
expected_output
.
size
(),
output
.
size
())
torch
.
testing
.
assert_close
(
output
,
expected_output
,
check_stride
=
False
)
@
unittest
.
skipIf
(
accimage
is
None
,
'accimage not available'
)
def
test_accimage_resize
(
self
):
trans
=
transforms
.
Compose
([
transforms
.
Resize
(
256
,
interpolation
=
Image
.
LINEAR
),
transforms
.
ToTensor
(),
])
# Checking if Compose, Resize and ToTensor can be printed as string
trans
.
__repr__
()
expected_output
=
trans
(
Image
.
open
(
GRACE_HOPPER
).
convert
(
'RGB'
))
output
=
trans
(
accimage
.
Image
(
GRACE_HOPPER
))
self
.
assertEqual
(
expected_output
.
size
(),
output
.
size
())
self
.
assertLess
(
np
.
abs
((
expected_output
-
output
).
mean
()),
1e-3
)
self
.
assertLess
((
expected_output
-
output
).
var
(),
1e-5
)
# note the high absolute tolerance
self
.
assertTrue
(
np
.
allclose
(
output
.
numpy
(),
expected_output
.
numpy
(),
atol
=
5e-2
))
@
unittest
.
skipIf
(
accimage
is
None
,
'accimage not available'
)
def
test_accimage_crop
(
self
):
trans
=
transforms
.
Compose
([
transforms
.
CenterCrop
(
256
),
transforms
.
ToTensor
(),
])
# Checking if Compose, CenterCrop and ToTensor can be printed as string
trans
.
__repr__
()
expected_output
=
trans
(
Image
.
open
(
GRACE_HOPPER
).
convert
(
'RGB'
))
output
=
trans
(
accimage
.
Image
(
GRACE_HOPPER
))
self
.
assertEqual
(
expected_output
.
size
(),
output
.
size
())
torch
.
testing
.
assert_close
(
output
,
expected_output
)
def
test_color_jitter
(
self
):
def
test_color_jitter
(
self
):
color_jitter
=
transforms
.
ColorJitter
(
2
,
2
,
2
,
0.1
)
color_jitter
=
transforms
.
ColorJitter
(
2
,
2
,
2
,
0.1
)
...
@@ -613,6 +559,60 @@ class Tester(unittest.TestCase):
...
@@ -613,6 +559,60 @@ class Tester(unittest.TestCase):
transform
.
__repr__
()
transform
.
__repr__
()
@
pytest
.
mark
.
skipif
(
accimage
is
None
,
reason
=
"accimage not available"
)
class
TestAccImage
:
def
test_accimage_to_tensor
(
self
):
trans
=
transforms
.
ToTensor
()
expected_output
=
trans
(
Image
.
open
(
GRACE_HOPPER
).
convert
(
'RGB'
))
output
=
trans
(
accimage
.
Image
(
GRACE_HOPPER
))
torch
.
testing
.
assert_close
(
output
,
expected_output
)
def
test_accimage_pil_to_tensor
(
self
):
trans
=
transforms
.
PILToTensor
()
expected_output
=
trans
(
Image
.
open
(
GRACE_HOPPER
).
convert
(
'RGB'
))
output
=
trans
(
accimage
.
Image
(
GRACE_HOPPER
))
assert
expected_output
.
size
()
==
output
.
size
()
torch
.
testing
.
assert_close
(
output
,
expected_output
,
check_stride
=
False
)
def
test_accimage_resize
(
self
):
trans
=
transforms
.
Compose
([
transforms
.
Resize
(
256
,
interpolation
=
Image
.
LINEAR
),
transforms
.
ToTensor
(),
])
# Checking if Compose, Resize and ToTensor can be printed as string
trans
.
__repr__
()
expected_output
=
trans
(
Image
.
open
(
GRACE_HOPPER
).
convert
(
'RGB'
))
output
=
trans
(
accimage
.
Image
(
GRACE_HOPPER
))
assert
expected_output
.
size
()
==
output
.
size
()
assert
np
.
abs
((
expected_output
-
output
).
mean
())
<
1e-3
assert
(
expected_output
-
output
).
var
()
<
1e-5
# note the high absolute tolerance
torch
.
testing
.
assert_close
(
output
.
numpy
(),
expected_output
.
numpy
(),
rtol
=
1e-5
,
atol
=
5e-2
)
def
test_accimage_crop
(
self
):
trans
=
transforms
.
Compose
([
transforms
.
CenterCrop
(
256
),
transforms
.
ToTensor
(),
])
# Checking if Compose, CenterCrop and ToTensor can be printed as string
trans
.
__repr__
()
expected_output
=
trans
(
Image
.
open
(
GRACE_HOPPER
).
convert
(
'RGB'
))
output
=
trans
(
accimage
.
Image
(
GRACE_HOPPER
))
assert
expected_output
.
size
()
==
output
.
size
()
torch
.
testing
.
assert_close
(
output
,
expected_output
)
@
pytest
.
mark
.
parametrize
(
'channels'
,
[
1
,
3
,
4
])
@
pytest
.
mark
.
parametrize
(
'channels'
,
[
1
,
3
,
4
])
def
test_to_tensor
(
channels
):
def
test_to_tensor
(
channels
):
height
,
width
=
4
,
4
height
,
width
=
4
,
4
...
...
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