





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 :   str  			=  logging.get_logger(__name__)



def 	_a						(   UpperCAmelCase					)    ->    List[List[ImageInput]]:







   """simple docstring"""
   if isinstance(UpperCAmelCase      ,  (list, tuple)					) and isinstance(videos[0]      ,  (list, tuple)					) and is_valid_image(videos[0][0]					):
      return videos

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

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

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




class        __SCREAMING_SNAKE_CASE      (			lowerCAmelCase_ ):
       _UpperCAmelCase				:  Optional[int]			   =   ["pixel_values"]







       def __init__(				self					:     int		, A					:     bool = True		, A					:     Dict[str, int] = None		, A					:     PILImageResampling = PILImageResampling.BILINEAR		, A					:     bool = True		, A					:     Dict[str, int] = None		, A					:     bool = True		, A					:     Union[int, float] = 1 / 2_5_5		, A					:     bool = True		, A					:     bool = True		, A					:     Optional[Union[float, List[float]]] = None		, A					:     Optional[Union[float, List[float]]] = None		, **A					:     List[str]		, )       ->None:
          super().__init__(**A      )
          lowerCamelCase__       :						str        =							size if size is not None else {'''shortest_edge''': 2_5_6}
          lowerCamelCase__       :						Optional[Any]        =							get_size_dict(A		, default_to_square=A      )
          lowerCamelCase__       :						Dict        =							crop_size if crop_size is not None else {'''height''': 2_2_4, '''width''': 2_2_4}
          lowerCamelCase__       :						Union[str, Any]        =							get_size_dict(A		, param_name='''crop_size'''      )

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







       def 						__lowerCamelCase   (				self					:     Optional[Any]		, A					:     np.ndarray		, A					:     Dict[str, int]		, A					:     PILImageResampling = PILImageResampling.BILINEAR		, A					:     Optional[Union[str, ChannelDimension]] = None		, **A					:     str		, )       ->np.ndarray:
          lowerCamelCase__       :						Any        =							get_size_dict(A		, default_to_square=A      )
          if "shortest_edge" in size:
             lowerCamelCase__       :						Dict        =							get_resize_output_image_size(A		, size['''shortest_edge''']		, default_to_square=A      )
          elif "height" in size and "width" in size:
             lowerCamelCase__       :						List[Any]        =							(size['''height'''], size['''width'''])
          else:
             raise ValueError(F"Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"      )
          return resize(A		, size=A		, resample=A		, data_format=A		, **A      )







       def 						__lowerCamelCase   (				self					:     Optional[int]		, A					:     np.ndarray		, A					:     Dict[str, int]		, A					:     Optional[Union[str, ChannelDimension]] = None		, **A					:     Dict		, )       ->np.ndarray:
          lowerCamelCase__       :						Optional[Any]        =							get_size_dict(A      )
          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(A		, size=(size['''height'''], size['''width'''])		, data_format=A		, **A      )







       def 						__lowerCamelCase   (				self					:     List[str]		, A					:     np.ndarray		, A					:     Union[int, float]		, A					:     bool = True		, A					:     Optional[Union[str, ChannelDimension]] = None		, **A					:     List[Any]		, )       ->Optional[Any]:
          lowerCamelCase__       :						Optional[int]        =							image.astype(np.floataa      )
          if offset:
             lowerCamelCase__       :						int        =							image - (scale / 2)
          return rescale(A		, scale=A		, data_format=A		, **A      )







       def 						__lowerCamelCase   (				self					:     List[str]		, A					:     np.ndarray		, A					:     Union[float, List[float]]		, A					:     Union[float, List[float]]		, A					:     Optional[Union[str, ChannelDimension]] = None		, **A					:     List[str]		, )       ->np.ndarray:
          return normalize(A		, mean=A		, std=A		, data_format=A		, **A      )







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

          if do_resize:
             lowerCamelCase__       :						Union[str, Any]        =							self.resize(image=A		, size=A		, resample=A      )

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

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

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

          lowerCamelCase__       :						Dict        =							to_channel_dimension_format(A		, A      )
          return image







       def 						__lowerCamelCase   (				self					:     List[str]		, A					:     ImageInput		, A					:     bool = None		, A					:     Dict[str, int] = None		, A					:     PILImageResampling = None		, A					:     bool = None		, A					:     Dict[str, int] = None		, A					:     bool = None		, A					:     float = None		, A					:     bool = None		, A					:     bool = None		, A					:     Optional[Union[float, List[float]]] = None		, A					:     Optional[Union[float, List[float]]] = None		, A					:     Optional[Union[str, TensorType]] = None		, A					:     ChannelDimension = ChannelDimension.FIRST		, **A					:     Optional[int]		, )       ->PIL.Image.Image:
          lowerCamelCase__       :						List[Any]        =							do_resize if do_resize is not None else self.do_resize
          lowerCamelCase__       :						str        =							resample if resample is not None else self.resample
          lowerCamelCase__       :						Optional[Any]        =							do_center_crop if do_center_crop is not None else self.do_center_crop
          lowerCamelCase__       :						Optional[Any]        =							do_rescale if do_rescale is not None else self.do_rescale
          lowerCamelCase__       :						Any        =							rescale_factor if rescale_factor is not None else self.rescale_factor
          lowerCamelCase__       :						Dict        =							offset if offset is not None else self.offset
          lowerCamelCase__       :						List[str]        =							do_normalize if do_normalize is not None else self.do_normalize
          lowerCamelCase__       :						str        =							image_mean if image_mean is not None else self.image_mean
          lowerCamelCase__       :						Dict        =							image_std if image_std is not None else self.image_std

          lowerCamelCase__       :						int        =							size if size is not None else self.size
          lowerCamelCase__       :						Union[str, Any]        =							get_size_dict(A		, default_to_square=A      )
          lowerCamelCase__       :						List[Any]        =							crop_size if crop_size is not None else self.crop_size
          lowerCamelCase__       :						int        =							get_size_dict(A		, param_name='''crop_size'''      )

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

          lowerCamelCase__       :						Union[str, Any]        =							make_batched(A      )

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

          lowerCamelCase__       :						List[str]        =							{'''pixel_values''': videos}
          return BatchFeature(data=A		, tensor_type=A      )










