Skip to content

AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' #41

Description

@amrzv

Hi.
When running Idinvert.ipynb notebook in colab on line target_image = align(inverter, im_name) the error is raised

AttributeError                            Traceback (most recent call last)
[<ipython-input-3-ac856af3bcc2>](https://localhost:8080/#) in <cell line: 0>()
     14   target_name = '000006.png'
     15   im_name = os.path.join(pre, target_name)
---> 16   target_image = align(inverter, im_name)
     17 print('Target image ready!!!')
     18 

2 frames
[<ipython-input-2-3730a37eebf4>](https://localhost:8080/#) in align(inverter, image_path)
    203 def align(inverter, image_path):
    204   """Aligns an unloaded image."""
--> 205   aligned_image = align_face(image_path,
    206                              align_size=inverter.G.resolution)
    207   return aligned_image

[<ipython-input-2-3730a37eebf4>](https://localhost:8080/#) in align_face(image_path, align_size)
    180   face_infos = model.detect(image_path)
    181   face_infos = face_infos[0]
--> 182   img = model.align(face_infos)
    183   return img
    184 

[<ipython-input-2-3730a37eebf4>](https://localhost:8080/#) in align(self, face_info)
    170     img = img.transform((self.align_size * 4, self.align_size * 4), Image.QUAD,
    171                         (quad + 0.5).flatten(), Image.BILINEAR)
--> 172     img = img.resize((self.align_size, self.align_size), Image.ANTIALIAS)
    173 
    174     return np.array(img)

AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

Looks like it's due to a breaking change in PIL, see thread, so the code doesn't work with PIL==11.2.1.
To resolve, two options

  1. fix the version in requirements pil<10
  2. use PIL.Image.LANCZOS instead of PIL.Image.ANTIALIAS

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions