UserWarning: Palette images

How do I get rid of this:
/usr/local/lib/python3.7/dist-packages/PIL/ UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
"Palette images with Transparency expressed in bytes should be "

Converting PNG (GIF?) images to full RGBA PNG images seems to fix the problem.

I put this code after removing the ‘failed’ images:

for o in bear_types:
    # convert all PNG, GIF images to RGBA
    for image in os.listdir(path/o):
        ext = os.path.splitext(image)[1]
        if ext in ['.png', '.gif']:
            new_filename = os.path.splitext(image)[0]+'.png'
            img =
            print('saving: ' + new_filename)

I used this topic for reference:

What are the potential drawbacks of using ImageFile.LOAD_TRUNCATED_IMAGES = True to handle truncated images in PIL library?

To fix the Palette image I added the import before running the learner:

from PIL import ImageFile

then run:

  • learn = vision_learner(dls, resnet18, metrics=error_rate)

  • learn.fine_tune(4)