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
05bcb18e
Commit
05bcb18e
authored
Nov 28, 2016
by
Soumith Chintala
Browse files
making cifar data loader also return PIL Image
parent
98b9aa54
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
183 additions
and
6 deletions
+183
-6
test/sanity_checks.ipynb
test/sanity_checks.ipynb
+168
-5
torchvision/datasets/cifar.py
torchvision/datasets/cifar.py
+4
-0
torchvision/utils.py
torchvision/utils.py
+11
-1
No files found.
test/sanity_checks.ipynb
View file @
05bcb18e
This source diff could not be displayed because it is too large. You can
view the blob
instead.
torchvision/datasets/cifar.py
View file @
05bcb18e
...
...
@@ -77,6 +77,10 @@ class CIFAR10(data.Dataset):
img
,
target
=
self
.
train_data
[
index
],
self
.
train_labels
[
index
]
else
:
img
,
target
=
self
.
test_data
[
index
],
self
.
test_labels
[
index
]
# doing this so that it is consistent with all other datasets
# to return a PIL Image
img
=
Image
.
fromarray
(
np
.
transpose
(
img
,
(
1
,
2
,
0
)))
if
self
.
transform
is
not
None
:
img
=
self
.
transform
(
img
)
...
...
torchvision/utils.py
View file @
05bcb18e
import
torch
import
math
def
make_grid
(
tensor
,
nrow
=
8
,
padding
=
2
):
"""
Given a 4D mini-batch Tensor of shape (B x C x H x W),
or a list of images all of the same size,
makes a grid of images
"""
import
math
tensorlist
=
None
if
isinstance
(
tensor
,
list
):
tensorlist
=
tensor
numImages
=
len
(
tensorlist
)
size
=
torch
.
Size
(
torch
.
Size
([
long
(
numImages
)])
+
tensorlist
[
0
].
size
())
tensor
=
tensorlist
[
0
].
new
(
size
)
for
i
in
range
(
numImages
):
tensor
[
i
].
copy_
(
tensorlist
[
i
])
if
tensor
.
dim
()
==
3
:
# single image
return
tensor
# make the mini-batch of images into a grid
...
...
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