




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


UpperCamelCase__			:     str			       =				logging.get_logger(__name__)
class      A__   (   lowercase_  ):
	A_				:					Optional[int]      =   ["""pixel_values"""]




	def __init__( self	:						Dict   ,     lowercase	:						bool = True   ,     lowercase	:						Optional[Dict[str, int]] = None   ,     lowercase	:						PILImageResampling = PILImageResampling.BILINEAR   ,     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	:						Optional[Any]   ,     )       ->			None:
						super().__init__(**lowercase						)
						__snake_case        =						size if size is not None else {"""height""": 224, """width""": 224}
						__snake_case        =						get_size_dict(lowercase						)
						__snake_case        =						do_resize
						__snake_case        =						do_rescale
						__snake_case        =						do_normalize
						__snake_case        =						size
						__snake_case        =						resample
						__snake_case        =						rescale_factor
						__snake_case        =						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
						__snake_case        =						image_std if image_std is not None else IMAGENET_STANDARD_STD




	def 				a_		( self	:						Union[str, Any]   ,     lowercase	:						np.ndarray   ,     lowercase	:						Dict[str, int]   ,     lowercase	:						PILImageResampling = PILImageResampling.BILINEAR   ,     lowercase	:						Optional[Union[str, ChannelDimension]] = None   ,     **lowercase	:						Dict   ,     )       ->			np.ndarray:
						__snake_case        =						get_size_dict(lowercase						)
						if "height" not in size or "width" not in size:
											raise ValueError(f'''The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'''						)
						return resize(
						    lowercase   ,     size=(size["""height"""], size["""width"""])   ,     resample=lowercase   ,     data_format=lowercase   ,     **lowercase						)




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




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




	def 				a_		( self	:						Tuple   ,     lowercase	:						ImageInput   ,     lowercase	:						Optional[bool] = None   ,     lowercase	:						Dict[str, int] = None   ,     lowercase	:						PILImageResampling = 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	:						Union[str, Any]   ,     )       ->			Union[str, Any]:
						__snake_case        =						do_resize if do_resize is not None else self.do_resize
						__snake_case        =						do_rescale if do_rescale is not None else self.do_rescale
						__snake_case        =						do_normalize if do_normalize is not None else self.do_normalize
						__snake_case        =						resample if resample is not None else self.resample
						__snake_case        =						rescale_factor if rescale_factor is not None else self.rescale_factor
						__snake_case        =						image_mean if image_mean is not None else self.image_mean
						__snake_case        =						image_std if image_std is not None else self.image_std

						__snake_case        =						size if size is not None else self.size
						__snake_case        =						get_size_dict(lowercase						)

						__snake_case        =						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_rescale and rescale_factor is None:
											raise ValueError("""Rescale factor must be specified if do_rescale is True."""						)

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

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

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

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

						__snake_case        =						[to_channel_dimension_format(lowercase   ,     lowercase						) for image in images]

						__snake_case        =						{"""pixel_values""": images}
						return BatchFeature(data=lowercase   ,     tensor_type=lowercase						)








"""simple docstring"""

import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig
from ..clip.configuration_clip import CLIPVisionConfig


UpperCamelCase__			:     Optional[Any]			       =				logging.get_logger(__name__)
class      A__   (   lowercase_  ):
	A_				:					List[str]      =   """vision-text-dual-encoder"""
	A_				:					Tuple      =   True




	def __init__( self	:						Tuple   ,     lowercase	:						List[Any]=512   ,     lowercase	:						Any=2.65_92   ,     **lowercase	:						int						)       ->			int:
						super().__init__(**lowercase						)

						if "vision_config" not in kwargs:
											raise ValueError("""`vision_config` can not be `None`."""						)

						if "text_config" not in kwargs:
											raise ValueError("""`text_config` can not be `None`."""						)

						__snake_case        =						kwargs.pop("""vision_config"""						)
						__snake_case        =						kwargs.pop("""text_config"""						)

						__snake_case        =						vision_config.pop("""model_type"""						)
						__snake_case        =						text_config.pop("""model_type"""						)

						if vision_model_type == "clip":
											__snake_case        =						AutoConfig.for_model(lowercase   ,     **lowercase						).vision_config
						elif vision_model_type == "clip_vision_model":
											__snake_case        =						CLIPVisionConfig(**lowercase						)
						else:
											__snake_case        =						AutoConfig.for_model(lowercase   ,     **lowercase						)

						__snake_case        =						AutoConfig.for_model(lowercase   ,     **lowercase						)

						__snake_case        =						projection_dim
						__snake_case        =						logit_scale_init_value




	@classmethod
	def 				a_		( cls	:						Union[str, Any]   ,     lowercase	:						PretrainedConfig   ,     lowercase	:						PretrainedConfig   ,     **lowercase	:						Optional[int]						)       ->			Dict:
						return cls(vision_config=vision_config.to_dict()   ,     text_config=text_config.to_dict()   ,     **lowercase						)




	def 				a_		( self	:						Dict						)       ->			Dict:
						__snake_case        =						copy.deepcopy(self.__dict__						)
						__snake_case        =						self.vision_config.to_dict()
						__snake_case        =						self.text_config.to_dict()
						__snake_case        =						self.__class__.model_type
						return output


