Skip to content

Fix #3446 #3457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions paddlenlp/transformers/clip/feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@

import paddle
import numpy as np
import PIL.Image
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

from ...utils.tools import compare_version

if compare_version(PIL.__version__, "9.1.0") >= 0:
Resampling = PIL.Image.Resampling
else:
Resampling = PIL.Image

__all__ = ["CLIPFeatureExtractor"]


Expand All @@ -37,10 +44,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.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`.
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.
Expand Down
17 changes: 12 additions & 5 deletions paddlenlp/transformers/ernie_vil/feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@

import paddle
import numpy as np
import PIL.Image
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

from ...utils.tools import compare_version

if compare_version(PIL.__version__, "9.1.0") >= 0:
Resampling = PIL.Image.Resampling
else:
Resampling = PIL.Image

__all__ = ["ErnieViLFeatureExtractor"]


Expand All @@ -39,10 +46,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.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`.
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.
Expand Down
4 changes: 2 additions & 2 deletions paddlenlp/transformers/guided_diffusion_utils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def affine(
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image[.Resampling].NEAREST``) are still accepted,
For backward compatibility integer values (e.g. ``PIL.Image.[Resampling.]NEAREST``) are still accepted,
but deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum.
fill (sequence or number, optional): Pixel fill value for the area outside the transformed
image. If given a number, the value is used for all bands respectively.
Expand Down Expand Up @@ -660,7 +660,7 @@ class RandomAffine(nn.Layer):
interpolation (InterpolationMode): Desired interpolation enum defined by
:class:`torchvision.transforms.InterpolationMode`. Default is ``InterpolationMode.NEAREST``.
If input is Tensor, only ``InterpolationMode.NEAREST``, ``InterpolationMode.BILINEAR`` are supported.
For backward compatibility integer values (e.g. ``PIL.Image[.Resampling].NEAREST``) are still accepted,
For backward compatibility integer values (e.g. ``PIL.Image.[Resampling.]NEAREST``) are still accepted,
but deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum.
fill (sequence or number): Pixel fill value for the area outside the transformed
image. Default is ``0``. If given a number, the value is used for all bands respectively.
Expand Down
9 changes: 7 additions & 2 deletions paddlenlp/transformers/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
import numpy as np
import PIL.Image
import PIL.ImageOps
from PIL.Image import Resampling

import requests
from ..utils.tools import compare_version

if compare_version(PIL.__version__, "9.1.0") >= 0:
Resampling = PIL.Image.Resampling
else:
Resampling = PIL.Image

IMAGENET_DEFAULT_MEAN = [0.485, 0.456, 0.406]
IMAGENET_DEFAULT_STD = [0.229, 0.224, 0.225]
Expand Down Expand Up @@ -224,7 +229,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.Resampling.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
Expand Down