




'''simple docstring'''





from typing import Dict, List, Optional, Union

import numpy as np

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


if is_vision_available():
      import PIL


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




class     UpperCamelCase					(  snake_case__					):
  a    :int      					=				['pixel_values']



  def __init__( self		,    __lowerCAmelCase = True		,    __lowerCAmelCase = None		,    __lowerCAmelCase = PIL.Image.NEAREST		,    __lowerCAmelCase = False		,    __lowerCAmelCase = None		,    __lowerCAmelCase = 1 / 255		,    __lowerCAmelCase = False		,    __lowerCAmelCase = True		,    __lowerCAmelCase = True		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = True		,    **__lowerCAmelCase		,    ):







      '''simple docstring'''


      super().__init__(**__lowerCAmelCase   )
      _a							:       Optional[Any]       					=			size if size is not None else {"""height""": 346, """width""": 346}
      _a							:       Dict       					=			get_size_dict(__lowerCAmelCase   )
      _a							:       int       					=			crop_size if crop_size is not None else {"""height""": 289, """width""": 289}
      _a							:       Optional[int]       					=			get_size_dict(__lowerCAmelCase		,    param_name="""crop_size"""   )

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



  def 						a_       ( self		,    __lowerCAmelCase		,    __lowerCAmelCase		,    __lowerCAmelCase = PIL.Image.NEAREST		,    __lowerCAmelCase = None		,    **__lowerCAmelCase		,    ):







      '''simple docstring'''


      _a							:       Optional[Any]       					=			get_size_dict(__lowerCAmelCase   )
      if "height" not in size or "width" not in size:
          raise ValueError(f'''The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'''   )
      return resize(
          __lowerCAmelCase		,    size=(size["""height"""], size["""width"""])		,    resample=__lowerCAmelCase		,    data_format=__lowerCAmelCase		,    **__lowerCAmelCase   )



  def 						a_       ( self		,    __lowerCAmelCase		,    __lowerCAmelCase		,    __lowerCAmelCase = None		,    **__lowerCAmelCase		,    ):







      '''simple docstring'''


      _a							:       List[Any]       					=			get_size_dict(__lowerCAmelCase   )
      if "height" not in size or "width" not in size:
          raise ValueError(f'''The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'''   )
      return center_crop(__lowerCAmelCase		,    size=(size["""height"""], size["""width"""])		,    data_format=__lowerCAmelCase		,    **__lowerCAmelCase   )



  def 						a_       ( self		,    __lowerCAmelCase		,    __lowerCAmelCase		,    __lowerCAmelCase = True		,    __lowerCAmelCase = None		,    **__lowerCAmelCase		,    ):







      '''simple docstring'''


      if offset:
          _a							:       Tuple       					=			(image - 127.5) * scale
          if data_format is not None:
              _a							:       List[Any]       					=			to_channel_dimension_format(__lowerCAmelCase		,    __lowerCAmelCase   )
          _a							:       Dict       					=			rescaled_image.astype(np.floataa   )
      else:
          _a							:       Dict       					=			rescale(__lowerCAmelCase		,    scale=__lowerCAmelCase		,    data_format=__lowerCAmelCase		,    **__lowerCAmelCase   )
      return rescaled_image



  def 						a_       ( self		,    __lowerCAmelCase		,    __lowerCAmelCase		,    __lowerCAmelCase		,    __lowerCAmelCase = None		,    **__lowerCAmelCase		,    ):







      '''simple docstring'''


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



  def 						a_       ( self		,    __lowerCAmelCase		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase=None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = None		,    __lowerCAmelCase = ChannelDimension.FIRST		,    **__lowerCAmelCase		,    ):







      '''simple docstring'''


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

      _a							:       Tuple       					=			size if size is not None else self.size
      _a							:       str       					=			get_size_dict(__lowerCAmelCase   )
      _a							:       Tuple       					=			crop_size if crop_size is not None else self.crop_size
      _a							:       List[str]       					=			get_size_dict(__lowerCAmelCase		,    param_name="""crop_size"""   )

      _a							:       int       					=			make_list_of_images(__lowerCAmelCase   )

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

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

      # All transformations expect numpy arrays.
      _a							:       List[str]       					=			[to_numpy_array(__lowerCAmelCase   ) for image in images]

      if do_resize:
          _a							:       Optional[Any]       					=			[self.resize(image=__lowerCAmelCase		,    size=__lowerCAmelCase		,    resample=__lowerCAmelCase   ) for image in images]

      if do_center_crop:
          _a							:       List[Any]       					=			[self.center_crop(image=__lowerCAmelCase		,    size=__lowerCAmelCase   ) for image in images]

      if do_rescale:
          _a							:       int       					=			[self.rescale(image=__lowerCAmelCase		,    scale=__lowerCAmelCase		,    offset=__lowerCAmelCase   ) for image in images]

      if do_normalize:
          _a							:       Dict       					=			[self.normalize(image=__lowerCAmelCase		,    mean=__lowerCAmelCase		,    std=__lowerCAmelCase   ) for image in images]

      if include_top:
          _a							:       Dict       					=			[self.normalize(image=__lowerCAmelCase		,    mean=[0, 0, 0]		,    std=__lowerCAmelCase   ) for image in images]

      _a							:       List[Any]       					=			[to_channel_dimension_format(__lowerCAmelCase		,    __lowerCAmelCase   ) for image in images]

      _a							:       Union[str, Any]       					=			{"""pixel_values""": images}
      return BatchFeature(data=__lowerCAmelCase		,    tensor_type=__lowerCAmelCase   )








'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


a		:  Dict   			=			{
    '''configuration_mobilevitv2''': [
        '''MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''MobileViTV2Config''',
        '''MobileViTV2OnnxConfig''',
    ],
}


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a		:  List[str]   			=			[
      '''MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''MobileViTV2ForImageClassification''',
      '''MobileViTV2ForSemanticSegmentation''',
      '''MobileViTV2Model''',
      '''MobileViTV2PreTrainedModel''',
  ]

if TYPE_CHECKING:
  from .configuration_mobilevitva import (
      MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
      MobileViTVaConfig,
      MobileViTVaOnnxConfig,
  )

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_mobilevitva import (
        MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
        MobileViTVaForImageClassification,
        MobileViTVaForSemanticSegmentation,
        MobileViTVaModel,
        MobileViTVaPreTrainedModel,
    )

else:
  import sys

  a		:  Dict   			=			_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


