Unverified Commit 6cc06d17 authored by amyeroberts's avatar amyeroberts Committed by GitHub
Browse files

Fix type - update any PIL.Image.Resampling (#20172)

parent cbbeca3d
...@@ -232,7 +232,7 @@ def resize( ...@@ -232,7 +232,7 @@ def resize(
The image to resize. The image to resize.
size (`Tuple[int, int]`): size (`Tuple[int, int]`):
The size to use for resizing the image. The size to use for resizing the image.
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`): resample (`int`, *optional*, defaults to `PILImageResampling.BILINEAR`):
The filter to user for resampling. The filter to user for resampling.
data_format (`ChannelDimension`, *optional*): data_format (`ChannelDimension`, *optional*):
The channel dimension format of the output image. If `None`, will use the inferred format from the input. The channel dimension format of the output image. If `None`, will use the inferred format from the input.
......
...@@ -372,7 +372,7 @@ class ImageFeatureExtractionMixin: ...@@ -372,7 +372,7 @@ class ImageFeatureExtractionMixin:
If `size` is an int and `default_to_square` is `True`, then image will be resized to (size, size). If 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 `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). 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 `PILImageResampling.BILINEAR`):
The filter to user for resampling. The filter to user for resampling.
default_to_square (`bool`, *optional*, defaults to `True`): 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 How to convert `size` when it is a single int. If set to `True`, the `size` will be converted to a
......
...@@ -48,11 +48,10 @@ class DonutFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin) ...@@ -48,11 +48,10 @@ class DonutFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin)
size (`Tuple(int)`, *optional*, defaults to [1920, 2560]): size (`Tuple(int)`, *optional*, defaults to [1920, 2560]):
Resize the shorter edge of the input to the minimum value of the given size. Should be a tuple of (width, Resize the shorter edge of the input to the minimum value of the given size. Should be a tuple of (width,
height). Only has an effect if `do_resize` is set to `True`. height). Only has an effect if `do_resize` is set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`): resample (`int`, *optional*, defaults to `PILImageResampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`, An optional resampling filter. This can be one of `PILImageResampling.NEAREST`, `PILImageResampling.BOX`,
`PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`, `PILImageResampling.BILINEAR`, `PILImageResampling.HAMMING`, `PILImageResampling.BICUBIC` or
`PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set `PILImageResampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`.
to `True`.
do_thumbnail (`bool`, *optional*, defaults to `True`): do_thumbnail (`bool`, *optional*, defaults to `True`):
Whether to thumbnail the input to the given `size`. Whether to thumbnail the input to the given `size`.
do_align_long_axis (`bool`, *optional*, defaults to `False`): do_align_long_axis (`bool`, *optional*, defaults to `False`):
......
...@@ -42,7 +42,7 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -42,7 +42,7 @@ class GLPNImageProcessor(BaseImageProcessor):
size_divisor (`int`, *optional*, defaults to 32): size_divisor (`int`, *optional*, defaults to 32):
When `do_resize` is `True`, images are resized so their height and width are rounded down to the closest When `do_resize` is `True`, images are resized so their height and width are rounded down to the closest
multiple of `size_divisor`. Can be overridden by `size_divisor` in `preprocess`. multiple of `size_divisor`. Can be overridden by `size_divisor` in `preprocess`.
resample (`PIL.Image` resampling filter, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`): resample (`PIL.Image` resampling filter, *optional*, defaults to `PILImageResampling.BILINEAR`):
Resampling filter to use if resizing the image. Can be overridden by `resample` in `preprocess`. Resampling filter to use if resizing the image. Can be overridden by `resample` in `preprocess`.
do_rescale (`bool`, *optional*, defaults to `True`): do_rescale (`bool`, *optional*, defaults to `True`):
Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.). Can be Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.). Can be
...@@ -80,7 +80,7 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -80,7 +80,7 @@ class GLPNImageProcessor(BaseImageProcessor):
The image is resized so its height and width are rounded down to the closest multiple of The image is resized so its height and width are rounded down to the closest multiple of
`size_divisor`. `size_divisor`.
resample: resample:
`PIL.Image` resampling filter to use when resizing the image e.g. `PIL.Image.Resampling.BILINEAR`. `PIL.Image` resampling filter to use when resizing the image e.g. `PILImageResampling.BILINEAR`.
data_format (`ChannelDimension` or `str`, *optional*): data_format (`ChannelDimension` or `str`, *optional*):
The channel dimension format for the output image. If `None`, the channel dimension format of the input The channel dimension format for the output image. If `None`, the channel dimension format of the input
image is used. Can be one of: image is used. Can be one of:
...@@ -142,8 +142,8 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -142,8 +142,8 @@ class GLPNImageProcessor(BaseImageProcessor):
When `do_resize` is `True`, images are resized so their height and width are rounded down to the When `do_resize` is `True`, images are resized so their height and width are rounded down to the
closest multiple of `size_divisor`. closest multiple of `size_divisor`.
resample (`PIL.Image` resampling filter, *optional*, defaults to `self.resample`): resample (`PIL.Image` resampling filter, *optional*, defaults to `self.resample`):
`PIL.Image` resampling filter to use if resizing the image e.g. `PIL.Image.Resampling.BILINEAR`. Only `PIL.Image` resampling filter to use if resizing the image e.g. `PILImageResampling.BILINEAR`. Only has
has an effect if `do_resize` is set to `True`. an effect if `do_resize` is set to `True`.
do_rescale (`bool`, *optional*, defaults to `self.do_rescale`): do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.). Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.).
return_tensors (`str` or `TensorType`, *optional*): return_tensors (`str` or `TensorType`, *optional*):
......
...@@ -209,11 +209,10 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM ...@@ -209,11 +209,10 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
max_size (`int`, *optional*, defaults to 1333): max_size (`int`, *optional*, defaults to 1333):
The largest size an image dimension can have (otherwise it's capped). Only has an effect if `do_resize` is The largest size an image dimension can have (otherwise it's capped). Only has an effect if `do_resize` is
set to `True`. set to `True`.
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`): resample (`int`, *optional*, defaults to `PILImageResampling.BILINEAR`):
An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`, An optional resampling filter. This can be one of `PILImageResampling.NEAREST`, `PILImageResampling.BOX`,
`PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`, `PILImageResampling.BILINEAR`, `PILImageResampling.HAMMING`, `PILImageResampling.BICUBIC` or
`PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set `PILImageResampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`.
to `True`.
size_divisibility (`int`, *optional*, defaults to 32): size_divisibility (`int`, *optional*, defaults to 32):
Some backbones need images divisible by a certain number. If not passed, it defaults to the value used in Some backbones need images divisible by a certain number. If not passed, it defaults to the value used in
Swin Transformer. Swin Transformer.
......
...@@ -56,11 +56,10 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin ...@@ -56,11 +56,10 @@ class OwlViTFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin
The size to use for resizing the image. Only has an effect if `do_resize` is set to `True`. If `size` is a The size to use for resizing the image. Only has an effect if `do_resize` is set to `True`. If `size` is a
sequence like (h, w), output size will be matched to this. If `size` is an int, then image will be resized sequence like (h, w), output size will be matched to this. If `size` is an int, then image will be resized
to (size, size). to (size, size).
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BICUBIC`): resample (`int`, *optional*, defaults to `PILImageResampling.BICUBIC`):
An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`, An optional resampling filter. This can be one of `PILImageResampling.NEAREST`, `PILImageResampling.BOX`,
`PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`, `PILImageResampling.BILINEAR`, `PILImageResampling.HAMMING`, `PILImageResampling.BICUBIC` or
`PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set `PILImageResampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`.
to `True`.
do_center_crop (`bool`, *optional*, defaults to `False`): do_center_crop (`bool`, *optional*, defaults to `False`):
Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the 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. image is padded with 0's and then center cropped.
......
...@@ -228,7 +228,7 @@ class SegformerImageProcessor(BaseImageProcessor): ...@@ -228,7 +228,7 @@ class SegformerImageProcessor(BaseImageProcessor):
do_rescale: bool, do_rescale: bool,
do_normalize: bool, do_normalize: bool,
size: Optional[Dict[str, int]] = None, size: Optional[Dict[str, int]] = None,
resample: Optional[PILImageResampling] = None, resample: PILImageResampling = None,
rescale_factor: Optional[float] = None, rescale_factor: Optional[float] = None,
image_mean: Optional[Union[float, List[float]]] = None, image_mean: Optional[Union[float, List[float]]] = None,
image_std: Optional[Union[float, List[float]]] = None, image_std: Optional[Union[float, List[float]]] = None,
...@@ -325,7 +325,7 @@ class SegformerImageProcessor(BaseImageProcessor): ...@@ -325,7 +325,7 @@ class SegformerImageProcessor(BaseImageProcessor):
segmentation_maps: Optional[ImageInput] = None, segmentation_maps: Optional[ImageInput] = None,
do_resize: Optional[bool] = None, do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None, size: Optional[Dict[str, int]] = None,
resample: Optional[PILImageResampling] = None, resample: PILImageResampling = None,
do_rescale: Optional[bool] = None, do_rescale: Optional[bool] = None,
rescale_factor: Optional[float] = None, rescale_factor: Optional[float] = None,
do_normalize: Optional[bool] = None, do_normalize: Optional[bool] = None,
......
...@@ -31,6 +31,7 @@ if is_vision_available(): ...@@ -31,6 +31,7 @@ if is_vision_available():
import PIL import PIL
from transformers import FlavaFeatureExtractor from transformers import FlavaFeatureExtractor
from transformers.image_utils import PILImageResampling
from transformers.models.flava.image_processing_flava import ( from transformers.models.flava.image_processing_flava import (
FLAVA_CODEBOOK_MEAN, FLAVA_CODEBOOK_MEAN,
FLAVA_CODEBOOK_STD, FLAVA_CODEBOOK_STD,
...@@ -89,7 +90,7 @@ class FlavaFeatureExtractionTester(unittest.TestCase): ...@@ -89,7 +90,7 @@ class FlavaFeatureExtractionTester(unittest.TestCase):
self.min_resolution = min_resolution self.min_resolution = min_resolution
self.max_resolution = max_resolution self.max_resolution = max_resolution
self.size = size self.size = size
self.resample = resample if resample is not None else PIL.Image.Resampling.BICUBIC self.resample = resample if resample is not None else PILImageResampling.BICUBIC
self.do_normalize = do_normalize self.do_normalize = do_normalize
self.image_mean = image_mean self.image_mean = image_mean
self.image_std = image_std self.image_std = image_std
...@@ -105,7 +106,7 @@ class FlavaFeatureExtractionTester(unittest.TestCase): ...@@ -105,7 +106,7 @@ class FlavaFeatureExtractionTester(unittest.TestCase):
self.codebook_do_resize = codebook_do_resize self.codebook_do_resize = codebook_do_resize
self.codebook_size = codebook_size self.codebook_size = codebook_size
self.codebook_resample = codebook_resample if codebook_resample is not None else PIL.Image.Resampling.LANCZOS self.codebook_resample = codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
self.codebook_do_center_crop = codebook_do_center_crop self.codebook_do_center_crop = codebook_do_center_crop
self.codebook_crop_size = codebook_crop_size self.codebook_crop_size = codebook_crop_size
self.codebook_do_map_pixels = codebook_do_map_pixels self.codebook_do_map_pixels = codebook_do_map_pixels
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment