






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_	:	List[Any]				=				logging.get_logger(__name__)




class        _lowerCAmelCase( UpperCAmelCase_      ):





       """simple docstring"""







       a       :	List[str]								=['''pixel_values''']





       def __init__(      self						,    _lowerCamelCase = True						,    _lowerCamelCase = None						,    _lowerCamelCase = PIL.Image.NEAREST						,    _lowerCamelCase = False						,    _lowerCamelCase = None						,    _lowerCamelCase = 1 / 2_5_5						,    _lowerCamelCase = False						,    _lowerCamelCase = True						,    _lowerCamelCase = True						,    _lowerCamelCase = None						,    _lowerCamelCase = None						,    _lowerCamelCase = True						,    **_lowerCamelCase						,    ):
         super().__init__(**_lowerCamelCase							)
         UpperCamelCase_:      List[str]					   =       size if size is not None else {'height': 3_4_6, 'width': 3_4_6}
         UpperCamelCase_:      List[str]					   =       get_size_dict(_lowerCamelCase							)
         UpperCamelCase_:      int					   =       crop_size if crop_size is not None else {'height': 2_8_9, 'width': 2_8_9}
         UpperCamelCase_:      int					   =       get_size_dict(_lowerCamelCase						,    param_name='crop_size'							)

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





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase = PIL.Image.NEAREST						,    _lowerCamelCase = None						,    **_lowerCamelCase						,    ):
         UpperCamelCase_:      Union[str, 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						,    ):
         UpperCamelCase_:      str					   =       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						,    ):
         if offset:
           UpperCamelCase_:      Union[str, Any]					   =       (image - 1_2_7.5) * scale
           if data_format is not None:
             UpperCamelCase_:      Optional[Any]					   =       to_channel_dimension_format(_lowerCamelCase						,    _lowerCamelCase							)
           UpperCamelCase_:      List[str]					   =       rescaled_image.astype(np.floataa							)
         else:
           UpperCamelCase_:      List[str]					   =       rescale(_lowerCamelCase						,    scale=_lowerCamelCase						,    data_format=_lowerCamelCase						,    **_lowerCamelCase							)
         return rescaled_image





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase = None						,    **_lowerCamelCase						,    ):
         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						,    ):
         UpperCamelCase_:      List[Any]					   =       do_resize if do_resize is not None else self.do_resize
         UpperCamelCase_:      Dict					   =       resample if resample is not None else self.resample
         UpperCamelCase_:      Optional[int]					   =       do_center_crop if do_center_crop is not None else self.do_center_crop
         UpperCamelCase_:      List[str]					   =       do_rescale if do_rescale is not None else self.do_rescale
         UpperCamelCase_:      Optional[int]					   =       rescale_factor if rescale_factor is not None else self.rescale_factor
         UpperCamelCase_:      Union[str, Any]					   =       rescale_offset if rescale_offset is not None else self.rescale_offset
         UpperCamelCase_:      Optional[Any]					   =       do_normalize if do_normalize is not None else self.do_normalize
         UpperCamelCase_:      List[str]					   =       image_mean if image_mean is not None else self.image_mean
         UpperCamelCase_:      List[Any]					   =       image_std if image_std is not None else self.image_std
         UpperCamelCase_:      Any					   =       include_top if include_top is not None else self.include_top

         UpperCamelCase_:      int					   =       size if size is not None else self.size
         UpperCamelCase_:      Optional[Any]					   =       get_size_dict(_lowerCamelCase							)
         UpperCamelCase_:      List[Any]					   =       crop_size if crop_size is not None else self.crop_size
         UpperCamelCase_:      int					   =       get_size_dict(_lowerCamelCase						,    param_name='crop_size'							)

         UpperCamelCase_:      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.
         UpperCamelCase_:      List[Any]					   =       [to_numpy_array(_lowerCamelCase							) for image in images]

         if do_resize:
           UpperCamelCase_:      str					   =       [self.resize(image=_lowerCamelCase						,    size=_lowerCamelCase						,    resample=_lowerCamelCase							) for image in images]

         if do_center_crop:
           UpperCamelCase_:      Tuple					   =       [self.center_crop(image=_lowerCamelCase						,    size=_lowerCamelCase							) for image in images]

         if do_rescale:
           UpperCamelCase_:      List[Any]					   =       [self.rescale(image=_lowerCamelCase						,    scale=_lowerCamelCase						,    offset=_lowerCamelCase							) for image in images]

         if do_normalize:
           UpperCamelCase_:      int					   =       [self.normalize(image=_lowerCamelCase						,    mean=_lowerCamelCase						,    std=_lowerCamelCase							) for image in images]

         if include_top:
           UpperCamelCase_:      int					   =       [self.normalize(image=_lowerCamelCase						,    mean=[0, 0, 0]						,    std=_lowerCamelCase							) for image in images]

         UpperCamelCase_:      int					   =       [to_channel_dimension_format(_lowerCamelCase						,    _lowerCamelCase							) for image in images]

         UpperCamelCase_:      Any					   =       {'pixel_values': images}
         return BatchFeature(data=_lowerCamelCase						,    tensor_type=_lowerCamelCase							)







