


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


A				:       Any      =  logging.get_logger(__name__)

A				:       str      =  {
    '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(	UpperCamelCase__ ):
					snake_case_		:					str    					=						"""owlvit_text_model"""


					def __init__(    self						:		List[str]  ,     SCREAMING_SNAKE_CASE						:		List[str]=4_9_4_0_8  ,     SCREAMING_SNAKE_CASE						:		str=5_1_2  ,     SCREAMING_SNAKE_CASE						:		Dict=2_0_4_8  ,     SCREAMING_SNAKE_CASE						:		Any=1_2  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any]=8  ,     SCREAMING_SNAKE_CASE						:		Tuple=1_6  ,     SCREAMING_SNAKE_CASE						:		str="quick_gelu"  ,     SCREAMING_SNAKE_CASE						:		Dict=1e-5  ,     SCREAMING_SNAKE_CASE						:		Any=0.0  ,     SCREAMING_SNAKE_CASE						:		Dict=0.02  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any]=1.0  ,     SCREAMING_SNAKE_CASE						:		str=0  ,     SCREAMING_SNAKE_CASE						:		Optional[int]=4_9_4_0_6  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any]=4_9_4_0_7  ,     **SCREAMING_SNAKE_CASE						:		List[str]  ,     )      ->						Optional[Any]:




											'''simple docstring'''

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

											__snake_case				=		vocab_size
											__snake_case				=		hidden_size
											__snake_case				=		intermediate_size
											__snake_case				=		num_hidden_layers
											__snake_case				=		num_attention_heads
											__snake_case				=		max_position_embeddings
											__snake_case				=		hidden_act
											__snake_case				=		layer_norm_eps
											__snake_case				=		attention_dropout
											__snake_case				=		initializer_range
											__snake_case				=		initializer_factor






					@classmethod
					def 				SCREAMING_SNAKE_CASE_	(    cls						:		Dict  ,     SCREAMING_SNAKE_CASE						:		List[str]  ,     **SCREAMING_SNAKE_CASE						:		Optional[Any]    )      ->						List[str]:




											'''simple docstring'''

											cls._set_token_in_kwargs(__lowerCamelCase    )

											__snake_case		,       __snake_case				=		cls.get_config_dict(__lowerCamelCase  ,     **__lowerCamelCase    )

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






class      UpperCamelCase(	UpperCamelCase__ ):
					snake_case_		:					Optional[Any]    					=						"""owlvit_vision_model"""


					def __init__(    self						:		Optional[int]  ,     SCREAMING_SNAKE_CASE						:		int=7_6_8  ,     SCREAMING_SNAKE_CASE						:		Optional[int]=3_0_7_2  ,     SCREAMING_SNAKE_CASE						:		Optional[int]=1_2  ,     SCREAMING_SNAKE_CASE						:		Tuple=1_2  ,     SCREAMING_SNAKE_CASE						:		Tuple=3  ,     SCREAMING_SNAKE_CASE						:		Optional[int]=7_6_8  ,     SCREAMING_SNAKE_CASE						:		Optional[int]=3_2  ,     SCREAMING_SNAKE_CASE						:		Tuple="quick_gelu"  ,     SCREAMING_SNAKE_CASE						:		str=1e-5  ,     SCREAMING_SNAKE_CASE						:		Tuple=0.0  ,     SCREAMING_SNAKE_CASE						:		str=0.02  ,     SCREAMING_SNAKE_CASE						:		Any=1.0  ,     **SCREAMING_SNAKE_CASE						:		Union[str, Any]  ,     )      ->						Any:




											'''simple docstring'''

											super().__init__(**__lowerCamelCase    )

											__snake_case				=		hidden_size
											__snake_case				=		intermediate_size
											__snake_case				=		num_hidden_layers
											__snake_case				=		num_attention_heads
											__snake_case				=		num_channels
											__snake_case				=		image_size
											__snake_case				=		patch_size
											__snake_case				=		hidden_act
											__snake_case				=		layer_norm_eps
											__snake_case				=		attention_dropout
											__snake_case				=		initializer_range
											__snake_case				=		initializer_factor






					@classmethod
					def 				SCREAMING_SNAKE_CASE_	(    cls						:		Optional[int]  ,     SCREAMING_SNAKE_CASE						:		List[str]  ,     **SCREAMING_SNAKE_CASE						:		List[Any]    )      ->						int:




											'''simple docstring'''

											cls._set_token_in_kwargs(__lowerCamelCase    )

											__snake_case		,       __snake_case				=		cls.get_config_dict(__lowerCamelCase  ,     **__lowerCamelCase    )

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






