Unverified Commit 1c81132e authored by Pablo Montalvo's avatar Pablo Montalvo Committed by GitHub
Browse files

Raise unused kwargs image processor (#29063)

* draft processor arg capture

* add missing vivit model

* add new common test for image preprocess signature

* fix quality

* fix up

* add back missing validations

* quality

* move info level to warning for unused kwargs
parent b8b16475
...@@ -759,3 +759,11 @@ def validate_annotations( ...@@ -759,3 +759,11 @@ def validate_annotations(
"(batch of images) with the following keys: `image_id`, `file_name` and `segments_info`, with " "(batch of images) with the following keys: `image_id`, `file_name` and `segments_info`, with "
"the latter being a list of annotations in the COCO format." "the latter being a list of annotations in the COCO format."
) )
def validate_kwargs(valid_processor_keys: List[str], captured_kwargs: List[str]):
unused_keys = set(captured_kwargs).difference(set(valid_processor_keys))
if unused_keys:
unused_key_str = ", ".join(unused_keys)
# TODO raise a warning here instead of simply logging?
logger.warning(f"Unused or unrecognized kwargs: {unused_key_str}.")
...@@ -32,6 +32,7 @@ from ...image_utils import ( ...@@ -32,6 +32,7 @@ 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, is_vision_available, logging from ...utils import TensorType, is_torch_available, is_torch_tensor, is_vision_available, logging
...@@ -130,6 +131,24 @@ class BeitImageProcessor(BaseImageProcessor): ...@@ -130,6 +131,24 @@ class BeitImageProcessor(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.do_reduce_labels = do_reduce_labels self.do_reduce_labels = do_reduce_labels
self._valid_processor_keys = [
"images",
"segmentation_maps",
"do_resize",
"size",
"resample",
"do_center_crop",
"crop_size",
"do_rescale",
"rescale_factor",
"do_normalize",
"image_mean",
"image_std",
"do_reduce_labels",
"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):
...@@ -337,6 +356,9 @@ class BeitImageProcessor(BaseImageProcessor): ...@@ -337,6 +356,9 @@ class BeitImageProcessor(BaseImageProcessor):
images (`ImageInput`): images (`ImageInput`):
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set `do_rescale=False`. passing in images with pixel values between 0 and 1, set `do_rescale=False`.
segmentation_maps (`ImageInput`, *optional*)
Segmentation maps to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set `do_rescale=False`.
do_resize (`bool`, *optional*, defaults to `self.do_resize`): do_resize (`bool`, *optional*, defaults to `self.do_resize`):
Whether to resize the image. Whether to resize the image.
size (`Dict[str, int]`, *optional*, defaults to `self.size`): size (`Dict[str, int]`, *optional*, defaults to `self.size`):
...@@ -396,6 +418,8 @@ class BeitImageProcessor(BaseImageProcessor): ...@@ -396,6 +418,8 @@ class BeitImageProcessor(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_reduce_labels = do_reduce_labels if do_reduce_labels is not None else self.do_reduce_labels do_reduce_labels = do_reduce_labels if do_reduce_labels is not None else self.do_reduce_labels
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 segmentation_maps is not None: if segmentation_maps is not None:
......
...@@ -36,6 +36,7 @@ from ...image_utils import ( ...@@ -36,6 +36,7 @@ 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, is_vision_available, logging
...@@ -121,6 +122,23 @@ class BitImageProcessor(BaseImageProcessor): ...@@ -121,6 +122,23 @@ 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(
...@@ -256,6 +274,8 @@ class BitImageProcessor(BaseImageProcessor): ...@@ -256,6 +274,8 @@ 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,6 +31,7 @@ from ...image_utils import ( ...@@ -31,6 +31,7 @@ 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, is_vision_available, logging
...@@ -106,6 +107,21 @@ class BlipImageProcessor(BaseImageProcessor): ...@@ -106,6 +107,21 @@ 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(
...@@ -234,6 +250,8 @@ class BlipImageProcessor(BaseImageProcessor): ...@@ -234,6 +250,8 @@ 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,6 +32,7 @@ from ...image_utils import ( ...@@ -32,6 +32,7 @@ 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, is_vision_available, logging
...@@ -204,6 +205,24 @@ class BridgeTowerImageProcessor(BaseImageProcessor): ...@@ -204,6 +205,24 @@ 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(
...@@ -465,6 +484,8 @@ class BridgeTowerImageProcessor(BaseImageProcessor): ...@@ -465,6 +484,8 @@ 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]
......
...@@ -36,6 +36,7 @@ from ...image_utils import ( ...@@ -36,6 +36,7 @@ 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, is_vision_available, logging
...@@ -121,6 +122,23 @@ class ChineseCLIPImageProcessor(BaseImageProcessor): ...@@ -121,6 +122,23 @@ 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,
...@@ -247,6 +265,8 @@ class ChineseCLIPImageProcessor(BaseImageProcessor): ...@@ -247,6 +265,8 @@ 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,6 +36,7 @@ from ...image_utils import ( ...@@ -36,6 +36,7 @@ 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, is_vision_available, logging
...@@ -121,6 +122,23 @@ class CLIPImageProcessor(BaseImageProcessor): ...@@ -121,6 +122,23 @@ class CLIPImageProcessor(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",
]
# for backwards compatibility of KOSMOS-2 # for backwards compatibility of KOSMOS-2
if "use_square_size" in kwargs: if "use_square_size" in kwargs:
...@@ -259,6 +277,8 @@ class CLIPImageProcessor(BaseImageProcessor): ...@@ -259,6 +277,8 @@ class CLIPImageProcessor(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):
......
...@@ -49,6 +49,7 @@ from ...image_utils import ( ...@@ -49,6 +49,7 @@ from ...image_utils import (
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_annotations, validate_annotations,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import ( from ...utils import (
...@@ -845,6 +846,26 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -845,6 +846,26 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
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.do_pad = do_pad self.do_pad = do_pad
self._valid_processor_keys = [
"images",
"annotations",
"return_segmentation_masks",
"masks_path",
"do_resize",
"size",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"do_convert_annotations",
"image_mean",
"image_std",
"do_pad",
"format",
"return_tensors",
"data_format",
"input_data_format",
]
@classmethod @classmethod
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.from_dict with Detr->ConditionalDetr # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.from_dict with Detr->ConditionalDetr
...@@ -1299,6 +1320,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -1299,6 +1320,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
"torch.Tensor, tf.Tensor or jax.ndarray." "torch.Tensor, tf.Tensor or jax.ndarray."
) )
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
# Here, the pad() method pads to the maximum of (width, height). It does not need to be validated. # Here, the pad() method pads to the maximum of (width, height). It does not need to be validated.
......
...@@ -36,6 +36,7 @@ from ...image_utils import ( ...@@ -36,6 +36,7 @@ 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, is_vision_available, logging
...@@ -113,6 +114,21 @@ class ConvNextImageProcessor(BaseImageProcessor): ...@@ -113,6 +114,21 @@ 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,
...@@ -260,6 +276,8 @@ class ConvNextImageProcessor(BaseImageProcessor): ...@@ -260,6 +276,8 @@ 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):
......
...@@ -49,6 +49,7 @@ from ...image_utils import ( ...@@ -49,6 +49,7 @@ from ...image_utils import (
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_annotations, validate_annotations,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import ( from ...utils import (
...@@ -843,6 +844,26 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -843,6 +844,26 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
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.do_pad = do_pad self.do_pad = do_pad
self._valid_processor_keys = [
"images",
"annotations",
"return_segmentation_masks",
"masks_path",
"do_resize",
"size",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"do_convert_annotations",
"image_mean",
"image_std",
"do_pad",
"format",
"return_tensors",
"data_format",
"input_data_format",
]
@classmethod @classmethod
# Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.from_dict with Detr->DeformableDetr # Copied from transformers.models.detr.image_processing_detr.DetrImageProcessor.from_dict with Detr->DeformableDetr
...@@ -1297,6 +1318,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -1297,6 +1318,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
"torch.Tensor, tf.Tensor or jax.ndarray." "torch.Tensor, tf.Tensor or jax.ndarray."
) )
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
# Here, the pad() method pads to the maximum of (width, height). It does not need to be validated. # Here, the pad() method pads to the maximum of (width, height). It does not need to be validated.
......
...@@ -31,6 +31,7 @@ from ...image_utils import ( ...@@ -31,6 +31,7 @@ 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, is_vision_available, logging
...@@ -109,6 +110,22 @@ class DeiTImageProcessor(BaseImageProcessor): ...@@ -109,6 +110,22 @@ 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(
...@@ -240,6 +257,8 @@ class DeiTImageProcessor(BaseImageProcessor): ...@@ -240,6 +257,8 @@ 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, "
......
...@@ -48,6 +48,7 @@ from ...image_utils import ( ...@@ -48,6 +48,7 @@ from ...image_utils import (
to_numpy_array, to_numpy_array,
valid_images, valid_images,
validate_annotations, validate_annotations,
validate_kwargs,
validate_preprocess_arguments, validate_preprocess_arguments,
) )
from ...utils import ( from ...utils import (
...@@ -828,6 +829,26 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -828,6 +829,26 @@ class DetrImageProcessor(BaseImageProcessor):
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.do_pad = do_pad self.do_pad = do_pad
self._valid_processor_keys = [
"images",
"annotations",
"return_segmentation_masks",
"masks_path",
"do_resize",
"size",
"resample",
"do_rescale",
"rescale_factor",
"do_normalize",
"do_convert_annotations",
"image_mean",
"image_std",
"do_pad",
"format",
"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):
...@@ -1269,6 +1290,7 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1269,6 +1290,7 @@ class DetrImageProcessor(BaseImageProcessor):
"Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, " "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
"torch.Tensor, tf.Tensor or jax.ndarray." "torch.Tensor, tf.Tensor or jax.ndarray."
) )
validate_kwargs(captured_kwargs=kwargs.keys(), valid_processor_keys=self._valid_processor_keys)
# Here, the pad() method pads to the maximum of (width, height). It does not need to be validated. # Here, the pad() method pads to the maximum of (width, height). It does not need to be validated.
......
...@@ -37,6 +37,7 @@ from ...image_utils import ( ...@@ -37,6 +37,7 @@ 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, logging
...@@ -123,6 +124,24 @@ class DonutImageProcessor(BaseImageProcessor): ...@@ -123,6 +124,24 @@ 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,
...@@ -388,6 +407,8 @@ class DonutImageProcessor(BaseImageProcessor): ...@@ -388,6 +407,8 @@ 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,6 +35,7 @@ from ...image_utils import ( ...@@ -35,6 +35,7 @@ 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, is_vision_available, logging
...@@ -164,6 +165,24 @@ class DPTImageProcessor(BaseImageProcessor): ...@@ -164,6 +165,24 @@ 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,
...@@ -350,6 +369,8 @@ class DPTImageProcessor(BaseImageProcessor): ...@@ -350,6 +369,8 @@ 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, "
......
...@@ -35,6 +35,7 @@ from ...image_utils import ( ...@@ -35,6 +35,7 @@ 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, logging from ...utils import TensorType, logging
...@@ -112,6 +113,22 @@ class EfficientFormerImageProcessor(BaseImageProcessor): ...@@ -112,6 +113,22 @@ class EfficientFormerImageProcessor(BaseImageProcessor):
self.rescale_factor = rescale_factor self.rescale_factor = rescale_factor
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,
...@@ -238,6 +255,8 @@ class EfficientFormerImageProcessor(BaseImageProcessor): ...@@ -238,6 +255,8 @@ class EfficientFormerImageProcessor(BaseImageProcessor):
size = size if size is not None else self.size size = size if size is not None else self.size
size_dict = get_size_dict(size) size_dict = get_size_dict(size)
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]
......
...@@ -31,6 +31,7 @@ from ...image_utils import ( ...@@ -31,6 +31,7 @@ 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, is_vision_available, logging
...@@ -118,6 +119,24 @@ class EfficientNetImageProcessor(BaseImageProcessor): ...@@ -118,6 +119,24 @@ 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(
...@@ -297,6 +316,8 @@ class EfficientNetImageProcessor(BaseImageProcessor): ...@@ -297,6 +316,8 @@ 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,6 +34,7 @@ from ...image_utils import ( ...@@ -34,6 +34,7 @@ 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, is_vision_available, logging
...@@ -301,6 +302,41 @@ class FlavaImageProcessor(BaseImageProcessor): ...@@ -301,6 +302,41 @@ 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):
...@@ -636,6 +672,8 @@ class FlavaImageProcessor(BaseImageProcessor): ...@@ -636,6 +672,8 @@ 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, "
......
...@@ -261,6 +261,24 @@ class FuyuImageProcessor(BaseImageProcessor): ...@@ -261,6 +261,24 @@ 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,
......
...@@ -30,6 +30,7 @@ from ...image_utils import ( ...@@ -30,6 +30,7 @@ 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, logging
...@@ -71,6 +72,16 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -71,6 +72,16 @@ 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,
...@@ -176,6 +187,8 @@ class GLPNImageProcessor(BaseImageProcessor): ...@@ -176,6 +187,8 @@ 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,6 +29,7 @@ from ...image_utils import ( ...@@ -29,6 +29,7 @@ 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, is_vision_available, logging
...@@ -102,6 +103,18 @@ class ImageGPTImageProcessor(BaseImageProcessor): ...@@ -102,6 +103,18 @@ 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(
...@@ -238,6 +251,8 @@ class ImageGPTImageProcessor(BaseImageProcessor): ...@@ -238,6 +251,8 @@ 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, "
......
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