Fast AI vision.widgets.Image shows up as PIL Image but is different

558 Views Asked by At

If I write the following

from PIL import Image
Image

I see that Image is <module 'PIL.Image' from '/usr/local/lib/python3.6/dist-packages/PIL/Image.py'>

and Image.open('tmp.jpg').to_thumb(128,128) gives an error saying `AttributeError: 'JpegImageFile' object has no attribute 'to_thumb'

However, if I replace the import from that from Fast AI

from fastai.vision.widgets import Image
Image

I still see it is from <module 'PIL.Image' from '/usr/local/lib/python3.6/dist-packages/PIL/Image.py'> but this time Image.open('tmp.jpg').to_thumb(128,128) actually produces a thumbnail.

So what is this Image module in Fast Ai and how does it show itself to be the same as the PIL Image module. Perhaps most important question is why? Why are Fast AI folks modifying the module and yet making it appear as PIL's module. This caused me to spend a good amount of time trying to see if there was a bug in my code.

1

There are 1 best solutions below

0
On

Not sure if this helps...

You may want to import PIL image as:

from PIL import Image as PILImage

Adapted from Source | line 12.