Skip to content

Commit 6011ed8

Browse files
authored
Fix #3446 (#3457)
* update Pillow version * compare version
1 parent c65dbb4 commit 6011ed8

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

paddlenlp/transformers/clip/feature_extraction.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@
1818

1919
import paddle
2020
import numpy as np
21+
import PIL.Image
2122
from PIL import Image
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
2626

27+
from ...utils.tools import compare_version
28+
29+
if compare_version(PIL.__version__, "9.1.0") >= 0:
30+
Resampling = PIL.Image.Resampling
31+
else:
32+
Resampling = PIL.Image
33+
2734
__all__ = ["CLIPFeatureExtractor"]
2835

2936

@@ -37,10 +44,10 @@ class CLIPFeatureExtractor(ImageFeatureExtractionMixin):
3744
Whether to resize the input to a certain `size`.
3845
size (`int`, *optional*, defaults to 224):
3946
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.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`.
47+
resample (`int`, *optional*, defaults to `PIL.Image.[Resampling.]BICUBIC`):
48+
An optional resampling filter. This can be one of `PIL.Image.[Resampling.]NEAREST`, `PIL.Image.[Resampling.]BOX`,
49+
`PIL.Image.[Resampling.]BILINEAR`, `PIL.Image.[Resampling.]HAMMING`, `PIL.Image.[Resampling.]BICUBIC` or
50+
`PIL.Image.[Resampling.]LANCZOS`. Only has an effect if `do_resize` is set to `True`.
4451
do_center_crop (`bool`, *optional*, defaults to `True`):
4552
Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
4653
image is padded with 0's and then center cropped.

paddlenlp/transformers/ernie_vil/feature_extraction.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@
1919

2020
import paddle
2121
import numpy as np
22+
import PIL.Image
2223
from PIL import Image
23-
from PIL.Image import Resampling
2424

2525
from ..feature_extraction_utils import BatchFeature
2626
from ..tokenizer_utils_base import TensorType
2727
from ..image_utils import ImageFeatureExtractionMixin
2828

29+
from ...utils.tools import compare_version
30+
31+
if compare_version(PIL.__version__, "9.1.0") >= 0:
32+
Resampling = PIL.Image.Resampling
33+
else:
34+
Resampling = PIL.Image
35+
2936
__all__ = ["ErnieViLFeatureExtractor"]
3037

3138

@@ -39,10 +46,10 @@ class ErnieViLFeatureExtractor(ImageFeatureExtractionMixin):
3946
Whether to resize the input to a certain `size`.
4047
size (`int`, *optional*, defaults to 224):
4148
Resize the input to the given size. Only has an effect 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`.
49+
resample (`int`, *optional*, defaults to `PIL.Image.[Resampling.]BICUBIC`):
50+
An optional resampling filter. This can be one of `PIL.Image.[Resampling.]NEAREST`, `PIL.Image.[Resampling.]BOX`,
51+
`PIL.Image.[Resampling.]BILINEAR`, `PIL.Image.[Resampling.]HAMMING`, `PIL.Image.[Resampling.]BICUBIC` or
52+
`PIL.Image.[Resampling.]LANCZOS`. Only has an effect if `do_resize` is set to `True`.
4653
do_center_crop (`bool`, *optional*, defaults to `True`):
4754
Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
4855
image is padded with 0's and then center cropped.

paddlenlp/transformers/guided_diffusion_utils/transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def affine(
511511
interpolation (InterpolationMode): Desired interpolation enum defined by
512512
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
513513
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
514-
For backward compatibility integer values (e.g. ``PIL.Image[.Resampling].NEAREST``) are still accepted,
514+
For backward compatibility integer values (e.g. ``PIL.Image.[Resampling.]NEAREST``) are still accepted,
515515
but deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum.
516516
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
517517
image. If given a number, the value is used for all bands respectively.
@@ -660,7 +660,7 @@ class RandomAffine(nn.Layer):
660660
interpolation (InterpolationMode): Desired interpolation enum defined by
661661
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
662662
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
663-
For backward compatibility integer values (e.g. ``PIL.Image[.Resampling].NEAREST``) are still accepted,
663+
For backward compatibility integer values (e.g. ``PIL.Image.[Resampling.]NEAREST``) are still accepted,
664664
but deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum.
665665
fill (sequence or number): Pixel fill value for the area outside the transformed
666666
image. Default is ``0``. If given a number, the value is used for all bands respectively.

paddlenlp/transformers/image_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
import numpy as np
2121
import PIL.Image
2222
import PIL.ImageOps
23-
from PIL.Image import Resampling
2423

2524
import requests
25+
from ..utils.tools import compare_version
26+
27+
if compare_version(PIL.__version__, "9.1.0") >= 0:
28+
Resampling = PIL.Image.Resampling
29+
else:
30+
Resampling = PIL.Image
2631

2732
IMAGENET_DEFAULT_MEAN = [0.485, 0.456, 0.406]
2833
IMAGENET_DEFAULT_STD = [0.229, 0.224, 0.225]
@@ -224,7 +229,7 @@ def resize(self,
224229
If `size` is an int and `default_to_square` is `True`, then image will be resized to (size, size). If
225230
`size` is an int and `default_to_square` is `False`, then smaller edge of the image will be matched to
226231
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.Resampling.BILINEAR`):
232+
resample (`int`, *optional*, defaults to `PIL.Image.[Resampling.]BILINEAR`):
228233
The filter to user for resampling.
229234
default_to_square (`bool`, *optional*, defaults to `True`):
230235
How to convert `size` when it is a single int. If set to `True`, the `size` will be converted to a

0 commit comments

Comments
 (0)