


"""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		=       logging.get_logger(__name__)
def       A_   (   _lowerCAmelCase     :					Dict       ):






     """simple docstring"""

     if isinstance(_lowerCAmelCase,     (list, tuple)       ) and isinstance(videos[0],     (list, tuple)       ) and is_valid_image(videos[0][0]       ):
          return videos

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

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

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


class     __lowerCamelCase  (					a__				):

     '''simple docstring'''
     A_       :	int    =		['pixel_values']


     def __init__(      self    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = PILImageResampling.BILINEAR    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = 1 / 255    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							None:
          super().__init__(**__UpperCAmelCase							)
          _a    	=				size if size is not None else {'''shortest_edge''': 256}
          _a    	=				get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase							)
          _a    	=				crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
          _a    	=				get_size_dict(__UpperCAmelCase    ,				param_name='''crop_size'''							)

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


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase = PILImageResampling.BILINEAR    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							np.ndarray:
          _a    	=				get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase							)
          if "shortest_edge" in size:
               _a    	=				get_resize_output_image_size(__UpperCAmelCase    ,				size['''shortest_edge''']    ,				default_to_square=__UpperCAmelCase							)
          elif "height" in size and "width" in size:
               _a    	=				(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 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							np.ndarray:
          _a    	=				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 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							str:
          _a    	=				image.astype(np.floataa							)
          if offset:
               _a    	=				image - (scale / 2)
          return rescale(__UpperCAmelCase    ,				scale=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							np.ndarray:
          return normalize(__UpperCAmelCase    ,				mean=__UpperCAmelCase    ,				std=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = ChannelDimension.FIRST    ,				)       ->							np.ndarray:
          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.
          _a    	=				to_numpy_array(__UpperCAmelCase							)

          if do_resize:
               _a    	=				self.resize(image=__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				resample=__UpperCAmelCase							)

          if do_center_crop:
               _a    	=				self.center_crop(__UpperCAmelCase    ,				size=__UpperCAmelCase							)

          if do_rescale:
               _a    	=				self.rescale(image=__UpperCAmelCase    ,				scale=__UpperCAmelCase    ,				offset=__UpperCAmelCase							)

          if do_normalize:
               _a    	=				self.normalize(image=__UpperCAmelCase    ,				mean=__UpperCAmelCase    ,				std=__UpperCAmelCase							)

          _a    	=				to_channel_dimension_format(__UpperCAmelCase    ,				__UpperCAmelCase							)
          return image





     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = ChannelDimension.FIRST    ,				**__UpperCAmelCase    ,				)       ->							PIL.Image.Image:
          _a    	=				do_resize if do_resize is not None else self.do_resize
          _a    	=				resample if resample is not None else self.resample
          _a    	=				do_center_crop if do_center_crop is not None else self.do_center_crop
          _a    	=				do_rescale if do_rescale is not None else self.do_rescale
          _a    	=				rescale_factor if rescale_factor is not None else self.rescale_factor
          _a    	=				offset if offset is not None else self.offset
          _a    	=				do_normalize if do_normalize is not None else self.do_normalize
          _a    	=				image_mean if image_mean is not None else self.image_mean
          _a    	=				image_std if image_std is not None else self.image_std

          _a    	=				size if size is not None else self.size
          _a    	=				get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase							)
          _a    	=				crop_size if crop_size is not None else self.crop_size
          _a    	=				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.'''							)

          _a    	=				make_batched(__UpperCAmelCase							)

          _a    	=				[
              [
                  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
          ]

          _a    	=				{'''pixel_values''': videos}
          return BatchFeature(data=__UpperCAmelCase    ,				tensor_type=__UpperCAmelCase							)



"""simple docstring"""






from . import __version__

# Backward compatibility imports, to make sure all those objects can be found in file_utils
from .utils import (
    CLOUDFRONT_DISTRIB_PREFIX,
    CONFIG_NAME,
    DISABLE_TELEMETRY,
    DUMMY_INPUTS,
    DUMMY_MASK,
    ENV_VARS_TRUE_AND_AUTO_VALUES,
    ENV_VARS_TRUE_VALUES,
    FEATURE_EXTRACTOR_NAME,
    FLAX_WEIGHTS_NAME,
    HF_MODULES_CACHE,
    HUGGINGFACE_CO_PREFIX,
    HUGGINGFACE_CO_RESOLVE_ENDPOINT,
    MODEL_CARD_NAME,
    MULTIPLE_CHOICE_DUMMY_INPUTS,
    PYTORCH_PRETRAINED_BERT_CACHE,
    PYTORCH_TRANSFORMERS_CACHE,
    S3_BUCKET_PREFIX,
    SENTENCEPIECE_UNDERLINE,
    SPIECE_UNDERLINE,
    TF2_WEIGHTS_NAME,
    TF_WEIGHTS_NAME,
    TORCH_FX_REQUIRED_VERSION,
    TRANSFORMERS_CACHE,
    TRANSFORMERS_DYNAMIC_MODULE_NAME,
    USE_JAX,
    USE_TF,
    USE_TORCH,
    WEIGHTS_INDEX_NAME,
    WEIGHTS_NAME,
    ContextManagers,
    DummyObject,
    EntryNotFoundError,
    ExplicitEnum,
    ModelOutput,
    PaddingStrategy,
    PushToHubMixin,
    RepositoryNotFoundError,
    RevisionNotFoundError,
    TensorType,
    _LazyModule,
    add_code_sample_docstrings,
    add_end_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    cached_property,
    copy_func,
    default_cache_path,
    define_sagemaker_information,
    get_cached_models,
    get_file_from_repo,
    get_full_repo_name,
    get_torch_version,
    has_file,
    http_user_agent,
    is_apex_available,
    is_bsa_available,
    is_coloredlogs_available,
    is_datasets_available,
    is_detectrona_available,
    is_faiss_available,
    is_flax_available,
    is_ftfy_available,
    is_in_notebook,
    is_ipex_available,
    is_librosa_available,
    is_offline_mode,
    is_onnx_available,
    is_pandas_available,
    is_phonemizer_available,
    is_protobuf_available,
    is_psutil_available,
    is_pyanvml_available,
    is_pyctcdecode_available,
    is_pytesseract_available,
    is_pytorch_quantization_available,
    is_rjieba_available,
    is_sagemaker_dp_enabled,
    is_sagemaker_mp_enabled,
    is_scipy_available,
    is_sentencepiece_available,
    is_seqio_available,
    is_sklearn_available,
    is_soundfile_availble,
    is_spacy_available,
    is_speech_available,
    is_tensor,
    is_tensorflow_probability_available,
    is_tfaonnx_available,
    is_tf_available,
    is_timm_available,
    is_tokenizers_available,
    is_torch_available,
    is_torch_bfaa_available,
    is_torch_cuda_available,
    is_torch_fx_available,
    is_torch_fx_proxy,
    is_torch_mps_available,
    is_torch_tfaa_available,
    is_torch_tpu_available,
    is_torchaudio_available,
    is_training_run_on_sagemaker,
    is_vision_available,
    replace_return_docstrings,
    requires_backends,
    to_numpy,
    to_py_obj,
    torch_only_method,
)