avatarAvinash

Summary

The web content provides a solution for an "AttributeError" related to the PIL.Image module in Google Colab, which is caused by using an older version of Pillow, by upgrading to version 5.3.0.

Abstract

The article addresses a common error encountered in Google Colab when performing transfer learning: AttributeError: module 'PIL.Image' has no attribute 'register_extensions'. This issue arises due to the use of an outdated version of the Pillow library. The author suggests a straightforward fix: uninstalling the current version of Pillow and installing the newer version 5.3.0. The article provides a step-by-step guide to resolve the error, including the necessary commands to execute in a Colab cell. It also advises verifying the installation by printing the version number and restarting the runtime if the new version does not take effect. Additionally, the author offers a pro tip, pointing readers to a custom Google Colab notebook that simplifies the process of loading data and ensures the correct Pillow version is installed for transfer learning exercises.

Opinions

  • The author implies that updating to Pillow version 5.3.0 is a simple and effective solution to the encountered error.
  • It is suggested that the error is a common issue for those using older versions of Pillow in Google Colab.
  • The author provides a value-added resource (a custom Colab notebook) to streamline the process for users, indicating a user-centric approach.
  • The inclusion of a pro tip indicates the author's experience and willingness to share best practices with the community.

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://readmedium.com/handy-google-colab-notebook-for-transfer-learning-exercise-lesson-4-9fe541688a3

Deep Learning
Udacity
Google Colab
Pytorch
Pytorchudacityscholar
Recommended from ReadMedium