




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,
    convert_to_rgb,
    get_resize_output_image_size,
    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


UpperCamelCase__       				=	logging.get_logger(__name__)


if is_vision_available():
  import PIL
class 							__lowercase   (			_snake_case    ):
     _lowerCAmelCase		       =						["pixel_values"]



     def __init__(  self   :							str      ,		lowercase__   :							bool = True      ,		lowercase__   :							Dict[str, int] = None      ,		lowercase__   :							PILImageResampling = PILImageResampling.BICUBIC      ,		lowercase__   :							bool = True      ,		lowercase__   :							Dict[str, int] = None      ,		lowercase__   :							bool = True      ,		lowercase__   :							Union[int, float] = 1 / 2_5_5      ,		lowercase__   :							bool = True      ,		lowercase__   :							Optional[Union[float, List[float]]] = None      ,		lowercase__   :							Optional[Union[float, List[float]]] = None      ,		lowercase__   :							bool = True      ,		**lowercase__   :							str      ,		):
       super().__init__(**lowerCAmelCase__       )
       a_		    =  size if size is not None else {'''shortest_edge''': 2_2_4}
       a_		    =  get_size_dict(lowerCAmelCase__      ,		default_to_square=lowerCAmelCase__       )
       a_		    =  crop_size if crop_size is not None else {'''height''': 2_2_4, '''width''': 2_2_4}
       a_		    =  get_size_dict(lowerCAmelCase__       )

       a_		    =  do_resize
       a_		    =  size
       a_		    =  resample
       a_		    =  do_center_crop
       a_		    =  crop_size
       a_		    =  do_rescale
       a_		    =  rescale_factor
       a_		    =  do_normalize
       a_		    =  image_mean if image_mean is not None else OPENAI_CLIP_MEAN
       a_		    =  image_std if image_std is not None else OPENAI_CLIP_STD
       a_		    =  do_convert_rgb



     def 				__magic_name__		(  self   :							Optional[Any]      ,		lowercase__   :							np.ndarray      ,		lowercase__   :							Dict[str, int]      ,		lowercase__   :							PILImageResampling = PILImageResampling.BICUBIC      ,		lowercase__   :							Optional[Union[str, ChannelDimension]] = None      ,		**lowercase__   :							Optional[int]      ,		):
       a_		    =  get_size_dict(lowerCAmelCase__      ,		default_to_square=lowerCAmelCase__       )
       a_		    =  get_resize_output_image_size(
           lowerCAmelCase__      ,		size=(size['''height'''], size['''width'''])      ,		default_to_square=lowerCAmelCase__       )
       return resize(lowerCAmelCase__      ,		size=lowerCAmelCase__      ,		resample=lowerCAmelCase__      ,		data_format=lowerCAmelCase__      ,		**lowerCAmelCase__       )



     def 				__magic_name__		(  self   :							List[Any]      ,		lowercase__   :							np.ndarray      ,		lowercase__   :							Dict[str, int]      ,		lowercase__   :							Optional[Union[str, ChannelDimension]] = None      ,		**lowercase__   :							List[Any]      ,		):
       a_		    =  get_size_dict(lowerCAmelCase__       )
       return center_crop(lowerCAmelCase__      ,		size=(size['''height'''], size['''width'''])      ,		data_format=lowerCAmelCase__      ,		**lowerCAmelCase__       )



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



     def 				__magic_name__		(  self   :							Union[str, Any]      ,		lowercase__   :							np.ndarray      ,		lowercase__   :							Union[float, List[float]]      ,		lowercase__   :							Union[float, List[float]]      ,		lowercase__   :							Optional[Union[str, ChannelDimension]] = None      ,		**lowercase__   :							List[str]      ,		):
       return normalize(lowerCAmelCase__      ,		mean=lowerCAmelCase__      ,		std=lowerCAmelCase__      ,		data_format=lowerCAmelCase__      ,		**lowerCAmelCase__       )



     def 				__magic_name__		(  self   :							List[str]      ,		lowercase__   :							ImageInput      ,		lowercase__   :							bool = None      ,		lowercase__   :							Dict[str, int] = None      ,		lowercase__   :							PILImageResampling = None      ,		lowercase__   :							bool = None      ,		lowercase__   :							int = None      ,		lowercase__   :							bool = None      ,		lowercase__   :							float = None      ,		lowercase__   :							bool = None      ,		lowercase__   :							Optional[Union[float, List[float]]] = None      ,		lowercase__   :							Optional[Union[float, List[float]]] = None      ,		lowercase__   :							bool = None      ,		lowercase__   :							Optional[Union[str, TensorType]] = None      ,		lowercase__   :							Optional[ChannelDimension] = ChannelDimension.FIRST      ,		**lowercase__   :							int      ,		):
       a_		    =  do_resize if do_resize is not None else self.do_resize
       a_		    =  size if size is not None else self.size
       a_		    =  get_size_dict(lowerCAmelCase__      ,		default_to_square=lowerCAmelCase__       )
       a_		    =  resample if resample is not None else self.resample
       a_		    =  do_center_crop if do_center_crop is not None else self.do_center_crop
       a_		    =  crop_size if crop_size is not None else self.crop_size
       a_		    =  get_size_dict(lowerCAmelCase__       )
       a_		    =  do_rescale if do_rescale is not None else self.do_rescale
       a_		    =  rescale_factor if rescale_factor is not None else self.rescale_factor
       a_		    =  do_normalize if do_normalize is not None else self.do_normalize
       a_		    =  image_mean if image_mean is not None else self.image_mean
       a_		    =  image_std if image_std is not None else self.image_std
       a_		    =  do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

       a_		    =  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:
         raise ValueError('''Size 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.'''       )

       # PIL RGBA images are converted to RGB
       if do_convert_rgb:
         a_		    =  [convert_to_rgb(lowerCAmelCase__       ) for image in images]

       # All transformations expect numpy arrays.
       a_		    =  [to_numpy_array(lowerCAmelCase__       ) for image in images]

       if do_resize:
         a_		    =  [self.resize(image=lowerCAmelCase__      ,		size=lowerCAmelCase__      ,		resample=lowerCAmelCase__       ) for image in images]

       if do_center_crop:
         a_		    =  [self.center_crop(image=lowerCAmelCase__      ,		size=lowerCAmelCase__       ) for image in images]

       if do_rescale:
         a_		    =  [self.rescale(image=lowerCAmelCase__      ,		scale=lowerCAmelCase__       ) for image in images]

       if do_normalize:
         a_		    =  [self.normalize(image=lowerCAmelCase__      ,		mean=lowerCAmelCase__      ,		std=lowerCAmelCase__       ) for image in images]

       a_		    =  [to_channel_dimension_format(lowerCAmelCase__      ,		lowerCAmelCase__       ) for image in images]

       a_		    =  {'''pixel_values''': images}
       return BatchFeature(data=lowerCAmelCase__      ,		tensor_type=lowerCAmelCase__       )



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,
    convert_to_rgb,
    get_resize_output_image_size,
    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


