cclover
December 2, 2019, 6:21am
#1
I don’t have CIFAR10 data locally, and then I download one, but it doesn’t download automatically, and the read fails.
import torchvision as tv
import torchvision.transforms as transforms
from torchvision.transforms import ToPILImage
import torch as t
transform = transforms.Compose([
transforms.ToTensor()
,transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))
])
trainset = tv.datasets.CIFAR10(
root = './data',
train = True,
download = True,
transform = transform
)
trainloader = t.utils.data.DataLoader(
trainset,
batch_size = 4,
shuffle = True,
num_workers=2
)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-38-355678cb95ef> in <module>
1 trainloader = t.utils.data.DataLoader(
----> 2 trainset,
3 batch_size = 4,
4 shuffle = True,
5 num_workers=2
NameError: name 'trainset' is not defined
Best
ptrblck
December 2, 2019, 7:40am
#2
What do these lines of code return:
trainset = tv.datasets.CIFAR10(
root = './data',
train = True,
download = True,
transform = transform
)
Do you get any error trying to download the data?
cclover
December 2, 2019, 8:55am
#3
The code doesn’t return anything.
Bset
ptrblck
December 2, 2019, 8:57am
#4
In that case trainset
should be properly initialized.
What does print(trainset)
afterwards print out?
cclover
December 2, 2019, 9:00am
#5
Got nothing and changed nothing
trainset = tv.datasets.CIFAR10(
root = './data',
train = True,
download = True,
transform = transform
)
print(trainset)
ptrblck
December 2, 2019, 9:01am
#6
print(trainset)
prints nothing out?
What does print(len(trainset))
output?
cclover
December 2, 2019, 9:03am
#7
Oh, I still didn’t get anything, but I copied the code to another block of code, and it’s done.
Sincerely thank you for helping me again.
Best
cclover
December 2, 2019, 9:04am
#8
Maybe the jupyter notebook have something wrong?
ptrblck
December 2, 2019, 9:05am
#9
Might be. I’ve seen all kind of weird restarts etc. with notebooks.
So if something doesn’t seem to right, I would recommend to run the script in a terminal, which should work.
cclover
December 2, 2019, 9:09am
#10
Thank you again. I’ll take your advice