Skip to content

Commit 6b54c4e

Browse files
JunnYugongenlei
andauthored
fix pillow deperate warning (#3404)
Co-authored-by: gongenlei <[email protected]>
1 parent fcb477d commit 6b54c4e

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

paddlenlp/transformers/clip/feature_extraction.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import paddle
2020
import numpy as np
2121
from PIL import Image
22-
22+
from PIL.Image import Resampling
2323
from ..feature_extraction_utils import BatchFeature
2424
from ..tokenizer_utils_base import TensorType
2525
from ..image_utils import ImageFeatureExtractionMixin
@@ -37,10 +37,10 @@ class CLIPFeatureExtractor(ImageFeatureExtractionMixin):
3737
Whether to resize the input to a certain `size`.
3838
size (`int`, *optional*, defaults to 224):
3939
Resize the input to the given size. Only has an effect if `do_resize` is set to `True`.
40-
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`):
41-
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`,
42-
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect
43-
if `do_resize` is set to `True`.
40+
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
41+
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.Resampling.BOX`,
42+
`PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`, `PIL.Image.Resampling.BICUBIC` or
43+
`PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`.
4444
do_center_crop (`bool`, *optional*, defaults to `True`):
4545
Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
4646
image is padded with 0's and then center cropped.
@@ -61,7 +61,7 @@ class CLIPFeatureExtractor(ImageFeatureExtractionMixin):
6161
def __init__(self,
6262
do_resize=True,
6363
size=224,
64-
resample=Image.BICUBIC,
64+
resample=Resampling.BICUBIC,
6565
do_center_crop=True,
6666
crop_size=224,
6767
do_normalize=True,

paddlenlp/transformers/ernie_vil/feature_extraction.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import paddle
2121
import numpy as np
2222
from PIL import Image
23+
from PIL.Image import Resampling
2324

2425
from ..feature_extraction_utils import BatchFeature
2526
from ..tokenizer_utils_base import TensorType
@@ -38,10 +39,10 @@ class ErnieViLFeatureExtractor(ImageFeatureExtractionMixin):
3839
Whether to resize the input to a certain `size`.
3940
size (`int`, *optional*, defaults to 224):
4041
Resize the input to the given size. Only has an effect if `do_resize` is set to `True`.
41-
resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`):
42-
An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`,
43-
`PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect
44-
if `do_resize` is set to `True`.
42+
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`):
43+
An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`, `PIL.Image.Resampling.BOX`,
44+
`PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`, `PIL.Image.Resampling.BICUBIC` or
45+
`PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`.
4546
do_center_crop (`bool`, *optional*, defaults to `True`):
4647
Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
4748
image is padded with 0's and then center cropped.
@@ -62,7 +63,7 @@ class ErnieViLFeatureExtractor(ImageFeatureExtractionMixin):
6263
def __init__(self,
6364
do_resize=True,
6465
size=224,
65-
resample=Image.BICUBIC,
66+
resample=Resampling.BICUBIC,
6667
do_center_crop=True,
6768
crop_size=224,
6869
do_normalize=True,

paddlenlp/transformers/image_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding=utf-8
2-
# Copyright 2021 The HuggingFace Inc. team.
32
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
3+
# Copyright 2021 The HuggingFace Inc. team.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -18,9 +18,9 @@
1818
from typing import List, Union
1919
import paddle
2020
import numpy as np
21-
from PIL import Image
2221
import PIL.Image
2322
import PIL.ImageOps
23+
from PIL.Image import Resampling
2424

2525
import requests
2626

@@ -210,7 +210,7 @@ def normalize(self, image, mean, std):
210210
def resize(self,
211211
image,
212212
size,
213-
resample=Image.BILINEAR,
213+
resample=Resampling.BILINEAR,
214214
default_to_square=True,
215215
max_size=None):
216216
"""
@@ -224,7 +224,7 @@ def resize(self,
224224
If `size` is an int and `default_to_square` is `True`, then image will be resized to (size, size). If
225225
`size` is an int and `default_to_square` is `False`, then smaller edge of the image will be matched to
226226
this number. i.e, if height > width, then image will be rescaled to (size * height / width, size).
227-
resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`):
227+
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
228228
The filter to user for resampling.
229229
default_to_square (`bool`, *optional*, defaults to `True`):
230230
How to convert `size` when it is a single int. If set to `True`, the `size` will be converted to a
@@ -376,7 +376,7 @@ def flip_channel_order(self, image):
376376
def rotate(self,
377377
image,
378378
angle,
379-
resample=Image.NEAREST,
379+
resample=Resampling.NEAREST,
380380
expand=0,
381381
center=None,
382382
translate=None,

0 commit comments

Comments
 (0)