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 ,
@@ -163,28 +163,6 @@ def divide_to_patches(
163163 return patches
164164
165165
166- class DefaultFastImageProcessorKwargs (TypedDict , total = False ):
167- do_resize : Optional [bool ]
168- size : Optional [dict [str , int ]]
169- default_to_square : Optional [bool ]
170- resample : Optional [Union ["PILImageResampling" , "F.InterpolationMode" ]]
171- do_center_crop : Optional [bool ]
172- crop_size : Optional [dict [str , int ]]
173- do_rescale : Optional [bool ]
174- rescale_factor : Optional [Union [int , float ]]
175- do_normalize : Optional [bool ]
176- image_mean : Optional [Union [float , list [float ]]]
177- image_std : Optional [Union [float , list [float ]]]
178- do_pad : Optional [bool ]
179- pad_size : Optional [dict [str , int ]]
180- do_convert_rgb : Optional [bool ]
181- return_tensors : Optional [Union [str , TensorType ]]
182- data_format : Optional [ChannelDimension ]
183- input_data_format : Optional [Union [str , ChannelDimension ]]
184- device : Optional ["torch.device" ]
185- disable_grouping : Optional [bool ]
186-
187-
188166@auto_docstring
189167class BaseImageProcessorFast (BaseImageProcessor ):
190168 resample = None
@@ -206,10 +184,10 @@ class BaseImageProcessorFast(BaseImageProcessor):
206184 input_data_format = None
207185 device = None
208186 model_input_names = ["pixel_values" ]
209- valid_kwargs = DefaultFastImageProcessorKwargs
187+ valid_kwargs = ImagesKwargs
210188 unused_kwargs = None
211189
212- def __init__ (self , ** kwargs : Unpack [DefaultFastImageProcessorKwargs ]):
190+ def __init__ (self , ** kwargs : Unpack [ImagesKwargs ]):
213191 super ().__init__ (** kwargs )
214192 kwargs = self .filter_out_unused_kwargs (kwargs )
215193 size = kwargs .pop ("size" , self .size )
@@ -728,11 +706,8 @@ def _validate_preprocess_kwargs(
728706 data_format = data_format ,
729707 )
730708
731- def __call__ (self , images : ImageInput , * args , ** kwargs : Unpack [DefaultFastImageProcessorKwargs ]) -> BatchFeature :
732- return self .preprocess (images , * args , ** kwargs )
733-
734709 @auto_docstring
735- def preprocess (self , images : ImageInput , * args , ** kwargs : Unpack [DefaultFastImageProcessorKwargs ]) -> BatchFeature :
710+ def preprocess (self , images : ImageInput , * args , ** kwargs : Unpack [ImagesKwargs ]) -> BatchFeature :
736711 # args are not validated, but their order in the `preprocess` and `_preprocess` signatures must be the same
737712 validate_kwargs (captured_kwargs = kwargs .keys (), valid_processor_keys = self ._valid_kwargs_names )
738713 # Set default kwargs from self. This ensures that if a kwarg is not provided
@@ -765,7 +740,7 @@ def _preprocess_image_like_inputs(
765740 do_convert_rgb : bool ,
766741 input_data_format : ChannelDimension ,
767742 device : Optional [Union [str , "torch.device" ]] = None ,
768- ** kwargs : Unpack [DefaultFastImageProcessorKwargs ],
743+ ** kwargs : Unpack [ImagesKwargs ],
769744 ) -> BatchFeature :
770745 """
771746 Preprocess image-like inputs.
0 commit comments