



"""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


_lowercase				:				Tuple   		=		logging.get_logger(__name__)


if is_vision_available():
  import PIL

class  __SCREAMING_SNAKE_CASE			(   lowercase__     ):


     '''simple docstring'''





     _a         =							['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 / 255,						lowerCamelCase							:						bool = True,						lowerCamelCase							:						Optional[Union[float, List[float]]] = None,						lowerCamelCase							:						Optional[Union[float, List[float]]] = None,						lowerCamelCase							:						bool = True,						**lowerCamelCase							:						List[Any],						)->      int:
        super().__init__(**__lowerCamelCase  )
        lowerCamelCase__	:	int				=size if size is not None else {"shortest_edge": 224}
        lowerCamelCase__	:	Optional[Any]				=get_size_dict(__lowerCamelCase,						default_to_square=__lowerCamelCase  )
        lowerCamelCase__	:	Tuple				=crop_size if crop_size is not None else {"height": 224, "width": 224}
        lowerCamelCase__	:	Union[str, Any]				=get_size_dict(__lowerCamelCase,						default_to_square=__lowerCamelCase,						param_name='''crop_size'''  )

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



     def 	snake_case ( self							:						Tuple,						lowerCamelCase							:						np.ndarray,						lowerCamelCase							:						Dict[str, int],						lowerCamelCase							:						PILImageResampling = PILImageResampling.BICUBIC,						lowerCamelCase							:						Optional[Union[str, ChannelDimension]] = None,						**lowerCamelCase							:						str,						)->      Union[str, Any]:
        lowerCamelCase__	:	int				=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()}'''  )
        lowerCamelCase__	:	Any				=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 	snake_case ( self							:						List[Any],						lowerCamelCase							:						np.ndarray,						lowerCamelCase							:						Dict[str, int],						lowerCamelCase							:						Optional[Union[str, ChannelDimension]] = None,						**lowerCamelCase							:						Optional[int],						)->      Union[str, Any]:
        lowerCamelCase__	:	Any				=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 	snake_case ( self							:						List[str],						lowerCamelCase							:						np.ndarray,						lowerCamelCase							:						Union[int, float],						lowerCamelCase							:						Optional[Union[str, ChannelDimension]] = None,						**lowerCamelCase							:						List[str],						)->      Tuple:
        return rescale(__lowerCamelCase,						scale=__lowerCamelCase,						data_format=__lowerCamelCase,						**__lowerCamelCase  )



     def 	snake_case ( self							:						List[str],						lowerCamelCase							:						np.ndarray,						lowerCamelCase							:						Union[float, List[float]],						lowerCamelCase							:						Union[float, List[float]],						lowerCamelCase							:						Optional[Union[str, ChannelDimension]] = None,						**lowerCamelCase							:						Dict,						)->      Tuple:
        return normalize(__lowerCamelCase,						mean=__lowerCamelCase,						std=__lowerCamelCase,						data_format=__lowerCamelCase,						**__lowerCamelCase  )




     def 	snake_case ( self							:						Dict,						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							:						Optional[Any],						)->      Union[str, Any]:
        lowerCamelCase__	:	int				=do_resize if do_resize is not None else self.do_resize
        lowerCamelCase__	:	Dict				=size if size is not None else self.size
        lowerCamelCase__	:	str				=get_size_dict(__lowerCamelCase,						param_name='''size''',						default_to_square=__lowerCamelCase  )
        lowerCamelCase__	:	Dict				=resample if resample is not None else self.resample
        lowerCamelCase__	:	List[str]				=do_center_crop if do_center_crop is not None else self.do_center_crop
        lowerCamelCase__	:	int				=crop_size if crop_size is not None else self.crop_size
        lowerCamelCase__	:	List[str]				=get_size_dict(__lowerCamelCase,						param_name='''crop_size''',						default_to_square=__lowerCamelCase  )
        lowerCamelCase__	:	Dict				=do_rescale if do_rescale is not None else self.do_rescale
        lowerCamelCase__	:	Dict				=rescale_factor if rescale_factor is not None else self.rescale_factor
        lowerCamelCase__	:	List[str]				=do_normalize if do_normalize is not None else self.do_normalize
        lowerCamelCase__	:	Tuple				=image_mean if image_mean is not None else self.image_mean
        lowerCamelCase__	:	Optional[int]				=image_std if image_std is not None else self.image_std
        lowerCamelCase__	:	Optional[Any]				=do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

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

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

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

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

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

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

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

        lowerCamelCase__	:	Dict				={"pixel_values": images}
        return BatchFeature(data=__lowerCamelCase,						tensor_type=__lowerCamelCase  )









"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


_lowercase				:				Optional[Any]   		=		{
    "configuration_clip": [
        "CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "CLIPConfig",
        "CLIPOnnxConfig",
        "CLIPTextConfig",
        "CLIPVisionConfig",
    ],
    "processing_clip": ["CLIPProcessor"],
    "tokenization_clip": ["CLIPTokenizer"],
}

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				:				str   		=		["CLIPTokenizerFast"]

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				:				Any   		=		["CLIPFeatureExtractor"]
		_lowercase				:				int   		=		["CLIPImageProcessor"]

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				:				Optional[Any]   		=		[
		    "CLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "CLIPModel",
		    "CLIPPreTrainedModel",
		    "CLIPTextModel",
		    "CLIPTextModelWithProjection",
		    "CLIPVisionModel",
		    "CLIPVisionModelWithProjection",
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				:				Dict   		=		[
		    "TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "TFCLIPModel",
		    "TFCLIPPreTrainedModel",
		    "TFCLIPTextModel",
		    "TFCLIPVisionModel",
		]

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowercase				:				Union[str, Any]   		=		[
		    "FlaxCLIPModel",
		    "FlaxCLIPPreTrainedModel",
		    "FlaxCLIPTextModel",
		    "FlaxCLIPTextPreTrainedModel",
		    "FlaxCLIPVisionModel",
		    "FlaxCLIPVisionPreTrainedModel",
		]


if TYPE_CHECKING:
		from .configuration_clip import (
		    CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    CLIPConfig,
		    CLIPOnnxConfig,
		    CLIPTextConfig,
		    CLIPVisionConfig,
		)
		from .processing_clip import CLIPProcessor
		from .tokenization_clip import CLIPTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_clip_fast import CLIPTokenizerFast

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_clip import CLIPFeatureExtractor
				from .image_processing_clip import CLIPImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_clip import (
				    CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    CLIPModel,
				    CLIPPreTrainedModel,
				    CLIPTextModel,
				    CLIPTextModelWithProjection,
				    CLIPVisionModel,
				    CLIPVisionModelWithProjection,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_clip import (
				    TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFCLIPModel,
				    TFCLIPPreTrainedModel,
				    TFCLIPTextModel,
				    TFCLIPVisionModel,
				)

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_clip import (
				    FlaxCLIPModel,
				    FlaxCLIPPreTrainedModel,
				    FlaxCLIPTextModel,
				    FlaxCLIPTextPreTrainedModel,
				    FlaxCLIPVisionModel,
				    FlaxCLIPVisionPreTrainedModel,
				)


else:
		import sys

		_lowercase				:				Union[str, Any]   		=		_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




