'''simple docstring'''




import copy

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


__lowercase          =  logging.get_logger(__name__)

__lowercase          =  {
    'ut/deta': 'https://huggingface.co/ut/deta/resolve/main/config.json',
}






class 				a__(					lowerCAmelCase__	):


			'''simple docstring'''






			UpperCAmelCase_			:     List[Any]      =       '''deta'''
			UpperCAmelCase_			:     Dict      =       {
			    '''hidden_size''': '''d_model''',
			    '''num_attention_heads''': '''encoder_attention_heads''',
			}



			def __init__(   self       ,    __lowerCAmelCase=None       ,    __lowerCAmelCase=900       ,    __lowerCAmelCase=2048       ,    __lowerCAmelCase=6       ,    __lowerCAmelCase=2048       ,    __lowerCAmelCase=8       ,    __lowerCAmelCase=6       ,    __lowerCAmelCase=1024       ,    __lowerCAmelCase=8       ,    __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=True       ,    __lowerCAmelCase=False       ,    __lowerCAmelCase="sine"       ,    __lowerCAmelCase=5       ,    __lowerCAmelCase=4       ,    __lowerCAmelCase=4       ,    __lowerCAmelCase=True       ,    __lowerCAmelCase=300       ,    __lowerCAmelCase=True       ,    __lowerCAmelCase=True       ,    __lowerCAmelCase=1       ,    __lowerCAmelCase=5       ,    __lowerCAmelCase=2       ,    __lowerCAmelCase=1       ,    __lowerCAmelCase=1       ,    __lowerCAmelCase=5       ,    __lowerCAmelCase=2       ,    __lowerCAmelCase=0.1       ,    __lowerCAmelCase=0.25       ,    **__lowerCAmelCase       ,    ):




					"""simple docstring"""


					if backbone_config is None:
							logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.""")
							lowerCAmelCase   					=  CONFIG_MAPPING["""resnet"""](out_features=["""stage2""", """stage3""", """stage4"""])
					else:
							if isinstance(__lowerCAmelCase       ,    __lowerCAmelCase):
									lowerCAmelCase   					=  backbone_config.pop("""model_type""")
									lowerCAmelCase   					=  CONFIG_MAPPING[backbone_model_type]
									lowerCAmelCase   					=  config_class.from_dict(__lowerCAmelCase)

					lowerCAmelCase   					=  backbone_config
					lowerCAmelCase   					=  num_queries
					lowerCAmelCase   					=  max_position_embeddings
					lowerCAmelCase   					=  d_model
					lowerCAmelCase   					=  encoder_ffn_dim
					lowerCAmelCase   					=  encoder_layers
					lowerCAmelCase   					=  encoder_attention_heads
					lowerCAmelCase   					=  decoder_ffn_dim
					lowerCAmelCase   					=  decoder_layers
					lowerCAmelCase   					=  decoder_attention_heads
					lowerCAmelCase   					=  dropout
					lowerCAmelCase   					=  attention_dropout
					lowerCAmelCase   					=  activation_dropout
					lowerCAmelCase   					=  activation_function
					lowerCAmelCase   					=  init_std
					lowerCAmelCase   					=  init_xavier_std
					lowerCAmelCase   					=  encoder_layerdrop
					lowerCAmelCase   					=  auxiliary_loss
					lowerCAmelCase   					=  position_embedding_type
					# deformable attributes
					lowerCAmelCase   					=  num_feature_levels
					lowerCAmelCase   					=  encoder_n_points
					lowerCAmelCase   					=  decoder_n_points
					lowerCAmelCase   					=  two_stage
					lowerCAmelCase   					=  two_stage_num_proposals
					lowerCAmelCase   					=  with_box_refine
					lowerCAmelCase   					=  assign_first_stage
					if two_stage is True and with_box_refine is False:
							raise ValueError("""If two_stage is True, with_box_refine must be True.""")
					# Hungarian matcher
					lowerCAmelCase   					=  class_cost
					lowerCAmelCase   					=  bbox_cost
					lowerCAmelCase   					=  giou_cost
					# Loss coefficients
					lowerCAmelCase   					=  mask_loss_coefficient
					lowerCAmelCase   					=  dice_loss_coefficient
					lowerCAmelCase   					=  bbox_loss_coefficient
					lowerCAmelCase   					=  giou_loss_coefficient
					lowerCAmelCase   					=  eos_coefficient
					lowerCAmelCase   					=  focal_alpha
					super().__init__(is_encoder_decoder=__lowerCAmelCase       ,    **__lowerCAmelCase)



			@property
			def 							a_       (   self):




					"""simple docstring"""


					return self.encoder_attention_heads



			@property
			def 							a_       (   self):




					"""simple docstring"""


					return self.d_model







			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  copy.deepcopy(self.__dict__)
					lowerCAmelCase   					=  self.backbone_config.to_dict()
					lowerCAmelCase   					=  self.__class__.model_type
					return output








"""simple docstring"""






from importlib import import_module

from .logging import get_logger


UpperCAmelCase    :     Any   						=		get_logger(__name__)





class      lowerCamelCase__   :







					"""simple docstring"""


					def __init__(       self    : Optional[int] ,       UpperCamelCase    : List[Any] ,       UpperCamelCase    : int=None  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Tuple      							=					attrs or []
												if module is not None:
																			for key in module.__dict__:
																										if key in attrs or not key.startswith("""__"""  ):
																																	setattr(self ,       UpperCamelCase ,       getattr(UpperCamelCase ,       UpperCamelCase  )  )
												__UpperCAmelCase   :						Any      							=					module._original_module if isinstance(UpperCamelCase ,       _PatchedModuleObj  ) else module






class      lowerCamelCase__   :







					"""simple docstring"""


					__a	       =							[]






					def __init__(       self    : str ,       UpperCamelCase    : Tuple ,       UpperCamelCase    : str ,       UpperCamelCase    : List[str] ,       UpperCamelCase    : Optional[Any]=None  ):
												'''simple docstring'''






												__UpperCAmelCase   :						int      							=					obj
												__UpperCAmelCase   :						Union[str, Any]      							=					target
												__UpperCAmelCase   :						List[str]      							=					new
												__UpperCAmelCase   :						Optional[int]      							=					target.split("""."""  )[0]
												__UpperCAmelCase   :						Tuple      							=					{}
												__UpperCAmelCase   :						Union[str, Any]      							=					attrs or []






					def __enter__(       self    : Dict  ):
												'''simple docstring'''






												*__UpperCAmelCase							,__UpperCAmelCase   :						str      							=					self.target.split("""."""  )

												# Patch modules:
												# it's used to patch attributes of submodules like "os.path.join";
												# in this case we need to patch "os" and "os.path"

												for i in range(len(UpperCamelCase  )  ):
																			try:
																										__UpperCAmelCase   :						List[Any]      							=					import_module(""".""".join(submodules[: i + 1]  )  )
																			except ModuleNotFoundError:
																										continue
																			# We iterate over all the globals in self.obj in case we find "os" or "os.path"
																			for attr in self.obj.__dir__():
																										__UpperCAmelCase   :						List[Any]      							=					getattr(self.obj ,       UpperCamelCase  )
																										# We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
																										# This allows to patch renamed modules like "from os import path as ospath".
																										if obj_attr is submodule or (
																										    (isinstance(UpperCamelCase ,       _PatchedModuleObj  ) and obj_attr._original_module is submodule)
																										):
																																	__UpperCAmelCase   :						Tuple      							=					obj_attr
																																	# patch at top level
																																	setattr(self.obj ,       UpperCamelCase ,       _PatchedModuleObj(UpperCamelCase ,       attrs=self.attrs  )  )
																																	__UpperCAmelCase   :						int      							=					getattr(self.obj ,       UpperCamelCase  )
																																	# construct lower levels patches
																																	for key in submodules[i + 1 :]:
																																								setattr(UpperCamelCase ,       UpperCamelCase ,       _PatchedModuleObj(getattr(UpperCamelCase ,       UpperCamelCase ,       UpperCamelCase  ) ,       attrs=self.attrs  )  )
																																								__UpperCAmelCase   :						Optional[int]      							=					getattr(UpperCamelCase ,       UpperCamelCase  )
																																	# finally set the target attribute
																																	setattr(UpperCamelCase ,       UpperCamelCase ,       self.new  )

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

												if submodules:  # if it's an attribute of a submodule like "os.path.join"
																			try:
																										__UpperCAmelCase   :						int      							=					getattr(import_module(""".""".join(UpperCamelCase  )  ) ,       UpperCamelCase  )
																			except (AttributeError, ModuleNotFoundError):
																										return
																			# We iterate over all the globals in self.obj in case we find "os.path.join"
																			for attr in self.obj.__dir__():
																										# We don't check for the name of the global, but rather if its value *is* "os.path.join".
																										# This allows to patch renamed attributes like "from os.path import join as pjoin".
																										if getattr(self.obj ,       UpperCamelCase  ) is attr_value:
																																	__UpperCAmelCase   :						Union[str, Any]      							=					getattr(self.obj ,       UpperCamelCase  )
																																	setattr(self.obj ,       UpperCamelCase ,       self.new  )
												elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
																			__UpperCAmelCase   :						str      							=					globals()["""__builtins__"""][target_attr]
																			setattr(self.obj ,       UpperCamelCase ,       self.new  )
												else:
																			raise RuntimeError(f'''Tried to patch attribute {target_attr} instead of a submodule.'''  )






					def __exit__(       self    : str ,       *UpperCamelCase    : Optional[int]  ):
												'''simple docstring'''






												for attr in list(self.original  ):
																			setattr(self.obj ,       UpperCamelCase ,       self.original.pop(UpperCamelCase  )  )






					def lowerCamelCase__							(       self    : int  ):
												'''simple docstring'''






												self.__enter__()
												self._active_patches.append(self  )






					def lowerCamelCase__							(       self    : List[Any]  ):
												'''simple docstring'''






												try:
																			self._active_patches.remove(self  )
												except ValueError:
																			# If the patch hasn't been started this will fail
																			return None

												return self.__exit__()
