RuntimeError: Could not infer dtype of PILImage

Hi, Im trying to run lesson 2 on VSCode with an Ubuntu WSL2, and I’m getting weird errors.
I have a fresh virtual environment with python 3.7.
I have a folder structure as in the lesson 2 lab with images already downloaded.
After running

!pip3 install -Uqq fastbook
import fastbook
from import *
from fastbook import *

path = Path('bears')
fns = get_image_files(path)
failed = verify_images(fns)
sports_data_block = DataBlock(
    blocks=(ImageBlock, CategoryBlock), 
    splitter=RandomSplitter(valid_pct=0.2, seed=42),
dls = sports_data_block.dataloaders(path)
dls.valid.show_batch(max_n=4, nrows=1)

I get the following error:

Could not do one pass in your dataloader, there is something wrong in it
RuntimeError: Could not infer dtype of PILImage
and a long traceback to line 137 of fastai/

Could someone help with this please? I have no idea what’s wrong. Since the same code works on Google Colab, I assume this is an environment or version issue.

1 Like

Looks like the new pillow version 8.3 is the problem. Downgrade to fix.


same here. Downgrade to pillow==8.2 solves the problem

1 Like

Thank you!

This is fixed in the latest fastai now.