
import copy

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


A     :	List[Any]    = logging.get_logger(__name__)

A     :	Union[str, Any]    = {
    'SenseTime/deformable-detr': 'https://huggingface.co/sensetime/deformable-detr/resolve/main/config.json',
    # See all Deformable DETR models at https://huggingface.co/models?filter=deformable-detr
}







class 			__A( a			):
				snake_case_						   =    '''deformable_detr'''
				snake_case_						   =    {
				    '''hidden_size''': '''d_model''',
				    '''num_attention_heads''': '''encoder_attention_heads''',
				}




				def __init__(     self		,     _snake_case=True		,     _snake_case=None		,     _snake_case=3		,     _snake_case=300		,     _snake_case=1_024		,     _snake_case=6		,     _snake_case=1_024		,     _snake_case=8		,     _snake_case=6		,     _snake_case=1_024		,     _snake_case=8		,     _snake_case=0.0		,     _snake_case=True		,     _snake_case="relu"		,     _snake_case=256		,     _snake_case=0.1		,     _snake_case=0.0		,     _snake_case=0.0		,     _snake_case=0.02		,     _snake_case=1.0		,     _snake_case=True		,     _snake_case=False		,     _snake_case="sine"		,     _snake_case="resnet50"		,     _snake_case=True		,     _snake_case=False		,     _snake_case=4		,     _snake_case=4		,     _snake_case=4		,     _snake_case=False		,     _snake_case=300		,     _snake_case=False		,     _snake_case=1		,     _snake_case=5		,     _snake_case=2		,     _snake_case=1		,     _snake_case=1		,     _snake_case=5		,     _snake_case=2		,     _snake_case=0.1		,     _snake_case=0.25		,     _snake_case=False		,     **_snake_case		,     )    ->      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(_snake_case		,     _snake_case				):
																__a										=    backbone_config.get('''model_type'''				)
																__a										=    CONFIG_MAPPING[backbone_model_type]
																__a										=    config_class.from_dict(_snake_case				)
								__a										=    use_timm_backbone
								__a										=    backbone_config
								__a										=    num_channels
								__a										=    num_queries
								__a										=    max_position_embeddings
								__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										=    auxiliary_loss
								__a										=    position_embedding_type
								__a										=    backbone
								__a										=    use_pretrained_backbone
								__a										=    dilation
								# deformable attributes
								__a										=    num_feature_levels
								__a										=    encoder_n_points
								__a										=    decoder_n_points
								__a										=    two_stage
								__a										=    two_stage_num_proposals
								__a										=    with_box_refine
								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
								__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
								__a										=    focal_alpha
								__a										=    disable_custom_kernels
								super().__init__(is_encoder_decoder=_snake_case		,     **_snake_case				)




				@property
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      int:


								'''simple docstring'''




								return self.encoder_attention_heads




				@property
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      int:


								'''simple docstring'''




								return self.d_model




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


								'''simple docstring'''




								__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

from typing import Dict

from .base import GenericTensor, Pipeline







class 			__A( a			):




				def 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case=None		,     _snake_case=None		,     _snake_case=None		,     **_snake_case				)    ->      Optional[Any]:


								'''simple docstring'''




								if tokenize_kwargs is None:
												__a										=    {}

								if truncation is not None:
												if "truncation" in tokenize_kwargs:
																raise ValueError(
																    '''truncation parameter defined twice (given as keyword argument as well as in tokenize_kwargs)'''				)
												__a										=    truncation

								__a										=    tokenize_kwargs

								__a										=    {}
								if return_tensors is not None:
												__a										=    return_tensors

								return preprocess_params, {}, postprocess_params




				def 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case		,     **_snake_case				)    ->      Dict[str, GenericTensor]:


								'''simple docstring'''




								__a										=    self.framework
								__a										=    self.tokenizer(_snake_case		,     return_tensors=_snake_case		,     **_snake_case				)
								return model_inputs




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


								'''simple docstring'''




								__a										=    self.model(**_snake_case				)
								return model_outputs




				def 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case		,     _snake_case=False				)    ->      Optional[int]:


								'''simple docstring'''




								if return_tensors:
												return model_outputs[0]
								if self.framework == "pt":
												return model_outputs[0].tolist()
								elif self.framework == "tf":
												return model_outputs[0].numpy().tolist()




				def __call__(     self		,     *_snake_case		,     **_snake_case				)    ->      Any:


								'''simple docstring'''




								return super().__call__(*_snake_case		,     **_snake_case				)