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
ff3f738e
Commit
ff3f738e
authored
Dec 06, 2017
by
Yashas Annadani
Committed by
Alykhan Tejani
Dec 06, 2017
Browse files
Normalize single images to make_grid (#360)
parent
aafaa2a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
1 deletion
+5
-1
torchvision/utils.py
torchvision/utils.py
+5
-1
No files found.
torchvision/utils.py
View file @
ff3f738e
...
@@ -39,7 +39,8 @@ def make_grid(tensor, nrow=8, padding=2,
...
@@ -39,7 +39,8 @@ def make_grid(tensor, nrow=8, padding=2,
if
tensor
.
dim
()
==
3
:
# single image
if
tensor
.
dim
()
==
3
:
# single image
if
tensor
.
size
(
0
)
==
1
:
# if single-channel, convert to 3-channel
if
tensor
.
size
(
0
)
==
1
:
# if single-channel, convert to 3-channel
tensor
=
torch
.
cat
((
tensor
,
tensor
,
tensor
),
0
)
tensor
=
torch
.
cat
((
tensor
,
tensor
,
tensor
),
0
)
return
tensor
tensor
=
tensor
.
view
(
1
,
tensor
.
size
(
0
),
tensor
.
size
(
1
),
tensor
.
size
(
2
))
if
tensor
.
dim
()
==
4
and
tensor
.
size
(
1
)
==
1
:
# single-channel images
if
tensor
.
dim
()
==
4
and
tensor
.
size
(
1
)
==
1
:
# single-channel images
tensor
=
torch
.
cat
((
tensor
,
tensor
,
tensor
),
1
)
tensor
=
torch
.
cat
((
tensor
,
tensor
,
tensor
),
1
)
...
@@ -65,6 +66,9 @@ def make_grid(tensor, nrow=8, padding=2,
...
@@ -65,6 +66,9 @@ def make_grid(tensor, nrow=8, padding=2,
else
:
else
:
norm_range
(
tensor
,
range
)
norm_range
(
tensor
,
range
)
if
tensor
.
size
(
0
)
==
1
:
return
tensor
.
squeeze
()
# make the mini-batch of images into a grid
# make the mini-batch of images into a grid
nmaps
=
tensor
.
size
(
0
)
nmaps
=
tensor
.
size
(
0
)
xmaps
=
min
(
nrow
,
nmaps
)
xmaps
=
min
(
nrow
,
nmaps
)
...
...
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