class      UpperCamelCase(	UpperCamelCase__ ):
					snake_case_		:					Dict    					=						"""owlvit"""
					snake_case_		:					List[Any]    					=						True


					def __init__(    self						:		Optional[int]  ,     SCREAMING_SNAKE_CASE						:		List[Any]=None  ,     SCREAMING_SNAKE_CASE						:		str=None  ,     SCREAMING_SNAKE_CASE						:		Any=5_1_2  ,     SCREAMING_SNAKE_CASE						:		Dict=2.6592  ,     SCREAMING_SNAKE_CASE						:		Optional[Any]=True  ,     **SCREAMING_SNAKE_CASE						:		Union[str, Any]  ,     )      ->						Any:




											'''simple docstring'''

											super().__init__(**__lowerCamelCase    )

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

											if vision_config is None:
																	__snake_case				=		{}
																	logger.info("vision_config is None. initializing the OwlViTVisionConfig with default values."    )

											__snake_case				=		OwlViTTextConfig(**__lowerCamelCase    )
											__snake_case				=		OwlViTVisionConfig(**__lowerCamelCase    )

											__snake_case				=		projection_dim
											__snake_case				=		logit_scale_init_value
											__snake_case				=		return_dict
											__snake_case				=		1.0


					@classmethod
					def 				SCREAMING_SNAKE_CASE_	(    cls						:		Any  ,     SCREAMING_SNAKE_CASE						:		Dict  ,     **SCREAMING_SNAKE_CASE						:		Optional[Any]    )      ->						Optional[Any]:




											'''simple docstring'''

											cls._set_token_in_kwargs(__lowerCamelCase    )

											__snake_case		,       __snake_case				=		cls.get_config_dict(__lowerCamelCase  ,     **__lowerCamelCase    )

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


					@classmethod
					def 				SCREAMING_SNAKE_CASE_	(    cls						:		Tuple  ,     SCREAMING_SNAKE_CASE						:		str  ,     SCREAMING_SNAKE_CASE						:		Dict  ,     **SCREAMING_SNAKE_CASE						:		Tuple    )      ->						Any:




											'''simple docstring'''

											__snake_case				=		{}
											__snake_case				=		text_config
											__snake_case				=		vision_config

											return cls.from_dict(__lowerCamelCase  ,     **__lowerCamelCase    )






					def 				SCREAMING_SNAKE_CASE_	(    self						:		List[Any]    )      ->						Optional[Any]:




											'''simple docstring'''

											__snake_case				=		copy.deepcopy(self.__dict__    )
											__snake_case				=		self.text_config.to_dict()
											__snake_case				=		self.vision_config.to_dict()
											__snake_case				=		self.__class__.model_type
											return output






class      UpperCamelCase(	UpperCamelCase__ ):


					@property
					def 				SCREAMING_SNAKE_CASE_	(    self						:		Optional[int]    )      ->						int:




											'''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						:		List[Any]    )      ->						Union[str, Any]:




											'''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						:		str    )      ->						Dict:




											'''simple docstring'''

											return 1e-4


					def 				SCREAMING_SNAKE_CASE_	(    self						:		int  ,     SCREAMING_SNAKE_CASE						:		Tuple  ,     SCREAMING_SNAKE_CASE						:		Dict = -1  ,     SCREAMING_SNAKE_CASE						:		Dict = -1  ,     SCREAMING_SNAKE_CASE						:		str = None  ,     )      ->						List[Any]:




											'''simple docstring'''

											__snake_case				=		super().generate_dummy_inputs(
											    processor.tokenizer  ,     batch_size=__lowerCamelCase  ,     seq_length=__lowerCamelCase  ,     framework=__lowerCamelCase    )
											__snake_case				=		super().generate_dummy_inputs(
											    processor.image_processor  ,     batch_size=__lowerCamelCase  ,     framework=__lowerCamelCase    )
											return {**text_input_dict, **image_input_dict}






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




											'''simple docstring'''

											return 1_4












import copy
from collections import OrderedDict
from typing import Mapping

from packaging import version

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


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

a__: Any							   =						{
    'microsoft/conditional-detr-resnet-50': (
        'https://huggingface.co/microsoft/conditional-detr-resnet-50/resolve/main/config.json'
    ),
}




