Answers for "TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'>"

1

TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'>

The error states that the DataLoader receives a PIL image. 
This is because there are no transforms made (transform=None) on the image.
You can add a transform that creates a tensor from the PIL image by adding transform:

from torchvision import transforms

transform = transforms.Compose([
    # you can add other transformations in this list
    transforms.ToTensor()
])
Posted by: Guest on April-19-2020

Code answers related to "TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'>"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language