[PyTorch]Read CIFAR10

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

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?

The code doesn’t return anything.
Bset

In that case trainset should be properly initialized.
What does print(trainset) afterwards print out?

Got nothing and changed nothing

trainset = tv.datasets.CIFAR10(
    root = './data',
    train = True,
    download = True, 
    transform = transform
)
print(trainset)

print(trainset) prints nothing out? :face_with_raised_eyebrow:
What does print(len(trainset)) output?

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

Maybe the jupyter notebook have something wrong?

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.

Thank you again. I’ll take your advice