class        SCREAMING_SNAKE_CASE__					(		UpperCamelCase__ ):
 __SCREAMING_SNAKE_CASE							=      '''conditional_detr'''
 __SCREAMING_SNAKE_CASE							=      ['''past_key_values''']
 __SCREAMING_SNAKE_CASE							=      {
     '''hidden_size''': '''d_model''',
     '''num_attention_heads''': '''encoder_attention_heads''',
 }



 def __init__(				self,__lowerCamelCase=True,__lowerCamelCase=None,__lowerCamelCase=3,__lowerCamelCase=300,__lowerCamelCase=6,__lowerCamelCase=2048,__lowerCamelCase=8,__lowerCamelCase=6,__lowerCamelCase=2048,__lowerCamelCase=8,__lowerCamelCase=0.0,__lowerCamelCase=0.0,__lowerCamelCase=True,__lowerCamelCase="relu",__lowerCamelCase=256,__lowerCamelCase=0.1,__lowerCamelCase=0.0,__lowerCamelCase=0.0,__lowerCamelCase=0.02,__lowerCamelCase=1.0,__lowerCamelCase=False,__lowerCamelCase="sine",__lowerCamelCase="resnet50",__lowerCamelCase=True,__lowerCamelCase=False,__lowerCamelCase=2,__lowerCamelCase=5,__lowerCamelCase=2,__lowerCamelCase=1,__lowerCamelCase=1,__lowerCamelCase=2,__lowerCamelCase=5,__lowerCamelCase=2,__lowerCamelCase=0.25,**__lowerCamelCase,):
        if backbone_config is not None and use_timm_backbone:
               raise ValueError('''You can\'t specify both `backbone_config` and `use_timm_backbone`.'''					)

        if not use_timm_backbone:
               if backbone_config is None:
                      logger.info('''`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.'''					)
                      A__		   =		CONFIG_MAPPING['''resnet'''](out_features=['''stage4''']					)
               elif isinstance(__lowerCamelCase,__lowerCamelCase					):
                      A__		   =		backbone_config.get('''model_type'''					)
                      A__		   =		CONFIG_MAPPING[backbone_model_type]
                      A__		   =		config_class.from_dict(__lowerCamelCase					)

        A__		   =		use_timm_backbone
        A__		   =		backbone_config
        A__		   =		num_channels
        A__		   =		num_queries
        A__		   =		d_model
        A__		   =		encoder_ffn_dim
        A__		   =		encoder_layers
        A__		   =		encoder_attention_heads
        A__		   =		decoder_ffn_dim
        A__		   =		decoder_layers
        A__		   =		decoder_attention_heads
        A__		   =		dropout
        A__		   =		attention_dropout
        A__		   =		activation_dropout
        A__		   =		activation_function
        A__		   =		init_std
        A__		   =		init_xavier_std
        A__		   =		encoder_layerdrop
        A__		   =		decoder_layerdrop
        A__		   =		encoder_layers
        A__		   =		auxiliary_loss
        A__		   =		position_embedding_type
        A__		   =		backbone
        A__		   =		use_pretrained_backbone
        A__		   =		dilation
        # Hungarian matcher
        A__		   =		class_cost
        A__		   =		bbox_cost
        A__		   =		giou_cost
        # Loss coefficients
        A__		   =		mask_loss_coefficient
        A__		   =		dice_loss_coefficient
        A__		   =		cls_loss_coefficient
        A__		   =		bbox_loss_coefficient
        A__		   =		giou_loss_coefficient
        A__		   =		focal_alpha
        super().__init__(is_encoder_decoder=__lowerCamelCase,**__lowerCamelCase					)



 @property
 def 							UpperCamelCase     (				self					):
        return self.encoder_attention_heads



 @property
 def 							UpperCamelCase     (				self					):
        return self.d_model




 def 							UpperCamelCase     (				self					):
        A__		   =		copy.deepcopy(self.__dict__					)
        if self.backbone_config is not None:
               A__		   =		self.backbone_config.to_dict()
        A__		   =		self.__class__.model_type
        return output




class        SCREAMING_SNAKE_CASE__					(		UpperCamelCase__ ):
 __SCREAMING_SNAKE_CASE							=      version.parse('''1.11''' )



 @property
 def 							UpperCamelCase     (				self					):
        return OrderedDict(
            [
                ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
                ('''pixel_mask''', {0: '''batch'''}),
            ]					)



 @property
 def 							UpperCamelCase     (				self					):
        return 1E-5




 @property
 def 							UpperCamelCase     (				self					):
        return 12





