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
e659e27e
"docs/source/ko/using-diffusers/custom_pipeline_examples.mdx" did not exist on "dc2a1c1d07bef046a76491ee5d4aab61ecfd67bc"
Commit
e659e27e
authored
Nov 11, 2016
by
Soumith Chintala
Browse files
fix ToTensor to handle numpy
parent
63dabcaf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
11 deletions
+40
-11
test/cifar.py
test/cifar.py
+29
-6
torchvision/transforms.py
torchvision/transforms.py
+11
-5
No files found.
test/cifar.py
View file @
e659e27e
import
torch
import
torch
import
torchvision.datasets
as
dset
import
torchvision.datasets
as
dset
import
torchvision.transforms
as
transforms
print
(
'
\n\n
Cifar 10'
)
#
print('\n\nCifar 10')
a
=
dset
.
CIFAR10
(
root
=
"abc/def/ghi"
,
download
=
True
)
#
a = dset.CIFAR10(root="abc/def/ghi", download=True)
print
(
a
[
3
])
#
print(a[3])
print
(
'
\n\n
Cifar 100'
)
# print('\n\nCifar 100')
a
=
dset
.
CIFAR100
(
root
=
"abc/def/ghi"
,
download
=
True
)
# a = dset.CIFAR100(root="abc/def/ghi", download=True)
# print(a[3])
dataset
=
dset
.
CIFAR10
(
root
=
'cifar'
,
download
=
True
,
transform
=
transforms
.
ToTensor
())
dataloader
=
torch
.
utils
.
data
.
DataLoader
(
dataset
,
batch_size
=
32
,
shuffle
=
True
,
num_workers
=
2
)
# miter = dataloader.__iter__()
# def getBatch():
# global miter
# try:
# return miter.next()
# except StopIteration:
# miter = dataloader.__iter__()
# return miter.next()
# i=0
# while True:
# print(i)
# img, target = getBatch()
# i+=1
print
(
a
[
3
])
torchvision/transforms.py
View file @
e659e27e
...
@@ -2,6 +2,7 @@ import torch
...
@@ -2,6 +2,7 @@ import torch
import
math
import
math
import
random
import
random
from
PIL
import
Image
from
PIL
import
Image
import
numpy
as
np
class
Compose
(
object
):
class
Compose
(
object
):
...
@@ -16,6 +17,11 @@ class Compose(object):
...
@@ -16,6 +17,11 @@ class Compose(object):
class
ToTensor
(
object
):
class
ToTensor
(
object
):
def
__call__
(
self
,
pic
):
def
__call__
(
self
,
pic
):
if
isinstance
(
pic
,
np
.
ndarray
):
# handle numpy array
img
=
torch
.
from_numpy
(
pic
)
else
:
# handle PIL Image
img
=
torch
.
ByteTensor
(
torch
.
ByteStorage
.
from_buffer
(
pic
.
tobytes
()))
img
=
torch
.
ByteTensor
(
torch
.
ByteStorage
.
from_buffer
(
pic
.
tobytes
()))
img
=
img
.
view
(
pic
.
size
[
0
],
pic
.
size
[
1
],
3
)
img
=
img
.
view
(
pic
.
size
[
0
],
pic
.
size
[
1
],
3
)
# put it in CHW format
# put it in CHW format
...
...
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