文章目录
欢迎访问个人网络日志🌹🌹知行空间🌹🌹
PIL Resize Image报错
报错AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
在使用yolov5做实例分割时,根据代码库自己安装的Pillow版本大于10.0.0,运行程序报错如下:
--------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [2], in <cell line: 4>()
1 from PIL import Image
3 image = Image.open(r"/hxx/Desktop/675264194_n.jpg")
----> 4 image = image.resize((20, 20), Image.ANTIALIAS)
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
原因及解决办法
报错原因是因为10.0.0以后版本的Pillow已经舍弃了ANTIALIAS,与其有同样作用的是PIL.Image.LANCZOS 或者 PIL.Image.Resampling.LANCZOS
所以解决办法有两个,
- 一个是修改代码
from PIL import Image
image = Image.open(r"/home/lx/Desktop/675264194_n.jpg")
image = image.resize((20, 20), Image.LANCZOS)
- 一个是修改环境
pip install Pillow==9.5.0
reference
欢迎访问个人网络日志🌹🌹知行空间🌹🌹
1万+





