


"""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

__SCREAMING_SNAKE_CASE							:      Optional[int]						=      logging.get_logger(__name__)







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

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

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

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





class        __A       (snake_case__):





				'''simple docstring'''

				__lowercase:						Any							 =      ["""pixel_values"""]



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



											"""simple docstring"""



											super().__init__(**UpperCAmelCase_    )
											snake_case_          =						size if size is not None else {"""shortest_edge""": 256}
											snake_case_          =						get_size_dict(UpperCAmelCase_						,    default_to_square=UpperCAmelCase_    )
											snake_case_          =						crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
											snake_case_          =						get_size_dict(UpperCAmelCase_						,    param_name="""crop_size"""    )

											snake_case_          =						do_resize
											snake_case_          =						size
											snake_case_          =						do_center_crop
											snake_case_          =						crop_size
											snake_case_          =						resample
											snake_case_          =						do_rescale
											snake_case_          =						rescale_factor
											snake_case_          =						offset
											snake_case_          =						do_normalize
											snake_case_          =						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
											snake_case_          =						image_std if image_std is not None else IMAGENET_STANDARD_STD



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



											"""simple docstring"""



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



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



											"""simple docstring"""



											snake_case_          =						get_size_dict(UpperCAmelCase_    )
											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(UpperCAmelCase_						,    size=(size["""height"""], size["""width"""])						,    data_format=UpperCAmelCase_						,    **UpperCAmelCase_    )



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



											"""simple docstring"""



											snake_case_          =						image.astype(np.floataa    )
											if offset:
																		snake_case_          =						image - (scale / 2)
											return rescale(UpperCAmelCase_						,    scale=UpperCAmelCase_						,    data_format=UpperCAmelCase_						,    **UpperCAmelCase_    )



				def 						lowerCAmelCase    (			self							: str						,    UpperCAmelCase_							: np.ndarray						,    UpperCAmelCase_							: Union[float, List[float]]						,    UpperCAmelCase_							: Union[float, List[float]]						,    UpperCAmelCase_							: Optional[Union[str, ChannelDimension]] = None						,    **UpperCAmelCase_							: Union[str, Any]						,    )   ->np.ndarray:



											"""simple docstring"""



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



				def 						lowerCAmelCase    (			self							: Dict						,    UpperCAmelCase_							: ImageInput						,    UpperCAmelCase_							: bool = None						,    UpperCAmelCase_							: Dict[str, int] = None						,    UpperCAmelCase_							: PILImageResampling = None						,    UpperCAmelCase_							: bool = None						,    UpperCAmelCase_							: Dict[str, int] = None						,    UpperCAmelCase_							: bool = None						,    UpperCAmelCase_							: float = None						,    UpperCAmelCase_							: bool = None						,    UpperCAmelCase_							: bool = None						,    UpperCAmelCase_							: Optional[Union[float, List[float]]] = None						,    UpperCAmelCase_							: Optional[Union[float, List[float]]] = None						,    UpperCAmelCase_							: 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.
											snake_case_          =						to_numpy_array(UpperCAmelCase_    )

											if do_resize:
																		snake_case_          =						self.resize(image=UpperCAmelCase_						,    size=UpperCAmelCase_						,    resample=UpperCAmelCase_    )

											if do_center_crop:
																		snake_case_          =						self.center_crop(UpperCAmelCase_						,    size=UpperCAmelCase_    )

											if do_rescale:
																		snake_case_          =						self.rescale(image=UpperCAmelCase_						,    scale=UpperCAmelCase_						,    offset=UpperCAmelCase_    )

											if do_normalize:
																		snake_case_          =						self.normalize(image=UpperCAmelCase_						,    mean=UpperCAmelCase_						,    std=UpperCAmelCase_    )

											snake_case_          =						to_channel_dimension_format(UpperCAmelCase_						,    UpperCAmelCase_    )
											return image



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



											"""simple docstring"""



											snake_case_          =						do_resize if do_resize is not None else self.do_resize
											snake_case_          =						resample if resample is not None else self.resample
											snake_case_          =						do_center_crop if do_center_crop is not None else self.do_center_crop
											snake_case_          =						do_rescale if do_rescale is not None else self.do_rescale
											snake_case_          =						rescale_factor if rescale_factor is not None else self.rescale_factor
											snake_case_          =						offset if offset is not None else self.offset
											snake_case_          =						do_normalize if do_normalize is not None else self.do_normalize
											snake_case_          =						image_mean if image_mean is not None else self.image_mean
											snake_case_          =						image_std if image_std is not None else self.image_std

											snake_case_          =						size if size is not None else self.size
											snake_case_          =						get_size_dict(UpperCAmelCase_						,    default_to_square=UpperCAmelCase_    )
											snake_case_          =						crop_size if crop_size is not None else self.crop_size
											snake_case_          =						get_size_dict(UpperCAmelCase_						,    param_name="""crop_size"""    )

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

											snake_case_          =						make_batched(UpperCAmelCase_    )

											snake_case_          =						[
											    [
											        self._preprocess_image(
											            image=UpperCAmelCase_						,    do_resize=UpperCAmelCase_						,    size=UpperCAmelCase_						,    resample=UpperCAmelCase_						,    do_center_crop=UpperCAmelCase_						,    crop_size=UpperCAmelCase_						,    do_rescale=UpperCAmelCase_						,    rescale_factor=UpperCAmelCase_						,    offset=UpperCAmelCase_						,    do_normalize=UpperCAmelCase_						,    image_mean=UpperCAmelCase_						,    image_std=UpperCAmelCase_						,    data_format=UpperCAmelCase_						,    )
											        for img in video
											    ]
											    for video in videos
											]

											snake_case_          =						{"""pixel_values""": videos}
											return BatchFeature(data=UpperCAmelCase_						,    tensor_type=UpperCAmelCase_    )







"""simple docstring"""
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__SCREAMING_SNAKE_CASE							:      Dict						=      logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							:      Tuple						=      {
    'google/mobilenet_v1_1.0_224': 'https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json',
    'google/mobilenet_v1_0.75_192': 'https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}





class        __A       (snake_case__):





							'''simple docstring'''

							__lowercase:						List[Any]							 =      """mobilenet_v1"""



							def __init__(			self							: Union[str, Any]						,    UpperCAmelCase_							: str=3						,    UpperCAmelCase_							: List[Any]=224						,    UpperCAmelCase_							: List[Any]=1.0						,    UpperCAmelCase_							: Any=8						,    UpperCAmelCase_							: int="relu6"						,    UpperCAmelCase_							: str=True						,    UpperCAmelCase_							: List[str]=0.999						,    UpperCAmelCase_							: Optional[Any]=0.02						,    UpperCAmelCase_							: List[Any]=0.001						,    **UpperCAmelCase_							: Any						,    )   ->Union[str, Any]:



														"""simple docstring"""



														super().__init__(**UpperCAmelCase_    )

														if depth_multiplier <= 0:
																					raise ValueError("""depth_multiplier must be greater than zero."""    )

														snake_case_          =						num_channels
														snake_case_          =						image_size
														snake_case_          =						depth_multiplier
														snake_case_          =						min_depth
														snake_case_          =						hidden_act
														snake_case_          =						tf_padding
														snake_case_          =						classifier_dropout_prob
														snake_case_          =						initializer_range
														snake_case_          =						layer_norm_eps





class        __A       (snake_case__):





							'''simple docstring'''

							__lowercase:						int							 =      version.parse("""1.11""")



							@property
							def 						lowerCAmelCase    (			self							: Union[str, Any]    )   ->Mapping[str, Mapping[int, str]]:



														"""simple docstring"""



														return OrderedDict([("""pixel_values""", {0: """batch"""})]    )



							@property
							def 						lowerCAmelCase    (			self							: int    )   ->Mapping[str, Mapping[int, str]]:



														"""simple docstring"""



														if self.task == "image-classification":
																					return OrderedDict([("""logits""", {0: """batch"""})]    )
														else:
																					return OrderedDict([("""last_hidden_state""", {0: """batch"""}), ("""pooler_output""", {0: """batch"""})]    )



							@property
							def 						lowerCAmelCase    (			self							: int    )   ->float:



														"""simple docstring"""



														return 1E-4



