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()
])

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'mmcv.parallel.data_container.DataContainer'> pytorch mnist TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'> TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'dataset.MICCDataset'> TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found object TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'> site:stackoverflow.com TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.JpegImagePlugin.JpegImageFile'> default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.JpegImagePlugin.JpegImageFile'> default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'pathlib.PosixPath'> TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'torchvision.transforms.transforms.Compose'> pytorch batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'> default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'> batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'pandas.core.series.Series'> default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'torchvision.transforms.transforms.ToTensor' default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'torchvision.transforms.transforms.ToTensor'> TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'NoneType'> TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <U6 TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.Image.Image'> TypeError: batch must contain tensors, numbers, dicts or lists; found <class 'PIL.Image.Image'> TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source