mirror of
https://github.com/saymrwulf/transformers.git
synced 2026-05-14 20:58:08 +00:00
Fix type - update any PIL.Image.Resampling (#20172)
This commit is contained in:
parent
cbbeca3d17
commit
6cc06d1739
8 changed files with 23 additions and 25 deletions
|
|
@ -232,7 +232,7 @@ def resize(
|
|||
The image to resize.
|
||||
size (`Tuple[int, int]`):
|
||||
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.
|
||||
data_format (`ChannelDimension`, *optional*):
|
||||
The channel dimension format of the output image. If `None`, will use the inferred format from the input.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
`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 `PILImageResampling.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
|
||||
|
|
|
|||
|
|
@ -48,11 +48,10 @@ class DonutFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionMixin)
|
|||
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,
|
||||
height). Only has an effect if `do_resize` is set to `True`.
|
||||
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
|
||||
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 `PILImageResampling.BILINEAR`):
|
||||
An optional resampling filter. This can be one of `PILImageResampling.NEAREST`, `PILImageResampling.BOX`,
|
||||
`PILImageResampling.BILINEAR`, `PILImageResampling.HAMMING`, `PILImageResampling.BICUBIC` or
|
||||
`PILImageResampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`.
|
||||
do_thumbnail (`bool`, *optional*, defaults to `True`):
|
||||
Whether to thumbnail the input to the given `size`.
|
||||
do_align_long_axis (`bool`, *optional*, defaults to `False`):
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class GLPNImageProcessor(BaseImageProcessor):
|
|||
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
|
||||
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`.
|
||||
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
|
||||
|
|
@ -80,7 +80,7 @@ class GLPNImageProcessor(BaseImageProcessor):
|
|||
The image is resized so its height and width are rounded down to the closest multiple of
|
||||
`size_divisor`.
|
||||
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*):
|
||||
The channel dimension format for the output image. If `None`, the channel dimension format of the input
|
||||
image is used. Can be one of:
|
||||
|
|
@ -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
|
||||
closest multiple of `size_divisor`.
|
||||
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
|
||||
has an effect if `do_resize` is set to `True`.
|
||||
`PIL.Image` resampling filter to use if resizing the image e.g. `PILImageResampling.BILINEAR`. Only has
|
||||
an effect if `do_resize` is set to `True`.
|
||||
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.).
|
||||
return_tensors (`str` or `TensorType`, *optional*):
|
||||
|
|
|
|||
|
|
@ -209,11 +209,10 @@ class MaskFormerFeatureExtractor(FeatureExtractionMixin, ImageFeatureExtractionM
|
|||
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
|
||||
set to `True`.
|
||||
resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
|
||||
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 `PILImageResampling.BILINEAR`):
|
||||
An optional resampling filter. This can be one of `PILImageResampling.NEAREST`, `PILImageResampling.BOX`,
|
||||
`PILImageResampling.BILINEAR`, `PILImageResampling.HAMMING`, `PILImageResampling.BICUBIC` or
|
||||
`PILImageResampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`.
|
||||
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
|
||||
Swin Transformer.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
sequence like (h, w), output size will be matched to this. If `size` is an int, then image will be resized
|
||||
to (size, size).
|
||||
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 `PILImageResampling.BICUBIC`):
|
||||
An optional resampling filter. This can be one of `PILImageResampling.NEAREST`, `PILImageResampling.BOX`,
|
||||
`PILImageResampling.BILINEAR`, `PILImageResampling.HAMMING`, `PILImageResampling.BICUBIC` or
|
||||
`PILImageResampling.LANCZOS`. Only has an effect if `do_resize` is set to `True`.
|
||||
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
|
||||
image is padded with 0's and then center cropped.
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ class SegformerImageProcessor(BaseImageProcessor):
|
|||
do_rescale: bool,
|
||||
do_normalize: bool,
|
||||
size: Optional[Dict[str, int]] = None,
|
||||
resample: Optional[PILImageResampling] = None,
|
||||
resample: PILImageResampling = None,
|
||||
rescale_factor: Optional[float] = None,
|
||||
image_mean: Optional[Union[float, List[float]]] = None,
|
||||
image_std: Optional[Union[float, List[float]]] = None,
|
||||
|
|
@ -325,7 +325,7 @@ class SegformerImageProcessor(BaseImageProcessor):
|
|||
segmentation_maps: Optional[ImageInput] = None,
|
||||
do_resize: Optional[bool] = None,
|
||||
size: Optional[Dict[str, int]] = None,
|
||||
resample: Optional[PILImageResampling] = None,
|
||||
resample: PILImageResampling = None,
|
||||
do_rescale: Optional[bool] = None,
|
||||
rescale_factor: Optional[float] = None,
|
||||
do_normalize: Optional[bool] = None,
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ if is_vision_available():
|
|||
import PIL
|
||||
|
||||
from transformers import FlavaFeatureExtractor
|
||||
from transformers.image_utils import PILImageResampling
|
||||
from transformers.models.flava.image_processing_flava import (
|
||||
FLAVA_CODEBOOK_MEAN,
|
||||
FLAVA_CODEBOOK_STD,
|
||||
|
|
@ -89,7 +90,7 @@ class FlavaFeatureExtractionTester(unittest.TestCase):
|
|||
self.min_resolution = min_resolution
|
||||
self.max_resolution = max_resolution
|
||||
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.image_mean = image_mean
|
||||
self.image_std = image_std
|
||||
|
|
@ -105,7 +106,7 @@ class FlavaFeatureExtractionTester(unittest.TestCase):
|
|||
|
||||
self.codebook_do_resize = codebook_do_resize
|
||||
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_crop_size = codebook_crop_size
|
||||
self.codebook_do_map_pixels = codebook_do_map_pixels
|
||||
|
|
|
|||
Loading…
Reference in a new issue