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
22385bc6
Commit
22385bc6
authored
Feb 12, 2018
by
vfdev
Committed by
Francisco Massa
Feb 12, 2018
Browse files
Fix bug with to_tensor on the input of ndarray of float32 (#415)
parent
ba7eb9f4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
test/test_transforms.py
test/test_transforms.py
+6
-1
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+4
-1
No files found.
test/test_transforms.py
View file @
22385bc6
...
...
@@ -269,11 +269,16 @@ class Tester(unittest.TestCase):
output
=
trans
(
img
)
assert
np
.
allclose
(
input_data
.
numpy
(),
output
.
numpy
())
ndarray
=
np
.
random
.
randint
(
low
=
0
,
high
=
255
,
size
=
(
height
,
width
,
channels
))
ndarray
=
np
.
random
.
randint
(
low
=
0
,
high
=
255
,
size
=
(
height
,
width
,
channels
))
.
astype
(
np
.
uint8
)
output
=
trans
(
ndarray
)
expected_output
=
ndarray
.
transpose
((
2
,
0
,
1
))
/
255.0
assert
np
.
allclose
(
output
.
numpy
(),
expected_output
)
ndarray
=
np
.
random
.
rand
(
height
,
width
,
channels
).
astype
(
np
.
float32
)
output
=
trans
(
ndarray
)
expected_output
=
ndarray
.
transpose
((
2
,
0
,
1
))
assert
np
.
allclose
(
output
.
numpy
(),
expected_output
)
@
unittest
.
skipIf
(
accimage
is
None
,
'accimage not available'
)
def
test_accimage_to_tensor
(
self
):
trans
=
transforms
.
ToTensor
()
...
...
torchvision/transforms/functional.py
View file @
22385bc6
...
...
@@ -47,7 +47,10 @@ def to_tensor(pic):
# handle numpy array
img
=
torch
.
from_numpy
(
pic
.
transpose
((
2
,
0
,
1
)))
# backward compatibility
if
isinstance
(
img
,
torch
.
ByteTensor
):
return
img
.
float
().
div
(
255
)
else
:
return
img
if
accimage
is
not
None
and
isinstance
(
pic
,
accimage
.
Image
):
nppic
=
np
.
zeros
([
pic
.
channels
,
pic
.
height
,
pic
.
width
],
dtype
=
np
.
float32
)
...
...
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