



"""simple docstring"""






from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
	import PIL

__snake_case				:  List[Any] =       logging.get_logger(__name__)


def      _lowercase							(    __snake_case      )		->  List[List[ImageInput]]:
			if isinstance(__snake_case   ,(list, tuple)      ) and isinstance(videos[0]   ,(list, tuple)      ) and is_valid_image(videos[0][0]      ):
						return videos

			elif isinstance(__snake_case   ,(list, tuple)      ) and is_valid_image(videos[0]      ):
						return [videos]

			elif is_valid_image(__snake_case      ):
						return [[videos]]

			raise ValueError(F"""Could not make batched video from {videos}"""      )





class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      ['pixel_values']

	def __init__(	self:						int			,     _SCREAMING_SNAKE_CASE:						bool = True			,     _SCREAMING_SNAKE_CASE:						Dict[str, int] = None			,     _SCREAMING_SNAKE_CASE:						PILImageResampling = PILImageResampling.BILINEAR			,     _SCREAMING_SNAKE_CASE:						bool = True			,     _SCREAMING_SNAKE_CASE:						Dict[str, int] = None			,     _SCREAMING_SNAKE_CASE:						bool = True			,     _SCREAMING_SNAKE_CASE:						Union[int, float] = 1 / 255			,     _SCREAMING_SNAKE_CASE:						bool = True			,     _SCREAMING_SNAKE_CASE:						bool = True			,     _SCREAMING_SNAKE_CASE:						Optional[Union[float, List[float]]] = None			,     _SCREAMING_SNAKE_CASE:						Optional[Union[float, List[float]]] = None			,     **_SCREAMING_SNAKE_CASE:						List[str]			,     )							->			None:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    Any				=			size if size is not None else {"shortest_edge": 256}
				__lowerCAmelCase :    str				=			get_size_dict(_SCREAMING_SNAKE_CASE			,     default_to_square=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    Optional[int]				=			crop_size if crop_size is not None else {"height": 224, "width": 224}
				__lowerCAmelCase :    Optional[Any]				=			get_size_dict(_SCREAMING_SNAKE_CASE			,     param_name="crop_size")

				__lowerCAmelCase :    Optional[int]				=			do_resize
				__lowerCAmelCase :    Tuple				=			size
				__lowerCAmelCase :    int				=			do_center_crop
				__lowerCAmelCase :    str				=			crop_size
				__lowerCAmelCase :    List[str]				=			resample
				__lowerCAmelCase :    Dict				=			do_rescale
				__lowerCAmelCase :    Optional[Any]				=			rescale_factor
				__lowerCAmelCase :    List[str]				=			offset
				__lowerCAmelCase :    str				=			do_normalize
				__lowerCAmelCase :    Any				=			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
				__lowerCAmelCase :    str				=			image_std if image_std is not None else IMAGENET_STANDARD_STD

	def 				_SCREAMING_SNAKE_CASE  (	self:						List[str]			,     _SCREAMING_SNAKE_CASE:						np.ndarray			,     _SCREAMING_SNAKE_CASE:						Dict[str, int]			,     _SCREAMING_SNAKE_CASE:						PILImageResampling = PILImageResampling.BILINEAR			,     _SCREAMING_SNAKE_CASE:						Optional[Union[str, ChannelDimension]] = None			,     **_SCREAMING_SNAKE_CASE:						Dict			,     )							->			np.ndarray:

				"""simple docstring"""

				__lowerCAmelCase :    List[str]				=			get_size_dict(_SCREAMING_SNAKE_CASE			,     default_to_square=_SCREAMING_SNAKE_CASE)
				if "shortest_edge" in size:
							__lowerCAmelCase :    int				=			get_resize_output_image_size(_SCREAMING_SNAKE_CASE			,     size["shortest_edge"]			,     default_to_square=_SCREAMING_SNAKE_CASE)
				elif "height" in size and "width" in size:
							__lowerCAmelCase :    Tuple				=			(size["height"], size["width"])
				else:
							raise ValueError(F"""Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}""")
				return resize(_SCREAMING_SNAKE_CASE			,     size=_SCREAMING_SNAKE_CASE			,     resample=_SCREAMING_SNAKE_CASE			,     data_format=_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						int			,     _SCREAMING_SNAKE_CASE:						np.ndarray			,     _SCREAMING_SNAKE_CASE:						Dict[str, int]			,     _SCREAMING_SNAKE_CASE:						Optional[Union[str, ChannelDimension]] = None			,     **_SCREAMING_SNAKE_CASE:						List[str]			,     )							->			np.ndarray:

				"""simple docstring"""

				__lowerCAmelCase :    List[Any]				=			get_size_dict(_SCREAMING_SNAKE_CASE)
				if "height" not in size or "width" not in size:
							raise ValueError(F"""Size must have 'height' and 'width' as keys. Got {size.keys()}""")
				return center_crop(_SCREAMING_SNAKE_CASE			,     size=(size["height"], size["width"])			,     data_format=_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						Any			,     _SCREAMING_SNAKE_CASE:						np.ndarray			,     _SCREAMING_SNAKE_CASE:						Union[int, float]			,     _SCREAMING_SNAKE_CASE:						bool = True			,     _SCREAMING_SNAKE_CASE:						Optional[Union[str, ChannelDimension]] = None			,     **_SCREAMING_SNAKE_CASE:						List[Any]			,     )							->			Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase :    Union[str, Any]				=			image.astype(np.floataa)
				if offset:
							__lowerCAmelCase :    Tuple				=			image - (scale / 2)
				return rescale(_SCREAMING_SNAKE_CASE			,     scale=_SCREAMING_SNAKE_CASE			,     data_format=_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						int			,     _SCREAMING_SNAKE_CASE:						np.ndarray			,     _SCREAMING_SNAKE_CASE:						Union[float, List[float]]			,     _SCREAMING_SNAKE_CASE:						Union[float, List[float]]			,     _SCREAMING_SNAKE_CASE:						Optional[Union[str, ChannelDimension]] = None			,     **_SCREAMING_SNAKE_CASE:						Dict			,     )							->			np.ndarray:

				"""simple docstring"""

				return normalize(_SCREAMING_SNAKE_CASE			,     mean=_SCREAMING_SNAKE_CASE			,     std=_SCREAMING_SNAKE_CASE			,     data_format=_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

	def 				_SCREAMING_SNAKE_CASE  (	self:						List[Any]			,     _SCREAMING_SNAKE_CASE:						ImageInput			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						Dict[str, int] = None			,     _SCREAMING_SNAKE_CASE:						PILImageResampling = None			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						Dict[str, int] = None			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						float = None			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						Optional[Union[float, List[float]]] = None			,     _SCREAMING_SNAKE_CASE:						Optional[Union[float, List[float]]] = None			,     _SCREAMING_SNAKE_CASE:						Optional[ChannelDimension] = ChannelDimension.FIRST			,     )							->			np.ndarray:

				"""simple docstring"""

				if do_resize and size is None or resample is None:
							raise ValueError("Size and resample must be specified if do_resize is True.")

				if do_center_crop and crop_size is None:
							raise ValueError("Crop size must be specified if do_center_crop is True.")

				if do_rescale and rescale_factor is None:
							raise ValueError("Rescale factor must be specified if do_rescale is True.")

				if do_normalize and (image_mean is None or image_std is None):
							raise ValueError("Image mean and std must be specified if do_normalize is True.")

				if offset and not do_rescale:
							raise ValueError("For offset, do_rescale must also be set to True.")

				# All transformations expect numpy arrays.
				__lowerCAmelCase :    Tuple				=			to_numpy_array(_SCREAMING_SNAKE_CASE)

				if do_resize:
							__lowerCAmelCase :    Dict				=			self.resize(image=_SCREAMING_SNAKE_CASE			,     size=_SCREAMING_SNAKE_CASE			,     resample=_SCREAMING_SNAKE_CASE)

				if do_center_crop:
							__lowerCAmelCase :    Tuple				=			self.center_crop(_SCREAMING_SNAKE_CASE			,     size=_SCREAMING_SNAKE_CASE)

				if do_rescale:
							__lowerCAmelCase :    Optional[Any]				=			self.rescale(image=_SCREAMING_SNAKE_CASE			,     scale=_SCREAMING_SNAKE_CASE			,     offset=_SCREAMING_SNAKE_CASE)

				if do_normalize:
							__lowerCAmelCase :    Any				=			self.normalize(image=_SCREAMING_SNAKE_CASE			,     mean=_SCREAMING_SNAKE_CASE			,     std=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Any				=			to_channel_dimension_format(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)
				return image







	def 				_SCREAMING_SNAKE_CASE  (	self:						Tuple			,     _SCREAMING_SNAKE_CASE:						ImageInput			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						Dict[str, int] = None			,     _SCREAMING_SNAKE_CASE:						PILImageResampling = None			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						Dict[str, int] = None			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						float = None			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						bool = None			,     _SCREAMING_SNAKE_CASE:						Optional[Union[float, List[float]]] = None			,     _SCREAMING_SNAKE_CASE:						Optional[Union[float, List[float]]] = None			,     _SCREAMING_SNAKE_CASE:						Optional[Union[str, TensorType]] = None			,     _SCREAMING_SNAKE_CASE:						ChannelDimension = ChannelDimension.FIRST			,     **_SCREAMING_SNAKE_CASE:						Dict			,     )							->			PIL.Image.Image:

				"""simple docstring"""

				__lowerCAmelCase :    Optional[int]				=			do_resize if do_resize is not None else self.do_resize
				__lowerCAmelCase :    Optional[Any]				=			resample if resample is not None else self.resample
				__lowerCAmelCase :    Tuple				=			do_center_crop if do_center_crop is not None else self.do_center_crop
				__lowerCAmelCase :    int				=			do_rescale if do_rescale is not None else self.do_rescale
				__lowerCAmelCase :    List[Any]				=			rescale_factor if rescale_factor is not None else self.rescale_factor
				__lowerCAmelCase :    Union[str, Any]				=			offset if offset is not None else self.offset
				__lowerCAmelCase :    List[Any]				=			do_normalize if do_normalize is not None else self.do_normalize
				__lowerCAmelCase :    Dict				=			image_mean if image_mean is not None else self.image_mean
				__lowerCAmelCase :    List[Any]				=			image_std if image_std is not None else self.image_std

				__lowerCAmelCase :    Any				=			size if size is not None else self.size
				__lowerCAmelCase :    str				=			get_size_dict(_SCREAMING_SNAKE_CASE			,     default_to_square=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    Optional[Any]				=			crop_size if crop_size is not None else self.crop_size
				__lowerCAmelCase :    Optional[Any]				=			get_size_dict(_SCREAMING_SNAKE_CASE			,     param_name="crop_size")

				if not valid_images(_SCREAMING_SNAKE_CASE):
							raise ValueError(
							    "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
							    "torch.Tensor, tf.Tensor or jax.ndarray.")

				__lowerCAmelCase :    Optional[int]				=			make_batched(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Union[str, Any]				=			[
				    [
				        self._preprocess_image(
				            image=_SCREAMING_SNAKE_CASE			,     do_resize=_SCREAMING_SNAKE_CASE			,     size=_SCREAMING_SNAKE_CASE			,     resample=_SCREAMING_SNAKE_CASE			,     do_center_crop=_SCREAMING_SNAKE_CASE			,     crop_size=_SCREAMING_SNAKE_CASE			,     do_rescale=_SCREAMING_SNAKE_CASE			,     rescale_factor=_SCREAMING_SNAKE_CASE			,     offset=_SCREAMING_SNAKE_CASE			,     do_normalize=_SCREAMING_SNAKE_CASE			,     image_mean=_SCREAMING_SNAKE_CASE			,     image_std=_SCREAMING_SNAKE_CASE			,     data_format=_SCREAMING_SNAKE_CASE			,     )
				        for img in video
				    ]
				    for video in videos
				]

				__lowerCAmelCase :    Optional[int]				=			{"pixel_values": videos}
				return BatchFeature(data=_SCREAMING_SNAKE_CASE			,     tensor_type=_SCREAMING_SNAKE_CASE)




"""simple docstring"""






from ..utils import DummyObject, requires_backends



class      A__  (    metaclass=__SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      ['torch', 'transformers', 'onnx']

	def __init__(	self:						Union[str, Any]			,     *_SCREAMING_SNAKE_CASE:						Any			,     **_SCREAMING_SNAKE_CASE:						int)							->			List[Any]:

				"""simple docstring"""

				requires_backends(self			,     ["torch", "transformers", "onnx"])

	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Union[str, Any]			,     *_SCREAMING_SNAKE_CASE:						List[Any]			,     **_SCREAMING_SNAKE_CASE:						Union[str, Any])							->			Union[str, Any]:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						int			,     *_SCREAMING_SNAKE_CASE:						Any			,     **_SCREAMING_SNAKE_CASE:						str)							->			Union[str, Any]:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])






class      A__  (    metaclass=__SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      ['torch', 'transformers', 'onnx']

	def __init__(	self:						Tuple			,     *_SCREAMING_SNAKE_CASE:						Optional[Any]			,     **_SCREAMING_SNAKE_CASE:						List[str])							->			Optional[int]:

				"""simple docstring"""

				requires_backends(self			,     ["torch", "transformers", "onnx"])

	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Dict			,     *_SCREAMING_SNAKE_CASE:						Optional[Any]			,     **_SCREAMING_SNAKE_CASE:						int)							->			List[Any]:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Optional[Any]			,     *_SCREAMING_SNAKE_CASE:						Dict			,     **_SCREAMING_SNAKE_CASE:						Optional[Any])							->			Union[str, Any]:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])






