diff --git a/paddlenlp/transformers/clip/feature_extraction.py b/paddlenlp/transformers/clip/feature_extraction.py index d1c9e68646ea..27544cc8e13c 100644 --- a/paddlenlp/transformers/clip/feature_extraction.py +++ b/paddlenlp/transformers/clip/feature_extraction.py @@ -19,7 +19,7 @@ import paddle import numpy as np from PIL import Image - +from PIL.Image import Resampling from ..feature_extraction_utils import BatchFeature from ..tokenizer_utils_base import TensorType from ..image_utils import ImageFeatureExtractionMixin @@ -37,10 +37,10 @@ class CLIPFeatureExtractor(ImageFeatureExtractionMixin): Whether to resize the input to a certain `size`. size (`int`, *optional*, defaults to 224): Resize the input to the given size. Only has an effect if `do_resize` is set to `True`. - resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): - An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, - `PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect - if `do_resize` is set to `True`. + resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`): + An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.Resampling.BOX`, + `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`, `PIL.Image.Resampling.BICUBIC` or + `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`. do_center_crop (`bool`, *optional*, defaults to `True`): Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the image is padded with 0's and then center cropped. @@ -61,7 +61,7 @@ class CLIPFeatureExtractor(ImageFeatureExtractionMixin): def __init__(self, do_resize=True, size=224, - resample=Image.BICUBIC, + resample=Resampling.BICUBIC, do_center_crop=True, crop_size=224, do_normalize=True, diff --git a/paddlenlp/transformers/ernie_vil/feature_extraction.py b/paddlenlp/transformers/ernie_vil/feature_extraction.py index 4becffeaffa5..f937beb44049 100644 --- a/paddlenlp/transformers/ernie_vil/feature_extraction.py +++ b/paddlenlp/transformers/ernie_vil/feature_extraction.py @@ -20,6 +20,7 @@ import paddle import numpy as np from PIL import Image +from PIL.Image import Resampling from ..feature_extraction_utils import BatchFeature from ..tokenizer_utils_base import TensorType @@ -38,10 +39,10 @@ class ErnieViLFeatureExtractor(ImageFeatureExtractionMixin): Whether to resize the input to a certain `size`. size (`int`, *optional*, defaults to 224): Resize the input to the given size. Only has an effect if `do_resize` is set to `True`. - resample (`int`, *optional*, defaults to `PIL.Image.BICUBIC`): - An optional resampling filter. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BOX`, - `PIL.Image.BILINEAR`, `PIL.Image.HAMMING`, `PIL.Image.BICUBIC` or `PIL.Image.LANCZOS`. Only has an effect - if `do_resize` is set to `True`. + resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`): + An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`, `PIL.Image.Resampling.BOX`, + `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`, `PIL.Image.Resampling.BICUBIC` or + `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`. do_center_crop (`bool`, *optional*, defaults to `True`): Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the image is padded with 0's and then center cropped. @@ -62,7 +63,7 @@ class ErnieViLFeatureExtractor(ImageFeatureExtractionMixin): def __init__(self, do_resize=True, size=224, - resample=Image.BICUBIC, + resample=Resampling.BICUBIC, do_center_crop=True, crop_size=224, do_normalize=True, diff --git a/paddlenlp/transformers/image_utils.py b/paddlenlp/transformers/image_utils.py index 4eb66338ef51..4945471d5020 100644 --- a/paddlenlp/transformers/image_utils.py +++ b/paddlenlp/transformers/image_utils.py @@ -1,6 +1,6 @@ # coding=utf-8 -# Copyright 2021 The HuggingFace Inc. team. # Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# Copyright 2021 The HuggingFace Inc. team. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ from typing import List, Union import paddle import numpy as np -from PIL import Image import PIL.Image import PIL.ImageOps +from PIL.Image import Resampling import requests @@ -210,7 +210,7 @@ def normalize(self, image, mean, std): def resize(self, image, size, - resample=Image.BILINEAR, + resample=Resampling.BILINEAR, default_to_square=True, max_size=None): """ @@ -224,7 +224,7 @@ def resize(self, If `size` is an int and `default_to_square` is `True`, then image will be resized to (size, size). If `size` is an int and `default_to_square` is `False`, then smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size). - resample (`int`, *optional*, defaults to `PIL.Image.BILINEAR`): + resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`): The filter to user for resampling. default_to_square (`bool`, *optional*, defaults to `True`): 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): def rotate(self, image, angle, - resample=Image.NEAREST, + resample=Resampling.NEAREST, expand=0, center=None, translate=None,