# Lint as: python3

import hashlib
from typing import Union

def 						snake_case      (UpperCAmelCase__						) ->       bytes:
  if isinstance(UpperCAmelCase__			,					UpperCAmelCase__						):
    # Data already in bytes, returns as it as
    return hash_data
  elif isinstance(UpperCAmelCase__			,					UpperCAmelCase__						):
    # We keep the data as it as for it ot be later encoded to UTF-8
    # However replace `\\` with `/` for Windows compatibility
    UpperCamelCase_:      List[str]					   =       hash_data.replace('\\'			,					'/'						)
  elif isinstance(UpperCAmelCase__			,					UpperCAmelCase__						):
    UpperCamelCase_:      Union[str, Any]					   =       str(UpperCAmelCase__						)
  else:
    # If data is not of the required type, raise error
    raise InvalidKeyError(UpperCAmelCase__						)

  return hash_data.encode('utf-8'						)




class        _lowerCAmelCase( UpperCAmelCase_      ):





       """simple docstring"""







       def __init__(      self						,    _lowerCamelCase							):
         UpperCamelCase_:      int					   =       '\nFAILURE TO GENERATE DATASET: Invalid key type detected'
         UpperCamelCase_:      Dict					   =       f'''\nFound Key {hash_data} of type {type(_lowerCamelCase							)}'''
         UpperCamelCase_:      Any					   =       '\nKeys should be either str, int or bytes type'
         super().__init__(f'''{self.prefix}{self.err_msg}{self.suffix}'''							)







class        _lowerCAmelCase( UpperCAmelCase_      ):





       """simple docstring"""







       def __init__(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase=""							):
         UpperCamelCase_:      int					   =       key
         UpperCamelCase_:      Dict					   =       duplicate_key_indices
         UpperCamelCase_:      int					   =       fix_msg
         UpperCamelCase_:      List[Any]					   =       'Found multiple examples generated with the same key'
         if len(_lowerCamelCase							) <= 2_0:
           UpperCamelCase_:      Tuple					   =       f'''\nThe examples at index {', '.join(_lowerCamelCase							)} have the key {key}'''
         else:
           UpperCamelCase_:      Optional[int]					   =       f'''\nThe examples at index {', '.join(duplicate_key_indices[:2_0]							)}... ({len(_lowerCamelCase							) - 2_0} more) have the key {key}'''
         UpperCamelCase_:      List[Any]					   =       '\n' + fix_msg if fix_msg else ''
         super().__init__(f'''{self.prefix}{self.err_msg}{self.suffix}'''							)







class        _lowerCAmelCase:





       """simple docstring"""







       def __init__(      self						,    _lowerCamelCase							):
         UpperCamelCase_:      int					   =       hashlib.mda(_as_bytes(_lowerCamelCase							)							)





       def     _a					(      self						,    _lowerCamelCase							):
         UpperCamelCase_:      Optional[int]					   =       self._split_mda.copy()
         UpperCamelCase_:      str					   =       _as_bytes(_lowerCamelCase							)
         mda.update(_lowerCamelCase							)
         # Convert to integer with hexadecimal conversion
         return int(mda.hexdigest()						,    1_6							)