Dealing with ‘PIL.Image’ has no attribute ‘register_extensions’
During the course, while doing transfer learning, we get this error with Pillow in Google Colab:
AttributeError: module 'PIL.Image' has no attribute 'register_extensions'
This error occurs if we are using older version of pillow. And the simple fix is to install a latest version. Add this to a cell and run it:
# we need pillow version of 5.3.0
# we will uninstall the older version first
!pip uninstall -y Pillow
# install the new one
!pip install Pillow==5.3.0
# import the new one
import PIL
print(PIL.PILLOW_VERSION)
# this should print 5.3.0. If it doesn't, then restart your runtime:
# Menu > Runtime > Restart Runtime
Above should print 5.3.0
, if it still prints 4.0
then just restart your runtime from the Menu > Runtime > Restart Runtime. Once that is done, Google Colab will load the latest one and this error won’t happen again.
Pro tip: if you are doing Transfer Learning exercise, I have created this custom notebook which loads data and also installs correct version of Pillow — https://medium.com/@ml_kid/handy-google-colab-notebook-for-transfer-learning-exercise-lesson-4-9fe541688a3