





import copy
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union


if TYPE_CHECKING:
				from ...processing_utils import ProcessorMixin
				from ...utils import TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__lowercase       :Optional[Any]       =  logging.get_logger(__name__)

__lowercase       :Any       =  {
    '''google/owlvit-base-patch32''': '''https://huggingface.co/google/owlvit-base-patch32/resolve/main/config.json''',
    '''google/owlvit-base-patch16''': '''https://huggingface.co/google/owlvit-base-patch16/resolve/main/config.json''',
    '''google/owlvit-large-patch14''': '''https://huggingface.co/google/owlvit-large-patch14/resolve/main/config.json''',
}



class    _a     (				__UpperCAmelCase							):






							"""simple docstring"""

							snake_case_							 =						'''owlvit_text_model'''

							def __init__(      self				:     str							,	a				:     Dict=4_94_08							,	a				:     Optional[int]=5_12							,	a				:     str=20_48							,	a				:     int=12							,	a				:     List[str]=8							,	a				:     Dict=16							,	a				:     Union[str, Any]="quick_gelu"							,	a				:     Optional[Any]=1E-5							,	a				:     List[str]=0.0							,	a				:     str=0.02							,	a				:     List[Any]=1.0							,	a				:     Dict=0							,	a				:     Tuple=4_94_06							,	a				:     List[Any]=4_94_07							,	**a				:     Union[str, Any]							,	)	->Optional[int]:
													super().__init__(pad_token_id=__SCREAMING_SNAKE_CASE							,	bos_token_id=__SCREAMING_SNAKE_CASE							,	eos_token_id=__SCREAMING_SNAKE_CASE							,	**__SCREAMING_SNAKE_CASE    )

													SCREAMING_SNAKE_CASE__     :				int   =					vocab_size
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					hidden_size
													SCREAMING_SNAKE_CASE__     :				Dict   =					intermediate_size
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					num_hidden_layers
													SCREAMING_SNAKE_CASE__     :				Tuple   =					num_attention_heads
													SCREAMING_SNAKE_CASE__     :				int   =					max_position_embeddings
													SCREAMING_SNAKE_CASE__     :				Tuple   =					hidden_act
													SCREAMING_SNAKE_CASE__     :				List[str]   =					layer_norm_eps
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					attention_dropout
													SCREAMING_SNAKE_CASE__     :				List[str]   =					initializer_range
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					initializer_factor






							@classmethod
							def      A_  (      cls				:     Tuple							,	a				:     Union[str, os.PathLike]							,	**a				:     List[Any]    )	->Dict:
													cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE    )

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				int   =					cls.get_config_dict(__SCREAMING_SNAKE_CASE							,	**__SCREAMING_SNAKE_CASE    )

													# get the text config dict if we are loading from OwlViTConfig
													if config_dict.get("model_type"    ) == "owlvit":
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					config_dict["text_config"]

													if "model_type" in config_dict and hasattr(cls							,	"model_type"    ) and config_dict["model_type"] != cls.model_type:
																			logger.warning(
																			    f"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
																			    f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""    )

													return cls.from_dict(__SCREAMING_SNAKE_CASE							,	**__SCREAMING_SNAKE_CASE    )