class      A__  (    metaclass=__SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      ['torch', 'transformers', 'onnx']

	def __init__(	self:						int			,     *_SCREAMING_SNAKE_CASE:						List[Any]			,     **_SCREAMING_SNAKE_CASE:						int)							->			List[str]:

				"""simple docstring"""

				requires_backends(self			,     ["torch", "transformers", "onnx"])

	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Dict			,     *_SCREAMING_SNAKE_CASE:						Any			,     **_SCREAMING_SNAKE_CASE:						Any)							->			str:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						List[Any]			,     *_SCREAMING_SNAKE_CASE:						List[str]			,     **_SCREAMING_SNAKE_CASE:						int)							->			int:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])






class      A__  (    metaclass=__SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      ['torch', 'transformers', 'onnx']

	def __init__(	self:						Tuple			,     *_SCREAMING_SNAKE_CASE:						List[str]			,     **_SCREAMING_SNAKE_CASE:						List[str])							->			Optional[Any]:

				"""simple docstring"""

				requires_backends(self			,     ["torch", "transformers", "onnx"])

	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						List[str]			,     *_SCREAMING_SNAKE_CASE:						Tuple			,     **_SCREAMING_SNAKE_CASE:						int)							->			int:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Optional[int]			,     *_SCREAMING_SNAKE_CASE:						str			,     **_SCREAMING_SNAKE_CASE:						Any)							->			int:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])






