



"""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,
    get_resize_output_image_size,
    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, logging


lowercase__    :  int							    =	logging.get_logger(__name__)




class        _UpperCAmelCase       (			lowerCAmelCase__):
 _lowerCAmelCase   :			str							=		["""pixel_values"""]

 def __init__(     self		:       Optional[Any]  ,     lowercase_		:       bool = True  ,     lowercase_		:       Optional[Dict[str, int]] = None  ,     lowercase_		:       PILImageResampling = PILImageResampling.BILINEAR  ,     lowercase_		:       bool = True  ,     lowercase_		:       Dict[str, int] = None  ,     lowercase_		:       bool = True  ,     lowercase_		:       Union[int, float] = 1 / 255  ,     lowercase_		:       bool = True  ,     lowercase_		:       Optional[Union[float, List[float]]] = None  ,     lowercase_		:       Optional[Union[float, List[float]]] = None  ,     **lowercase_		:       List[str]  ,     ):
     super().__init__(**lowercase_				)
     snake_case_ :     List[str]				=	size if size is not None else {'''shortest_edge''': 256}
     snake_case_ :     Optional[int]				=	get_size_dict(lowercase_  ,     default_to_square=lowercase_				)
     snake_case_ :     Dict				=	crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
     snake_case_ :     Dict				=	get_size_dict(lowercase_				)
     snake_case_ :     List[str]				=	do_resize
     snake_case_ :     Optional[int]				=	size
     snake_case_ :     Union[str, Any]				=	resample
     snake_case_ :     Dict				=	do_center_crop
     snake_case_ :     List[str]				=	crop_size
     snake_case_ :     int				=	do_rescale
     snake_case_ :     List[str]				=	rescale_factor
     snake_case_ :     int				=	do_normalize
     snake_case_ :     int				=	image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
     snake_case_ :     int				=	image_std if image_std is not None else IMAGENET_STANDARD_STD

 def 						_snake_case					(     self		:       int  ,     lowercase_		:       np.ndarray  ,     lowercase_		:       Dict[str, int]  ,     lowercase_		:       PILImageResampling = PILImageResampling.BICUBIC  ,     lowercase_		:       Optional[Union[str, ChannelDimension]] = None  ,     **lowercase_		:       Tuple  ,     ):
     snake_case_ :     str				=	get_size_dict(lowercase_  ,     default_to_square=lowercase_				)
     if "shortest_edge" not in size:
         raise ValueError(f"The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"				)
     snake_case_ :     Dict				=	get_resize_output_image_size(lowercase_  ,     size=size['''shortest_edge''']  ,     default_to_square=lowercase_				)
     return resize(lowercase_  ,     size=lowercase_  ,     resample=lowercase_  ,     data_format=lowercase_  ,     **lowercase_				)

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

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

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






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

     snake_case_ :     str				=	make_list_of_images(lowercase_				)

     if not valid_images(lowercase_				):
         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.
     snake_case_ :     List[Any]				=	[to_numpy_array(lowercase_				) for image in images]

     if do_resize:
         snake_case_ :     Optional[Any]				=	[self.resize(image=lowercase_  ,     size=lowercase_  ,     resample=lowercase_				) for image in images]

     if do_center_crop:
         snake_case_ :     List[str]				=	[self.center_crop(image=lowercase_  ,     size=lowercase_				) for image in images]

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

     if do_normalize:
         snake_case_ :     Dict				=	[self.normalize(image=lowercase_  ,     mean=lowercase_  ,     std=lowercase_				) for image in images]

     snake_case_ :     Tuple				=	[to_channel_dimension_format(lowercase_  ,     lowercase_				) for image in images]

     snake_case_ :     int				=	{'''pixel_values''': images}
     return BatchFeature(data=lowercase_  ,     tensor_type=lowercase_				)










"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase__    :  str							    =	{
    '''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:
     lowercase__    :  Tuple							    =	[
         '''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

     lowercase__    :  Tuple							    =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





