




'''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 convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_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_			      =		logging.get_logger(__name__)






class        lowercase_      (						_SCREAMING_SNAKE_CASE							):
     A_											=			["pixel_values"]





     def __init__(     self     :					Any     ,							__lowerCamelCase     :					bool = True     ,							__lowerCamelCase     :					Dict[str, int] = None     ,							__lowerCamelCase     :					PILImageResampling = PILImageResampling.BICUBIC     ,							__lowerCamelCase     :					bool = True     ,							__lowerCamelCase     :					Union[int, float] = 1 / 255     ,							__lowerCamelCase     :					bool = True     ,							__lowerCamelCase     :					Optional[Union[float, List[float]]] = None     ,							__lowerCamelCase     :					Optional[Union[float, List[float]]] = None     ,							__lowerCamelCase     :					bool = True     ,							**__lowerCamelCase     :					Union[str, Any]     ,							):
           super().__init__(**__lowerCamelCase			)
           snake_case__       :   Any	      =    size if size is not None else {"""height""": 384, """width""": 384}
           snake_case__       :   List[str]	      =    get_size_dict(__lowerCamelCase     ,							default_to_square=__lowerCamelCase			)

           snake_case__       :   Optional[int]	      =    do_resize
           snake_case__       :   Union[str, Any]	      =    size
           snake_case__       :   Tuple	      =    resample
           snake_case__       :   Tuple	      =    do_rescale
           snake_case__       :   Any	      =    rescale_factor
           snake_case__       :   int	      =    do_normalize
           snake_case__       :   Any	      =    image_mean if image_mean is not None else OPENAI_CLIP_MEAN
           snake_case__       :   Tuple	      =    image_std if image_std is not None else OPENAI_CLIP_STD
           snake_case__       :   List[Any]	      =    do_convert_rgb





     def 			_lowerCAmelCase      (     self     :					Union[str, Any]     ,							__lowerCamelCase     :					np.ndarray     ,							__lowerCamelCase     :					Dict[str, int]     ,							__lowerCamelCase     :					PILImageResampling = PILImageResampling.BICUBIC     ,							__lowerCamelCase     :					Optional[Union[str, ChannelDimension]] = None     ,							**__lowerCamelCase     :					Union[str, Any]     ,							):
           snake_case__       :   Optional[int]	      =    get_size_dict(__lowerCamelCase     ,							default_to_square=__lowerCamelCase			)
           if "height" not in size or "width" not in size:
                 raise ValueError(F"The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}"			)
           snake_case__       :   List[str]	      =    (size["""height"""], size["""width"""])
           return resize(__lowerCamelCase     ,							size=__lowerCamelCase     ,							resample=__lowerCamelCase     ,							data_format=__lowerCamelCase     ,							**__lowerCamelCase			)





     def 			_lowerCAmelCase      (     self     :					Any     ,							__lowerCamelCase     :					np.ndarray     ,							__lowerCamelCase     :					Union[int, float]     ,							__lowerCamelCase     :					Optional[Union[str, ChannelDimension]] = None     ,							**__lowerCamelCase     :					Union[str, Any]     ,							):
           return rescale(__lowerCamelCase     ,							scale=__lowerCamelCase     ,							data_format=__lowerCamelCase     ,							**__lowerCamelCase			)





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





     def 			_lowerCAmelCase      (     self     :					str     ,							__lowerCamelCase     :					ImageInput     ,							__lowerCamelCase     :					Optional[bool] = None     ,							__lowerCamelCase     :					Optional[Dict[str, int]] = None     ,							__lowerCamelCase     :					PILImageResampling = None     ,							__lowerCamelCase     :					Optional[bool] = None     ,							__lowerCamelCase     :					Optional[float] = None     ,							__lowerCamelCase     :					Optional[bool] = None     ,							__lowerCamelCase     :					Optional[Union[float, List[float]]] = None     ,							__lowerCamelCase     :					Optional[Union[float, List[float]]] = None     ,							__lowerCamelCase     :					Optional[Union[str, TensorType]] = None     ,							__lowerCamelCase     :					bool = None     ,							__lowerCamelCase     :					ChannelDimension = ChannelDimension.FIRST     ,							**__lowerCamelCase     :					Union[str, Any]     ,							):
           snake_case__       :   List[str]	      =    do_resize if do_resize is not None else self.do_resize
           snake_case__       :   int	      =    resample if resample is not None else self.resample
           snake_case__       :   Optional[int]	      =    do_rescale if do_rescale is not None else self.do_rescale
           snake_case__       :   Union[str, Any]	      =    rescale_factor if rescale_factor is not None else self.rescale_factor
           snake_case__       :   Dict	      =    do_normalize if do_normalize is not None else self.do_normalize
           snake_case__       :   List[str]	      =    image_mean if image_mean is not None else self.image_mean
           snake_case__       :   Dict	      =    image_std if image_std is not None else self.image_std
           snake_case__       :   Optional[int]	      =    do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

           snake_case__       :   Tuple	      =    size if size is not None else self.size
           snake_case__       :   Dict	      =    get_size_dict(__lowerCamelCase     ,							default_to_square=__lowerCamelCase			)

           snake_case__       :   Optional[Any]	      =    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_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.'			)

           # PIL RGBA images are converted to RGB
           if do_convert_rgb:
                 snake_case__       :   Optional[Any]	      =    [convert_to_rgb(__lowerCamelCase			) for image in images]

           # All transformations expect numpy arrays.
           snake_case__       :   int	      =    [to_numpy_array(__lowerCamelCase			) for image in images]

           if do_resize:
                 snake_case__       :   int	      =    [self.resize(image=__lowerCamelCase     ,							size=__lowerCamelCase     ,							resample=__lowerCamelCase			) for image in images]

           if do_rescale:
                 snake_case__       :   str	      =    [self.rescale(image=__lowerCamelCase     ,							scale=__lowerCamelCase			) for image in images]

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

           snake_case__       :   Any	      =    [to_channel_dimension_format(__lowerCamelCase     ,							__lowerCamelCase			) for image in images]

           snake_case__       :   Tuple	      =    BatchFeature(data={'pixel_values': images}     ,							tensor_type=__lowerCamelCase			)

           return encoded_outputs




'''simple docstring'''






def 							UpperCamelCase_     (       A__   :  bytes   ):
  '''simple docstring'''





  return "".join([hex(A__   )[2:].zfill(2   ).upper() for byte in list(A__   )]   )







def 							UpperCamelCase_     (       A__   :  str   ):
  '''simple docstring'''





  if (len(A__   ) % 2) != 0:
    raise ValueError(
        """Base16 encoded data is invalid:
Data does not have an even number of hex digits."""   )
  # Check the character set - the standard base16 alphabet
  # is uppercase according to RFC3548 section 6
  if not set(A__   ) <= set("""0123456789ABCDEF"""   ):
    raise ValueError(
        """Base16 encoded data is invalid:
Data is not uppercase hex or it contains invalid characters."""   )
  # For every two hexadecimal digits (= a byte), turn it into an integer.
  # Then, string the result together into bytes, and return it.
  return bytes(int(data[i] + data[i + 1]				,       16   ) for i in range(0				,       len(A__   )				,       2   )   )


if __name__ == "__main__":
  import doctest

  doctest.testmod()



