
'''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,
    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 UpperCAmelCase__	( SCREAMING_SNAKE_CASE__	):





  """simple docstring"""

  __UpperCAmelCase				:				Any   =					["pixel_values"]


  def __init__(		self      :     Dict							,_a      :     Optional[Any] = True							,_a      :     Any = None							,_a      :     Tuple = PILImageResampling.BICUBIC							,_a      :     str = True							,_a      :     Union[str, Any] = None							,_a      :     List[str] = True							,_a      :     int = 1 / 255							,_a      :     Dict = True							,_a      :     Tuple = None							,_a      :     List[str] = None							,_a      :     Tuple = True							,**_a      :     str							,):


     '''simple docstring'''






     super().__init__(**lowerCamelCase__       )
     _a				:	List[Any]			=   size if size is not None else {"""shortest_edge""": 224}
     _a				:	Any			=   get_size_dict(lowerCamelCase__							,default_to_square=lowerCamelCase__       )
     _a				:	Optional[Any]			=   crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
     _a				:	Optional[Any]			=   get_size_dict(lowerCamelCase__							,default_to_square=lowerCamelCase__							,param_name='crop_size'       )

     _a				:	Any			=   do_resize
     _a				:	Optional[Any]			=   size
     _a				:	Dict			=   resample
     _a				:	Optional[Any]			=   do_center_crop
     _a				:	List[str]			=   crop_size
     _a				:	Optional[int]			=   do_rescale
     _a				:	Any			=   rescale_factor
     _a				:	int			=   do_normalize
     _a				:	Optional[int]			=   image_mean if image_mean is not None else OPENAI_CLIP_MEAN
     _a				:	int			=   image_std if image_std is not None else OPENAI_CLIP_STD
     _a				:	Optional[Any]			=   do_convert_rgb


  def   __lowercase		(		self      :     Optional[int]							,_a      :     Optional[int]							,_a      :     Any							,_a      :     Tuple = PILImageResampling.BICUBIC							,_a      :     List[Any] = None							,**_a      :     Any							,):


     '''simple docstring'''






     _a				:	Tuple			=   get_size_dict(lowerCamelCase__							,default_to_square=lowerCamelCase__       )
     if "shortest_edge" not in size:
        raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""       )
     _a				:	Dict			=   get_resize_output_image_size(lowerCamelCase__							,size=size['shortest_edge']							,default_to_square=lowerCamelCase__       )
     return resize(lowerCamelCase__							,size=lowerCamelCase__							,resample=lowerCamelCase__							,data_format=lowerCamelCase__							,**lowerCamelCase__       )


  def   __lowercase		(		self      :     int							,_a      :     str							,_a      :     Dict							,_a      :     List[Any] = None							,**_a      :     List[str]							,):


     '''simple docstring'''






     _a				:	Optional[int]			=   get_size_dict(lowerCamelCase__       )
     if "height" not in size or "width" not in size:
        raise ValueError(F"""The `size` parameter must contain the keys (height, width). Got {size.keys()}"""       )
     return center_crop(lowerCamelCase__							,size=(size['height'], size['width'])							,data_format=lowerCamelCase__							,**lowerCamelCase__       )


  def   __lowercase		(		self      :     List[Any]							,_a      :     Optional[int]							,_a      :     List[Any]							,_a      :     Union[str, Any] = None							,**_a      :     Optional[int]							,):


     '''simple docstring'''






     return rescale(lowerCamelCase__							,scale=lowerCamelCase__							,data_format=lowerCamelCase__							,**lowerCamelCase__       )


  def   __lowercase		(		self      :     Optional[int]							,_a      :     Optional[Any]							,_a      :     int							,_a      :     List[str]							,_a      :     List[str] = None							,**_a      :     Optional[Any]							,):


     '''simple docstring'''






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


  def   __lowercase		(		self      :     Optional[Any]							,_a      :     int							,_a      :     Optional[int] = None							,_a      :     Any = None							,_a      :     Union[str, Any] = None							,_a      :     Any = None							,_a      :     str = None							,_a      :     List[str] = None							,_a      :     List[str] = None							,_a      :     Any = None							,_a      :     List[str] = None							,_a      :     Union[str, Any] = None							,_a      :     Optional[Any] = None							,_a      :     Tuple = None							,_a      :     Union[str, Any] = ChannelDimension.FIRST							,**_a      :     str							,):


     '''simple docstring'''






     _a				:	Optional[Any]			=   do_resize if do_resize is not None else self.do_resize
     _a				:	Dict			=   size if size is not None else self.size
     _a				:	Dict			=   get_size_dict(lowerCamelCase__							,param_name='size'							,default_to_square=lowerCamelCase__       )
     _a				:	Tuple			=   resample if resample is not None else self.resample
     _a				:	Tuple			=   do_center_crop if do_center_crop is not None else self.do_center_crop
     _a				:	str			=   crop_size if crop_size is not None else self.crop_size
     _a				:	int			=   get_size_dict(lowerCamelCase__							,param_name='crop_size'							,default_to_square=lowerCamelCase__       )
     _a				:	str			=   do_rescale if do_rescale is not None else self.do_rescale
     _a				:	Dict			=   rescale_factor if rescale_factor is not None else self.rescale_factor
     _a				:	List[Any]			=   do_normalize if do_normalize is not None else self.do_normalize
     _a				:	Dict			=   image_mean if image_mean is not None else self.image_mean
     _a				:	Dict			=   image_std if image_std is not None else self.image_std
     _a				:	List[str]			=   do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

     _a				:	List[str]			=   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				:	Union[str, Any]			=   [convert_to_rgb(lowerCamelCase__       ) for image in images]

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

     if do_resize:
        _a				:	Dict			=   [self.resize(image=lowerCamelCase__							,size=lowerCamelCase__							,resample=lowerCamelCase__       ) for image in images]

     if do_center_crop:
        _a				:	str			=   [self.center_crop(image=lowerCamelCase__							,size=lowerCamelCase__       ) for image in images]

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

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

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

     _a				:	int			=   {"""pixel_values""": images}
     return BatchFeature(data=lowerCamelCase__							,tensor_type=lowerCamelCase__       )








from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


SCREAMING_SNAKE_CASE_:str             =						{
    """configuration_transfo_xl""": ["""TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TransfoXLConfig"""],
    """tokenization_transfo_xl""": ["""TransfoXLCorpus""", """TransfoXLTokenizer"""],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     SCREAMING_SNAKE_CASE_:Union[str, Any]             =						[
         """TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """AdaptiveEmbedding""",
         """TransfoXLForSequenceClassification""",
         """TransfoXLLMHeadModel""",
         """TransfoXLModel""",
         """TransfoXLPreTrainedModel""",
         """load_tf_weights_in_transfo_xl""",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     SCREAMING_SNAKE_CASE_:Any             =						[
         """TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """TFAdaptiveEmbedding""",
         """TFTransfoXLForSequenceClassification""",
         """TFTransfoXLLMHeadModel""",
         """TFTransfoXLMainLayer""",
         """TFTransfoXLModel""",
         """TFTransfoXLPreTrainedModel""",
     ]


if TYPE_CHECKING:
     from .configuration_transfo_xl import TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP, TransfoXLConfig
     from .tokenization_transfo_xl import TransfoXLCorpus, TransfoXLTokenizer

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_transfo_xl import (
              TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
              AdaptiveEmbedding,
              TransfoXLForSequenceClassification,
              TransfoXLLMHeadModel,
              TransfoXLModel,
              TransfoXLPreTrainedModel,
              load_tf_weights_in_transfo_xl,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_transfo_xl import (
              TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFAdaptiveEmbedding,
              TFTransfoXLForSequenceClassification,
              TFTransfoXLLMHeadModel,
              TFTransfoXLMainLayer,
              TFTransfoXLModel,
              TFTransfoXLPreTrainedModel,
          )

else:
     import sys

     SCREAMING_SNAKE_CASE_:Dict             =						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


