How to turn a cifar10 dataset into a tensor

Question:

I am trying to turn the cifar10 dataset into a tensor with

trainset = datasets.CIFAR10(root='./data', train=True, download=True, transform=transforms.ToTensor())
but it continually returns false when I run it torch.is_tensor(trainset) function which means it’s not a tensor and it also doesn’t work for functions that require tensors in the code I’m running on.

I tried to print out the trainset with
print(trainset)
and I keep getting

Dataset CIFAR10
Number of datapoints: 50000
Root location: ./data
Split: Train
StandardTransform
Transform: ToTensor()

which means it’s not yet a tensor.

How exactly can I convert the entire cifar10 dataset to a tensor?

Asked By: greens trial

||

Answers:

trainset is a Dataset instance and you do not convert it to a tensor. You should load the data and then transform it.

for i, data in enumerate(trainset, 0):
    do whatever
Answered By: SamAtWork