Unverified Commit fb66ef81 authored by Pavel Iakubovskii's avatar Pavel Iakubovskii Committed by GitHub
Browse files

Update kwargs validation for `preprocess` with decorator (#32024)

* BLIP preprocess

* BIT preprocess

* BRIDGETOWER preprocess

* CHAMELEON preprocess

* CHINESE_CLIP preprocess

* CONVNEXT preprocess

* DEIT preprocess

* DONUT preprocess

* DPT preprocess

* FLAVA preprocess

* EFFICIENTNET preprocess

* FUYU preprocess

* GLPN preprocess

* IMAGEGPT preprocess

* INTRUCTBLIPVIDEO preprocess

* VIVIT preprocess

* ZOEDEPTH preprocess

* VITMATTE preprocess

* VIT preprocess

* VILT preprocess

* VIDEOMAE preprocess

* VIDEOLLAVA

* TVP processing

* TVP fixup

* SWIN2SR preprocess

* SIGLIP preprocess

* SAM preprocess

* RT-DETR preprocess

* PVT preprocess

* POOLFORMER preprocess

* PERCEIVER preprocess

* OWLVIT preprocess

* OWLV2 preprocess

* NOUGAT preprocess

* MOBILEVIT preprocess

* MOBILENETV2 preprocess

* MOBILENETV1 preprocess

* LEVIT preprocess

* LAYOUTLMV2 preprocess

* LAYOUTLMV3 preprocess

* Add test

* Update tests
parent e85d8639
...@@ -36,10 +36,9 @@ from ...image_utils import ( ...@@ -36,10 +36,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
logger = logging.get_logger(__name__) logger = logging.get_logger(__name__)
...@@ -122,23 +121,6 @@ class BitImageProcessor(BaseImageProcessor): ...@@ -122,23 +121,6 @@ class BitImageProcessor(BaseImageProcessor):
self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN
self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD
self.do_convert_rgb = do_convert_rgb self.do_convert_rgb = do_convert_rgb
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"do_convert_rgb",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.clip.image_processing_clip.CLIPImageProcessor.resize # Copied from transformers.models.clip.image_processing_clip.CLIPImageProcessor.resize
def resize( def resize(
...@@ -190,6 +172,7 @@ class BitImageProcessor(BaseImageProcessor): ...@@ -190,6 +172,7 @@ class BitImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -207,7 +190,6 @@ class BitImageProcessor(BaseImageProcessor): ...@@ -207,7 +190,6 @@ class BitImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = ChannelDimension.FIRST, data_format: Optional[ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -274,8 +256,6 @@ class BitImageProcessor(BaseImageProcessor): ...@@ -274,8 +256,6 @@ class BitImageProcessor(BaseImageProcessor):
image_std = image_std if image_std is not None else self.image_std image_std = image_std if image_std is not None else self.image_std
do_convert_rgb = do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb do_convert_rgb = do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
images = make_list_of_images(images) images = make_list_of_images(images)
if not valid_images(images): if not valid_images(images):
......
...@@ -31,10 +31,9 @@ from ...image_utils import ( ...@@ -31,10 +31,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_vision_available(): if is_vision_available():
...@@ -107,21 +106,6 @@ class BlipImageProcessor(BaseImageProcessor): ...@@ -107,21 +106,6 @@ class BlipImageProcessor(BaseImageProcessor):
self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN
self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD
self.do_convert_rgb = do_convert_rgb self.do_convert_rgb = do_convert_rgb
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"do_convert_rgb",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.BICUBIC # Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.BICUBIC
def resize( def resize(
...@@ -172,6 +156,7 @@ class BlipImageProcessor(BaseImageProcessor): ...@@ -172,6 +156,7 @@ class BlipImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -187,7 +172,6 @@ class BlipImageProcessor(BaseImageProcessor): ...@@ -187,7 +172,6 @@ class BlipImageProcessor(BaseImageProcessor):
do_convert_rgb: bool = None, do_convert_rgb: bool = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -250,8 +234,6 @@ class BlipImageProcessor(BaseImageProcessor): ...@@ -250,8 +234,6 @@ class BlipImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -32,10 +32,9 @@ from ...image_utils import ( ...@@ -32,10 +32,9 @@ from ...image_utils import (
is_scaled_image, is_scaled_image,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_vision_available(): if is_vision_available():
...@@ -205,24 +204,6 @@ class BridgeTowerImageProcessor(BaseImageProcessor): ...@@ -205,24 +204,6 @@ class BridgeTowerImageProcessor(BaseImageProcessor):
self.do_pad = do_pad self.do_pad = do_pad
self.do_center_crop = do_center_crop self.do_center_crop = do_center_crop
self.crop_size = crop_size self.crop_size = crop_size
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"size_divisor",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"do_pad",
"do_center_crop",
"crop_size",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.vilt.image_processing_vilt.ViltImageProcessor.resize # Copied from transformers.models.vilt.image_processing_vilt.ViltImageProcessor.resize
def resize( def resize(
...@@ -389,6 +370,7 @@ class BridgeTowerImageProcessor(BaseImageProcessor): ...@@ -389,6 +370,7 @@ class BridgeTowerImageProcessor(BaseImageProcessor):
return BatchFeature(data=data, tensor_type=return_tensors) return BatchFeature(data=data, tensor_type=return_tensors)
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -407,7 +389,6 @@ class BridgeTowerImageProcessor(BaseImageProcessor): ...@@ -407,7 +389,6 @@ class BridgeTowerImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -484,8 +465,6 @@ class BridgeTowerImageProcessor(BaseImageProcessor): ...@@ -484,8 +465,6 @@ class BridgeTowerImageProcessor(BaseImageProcessor):
size = size if size is not None else self.size size = size if size is not None else self.size
size = get_size_dict(size, default_to_square=False) size = get_size_dict(size, default_to_square=False)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not is_batched(images): if not is_batched(images):
images = [images] images = [images]
......
...@@ -33,10 +33,9 @@ from ...image_utils import ( ...@@ -33,10 +33,9 @@ from ...image_utils import (
is_valid_image, is_valid_image,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
logger = logging.get_logger(__name__) logger = logging.get_logger(__name__)
...@@ -141,23 +140,6 @@ class ChameleonImageProcessor(BaseImageProcessor): ...@@ -141,23 +140,6 @@ class ChameleonImageProcessor(BaseImageProcessor):
self.image_mean = image_mean if image_mean is not None else [1.0, 1.0, 1.0] self.image_mean = image_mean if image_mean is not None else [1.0, 1.0, 1.0]
self.image_std = image_std if image_std is not None else [1.0, 1.0, 1.0] self.image_std = image_std if image_std is not None else [1.0, 1.0, 1.0]
self.do_convert_rgb = do_convert_rgb self.do_convert_rgb = do_convert_rgb
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"do_convert_rgb",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.clip.image_processing_clip.CLIPImageProcessor.resize # Copied from transformers.models.clip.image_processing_clip.CLIPImageProcessor.resize
def resize( def resize(
...@@ -209,6 +191,7 @@ class ChameleonImageProcessor(BaseImageProcessor): ...@@ -209,6 +191,7 @@ class ChameleonImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -226,7 +209,6 @@ class ChameleonImageProcessor(BaseImageProcessor): ...@@ -226,7 +209,6 @@ class ChameleonImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = ChannelDimension.FIRST, data_format: Optional[ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -293,8 +275,6 @@ class ChameleonImageProcessor(BaseImageProcessor): ...@@ -293,8 +275,6 @@ class ChameleonImageProcessor(BaseImageProcessor):
image_std = image_std if image_std is not None else self.image_std image_std = image_std if image_std is not None else self.image_std
do_convert_rgb = do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb do_convert_rgb = do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
images = make_batched_images(images) images = make_batched_images(images)
if not valid_images(images): if not valid_images(images):
......
...@@ -36,10 +36,9 @@ from ...image_utils import ( ...@@ -36,10 +36,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
logger = logging.get_logger(__name__) logger = logging.get_logger(__name__)
...@@ -122,23 +121,6 @@ class ChineseCLIPImageProcessor(BaseImageProcessor): ...@@ -122,23 +121,6 @@ class ChineseCLIPImageProcessor(BaseImageProcessor):
self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN
self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD
self.do_convert_rgb = do_convert_rgb self.do_convert_rgb = do_convert_rgb
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"do_convert_rgb",
"return_tensors",
"data_format",
"input_data_format",
]
def resize( def resize(
self, self,
...@@ -179,6 +161,7 @@ class ChineseCLIPImageProcessor(BaseImageProcessor): ...@@ -179,6 +161,7 @@ class ChineseCLIPImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -196,7 +179,6 @@ class ChineseCLIPImageProcessor(BaseImageProcessor): ...@@ -196,7 +179,6 @@ class ChineseCLIPImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = ChannelDimension.FIRST, data_format: Optional[ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -265,8 +247,6 @@ class ChineseCLIPImageProcessor(BaseImageProcessor): ...@@ -265,8 +247,6 @@ class ChineseCLIPImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -36,10 +36,9 @@ from ...image_utils import ( ...@@ -36,10 +36,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_vision_available(): if is_vision_available():
...@@ -114,21 +113,6 @@ class ConvNextImageProcessor(BaseImageProcessor): ...@@ -114,21 +113,6 @@ class ConvNextImageProcessor(BaseImageProcessor):
self.do_normalize = do_normalize self.do_normalize = do_normalize
self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"crop_pct",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"return_tensors",
"data_format",
"input_data_format",
]
def resize( def resize(
self, self,
...@@ -199,6 +183,7 @@ class ConvNextImageProcessor(BaseImageProcessor): ...@@ -199,6 +183,7 @@ class ConvNextImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -214,7 +199,6 @@ class ConvNextImageProcessor(BaseImageProcessor): ...@@ -214,7 +199,6 @@ class ConvNextImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -276,8 +260,6 @@ class ConvNextImageProcessor(BaseImageProcessor): ...@@ -276,8 +260,6 @@ class ConvNextImageProcessor(BaseImageProcessor):
size = size if size is not None else self.size size = size if size is not None else self.size
size = get_size_dict(size, default_to_square=False) size = get_size_dict(size, default_to_square=False)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
images = make_list_of_images(images) images = make_list_of_images(images)
if not valid_images(images): if not valid_images(images):
......
...@@ -31,10 +31,9 @@ from ...image_utils import ( ...@@ -31,10 +31,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_vision_available(): if is_vision_available():
...@@ -110,22 +109,6 @@ class DeiTImageProcessor(BaseImageProcessor): ...@@ -110,22 +109,6 @@ class DeiTImageProcessor(BaseImageProcessor):
self.do_normalize = do_normalize self.do_normalize = do_normalize
self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.BICUBIC # Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.BICUBIC
def resize( def resize(
...@@ -176,6 +159,7 @@ class DeiTImageProcessor(BaseImageProcessor): ...@@ -176,6 +159,7 @@ class DeiTImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -192,7 +176,6 @@ class DeiTImageProcessor(BaseImageProcessor): ...@@ -192,7 +176,6 @@ class DeiTImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -257,8 +240,6 @@ class DeiTImageProcessor(BaseImageProcessor): ...@@ -257,8 +240,6 @@ class DeiTImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -37,10 +37,9 @@ from ...image_utils import ( ...@@ -37,10 +37,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, logging from ...utils import TensorType, filter_out_non_signature_kwargs, logging
from ...utils.import_utils import is_vision_available from ...utils.import_utils import is_vision_available
...@@ -124,24 +123,6 @@ class DonutImageProcessor(BaseImageProcessor): ...@@ -124,24 +123,6 @@ class DonutImageProcessor(BaseImageProcessor):
self.do_normalize = do_normalize self.do_normalize = do_normalize
self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_thumbnail",
"do_align_long_axis",
"do_pad",
"random_padding",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"return_tensors",
"data_format",
"input_data_format",
]
def align_long_axis( def align_long_axis(
self, self,
...@@ -314,6 +295,7 @@ class DonutImageProcessor(BaseImageProcessor): ...@@ -314,6 +295,7 @@ class DonutImageProcessor(BaseImageProcessor):
) )
return resized_image return resized_image
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -332,7 +314,6 @@ class DonutImageProcessor(BaseImageProcessor): ...@@ -332,7 +314,6 @@ class DonutImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = ChannelDimension.FIRST, data_format: Optional[ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -407,8 +388,6 @@ class DonutImageProcessor(BaseImageProcessor): ...@@ -407,8 +388,6 @@ class DonutImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -35,10 +35,9 @@ from ...image_utils import ( ...@@ -35,10 +35,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_torch_available(): if is_torch_available():
...@@ -165,24 +164,6 @@ class DPTImageProcessor(BaseImageProcessor): ...@@ -165,24 +164,6 @@ class DPTImageProcessor(BaseImageProcessor):
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
self.do_pad = do_pad self.do_pad = do_pad
self.size_divisor = size_divisor self.size_divisor = size_divisor
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"keep_aspect_ratio",
"ensure_multiple_of",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"do_pad",
"size_divisor",
"return_tensors",
"data_format",
"input_data_format",
]
def resize( def resize(
self, self,
...@@ -284,6 +265,7 @@ class DPTImageProcessor(BaseImageProcessor): ...@@ -284,6 +265,7 @@ class DPTImageProcessor(BaseImageProcessor):
return pad(image, ((pad_size_left, pad_size_right), (pad_size_top, pad_size_bottom)), data_format=data_format) return pad(image, ((pad_size_left, pad_size_right), (pad_size_top, pad_size_bottom)), data_format=data_format)
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -302,7 +284,6 @@ class DPTImageProcessor(BaseImageProcessor): ...@@ -302,7 +284,6 @@ class DPTImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -369,8 +350,6 @@ class DPTImageProcessor(BaseImageProcessor): ...@@ -369,8 +350,6 @@ class DPTImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -31,10 +31,9 @@ from ...image_utils import ( ...@@ -31,10 +31,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_vision_available(): if is_vision_available():
...@@ -119,24 +118,6 @@ class EfficientNetImageProcessor(BaseImageProcessor): ...@@ -119,24 +118,6 @@ class EfficientNetImageProcessor(BaseImageProcessor):
self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
self.include_top = include_top self.include_top = include_top
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"rescale_offset",
"do_normalize",
"image_mean",
"image_std",
"include_top",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.NEAREST # Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.NEAREST
def resize( def resize(
...@@ -227,6 +208,7 @@ class EfficientNetImageProcessor(BaseImageProcessor): ...@@ -227,6 +208,7 @@ class EfficientNetImageProcessor(BaseImageProcessor):
return rescaled_image return rescaled_image
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -245,7 +227,6 @@ class EfficientNetImageProcessor(BaseImageProcessor): ...@@ -245,7 +227,6 @@ class EfficientNetImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -316,8 +297,6 @@ class EfficientNetImageProcessor(BaseImageProcessor): ...@@ -316,8 +297,6 @@ class EfficientNetImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -34,10 +34,9 @@ from ...image_utils import ( ...@@ -34,10 +34,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_vision_available(): if is_vision_available():
...@@ -302,41 +301,6 @@ class FlavaImageProcessor(BaseImageProcessor): ...@@ -302,41 +301,6 @@ class FlavaImageProcessor(BaseImageProcessor):
self.codebook_image_mean = codebook_image_mean self.codebook_image_mean = codebook_image_mean
self.codebook_image_mean = codebook_image_mean if codebook_image_mean is not None else FLAVA_CODEBOOK_MEAN self.codebook_image_mean = codebook_image_mean if codebook_image_mean is not None else FLAVA_CODEBOOK_MEAN
self.codebook_image_std = codebook_image_std if codebook_image_std is not None else FLAVA_CODEBOOK_STD self.codebook_image_std = codebook_image_std if codebook_image_std is not None else FLAVA_CODEBOOK_STD
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"return_image_mask",
"input_size_patches",
"total_mask_patches",
"mask_group_min_patches",
"mask_group_max_patches",
"mask_group_min_aspect_ratio",
"mask_group_max_aspect_ratio",
"return_codebook_pixels",
"codebook_do_resize",
"codebook_size",
"codebook_resample",
"codebook_do_center_crop",
"codebook_crop_size",
"codebook_do_rescale",
"codebook_rescale_factor",
"codebook_do_map_pixels",
"codebook_do_normalize",
"codebook_image_mean",
"codebook_image_std",
"return_tensors",
"data_format",
"input_data_format",
]
@classmethod @classmethod
def from_dict(cls, image_processor_dict: Dict[str, Any], **kwargs): def from_dict(cls, image_processor_dict: Dict[str, Any], **kwargs):
...@@ -486,6 +450,7 @@ class FlavaImageProcessor(BaseImageProcessor): ...@@ -486,6 +450,7 @@ class FlavaImageProcessor(BaseImageProcessor):
image = to_channel_dimension_format(image, data_format, input_channel_dim=input_data_format) image = to_channel_dimension_format(image, data_format, input_channel_dim=input_data_format)
return image return image
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -523,7 +488,6 @@ class FlavaImageProcessor(BaseImageProcessor): ...@@ -523,7 +488,6 @@ class FlavaImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -672,8 +636,6 @@ class FlavaImageProcessor(BaseImageProcessor): ...@@ -672,8 +636,6 @@ class FlavaImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -39,6 +39,7 @@ from ...image_utils import ( ...@@ -39,6 +39,7 @@ from ...image_utils import (
) )
from ...utils import ( from ...utils import (
TensorType, TensorType,
filter_out_non_signature_kwargs,
is_torch_available, is_torch_available,
is_torch_device, is_torch_device,
is_torch_dtype, is_torch_dtype,
...@@ -261,24 +262,6 @@ class FuyuImageProcessor(BaseImageProcessor): ...@@ -261,24 +262,6 @@ class FuyuImageProcessor(BaseImageProcessor):
self.do_rescale = do_rescale self.do_rescale = do_rescale
self.rescale_factor = rescale_factor self.rescale_factor = rescale_factor
self.patch_size = patch_size if patch_size is not None else {"height": 30, "width": 30} self.patch_size = patch_size if patch_size is not None else {"height": 30, "width": 30}
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_pad",
"padding_value",
"padding_mode",
"do_normalize",
"image_mean",
"image_std",
"do_rescale",
"rescale_factor",
"patch_size",
"return_tensors",
"data_format",
"input_data_format",
]
def resize( def resize(
self, self,
...@@ -376,6 +359,7 @@ class FuyuImageProcessor(BaseImageProcessor): ...@@ -376,6 +359,7 @@ class FuyuImageProcessor(BaseImageProcessor):
) )
return padded_image return padded_image
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images, images,
......
...@@ -30,10 +30,9 @@ from ...image_utils import ( ...@@ -30,10 +30,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, logging from ...utils import TensorType, filter_out_non_signature_kwargs, logging
logger = logging.get_logger(__name__) logger = logging.get_logger(__name__)
...@@ -72,16 +71,6 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -72,16 +71,6 @@ class GLPNImageProcessor(BaseImageProcessor):
self.size_divisor = size_divisor self.size_divisor = size_divisor
self.resample = resample self.resample = resample
super().__init__(**kwargs) super().__init__(**kwargs)
self._valid_processor_keys = [
"images",
"do_resize",
"size_divisor",
"resample",
"do_rescale",
"return_tensors",
"data_format",
"input_data_format",
]
def resize( def resize(
self, self,
...@@ -133,6 +122,7 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -133,6 +122,7 @@ class GLPNImageProcessor(BaseImageProcessor):
) )
return image return image
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: Union["PIL.Image.Image", TensorType, List["PIL.Image.Image"], List[TensorType]], images: Union["PIL.Image.Image", TensorType, List["PIL.Image.Image"], List[TensorType]],
...@@ -143,7 +133,6 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -143,7 +133,6 @@ class GLPNImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[TensorType, str]] = None, return_tensors: Optional[Union[TensorType, str]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> BatchFeature: ) -> BatchFeature:
""" """
Preprocess the given images. Preprocess the given images.
...@@ -187,8 +176,6 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -187,8 +176,6 @@ class GLPNImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -29,10 +29,9 @@ from ...image_utils import ( ...@@ -29,10 +29,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_vision_available(): if is_vision_available():
...@@ -103,18 +102,6 @@ class ImageGPTImageProcessor(BaseImageProcessor): ...@@ -103,18 +102,6 @@ class ImageGPTImageProcessor(BaseImageProcessor):
self.resample = resample self.resample = resample
self.do_normalize = do_normalize self.do_normalize = do_normalize
self.do_color_quantize = do_color_quantize self.do_color_quantize = do_color_quantize
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_normalize",
"do_color_quantize",
"clusters",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize # Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize
def resize( def resize(
...@@ -186,6 +173,7 @@ class ImageGPTImageProcessor(BaseImageProcessor): ...@@ -186,6 +173,7 @@ class ImageGPTImageProcessor(BaseImageProcessor):
image = image - 1 image = image - 1
return image return image
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -198,7 +186,6 @@ class ImageGPTImageProcessor(BaseImageProcessor): ...@@ -198,7 +186,6 @@ class ImageGPTImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[Union[str, ChannelDimension]] = ChannelDimension.FIRST, data_format: Optional[Union[str, ChannelDimension]] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -251,8 +238,6 @@ class ImageGPTImageProcessor(BaseImageProcessor): ...@@ -251,8 +238,6 @@ class ImageGPTImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -35,10 +35,9 @@ from ...image_utils import ( ...@@ -35,10 +35,9 @@ from ...image_utils import (
is_valid_image, is_valid_image,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_vision_available, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_vision_available, logging
if is_vision_available(): if is_vision_available():
...@@ -128,21 +127,6 @@ class InstructBlipVideoImageProcessor(BaseImageProcessor): ...@@ -128,21 +127,6 @@ class InstructBlipVideoImageProcessor(BaseImageProcessor):
self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN
self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD
self.do_convert_rgb = do_convert_rgb self.do_convert_rgb = do_convert_rgb
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"do_convert_rgb",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.BICUBIC # Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.BICUBIC
def resize( def resize(
...@@ -195,6 +179,7 @@ class InstructBlipVideoImageProcessor(BaseImageProcessor): ...@@ -195,6 +179,7 @@ class InstructBlipVideoImageProcessor(BaseImageProcessor):
) )
# Ignore copy # Ignore copy
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: VideoInput = None, images: VideoInput = None,
...@@ -210,7 +195,6 @@ class InstructBlipVideoImageProcessor(BaseImageProcessor): ...@@ -210,7 +195,6 @@ class InstructBlipVideoImageProcessor(BaseImageProcessor):
do_convert_rgb: bool = None, do_convert_rgb: bool = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess a video or batch of images/videos. Preprocess a video or batch of images/videos.
...@@ -272,7 +256,6 @@ class InstructBlipVideoImageProcessor(BaseImageProcessor): ...@@ -272,7 +256,6 @@ class InstructBlipVideoImageProcessor(BaseImageProcessor):
size = get_size_dict(size, default_to_square=False) size = get_size_dict(size, default_to_square=False)
videos = make_batched_videos(images) videos = make_batched_videos(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
validate_preprocess_arguments( validate_preprocess_arguments(
do_rescale=do_rescale, do_rescale=do_rescale,
......
...@@ -28,10 +28,16 @@ from ...image_utils import ( ...@@ -28,10 +28,16 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_pytesseract_available, is_vision_available, logging, requires_backends from ...utils import (
TensorType,
filter_out_non_signature_kwargs,
is_pytesseract_available,
is_vision_available,
logging,
requires_backends,
)
if is_vision_available(): if is_vision_available():
...@@ -138,18 +144,6 @@ class LayoutLMv2ImageProcessor(BaseImageProcessor): ...@@ -138,18 +144,6 @@ class LayoutLMv2ImageProcessor(BaseImageProcessor):
self.apply_ocr = apply_ocr self.apply_ocr = apply_ocr
self.ocr_lang = ocr_lang self.ocr_lang = ocr_lang
self.tesseract_config = tesseract_config self.tesseract_config = tesseract_config
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"apply_ocr",
"ocr_lang",
"tesseract_config",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize # Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize
def resize( def resize(
...@@ -200,6 +194,7 @@ class LayoutLMv2ImageProcessor(BaseImageProcessor): ...@@ -200,6 +194,7 @@ class LayoutLMv2ImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -212,7 +207,6 @@ class LayoutLMv2ImageProcessor(BaseImageProcessor): ...@@ -212,7 +207,6 @@ class LayoutLMv2ImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -257,8 +251,6 @@ class LayoutLMv2ImageProcessor(BaseImageProcessor): ...@@ -257,8 +251,6 @@ class LayoutLMv2ImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -31,10 +31,16 @@ from ...image_utils import ( ...@@ -31,10 +31,16 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_pytesseract_available, is_vision_available, logging, requires_backends from ...utils import (
TensorType,
filter_out_non_signature_kwargs,
is_pytesseract_available,
is_vision_available,
logging,
requires_backends,
)
if is_vision_available(): if is_vision_available():
...@@ -165,23 +171,6 @@ class LayoutLMv3ImageProcessor(BaseImageProcessor): ...@@ -165,23 +171,6 @@ class LayoutLMv3ImageProcessor(BaseImageProcessor):
self.apply_ocr = apply_ocr self.apply_ocr = apply_ocr
self.ocr_lang = ocr_lang self.ocr_lang = ocr_lang
self.tesseract_config = tesseract_config self.tesseract_config = tesseract_config
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"apply_ocr",
"ocr_lang",
"tesseract_config",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize # Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize
def resize( def resize(
...@@ -232,6 +221,7 @@ class LayoutLMv3ImageProcessor(BaseImageProcessor): ...@@ -232,6 +221,7 @@ class LayoutLMv3ImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -249,7 +239,6 @@ class LayoutLMv3ImageProcessor(BaseImageProcessor): ...@@ -249,7 +239,6 @@ class LayoutLMv3ImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> PIL.Image.Image: ) -> PIL.Image.Image:
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -316,8 +305,6 @@ class LayoutLMv3ImageProcessor(BaseImageProcessor): ...@@ -316,8 +305,6 @@ class LayoutLMv3ImageProcessor(BaseImageProcessor):
tesseract_config = tesseract_config if tesseract_config is not None else self.tesseract_config tesseract_config = tesseract_config if tesseract_config is not None else self.tesseract_config
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -35,10 +35,9 @@ from ...image_utils import ( ...@@ -35,10 +35,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, logging from ...utils import TensorType, filter_out_non_signature_kwargs, logging
logger = logging.get_logger(__name__) logger = logging.get_logger(__name__)
...@@ -116,22 +115,6 @@ class LevitImageProcessor(BaseImageProcessor): ...@@ -116,22 +115,6 @@ class LevitImageProcessor(BaseImageProcessor):
self.do_normalize = do_normalize self.do_normalize = do_normalize
self.image_mean = image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN self.image_mean = image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
self.image_std = image_std if image_std is not None else IMAGENET_DEFAULT_STD self.image_std = image_std if image_std is not None else IMAGENET_DEFAULT_STD
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"return_tensors",
"data_format",
"input_data_format",
]
def resize( def resize(
self, self,
...@@ -188,6 +171,7 @@ class LevitImageProcessor(BaseImageProcessor): ...@@ -188,6 +171,7 @@ class LevitImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -204,7 +188,6 @@ class LevitImageProcessor(BaseImageProcessor): ...@@ -204,7 +188,6 @@ class LevitImageProcessor(BaseImageProcessor):
return_tensors: Optional[TensorType] = None, return_tensors: Optional[TensorType] = None,
data_format: ChannelDimension = ChannelDimension.FIRST, data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
) -> BatchFeature: ) -> BatchFeature:
""" """
Preprocess an image or batch of images to be used as input to a LeViT model. Preprocess an image or batch of images to be used as input to a LeViT model.
...@@ -271,8 +254,6 @@ class LevitImageProcessor(BaseImageProcessor): ...@@ -271,8 +254,6 @@ class LevitImageProcessor(BaseImageProcessor):
crop_size = get_size_dict(crop_size, param_name="crop_size") crop_size = get_size_dict(crop_size, param_name="crop_size")
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -35,10 +35,9 @@ from ...image_utils import ( ...@@ -35,10 +35,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, logging from ...utils import TensorType, filter_out_non_signature_kwargs, logging
logger = logging.get_logger(__name__) logger = logging.get_logger(__name__)
...@@ -114,22 +113,6 @@ class MobileNetV1ImageProcessor(BaseImageProcessor): ...@@ -114,22 +113,6 @@ class MobileNetV1ImageProcessor(BaseImageProcessor):
self.do_normalize = do_normalize self.do_normalize = do_normalize
self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.clip.image_processing_clip.CLIPImageProcessor.resize # Copied from transformers.models.clip.image_processing_clip.CLIPImageProcessor.resize
def resize( def resize(
...@@ -181,6 +164,7 @@ class MobileNetV1ImageProcessor(BaseImageProcessor): ...@@ -181,6 +164,7 @@ class MobileNetV1ImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -197,7 +181,6 @@ class MobileNetV1ImageProcessor(BaseImageProcessor): ...@@ -197,7 +181,6 @@ class MobileNetV1ImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Union[str, ChannelDimension] = ChannelDimension.FIRST, data_format: Union[str, ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
): ):
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -262,8 +245,6 @@ class MobileNetV1ImageProcessor(BaseImageProcessor): ...@@ -262,8 +245,6 @@ class MobileNetV1ImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
...@@ -35,10 +35,9 @@ from ...image_utils import ( ...@@ -35,10 +35,9 @@ from ...image_utils import (
make_list_of_images, make_list_of_images,
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging from ...utils import TensorType, filter_out_non_signature_kwargs, is_torch_available, is_torch_tensor, logging
if is_torch_available(): if is_torch_available():
...@@ -118,22 +117,6 @@ class MobileNetV2ImageProcessor(BaseImageProcessor): ...@@ -118,22 +117,6 @@ class MobileNetV2ImageProcessor(BaseImageProcessor):
self.do_normalize = do_normalize self.do_normalize = do_normalize
self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN self.image_mean = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
self._valid_processor_keys = [
"images",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"return_tensors",
"data_format",
"input_data_format",
]
# Copied from transformers.models.mobilenet_v1.image_processing_mobilenet_v1.MobileNetV1ImageProcessor.resize # Copied from transformers.models.mobilenet_v1.image_processing_mobilenet_v1.MobileNetV1ImageProcessor.resize
def resize( def resize(
...@@ -185,6 +168,7 @@ class MobileNetV2ImageProcessor(BaseImageProcessor): ...@@ -185,6 +168,7 @@ class MobileNetV2ImageProcessor(BaseImageProcessor):
**kwargs, **kwargs,
) )
@filter_out_non_signature_kwargs()
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
...@@ -201,7 +185,6 @@ class MobileNetV2ImageProcessor(BaseImageProcessor): ...@@ -201,7 +185,6 @@ class MobileNetV2ImageProcessor(BaseImageProcessor):
return_tensors: Optional[Union[str, TensorType]] = None, return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Union[str, ChannelDimension] = ChannelDimension.FIRST, data_format: Union[str, ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None, input_data_format: Optional[Union[str, ChannelDimension]] = None,
**kwargs,
): ):
""" """
Preprocess an image or batch of images. Preprocess an image or batch of images.
...@@ -266,8 +249,6 @@ class MobileNetV2ImageProcessor(BaseImageProcessor): ...@@ -266,8 +249,6 @@ class MobileNetV2ImageProcessor(BaseImageProcessor):
images = make_list_of_images(images) images = make_list_of_images(images)
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
if not valid_images(images): if not valid_images(images):
raise ValueError( raise ValueError(
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
......
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