1515from collections .abc import Iterable
1616from copy import deepcopy
1717from functools import lru_cache , partial
18- from typing import Any , Optional , TypedDict , Union
18+ from typing import Any , Optional , Union
1919
2020import numpy as np
2121
4040 validate_kwargs ,
4141 validate_preprocess_arguments ,
4242)
43- from .processing_utils import Unpack
43+ from .processing_utils import ImagesKwargs , Unpack
4444from .utils import (
4545 TensorType ,
4646 auto_docstring ,
@@ -165,28 +165,6 @@ def divide_to_patches(
165165 return patches
166166
167167
168- class DefaultFastImageProcessorKwargs (TypedDict , total = False ):
169- do_resize : Optional [bool ]
170- size : Optional [dict [str , int ]]
171- default_to_square : Optional [bool ]
172- resample : Optional [Union ["PILImageResampling" , "F.InterpolationMode" ]]
173- do_center_crop : Optional [bool ]
174- crop_size : Optional [dict [str , int ]]
175- do_rescale : Optional [bool ]
176- rescale_factor : Optional [Union [int , float ]]
177- do_normalize : Optional [bool ]
178- image_mean : Optional [Union [float , list [float ]]]
179- image_std : Optional [Union [float , list [float ]]]
180- do_pad : Optional [bool ]
181- pad_size : Optional [dict [str , int ]]
182- do_convert_rgb : Optional [bool ]
183- return_tensors : Optional [Union [str , TensorType ]]
184- data_format : Optional [ChannelDimension ]
185- input_data_format : Optional [Union [str , ChannelDimension ]]
186- device : Optional ["torch.device" ]
187- disable_grouping : Optional [bool ]
188-
189-
190168@auto_docstring
191169class BaseImageProcessorFast (BaseImageProcessor ):
192170 resample = None
@@ -208,10 +186,10 @@ class BaseImageProcessorFast(BaseImageProcessor):
208186 input_data_format = None
209187 device = None
210188 model_input_names = ["pixel_values" ]
211- valid_kwargs = DefaultFastImageProcessorKwargs
189+ valid_kwargs = ImagesKwargs
212190 unused_kwargs = None
213191
214- def __init__ (self , ** kwargs : Unpack [DefaultFastImageProcessorKwargs ]):
192+ def __init__ (self , ** kwargs : Unpack [ImagesKwargs ]):
215193 super ().__init__ (** kwargs )
216194 kwargs = self .filter_out_unused_kwargs (kwargs )
217195 size = kwargs .pop ("size" , self .size )
@@ -730,11 +708,8 @@ def _validate_preprocess_kwargs(
730708 data_format = data_format ,
731709 )
732710
733- def __call__ (self , images : ImageInput , * args , ** kwargs : Unpack [DefaultFastImageProcessorKwargs ]) -> BatchFeature :
734- return self .preprocess (images , * args , ** kwargs )
735-
736711 @auto_docstring
737- def preprocess (self , images : ImageInput , * args , ** kwargs : Unpack [DefaultFastImageProcessorKwargs ]) -> BatchFeature :
712+ def preprocess (self , images : ImageInput , * args , ** kwargs : Unpack [ImagesKwargs ]) -> BatchFeature :
738713 # args are not validated, but their order in the `preprocess` and `_preprocess` signatures must be the same
739714 validate_kwargs (captured_kwargs = kwargs .keys (), valid_processor_keys = self ._valid_kwargs_names )
740715 # Set default kwargs from self. This ensures that if a kwarg is not provided
@@ -767,7 +742,7 @@ def _preprocess_image_like_inputs(
767742 do_convert_rgb : bool ,
768743 input_data_format : ChannelDimension ,
769744 device : Optional [Union [str , "torch.device" ]] = None ,
770- ** kwargs : Unpack [DefaultFastImageProcessorKwargs ],
745+ ** kwargs : Unpack [ImagesKwargs ],
771746 ) -> BatchFeature :
772747 """
773748 Preprocess image-like inputs.
0 commit comments