lowerCAmelCase__							=			logging.get_logger(__name__)


if is_vision_available():
      import PIL






class     __magic_name__     (							_snake_case     ):
 UpperCAmelCase				     =    ["""pixel_values"""]


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

   UpperCAmelCase          =	do_resize
   UpperCAmelCase          =	size
   UpperCAmelCase          =	resample
   UpperCAmelCase          =	do_center_crop
   UpperCAmelCase          =	crop_size
   UpperCAmelCase          =	do_rescale
   UpperCAmelCase          =	rescale_factor
   UpperCAmelCase          =	do_normalize
   UpperCAmelCase          =	image_mean if image_mean is not None else OPENAI_CLIP_MEAN
   UpperCAmelCase          =	image_std if image_std is not None else OPENAI_CLIP_STD
   UpperCAmelCase          =	do_convert_rgb


 def _UpperCamelCase						(    self		:			Optional[Any]      ,    lowerCAmelCase__		:			np.ndarray      ,    lowerCAmelCase__		:			Dict[str, int]      ,    lowerCAmelCase__		:			PILImageResampling = PILImageResampling.BICUBIC      ,    lowerCAmelCase__		:			Optional[Union[str, ChannelDimension]] = None      ,    **lowerCAmelCase__		:			Optional[int]      ,    )     ->   np.ndarray:
   UpperCAmelCase          =	get_size_dict(lowerCAmelCase__      ,    default_to_square=lowerCAmelCase__     )
   UpperCAmelCase          =	get_resize_output_image_size(
       lowerCAmelCase__      ,    size=(size["height"], size["width"])      ,    default_to_square=lowerCAmelCase__     )
   return resize(lowerCAmelCase__      ,    size=lowerCAmelCase__      ,    resample=lowerCAmelCase__      ,    data_format=lowerCAmelCase__      ,    **lowerCAmelCase__     )


 def _UpperCamelCase						(    self		:			List[Any]      ,    lowerCAmelCase__		:			np.ndarray      ,    lowerCAmelCase__		:			Dict[str, int]      ,    lowerCAmelCase__		:			Optional[Union[str, ChannelDimension]] = None      ,    **lowerCAmelCase__		:			List[Any]      ,    )     ->   np.ndarray:
   UpperCAmelCase          =	get_size_dict(lowerCAmelCase__     )
   return center_crop(lowerCAmelCase__      ,    size=(size["height"], size["width"])      ,    data_format=lowerCAmelCase__      ,    **lowerCAmelCase__     )


 def _UpperCamelCase						(    self		:			Any      ,    lowerCAmelCase__		:			np.ndarray      ,    lowerCAmelCase__		:			Union[int, float]      ,    lowerCAmelCase__		:			Optional[Union[str, ChannelDimension]] = None      ,    **lowerCAmelCase__		:			List[Any]      ,    )     ->   Optional[int]:
   return rescale(lowerCAmelCase__      ,    scale=lowerCAmelCase__      ,    data_format=lowerCAmelCase__      ,    **lowerCAmelCase__     )


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


 def _UpperCamelCase						(    self		:			List[str]      ,    lowerCAmelCase__		:			ImageInput      ,    lowerCAmelCase__		:			bool = None      ,    lowerCAmelCase__		:			Dict[str, int] = None      ,    lowerCAmelCase__		:			PILImageResampling = None      ,    lowerCAmelCase__		:			bool = None      ,    lowerCAmelCase__		:			int = None      ,    lowerCAmelCase__		:			bool = None      ,    lowerCAmelCase__		:			float = None      ,    lowerCAmelCase__		:			bool = None      ,    lowerCAmelCase__		:			Optional[Union[float, List[float]]] = None      ,    lowerCAmelCase__		:			Optional[Union[float, List[float]]] = None      ,    lowerCAmelCase__		:			bool = None      ,    lowerCAmelCase__		:			Optional[Union[str, TensorType]] = None      ,    lowerCAmelCase__		:			Optional[ChannelDimension] = ChannelDimension.FIRST      ,    **lowerCAmelCase__		:			int      ,    )     ->   PIL.Image.Image:
   UpperCAmelCase          =	do_resize if do_resize is not None else self.do_resize
   UpperCAmelCase          =	size if size is not None else self.size
   UpperCAmelCase          =	get_size_dict(lowerCAmelCase__      ,    default_to_square=lowerCAmelCase__     )
   UpperCAmelCase          =	resample if resample is not None else self.resample
   UpperCAmelCase          =	do_center_crop if do_center_crop is not None else self.do_center_crop
   UpperCAmelCase          =	crop_size if crop_size is not None else self.crop_size
   UpperCAmelCase          =	get_size_dict(lowerCAmelCase__     )
   UpperCAmelCase          =	do_rescale if do_rescale is not None else self.do_rescale
   UpperCAmelCase          =	rescale_factor if rescale_factor is not None else self.rescale_factor
   UpperCAmelCase          =	do_normalize if do_normalize is not None else self.do_normalize
   UpperCAmelCase          =	image_mean if image_mean is not None else self.image_mean
   UpperCAmelCase          =	image_std if image_std is not None else self.image_std
   UpperCAmelCase          =	do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

   UpperCAmelCase          =	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:
     raise ValueError("Size 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."     )

   # PIL RGBA images are converted to RGB
   if do_convert_rgb:
     UpperCAmelCase          =	[convert_to_rgb(lowerCAmelCase__     ) for image in images]

   # All transformations expect numpy arrays.
   UpperCAmelCase          =	[to_numpy_array(lowerCAmelCase__     ) for image in images]

   if do_resize:
     UpperCAmelCase          =	[self.resize(image=lowerCAmelCase__      ,    size=lowerCAmelCase__      ,    resample=lowerCAmelCase__     ) for image in images]

   if do_center_crop:
     UpperCAmelCase          =	[self.center_crop(image=lowerCAmelCase__      ,    size=lowerCAmelCase__     ) for image in images]

   if do_rescale:
     UpperCAmelCase          =	[self.rescale(image=lowerCAmelCase__      ,    scale=lowerCAmelCase__     ) for image in images]

   if do_normalize:
     UpperCAmelCase          =	[self.normalize(image=lowerCAmelCase__      ,    mean=lowerCAmelCase__      ,    std=lowerCAmelCase__     ) for image in images]

   UpperCAmelCase          =	[to_channel_dimension_format(lowerCAmelCase__      ,    lowerCAmelCase__     ) for image in images]

   UpperCAmelCase          =	{"pixel_values": images}
   return BatchFeature(data=lowerCAmelCase__      ,    tensor_type=lowerCAmelCase__     )



