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
6cbb22bb
Commit
6cbb22bb
authored
Mar 23, 2017
by
Bodo Kaiser
Committed by
Soumith Chintala
Mar 23, 2017
Browse files
added support for signed ints, removed support for unsigned
parent
c1a835f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
test/test_transforms.py
test/test_transforms.py
+24
-2
torchvision/transforms.py
torchvision/transforms.py
+3
-1
No files found.
test/test_transforms.py
View file @
6cbb22bb
...
@@ -169,13 +169,35 @@ class Tester(unittest.TestCase):
...
@@ -169,13 +169,35 @@ class Tester(unittest.TestCase):
l
,
=
img
.
split
()
l
,
=
img
.
split
()
assert
np
.
allclose
(
l
,
img_data
[:,
:,
0
])
assert
np
.
allclose
(
l
,
img_data
[:,
:,
0
])
def
test_ndarray
16
_to_pil_image
(
self
):
def
test_ndarray
_bad_types
_to_pil_image
(
self
):
trans
=
transforms
.
ToPILImage
()
trans
=
transforms
.
ToPILImage
()
img_data
=
np
.
random
.
randint
(
0
,
65535
,
[
4
,
4
,
1
],
np
.
uint16
)
with
self
.
assertRaises
(
AssertionError
):
trans
(
np
.
ones
([
4
,
4
,
1
],
np
.
int64
))
trans
(
np
.
ones
([
4
,
4
,
1
],
np
.
uint16
))
trans
(
np
.
ones
([
4
,
4
,
1
],
np
.
uint32
))
trans
(
np
.
ones
([
4
,
4
,
1
],
np
.
float64
))
def
test_ndarray_gray_float32_to_pil_image
(
self
):
trans
=
transforms
.
ToPILImage
()
img_data
=
torch
.
FloatTensor
(
4
,
4
,
1
).
random_
().
numpy
()
img
=
trans
(
img_data
)
assert
img
.
mode
==
'F'
assert
np
.
allclose
(
img
,
img_data
[:,
:,
0
])
def
test_ndarray_gray_int16_to_pil_image
(
self
):
trans
=
transforms
.
ToPILImage
()
img_data
=
torch
.
ShortTensor
(
4
,
4
,
1
).
random_
().
numpy
()
img
=
trans
(
img_data
)
img
=
trans
(
img_data
)
assert
img
.
mode
==
'I;16'
assert
img
.
mode
==
'I;16'
assert
np
.
allclose
(
img
,
img_data
[:,
:,
0
])
assert
np
.
allclose
(
img
,
img_data
[:,
:,
0
])
def
test_ndarray_gray_int32_to_pil_image
(
self
):
trans
=
transforms
.
ToPILImage
()
img_data
=
torch
.
IntTensor
(
4
,
4
,
1
).
random_
().
numpy
()
img
=
trans
(
img_data
)
assert
img
.
mode
==
'I'
assert
np
.
allclose
(
img
,
img_data
[:,
:,
0
])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
torchvision/transforms.py
View file @
6cbb22bb
...
@@ -73,8 +73,10 @@ class ToPILImage(object):
...
@@ -73,8 +73,10 @@ class ToPILImage(object):
if
npimg
.
dtype
==
np
.
uint8
:
if
npimg
.
dtype
==
np
.
uint8
:
mode
=
'L'
mode
=
'L'
if
npimg
.
dtype
==
np
.
u
int16
:
if
npimg
.
dtype
==
np
.
int16
:
mode
=
'I;16'
mode
=
'I;16'
if
npimg
.
dtype
==
np
.
int32
:
mode
=
'I'
elif
npimg
.
dtype
==
np
.
float32
:
elif
npimg
.
dtype
==
np
.
float32
:
mode
=
'F'
mode
=
'F'
else
:
else
:
...
...
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