What to do if PIL.Image can't read my images?

I’m trying to apply concepts covered in lesson 1 - 2 on a dataset.
This dataset contains very large images (2000 x 1000) of format ‘tif’.
I ran the 3 rock-star lines of code and it mentioned that PIL doesn’t know how
to read this file:

File “/home/ubuntu/src/anaconda3/envs/fastai/lib/python3.6/site-packages/PIL/Image.py”, line 2519, in open
% (filename if filename else fp))
OSError: cannot identify image file ‘/home/ubuntu/data/mydataset/sample/train/class1/b074.tif’

I’ve tested opencv and it reads this image file without problem.
So the main question is:
how to use fastai and provide it a function (cv2.imread in my case) that could read our dataset images ?

Thank you for your help.

1 Like

I don’t think that providing it a function or changing how it read things would be very straightforward. Maybe you could convert your tiff images to jpg?

A quick google search shows a lot of tools being able to do that for you - not sure if any would be applicable here?

BTW instead of using those online converters, I think I would give something like this a shot.


Thank you so much !
Good work around and simple at the same time.
Sometimes we look for complex solutions while simple ones are just
under our feet!
I’ve just made a test, the converted one (.jpg) is exactly as the original.
In fact I was afraid about some losses.
Thank you again.

1 Like

ImageMagick and GraphicsMagick are great - most useful tool in the command line toolbox for images!

1 Like

Hi, my first question on a fastai forum!

I am trying to use images with a high bit depth so they are saved as .tiff files and I can’t convert them to other file types whilst keeping the bit depth. Does anyone know how I might be able to adapt the notebooks to deal with .tiff files?



Welcome Naomi,
Currently fastai reads .tiff images right out of the box.
Just try:
data = ImageList.from_folder(path='your_images_folder/')....

If it doesn’t work, specify the extension ‘.tiff’ :

data = ImageList.from_folder(path='your_images_folder/', extensions='tiff')

Good luck

1 Like