PILImage Image.open: no attribute 'read'

I am using a Kaggle dataset with jpeg files.

Screen Shot 2021-08-10 at 2.03.37 PM

When I try to open an image from the dblock.datasets, it is giving me an error:

  • I tried using PILImage, and it gave the same error.

  • I have successfully used these series of codes on a different dataset before.

  • The dls show_batch is working ok.

I would appreciate advice on how the error on image.open may be resolved.

Thank you!


From what I understand, PILImage and PILImageBW are both fastai-specific classes for images, so Image.open() doesn’t work on them.

If you’re just trying to view the image, you might try fastai’s to_image, which works on lots of things, including plain tensors and also the fastai image classes, as far as I’m aware:


That usually does the trick for me.

@nauzk Thank you, I am able to view the dsets with that!

1 Like

@nauzk, thanks to your lead, I also discovered the PILImageBW.show(), which gave me an image that was consistent with the dls.show_batch.

1 Like