
'''simple docstring'''
import copy
from collections import OrderedDict
from typing import Dict, Mapping

from packaging import version

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


__lowerCAmelCase												=	logging.get_logger(__name__)

__lowerCAmelCase												=	{
    'facebook/detr-resnet-50': 'https://huggingface.co/facebook/detr-resnet-50/resolve/main/config.json',
    # See all DETR models at https://huggingface.co/models?filter=detr
}


class       _lowerCAmelCase   (   __snake_case				):







							'''simple docstring'''

							lowerCAmelCase_ 						=						"detr"
							lowerCAmelCase_ 						=						["past_key_values"]
							lowerCAmelCase_ 						=						{
							    "hidden_size": "d_model",
							    "num_attention_heads": "encoder_attention_heads",
							}

							def __init__(self  ,  UpperCAmelCase=True  ,  UpperCAmelCase=None  ,  UpperCAmelCase=3  ,  UpperCAmelCase=100  ,  UpperCAmelCase=6  ,  UpperCAmelCase=2048  ,  UpperCAmelCase=8  ,  UpperCAmelCase=6  ,  UpperCAmelCase=2048  ,  UpperCAmelCase=8  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=True  ,  UpperCAmelCase="relu"  ,  UpperCAmelCase=256  ,  UpperCAmelCase=0.1  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.02  ,  UpperCAmelCase=1.0  ,  UpperCAmelCase=False  ,  UpperCAmelCase="sine"  ,  UpperCAmelCase="resnet50"  ,  UpperCAmelCase=True  ,  UpperCAmelCase=False  ,  UpperCAmelCase=1  ,  UpperCAmelCase=5  ,  UpperCAmelCase=2  ,  UpperCAmelCase=1  ,  UpperCAmelCase=1  ,  UpperCAmelCase=5  ,  UpperCAmelCase=2  ,  UpperCAmelCase=0.1  ,  **UpperCAmelCase  ,  )					->       int:
														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."""  )
																												_snake_case       =  CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]  )
																					elif isinstance(UpperCAmelCase  ,  UpperCAmelCase  ):
																												_snake_case       =  backbone_config.get("""model_type"""  )
																												_snake_case       =  CONFIG_MAPPING[backbone_model_type]
																												_snake_case       =  config_class.from_dict(UpperCAmelCase  )
																					# set timm attributes to None
																					_snake_case,							_snake_case,							_snake_case       =  None, None, None

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

							@property
							def 	lowercase							(self  )					->       int:
														return self.encoder_attention_heads

							@property
							def 	lowercase							(self  )					->       int:
														return self.d_model

							@classmethod
							def 	lowercase							(cls  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       Optional[int]:
														return cls(backbone_config=UpperCAmelCase  ,  **UpperCAmelCase  )





							def 	lowercase							(self  )					->       Dict[str, any]:
														_snake_case       =  copy.deepcopy(self.__dict__  )
														if output["backbone_config"] is not None:
																					_snake_case       =  self.backbone_config.to_dict()
														_snake_case       =  self.__class__.model_type
														return output


class       _lowerCAmelCase   (   __snake_case				):







							'''simple docstring'''

							lowerCAmelCase_ 						=						version.parse("1.11"				)

							@property
							def 	lowercase							(self  )					->       Mapping[str, Mapping[int, str]]:
														return OrderedDict(
														    [
														        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
														        ("""pixel_mask""", {0: """batch"""}),
														    ]  )

							@property
							def 	lowercase							(self  )					->       float:
														return 1e-5





							@property
							def 	lowercase							(self  )					->       int:
														return 12

'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__lowerCAmelCase												=	logging.get_logger(__name__)

__lowerCAmelCase												=	{
    'shi-labs/nat-mini-in1k-224': 'https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json',
    # See all Nat models at https://huggingface.co/models?filter=nat
}


class       _lowerCAmelCase   (   __snake_case					,							__snake_case				):







							'''simple docstring'''

							lowerCAmelCase_ 						=						"nat"

							lowerCAmelCase_ 						=						{
							    "num_attention_heads": "num_heads",
							    "num_hidden_layers": "num_layers",
							}

							def __init__(self  ,  UpperCAmelCase=4  ,  UpperCAmelCase=3  ,  UpperCAmelCase=64  ,  UpperCAmelCase=[3, 4, 6, 5]  ,  UpperCAmelCase=[2, 4, 8, 16]  ,  UpperCAmelCase=7  ,  UpperCAmelCase=3.0  ,  UpperCAmelCase=True  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.1  ,  UpperCAmelCase="gelu"  ,  UpperCAmelCase=0.02  ,  UpperCAmelCase=1e-5  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=None  ,  UpperCAmelCase=None  ,  **UpperCAmelCase  ,  )					->       str:
														super().__init__(**UpperCAmelCase  )

														_snake_case       =  patch_size
														_snake_case       =  num_channels
														_snake_case       =  embed_dim
														_snake_case       =  depths
														_snake_case       =  len(UpperCAmelCase  )
														_snake_case       =  num_heads
														_snake_case       =  kernel_size
														_snake_case       =  mlp_ratio
														_snake_case       =  qkv_bias
														_snake_case       =  hidden_dropout_prob
														_snake_case       =  attention_probs_dropout_prob
														_snake_case       =  drop_path_rate
														_snake_case       =  hidden_act
														_snake_case       =  layer_norm_eps
														_snake_case       =  initializer_range
														# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
														# this indicates the channel dimension after the last stage of the model
														_snake_case       =  int(embed_dim * 2 ** (len(UpperCAmelCase  ) - 1)  )
														_snake_case       =  layer_scale_init_value
														_snake_case       =  ["""stem"""] + [f"""stage{idx}""" for idx in range(1  ,  len(UpperCAmelCase  ) + 1  )]
														_snake_case,							_snake_case       =  get_aligned_output_features_output_indices(
														    out_features=UpperCAmelCase  ,  out_indices=UpperCAmelCase  ,  stage_names=self.stage_names  )