


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


SCREAMING_SNAKE_CASE :    Tuple									=				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE :    Tuple									=				{
    """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 			_UpperCAmelCase (							__snake_case				):






		'''simple docstring'''

		lowerCamelCase__				='owlvit_text_model'



		def __init__(self				,       a_=4_94_08				,       a_=5_12				,       a_=20_48				,       a_=12				,       a_=8				,       a_=16				,       a_="quick_gelu"				,       a_=1E-5				,       a_=0.0				,       a_=0.02				,       a_=1.0				,       a_=0				,       a_=4_94_06				,       a_=4_94_07				,       **a_				,       ):





			'''simple docstring'''

			super().__init__(pad_token_id=a_				,       bos_token_id=a_				,       eos_token_id=a_				,       **a_					)

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



		@classmethod
		def 				SCREAMING_SNAKE_CASE  (cls				,       a_				,       **a_					):





			'''simple docstring'''

			cls._set_token_in_kwargs(a_					)

			__snake_case	,							__snake_case	:						Optional[Any]						=				cls.get_config_dict(a_				,       **a_					)

			# get the text config dict if we are loading from OwlViTConfig
			if config_dict.get('''model_type'''					) == "owlvit":
				__snake_case	:						Any						=				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(a_				,       **a_					)



class 			_UpperCAmelCase (							__snake_case				):






		'''simple docstring'''

		lowerCamelCase__				='owlvit_vision_model'



		def __init__(self				,       a_=7_68				,       a_=30_72				,       a_=12				,       a_=12				,       a_=3				,       a_=7_68				,       a_=32				,       a_="quick_gelu"				,       a_=1E-5				,       a_=0.0				,       a_=0.02				,       a_=1.0				,       **a_				,       ):





			'''simple docstring'''

			super().__init__(**a_					)

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



		@classmethod
		def 				SCREAMING_SNAKE_CASE  (cls				,       a_				,       **a_					):





			'''simple docstring'''

			cls._set_token_in_kwargs(a_					)

			__snake_case	,							__snake_case	:						Optional[int]						=				cls.get_config_dict(a_				,       **a_					)

			# get the vision config dict if we are loading from OwlViTConfig
			if config_dict.get('''model_type'''					) == "owlvit":
				__snake_case	:						Dict						=				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(a_				,       **a_					)



class 			_UpperCAmelCase (							__snake_case				):






		'''simple docstring'''

		lowerCamelCase__				='owlvit'
		lowerCamelCase__				=True



		def __init__(self				,       a_=None				,       a_=None				,       a_=5_12				,       a_=2.6592				,       a_=True				,       **a_				,       ):





			'''simple docstring'''

			super().__init__(**a_					)

			if text_config is None:
				__snake_case	:						Union[str, Any]						=				{}
				logger.info('''text_config is None. Initializing the OwlViTTextConfig with default values.'''					)

			if vision_config is None:
				__snake_case	:						Optional[int]						=				{}
				logger.info('''vision_config is None. initializing the OwlViTVisionConfig with default values.'''					)

			__snake_case	:						str						=				OwlViTTextConfig(**a_					)
			__snake_case	:						Union[str, Any]						=				OwlViTVisionConfig(**a_					)

			__snake_case	:						List[str]						=				projection_dim
			__snake_case	:						Optional[int]						=				logit_scale_init_value
			__snake_case	:						List[str]						=				return_dict
			__snake_case	:						List[Any]						=				1.0



		@classmethod
		def 				SCREAMING_SNAKE_CASE  (cls				,       a_				,       **a_					):





			'''simple docstring'''

			cls._set_token_in_kwargs(a_					)

			__snake_case	,							__snake_case	:						int						=				cls.get_config_dict(a_				,       **a_					)

			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(a_				,       **a_					)



		@classmethod
		def 				SCREAMING_SNAKE_CASE  (cls				,       a_				,       a_				,       **a_					):





			'''simple docstring'''

			__snake_case	:						str						=				{}
			__snake_case	:						Dict						=				text_config
			__snake_case	:						Optional[Any]						=				vision_config

			return cls.from_dict(a_				,       **a_					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						str						=				copy.deepcopy(self.__dict__					)
			__snake_case	:						Dict						=				self.text_config.to_dict()
			__snake_case	:						Optional[int]						=				self.vision_config.to_dict()
			__snake_case	:						Tuple						=				self.__class__.model_type
			return output



class 			_UpperCAmelCase (							__snake_case				):






		'''simple docstring'''

		@property
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return OrderedDict(
			    [
			        ('''logits_per_image''', {0: '''batch'''}),
			        ('''logits_per_text''', {0: '''batch'''}),
			        ('''text_embeds''', {0: '''batch'''}),
			        ('''image_embeds''', {0: '''batch'''}),
			    ]					)



		@property
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return 1E-4



		def 				SCREAMING_SNAKE_CASE  (self				,       a_				,       a_ = -1				,       a_ = -1				,       a_ = None				,       ):





			'''simple docstring'''

			__snake_case	:						Union[str, Any]						=				super().generate_dummy_inputs(
			    processor.tokenizer				,       batch_size=a_				,       seq_length=a_				,       framework=a_					)
			__snake_case	:						Any						=				super().generate_dummy_inputs(
			    processor.image_processor				,       batch_size=a_				,       framework=a_					)
			return {**text_input_dict, **image_input_dict}



		@property
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return 14












import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import ClassLabel, Features, Image
from .base import TaskTemplate



@dataclass(frozen=__SCREAMING_SNAKE_CASE    )
class    _SCREAMING_SNAKE_CASE						(	__SCREAMING_SNAKE_CASE    ):







 '''simple docstring'''
 lowercase_		=			field(default="image-classification"    ,							metadata={"include_in_asdict_even_if_is_default": True}    )
 lowercase_		=			Features({"image": Image()}    )
 lowercase_		=			Features({"labels": ClassLabel}    )
 lowercase_		=			"image"
 lowercase_		=			"labels"

 def 							SCREAMING_SNAKE_CASE_					(self				:   Tuple       , UpperCAmelCase_				:   Union[str, Any])       ->Tuple:



   '''simple docstring'''



   if self.label_column not in features:
     raise ValueError(F"""Column {self.label_column} is not present in features.""")
   if not isinstance(features[self.label_column]       , UpperCAmelCase_):
     raise ValueError(F"""Column {self.label_column} is not a ClassLabel.""")
   lowerCamelCase__:      List[Any]			  =copy.deepcopy(self)
   lowerCamelCase__:      Optional[int]			  =self.label_schema.copy()
   lowerCamelCase__:      int			  =features[self.label_column]
   lowerCamelCase__:      int			  =label_schema
   return task_template







 @property
 def 							SCREAMING_SNAKE_CASE_					(self				:   Dict)       ->Dict[str, str]:



   '''simple docstring'''



   return {
       self.image_column: "image",
       self.label_column: "labels",
   }

