






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

__A							:							Dict  							=		logging.get_logger(__name__)






def    lowerCamelCase_     (    lowercase__):
 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 				lowercase       (							UpperCAmelCase__      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							["pixel_values"]

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

     '''simple docstring'''




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

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

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

     '''simple docstring'''




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

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

     '''simple docstring'''




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

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

     '''simple docstring'''




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

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

     '''simple docstring'''




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

    def    a__				(					self     :     List[str]				,     __lowerCamelCase     :     ImageInput				,     __lowerCamelCase     :     bool = None				,     __lowerCamelCase     :     Dict[str, int] = None				,     __lowerCamelCase     :     PILImageResampling = None				,     __lowerCamelCase     :     bool = None				,     __lowerCamelCase     :     Dict[str, int] = None				,     __lowerCamelCase     :     bool = None				,     __lowerCamelCase     :     float = None				,     __lowerCamelCase     :     bool = None				,     __lowerCamelCase     :     bool = None				,     __lowerCamelCase     :     Optional[Union[float, List[float]]] = None				,     __lowerCamelCase     :     Optional[Union[float, List[float]]] = None				,     __lowerCamelCase     :     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__  =     to_numpy_array(lowerCamelCase__     )

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

     if do_center_crop:
      lowerCamelCase__  =     self.center_crop(lowerCamelCase__				,     size=lowerCamelCase__     )

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

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

     lowerCamelCase__  =     to_channel_dimension_format(lowerCamelCase__				,     lowerCamelCase__     )
     return image




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

     '''simple docstring'''




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

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

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

     lowerCamelCase__  =     make_batched(lowerCamelCase__     )

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

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










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


__A							:							Optional[Any]  							=		logging.get_logger(__name__)

__A							:							int  							=		{
    """google/vit-base-patch16-224""": """https://huggingface.co/vit-base-patch16-224/resolve/main/config.json""",
    # See all ViT models at https://huggingface.co/models?filter=vit
}
class 				lowercase       (							_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							"vit"

    def __init__(					self     :     Optional[int]				,     __lowerCamelCase     :     Tuple=768				,     __lowerCamelCase     :     Tuple=12				,     __lowerCamelCase     :     Tuple=12				,     __lowerCamelCase     :     int=3072				,     __lowerCamelCase     :     Optional[Any]="gelu"				,     __lowerCamelCase     :     Optional[int]=0.0				,     __lowerCamelCase     :     Tuple=0.0				,     __lowerCamelCase     :     Optional[Any]=0.0_2				,     __lowerCamelCase     :     int=1E-12				,     __lowerCamelCase     :     Tuple=224				,     __lowerCamelCase     :     int=16				,     __lowerCamelCase     :     Optional[int]=3				,     __lowerCamelCase     :     List[str]=True				,     __lowerCamelCase     :     str=16				,     **__lowerCamelCase     :     Optional[int]				,     )							->							str:

     '''simple docstring'''




     super().__init__(**__lowerCamelCase     )

     lowerCamelCase__  =     hidden_size
     lowerCamelCase__  =     num_hidden_layers
     lowerCamelCase__  =     num_attention_heads
     lowerCamelCase__  =     intermediate_size
     lowerCamelCase__  =     hidden_act
     lowerCamelCase__  =     hidden_dropout_prob
     lowerCamelCase__  =     attention_probs_dropout_prob
     lowerCamelCase__  =     initializer_range
     lowerCamelCase__  =     layer_norm_eps
     lowerCamelCase__  =     image_size
     lowerCamelCase__  =     patch_size
     lowerCamelCase__  =     num_channels
     lowerCamelCase__  =     qkv_bias
     lowerCamelCase__  =     encoder_stride
class 				lowercase       (							_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							version.parse("1.11"      )

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

     '''simple docstring'''




     return OrderedDict(
         [
             ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
         ]     )




    @property
    def    a__				(					self     :     Optional[int]     )							->							float:

     '''simple docstring'''




     return 1E-4

