





"""simple docstring"""





from typing import Dict, Iterable, List, Optional, Union

import numpy as np

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


__A											=						logging.get_logger(__name__)






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       __magic_name__	:Optional[Any]						    =   ["""pixel_values"""]






       def __init__(       self       ,					__UpperCAmelCase = True       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = PILImageResampling.BICUBIC       ,					__UpperCAmelCase = True       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = True       ,					__UpperCAmelCase = 1 / 2_5_5       ,					__UpperCAmelCase = True       ,					__UpperCAmelCase = IMAGENET_DEFAULT_MEAN       ,					__UpperCAmelCase = IMAGENET_DEFAULT_STD       ,					**__UpperCAmelCase       ,					):



         '''simple docstring'''

         super().__init__(**__UpperCAmelCase )
         lowerCAmelCase__     :str											=				size if size is not None else {'shortest_edge': 2_2_4}
         lowerCAmelCase__     :int											=				get_size_dict(__UpperCAmelCase       ,					default_to_square=__UpperCAmelCase )
         lowerCAmelCase__     :Dict											=				crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
         lowerCAmelCase__     :Union[str, Any]											=				get_size_dict(__UpperCAmelCase       ,					param_name='crop_size' )

         lowerCAmelCase__     :int											=				do_resize
         lowerCAmelCase__     :str											=				size
         lowerCAmelCase__     :int											=				resample
         lowerCAmelCase__     :Tuple											=				do_center_crop
         lowerCAmelCase__     :List[str]											=				crop_size
         lowerCAmelCase__     :str											=				do_rescale
         lowerCAmelCase__     :Dict											=				rescale_factor
         lowerCAmelCase__     :Optional[int]											=				do_normalize
         lowerCAmelCase__     :int											=				image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
         lowerCAmelCase__     :Union[str, Any]											=				image_std if image_std is not None else IMAGENET_DEFAULT_STD






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase = PILImageResampling.BICUBIC       ,					__UpperCAmelCase = None       ,					**__UpperCAmelCase       ,					):



         '''simple docstring'''

         lowerCAmelCase__     :Any											=				get_size_dict(__UpperCAmelCase       ,					default_to_square=__UpperCAmelCase )
         # size_dict is a dict with either keys "height" and "width" or "shortest_edge"
         if "shortest_edge" in size:
           lowerCAmelCase__     :List[Any]											=				int((2_5_6 / 2_2_4) * size['shortest_edge'] )
           lowerCAmelCase__     :Union[str, Any]											=				get_resize_output_image_size(__UpperCAmelCase       ,					size=__UpperCAmelCase       ,					default_to_square=__UpperCAmelCase )
           lowerCAmelCase__     :List[str]											=				{'height': output_size[0], 'width': output_size[1]}
         if "height" not in size_dict or "width" not in size_dict:
           raise ValueError(
               F"Size dict must have keys 'height' and 'width' or 'shortest_edge'. Got {size_dict.keys()}" )
         return resize(
             __UpperCAmelCase       ,					size=(size_dict['height'], size_dict['width'])       ,					resample=__UpperCAmelCase       ,					data_format=__UpperCAmelCase       ,					**__UpperCAmelCase )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None       ,					**__UpperCAmelCase       ,					):



         '''simple docstring'''

         lowerCAmelCase__     :List[str]											=				get_size_dict(__UpperCAmelCase )
         if "height" not in size or "width" not in size:
           raise ValueError(F"Size dict must have keys 'height' and 'width'. Got {size.keys()}" )
         return center_crop(__UpperCAmelCase       ,					size=(size['height'], size['width'])       ,					data_format=__UpperCAmelCase       ,					**__UpperCAmelCase )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None       ,					**__UpperCAmelCase       ,					):



         '''simple docstring'''

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






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None       ,					**__UpperCAmelCase       ,					):



         '''simple docstring'''

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






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = ChannelDimension.FIRST       ,					**__UpperCAmelCase       ,					):



         '''simple docstring'''

         lowerCAmelCase__     :int											=				do_resize if do_resize is not None else self.do_resize
         lowerCAmelCase__     :List[Any]											=				resample if resample is not None else self.resample
         lowerCAmelCase__     :int											=				do_center_crop if do_center_crop is not None else self.do_center_crop
         lowerCAmelCase__     :str											=				do_rescale if do_rescale is not None else self.do_rescale
         lowerCAmelCase__     :int											=				rescale_factor if rescale_factor is not None else self.rescale_factor
         lowerCAmelCase__     :Optional[int]											=				do_normalize if do_normalize is not None else self.do_normalize
         lowerCAmelCase__     :List[str]											=				image_mean if image_mean is not None else self.image_mean
         lowerCAmelCase__     :int											=				image_std if image_std is not None else self.image_std

         lowerCAmelCase__     :Any											=				size if size is not None else self.size
         lowerCAmelCase__     :str											=				get_size_dict(__UpperCAmelCase       ,					default_to_square=__UpperCAmelCase )
         lowerCAmelCase__     :Optional[Any]											=				crop_size if crop_size is not None else self.crop_size
         lowerCAmelCase__     :Tuple											=				get_size_dict(__UpperCAmelCase       ,					param_name='crop_size' )

         lowerCAmelCase__     :Optional[int]											=				make_list_of_images(__UpperCAmelCase )

         if not valid_images(__UpperCAmelCase ):
           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.' )

         # All transformations expect numpy arrays.
         lowerCAmelCase__     :Union[str, Any]											=				[to_numpy_array(__UpperCAmelCase ) for image in images]

         if do_resize:
           lowerCAmelCase__     :Optional[Any]											=				[self.resize(__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ) for image in images]

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

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

         if do_normalize:
           lowerCAmelCase__     :Optional[Any]											=				[self.normalize(__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase ) for image in images]

         lowerCAmelCase__     :Optional[Any]											=				[to_channel_dimension_format(__UpperCAmelCase       ,					__UpperCAmelCase ) for image in images]

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







"""simple docstring"""





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__A											=						{
    """configuration_x_clip""": [
        """XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """XCLIPConfig""",
        """XCLIPTextConfig""",
        """XCLIPVisionConfig""",
    ],
    """processing_x_clip""": ["""XCLIPProcessor"""],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A											=						[
      """XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """XCLIPModel""",
      """XCLIPPreTrainedModel""",
      """XCLIPTextModel""",
      """XCLIPVisionModel""",
  ]

if TYPE_CHECKING:
  from .configuration_x_clip import (
      XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
      XCLIPConfig,
      XCLIPTextConfig,
      XCLIPVisionConfig,
  )
  from .processing_x_clip import XCLIPProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_x_clip import (
        XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
        XCLIPModel,
        XCLIPPreTrainedModel,
        XCLIPTextModel,
        XCLIPVisionModel,
    )

else:
  import sys

  __A											=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
