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 "

1 Like

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)


Be careful because this sentence doesn’t modify the original image, it returns a copy of the image but converted.

You need to do:

img = img.convert(‘RGBA’)

Sometimes, I get this error message too. I am wondering how strong the impact on the model is. Does it comprise my model? Or is better to convert these images to RGBA? What is your experience? Thank you!