class    _a     (				__UpperCAmelCase							):






							"""simple docstring"""

							snake_case_							 =						'''owlvit_vision_model'''

							def __init__(      self				:     str							,	a				:     Union[str, Any]=7_68							,	a				:     Union[str, Any]=30_72							,	a				:     List[Any]=12							,	a				:     Any=12							,	a				:     Union[str, Any]=3							,	a				:     str=7_68							,	a				:     Optional[Any]=32							,	a				:     Union[str, Any]="quick_gelu"							,	a				:     List[str]=1E-5							,	a				:     str=0.0							,	a				:     List[str]=0.02							,	a				:     Optional[int]=1.0							,	**a				:     Union[str, Any]							,	)	->Any:
													super().__init__(**__SCREAMING_SNAKE_CASE    )

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					hidden_size
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					intermediate_size
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					num_hidden_layers
													SCREAMING_SNAKE_CASE__     :				Dict   =					num_attention_heads
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					num_channels
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					image_size
													SCREAMING_SNAKE_CASE__     :				Tuple   =					patch_size
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					hidden_act
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					layer_norm_eps
													SCREAMING_SNAKE_CASE__     :				List[str]   =					attention_dropout
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					initializer_range
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					initializer_factor






							@classmethod
							def      A_  (      cls				:     Tuple							,	a				:     Union[str, os.PathLike]							,	**a				:     str    )	->Dict:
													cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE    )

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				List[Any]   =					cls.get_config_dict(__SCREAMING_SNAKE_CASE							,	**__SCREAMING_SNAKE_CASE    )

													# get the vision config dict if we are loading from OwlViTConfig
													if config_dict.get("model_type"    ) == "owlvit":
																			SCREAMING_SNAKE_CASE__     :				int   =					config_dict["vision_config"]

													if "model_type" in config_dict and hasattr(cls							,	"model_type"    ) and config_dict["model_type"] != cls.model_type:
																			logger.warning(
																			    f"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
																			    f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""    )

													return cls.from_dict(__SCREAMING_SNAKE_CASE							,	**__SCREAMING_SNAKE_CASE    )







