




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	:		List[Any]							       =   logging.get_logger(__name__)

_lowerCamelCase	:		Tuple							       =   {
    """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 				UpperCamelCase_    ( UpperCAmelCase__     ):

    '''simple docstring'''






    UpperCAmelCase__							  =      '''detr'''
    UpperCAmelCase__							  =      ['''past_key_values''']
    UpperCAmelCase__							  =      {
        '''hidden_size''': '''d_model''',
        '''num_attention_heads''': '''encoder_attention_heads''',
    }


    def __init__(			self      :	Dict					, UpperCAmelCase__      :	str=True					, UpperCAmelCase__      :	int=None					, UpperCAmelCase__      :	List[Any]=3					, UpperCAmelCase__      :	List[str]=100					, UpperCAmelCase__      :	Dict=6					, UpperCAmelCase__      :	Any=2_048					, UpperCAmelCase__      :	str=8					, UpperCAmelCase__      :	Any=6					, UpperCAmelCase__      :	Any=2_048					, UpperCAmelCase__      :	Any=8					, UpperCAmelCase__      :	Union[str, Any]=0.0					, UpperCAmelCase__      :	List[str]=0.0					, UpperCAmelCase__      :	int=True					, UpperCAmelCase__      :	Optional[Any]="relu"					, UpperCAmelCase__      :	int=256					, UpperCAmelCase__      :	Dict=0.1					, UpperCAmelCase__      :	Dict=0.0					, UpperCAmelCase__      :	Optional[int]=0.0					, UpperCAmelCase__      :	Optional[Any]=0.02					, UpperCAmelCase__      :	Optional[int]=1.0					, UpperCAmelCase__      :	Any=False					, UpperCAmelCase__      :	Optional[int]="sine"					, UpperCAmelCase__      :	Union[str, Any]="resnet50"					, UpperCAmelCase__      :	str=True					, UpperCAmelCase__      :	Union[str, Any]=False					, UpperCAmelCase__      :	Optional[Any]=1					, UpperCAmelCase__      :	Optional[Any]=5					, UpperCAmelCase__      :	Dict=2					, UpperCAmelCase__      :	Optional[Any]=1					, UpperCAmelCase__      :	Dict=1					, UpperCAmelCase__      :	Tuple=5					, UpperCAmelCase__      :	int=2					, UpperCAmelCase__      :	str=0.1					, **UpperCAmelCase__      :	str					, )						->List[Any]:





           '''simple docstring'''

           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(UpperCAmelCase__					, UpperCAmelCase__):
                         A__       =    backbone_config.get('''model_type''')
                         A__       =    CONFIG_MAPPING[backbone_model_type]
                         A__       =    config_class.from_dict(UpperCAmelCase__)
                  # set timm attributes to None
                  A__ ,							A__ ,							A__       =    None, None, None

           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__       =    bbox_loss_coefficient
           A__       =    giou_loss_coefficient
           A__       =    eos_coefficient
           super().__init__(is_encoder_decoder=UpperCAmelCase__					, **UpperCAmelCase__)


    @property
    def        SCREAMING_SNAKE_CASE							(			self      :	Any)						->int:





           '''simple docstring'''

           return self.encoder_attention_heads


    @property
    def        SCREAMING_SNAKE_CASE							(			self      :	Any)						->int:





           '''simple docstring'''

           return self.d_model


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





           '''simple docstring'''

           return cls(backbone_config=UpperCAmelCase__					, **UpperCAmelCase__)





    def        SCREAMING_SNAKE_CASE							(			self      :	str)						->Dict[str, any]:





           '''simple docstring'''

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


class 				UpperCamelCase_    ( UpperCAmelCase__     ):

    '''simple docstring'''






    UpperCAmelCase__							  =      version.parse('''1.11'''     )


    @property
    def        SCREAMING_SNAKE_CASE							(			self      :	str)						->Mapping[str, Mapping[int, str]]:





           '''simple docstring'''

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


    @property
    def        SCREAMING_SNAKE_CASE							(			self      :	Union[str, Any])						->float:





           '''simple docstring'''

           return 1e-5





    @property
    def        SCREAMING_SNAKE_CASE							(			self      :	str)						->int:





           '''simple docstring'''

           return 12








import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowerCamelCase	:		Any							       =   logging.get_logger(__name__)


class 				UpperCamelCase_    ( UpperCAmelCase__     ):

    '''simple docstring'''






    UpperCAmelCase__							  =      '''encoder-decoder'''
    UpperCAmelCase__							  =      True


    def __init__(			self      :	List[str]					, **UpperCAmelCase__      :	Union[str, Any])						->List[Any]:





           '''simple docstring'''

           super().__init__(**UpperCAmelCase__)
           assert (
               "encoder" in kwargs and "decoder" in kwargs
           ), "Config has to be initialized with encoder and decoder config"
           A__       =    kwargs.pop('''encoder''')
           A__       =    encoder_config.pop('''model_type''')
           A__       =    kwargs.pop('''decoder''')
           A__       =    decoder_config.pop('''model_type''')

           from ..auto.configuration_auto import AutoConfig

           A__       =    AutoConfig.for_model(UpperCAmelCase__					, **UpperCAmelCase__)
           A__       =    AutoConfig.for_model(UpperCAmelCase__					, **UpperCAmelCase__)
           A__       =    True


    @classmethod
    def        SCREAMING_SNAKE_CASE							(			cls      :	Union[str, Any]					, UpperCAmelCase__      :	PretrainedConfig					, UpperCAmelCase__      :	PretrainedConfig					, **UpperCAmelCase__      :	Union[str, Any])						->PretrainedConfig:





           '''simple docstring'''

           logger.info('''Set `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config''')
           A__       =    True
           A__       =    True

           return cls(encoder=encoder_config.to_dict()					, decoder=decoder_config.to_dict()					, **UpperCAmelCase__)





    def        SCREAMING_SNAKE_CASE							(			self      :	str)						->Optional[Any]:





           '''simple docstring'''

           A__       =    copy.deepcopy(self.__dict__)
           A__       =    self.encoder.to_dict()
           A__       =    self.decoder.to_dict()
           A__       =    self.__class__.model_type
           return output