from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


_A :   Tuple  			=  logging.get_logger(__name__)

_A :   List[str]  			=  {
    'shi-labs/nat-mini-in1k-224': 'https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json',
    # See all Nat models at https://huggingface.co/models?filter=nat
}


class        __SCREAMING_SNAKE_CASE      (			lowerCAmelCase_					,lowerCAmelCase_ ):
       _UpperCAmelCase				:  Dict			   =   "nat"

       _UpperCAmelCase				:  Tuple			   =   {
           "num_attention_heads": "num_heads",
           "num_hidden_layers": "num_layers",
       }







       def __init__(				self					:     List[Any]		, A					:     Union[str, Any]=4		, A					:     str=3		, A					:     List[Any]=6_4		, A					:     Optional[Any]=[3, 4, 6, 5]		, A					:     int=[2, 4, 8, 1_6]		, A					:     Optional[int]=7		, A					:     List[Any]=3.0		, A					:     str=True		, A					:     str=0.0		, A					:     Any=0.0		, A					:     int=0.1		, A					:     Tuple="gelu"		, A					:     List[Any]=0.02		, A					:     str=1e-5		, A					:     Optional[int]=0.0		, A					:     Optional[Any]=None		, A					:     Dict=None		, **A					:     str		, )       ->Union[str, Any]:
          super().__init__(**A      )

          lowerCamelCase__       :						Any        =							patch_size
          lowerCamelCase__       :						Optional[Any]        =							num_channels
          lowerCamelCase__       :						Any        =							embed_dim
          lowerCamelCase__       :						str        =							depths
          lowerCamelCase__       :						Union[str, Any]        =							len(A      )
          lowerCamelCase__       :						int        =							num_heads
          lowerCamelCase__       :						Optional[int]        =							kernel_size
          lowerCamelCase__       :						Optional[int]        =							mlp_ratio
          lowerCamelCase__       :						List[Any]        =							qkv_bias
          lowerCamelCase__       :						Tuple        =							hidden_dropout_prob
          lowerCamelCase__       :						List[str]        =							attention_probs_dropout_prob
          lowerCamelCase__       :						List[Any]        =							drop_path_rate
          lowerCamelCase__       :						Union[str, Any]        =							hidden_act
          lowerCamelCase__       :						Union[str, Any]        =							layer_norm_eps
          lowerCamelCase__       :						List[Any]        =							initializer_range
          # we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
          # this indicates the channel dimension after the last stage of the model
          lowerCamelCase__       :						str        =							int(embed_dim * 2 ** (len(A      ) - 1)      )
          lowerCamelCase__       :						Dict        =							layer_scale_init_value
          lowerCamelCase__       :						Dict        =							['''stem'''] + [F"stage{idx}" for idx in range(1		, len(A      ) + 1      )]
          lowerCamelCase__       ,							lowerCamelCase__       :						str        =							get_aligned_output_features_output_indices(
              out_features=A		, out_indices=A		, stage_names=self.stage_names      )



