lelouedec
(Lelouedec)
1
hey,
I am using the code example from here
in my code :
dsets = datasets.ImageFolder(‘./dataset/’)
dset_loaders = torch.utils.data.DataLoader(dsets, batch_size=1, shuffle=False)
but I end up getting the following error :
TypeError : batch must contain tensors, numbers … found <class PIL …
Am I doing it wrong ?
You have to transform the images into Tensor
s.
You could use this code taken from the ImageNet example:
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
train_dataset = datasets.ImageFolder(
traindir,
transforms.Compose([
transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
normalize,
]))
In your case you need the transforms.ToTensor()
transformation. The others are optional.