class    _a     (				__UpperCAmelCase							):






							"""simple docstring"""

							snake_case_							 =						'''owlvit'''
							snake_case_							 =						True

							def __init__(      self				:     Optional[Any]							,	a				:     int=None							,	a				:     Optional[Any]=None							,	a				:     Dict=5_12							,	a				:     str=2.6592							,	a				:     Dict=True							,	**a				:     Optional[Any]							,	)	->Dict:
													super().__init__(**__SCREAMING_SNAKE_CASE    )

													if text_config is None:
																			SCREAMING_SNAKE_CASE__     :				int   =					{}
																			logger.info("text_config is None. Initializing the OwlViTTextConfig with default values."    )

													if vision_config is None:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					{}
																			logger.info("vision_config is None. initializing the OwlViTVisionConfig with default values."    )

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					OwlViTTextConfig(**__SCREAMING_SNAKE_CASE    )
													SCREAMING_SNAKE_CASE__     :				str   =					OwlViTVisionConfig(**__SCREAMING_SNAKE_CASE    )

													SCREAMING_SNAKE_CASE__     :				List[str]   =					projection_dim
													SCREAMING_SNAKE_CASE__     :				Dict   =					logit_scale_init_value
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					return_dict
													SCREAMING_SNAKE_CASE__     :				int   =					1.0

							@classmethod
							def      A_  (      cls				:     str							,	a				:     Union[str, os.PathLike]							,	**a				:     Any    )	->Union[str, Any]:
													cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE    )

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				str   =					cls.get_config_dict(__SCREAMING_SNAKE_CASE							,	**__SCREAMING_SNAKE_CASE    )

													if "model_type" in config_dict and hasattr(cls							,	"model_type"    ) and config_dict["model_type"] != cls.model_type:
																			logger.warning(
																			    f"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
																			    f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""    )

													return cls.from_dict(__SCREAMING_SNAKE_CASE							,	**__SCREAMING_SNAKE_CASE    )

							@classmethod
							def      A_  (      cls				:     Union[str, Any]							,	a				:     Dict							,	a				:     Dict							,	**a				:     str    )	->str:
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					{}
													SCREAMING_SNAKE_CASE__     :				str   =					text_config
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					vision_config

													return cls.from_dict(__SCREAMING_SNAKE_CASE							,	**__SCREAMING_SNAKE_CASE    )






							def      A_  (      self				:     Dict    )	->str:
													SCREAMING_SNAKE_CASE__     :				int   =					copy.deepcopy(self.__dict__    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					self.text_config.to_dict()
													SCREAMING_SNAKE_CASE__     :				str   =					self.vision_config.to_dict()
													SCREAMING_SNAKE_CASE__     :				str   =					self.__class__.model_type
													return output







class    _a     (				__UpperCAmelCase							):






							"""simple docstring"""

							@property
							def      A_  (      self				:     Optional[Any]    )	->Tuple:
													return OrderedDict(
													    [
													        ("input_ids", {0: "batch", 1: "sequence"}),
													        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
													        ("attention_mask", {0: "batch", 1: "sequence"}),
													    ]    )

							@property
							def      A_  (      self				:     List[Any]    )	->Union[str, Any]:
													return OrderedDict(
													    [
													        ("logits_per_image", {0: "batch"}),
													        ("logits_per_text", {0: "batch"}),
													        ("text_embeds", {0: "batch"}),
													        ("image_embeds", {0: "batch"}),
													    ]    )

							@property
							def      A_  (      self				:     List[Any]    )	->Union[str, Any]:
													return 1E-4

							def      A_  (      self				:     int							,	a				:     "ProcessorMixin"							,	a				:     int = -1							,	a				:     int = -1							,	a				:     Optional["TensorType"] = None							,	)	->List[str]:
													SCREAMING_SNAKE_CASE__     :				Tuple   =					super().generate_dummy_inputs(
													    processor.tokenizer							,	batch_size=__SCREAMING_SNAKE_CASE							,	seq_length=__SCREAMING_SNAKE_CASE							,	framework=__SCREAMING_SNAKE_CASE    )
													SCREAMING_SNAKE_CASE__     :				Dict   =					super().generate_dummy_inputs(
													    processor.image_processor							,	batch_size=__SCREAMING_SNAKE_CASE							,	framework=__SCREAMING_SNAKE_CASE    )
													return {**text_input_dict, **image_input_dict}






							@property
							def      A_  (      self				:     List[Any]    )	->Union[str, Any]:
													return 14






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    _a     (				lowercase__							):






							"""simple docstring"""

							snake_case_							 =						["pixel_values"]

							def __init__(      self				:     int							,	a				:     bool = True							,	a				:     Optional[Dict[str, int]] = None							,	a				:     PILImageResampling = PILImageResampling.BILINEAR							,	a				:     bool = True							,	a				:     Dict[str, int] = None							,	a				:     bool = True							,	a				:     Union[int, float] = 1 / 2_55							,	a				:     bool = True							,	a				:     Optional[Union[float, List[float]]] = None							,	a				:     Optional[Union[float, List[float]]] = None							,	**a				:     List[str]							,	)	->None:
													super().__init__(**a    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					size if size is not None else {"shortest_edge": 2_56}
													SCREAMING_SNAKE_CASE__     :				Any   =					get_size_dict(a							,	default_to_square=a    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
													SCREAMING_SNAKE_CASE__     :				Dict   =					get_size_dict(a    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					do_resize
													SCREAMING_SNAKE_CASE__     :				List[str]   =					size
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					resample
													SCREAMING_SNAKE_CASE__     :				int   =					do_center_crop
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					crop_size
													SCREAMING_SNAKE_CASE__     :				Any   =					do_rescale
													SCREAMING_SNAKE_CASE__     :				Any   =					rescale_factor
													SCREAMING_SNAKE_CASE__     :				int   =					do_normalize
													SCREAMING_SNAKE_CASE__     :				str   =					image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
													SCREAMING_SNAKE_CASE__     :				int   =					image_std if image_std is not None else IMAGENET_STANDARD_STD

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

							def      A_  (      self				:     List[Any]							,	a				:     np.ndarray							,	a				:     Dict[str, int]							,	a				:     Optional[Union[str, ChannelDimension]] = None							,	**a				:     List[Any]							,	)	->np.ndarray:
													SCREAMING_SNAKE_CASE__     :				Tuple   =					get_size_dict(a    )
													return center_crop(a							,	size=(size["height"], size["width"])							,	data_format=a							,	**a    )

							def      A_  (      self				:     Optional[int]							,	a				:     np.ndarray							,	a				:     float							,	a				:     Optional[Union[str, ChannelDimension]] = None							,	**a				:     Dict    )	->np.ndarray:
													return rescale(a							,	scale=a							,	data_format=a							,	**a    )

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






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

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					make_list_of_images(a    )

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

													if do_resize:
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					[self.resize(image=a							,	size=a							,	resample=a    ) for image in images]

													if do_center_crop:
																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					[self.center_crop(image=a							,	size=a    ) for image in images]

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

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

													SCREAMING_SNAKE_CASE__     :				Dict   =					[to_channel_dimension_format(a							,	a    ) for image in images]

													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					{"pixel_values": images}
													return BatchFeature(data=a							,	tensor_type=a    )