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
bb5af1d7
Commit
bb5af1d7
authored
Jan 22, 2020
by
Philip Meier
Committed by
Francisco Massa
Jan 22, 2020
Browse files
generalize number of bands calculation in to_tensor (#1781)
parent
70dee777
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
8 deletions
+2
-8
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+2
-8
No files found.
torchvision/transforms/functional.py
View file @
bb5af1d7
...
...
@@ -85,14 +85,8 @@ def to_tensor(pic):
img
=
255
*
torch
.
from_numpy
(
np
.
array
(
pic
,
np
.
uint8
,
copy
=
False
))
else
:
img
=
torch
.
ByteTensor
(
torch
.
ByteStorage
.
from_buffer
(
pic
.
tobytes
()))
# PIL image mode: L, LA, P, I, F, RGB, YCbCr, RGBA, CMYK
if
pic
.
mode
==
'YCbCr'
:
nchannel
=
3
elif
pic
.
mode
==
'I;16'
:
nchannel
=
1
else
:
nchannel
=
len
(
pic
.
mode
)
img
=
img
.
view
(
pic
.
size
[
1
],
pic
.
size
[
0
],
nchannel
)
img
=
img
.
view
(
pic
.
size
[
1
],
pic
.
size
[
0
],
len
(
pic
.
getbands
()))
# put it from HWC to CHW format
# yikes, this transpose takes 80% of the loading time/CPU
img
=
img
.
transpose
(
0
,
1
).
transpose
(
0
,
2
).
contiguous
()
...
...
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