class      A__  (    metaclass=__SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      ['torch', 'transformers', 'onnx']

	def __init__(	self:						Optional[Any]			,     *_SCREAMING_SNAKE_CASE:						Union[str, Any]			,     **_SCREAMING_SNAKE_CASE:						Optional[int])							->			str:

				"""simple docstring"""

				requires_backends(self			,     ["torch", "transformers", "onnx"])

	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Optional[int]			,     *_SCREAMING_SNAKE_CASE:						List[Any]			,     **_SCREAMING_SNAKE_CASE:						Tuple)							->			Union[str, Any]:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						int			,     *_SCREAMING_SNAKE_CASE:						str			,     **_SCREAMING_SNAKE_CASE:						Any)							->			Optional[Any]:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])






class      A__  (    metaclass=__SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      ['torch', 'transformers', 'onnx']

	def __init__(	self:						List[Any]			,     *_SCREAMING_SNAKE_CASE:						List[str]			,     **_SCREAMING_SNAKE_CASE:						List[str])							->			int:

				"""simple docstring"""

				requires_backends(self			,     ["torch", "transformers", "onnx"])

	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Union[str, Any]			,     *_SCREAMING_SNAKE_CASE:						Optional[int]			,     **_SCREAMING_SNAKE_CASE:						Optional[Any])							->			List[Any]:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						str			,     *_SCREAMING_SNAKE_CASE:						Optional[int]			,     **_SCREAMING_SNAKE_CASE:						Dict)							->			Optional[Any]:

				"""simple docstring"""

				requires_backends(cls			,     ["torch", "transformers", "onnx"])