






'''simple docstring'''
import copy

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


UpperCamelCase__			=      logging.get_logger(__name__)

UpperCamelCase__			=      {
    '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 							_UpperCAmelCase    (		snake_case      ):
    __lowerCamelCase: Dict									=     'deformable_detr'
    __lowerCamelCase: int									=     {
        'hidden_size': 'd_model',
        'num_attention_heads': 'encoder_attention_heads',
    }




    def __init__(      self	:							Optional[int]	,  a	:							str=True	,  a	:							Optional[int]=None	,  a	:							Tuple=3	,  a	:							Optional[Any]=3_0_0	,  a	:							Tuple=1_0_2_4	,  a	:							Optional[int]=6	,  a	:							List[Any]=1_0_2_4	,  a	:							Optional[int]=8	,  a	:							Optional[Any]=6	,  a	:							int=1_0_2_4	,  a	:							Any=8	,  a	:							str=0.0	,  a	:							Any=True	,  a	:							Dict="relu"	,  a	:							List[str]=2_5_6	,  a	:							Union[str, Any]=0.1	,  a	:							Union[str, Any]=0.0	,  a	:							Any=0.0	,  a	:							Union[str, Any]=0.02	,  a	:							Any=1.0	,  a	:							List[Any]=True	,  a	:							Any=False	,  a	:							Dict="sine"	,  a	:							List[str]="resnet50"	,  a	:							Tuple=True	,  a	:							Dict=False	,  a	:							List[str]=4	,  a	:							Dict=4	,  a	:							Dict=4	,  a	:							Optional[Any]=False	,  a	:							Tuple=3_0_0	,  a	:							Any=False	,  a	:							List[Any]=1	,  a	:							Optional[int]=5	,  a	:							int=2	,  a	:							List[Any]=1	,  a	:							Union[str, Any]=1	,  a	:							Union[str, Any]=5	,  a	:							List[Any]=2	,  a	:							Optional[Any]=0.1	,  a	:							Dict=0.25	,  a	:							Any=False	,  **a	:							str	,  ):






       '''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."      )
             lowercase_						:     List[str]							     =  CONFIG_MAPPING["resnet"](out_features=["stage4"]      )
          elif isinstance(a	,  a      ):
             lowercase_						:     str							     =  backbone_config.get("model_type"      )
             lowercase_						:     List[Any]							     =  CONFIG_MAPPING[backbone_model_type]
             lowercase_						:     Any							     =  config_class.from_dict(a      )
       lowercase_						:     Tuple							     =  use_timm_backbone
       lowercase_						:     int							     =  backbone_config
       lowercase_						:     List[str]							     =  num_channels
       lowercase_						:     int							     =  num_queries
       lowercase_						:     Optional[int]							     =  max_position_embeddings
       lowercase_						:     Any							     =  d_model
       lowercase_						:     str							     =  encoder_ffn_dim
       lowercase_						:     Any							     =  encoder_layers
       lowercase_						:     List[Any]							     =  encoder_attention_heads
       lowercase_						:     Dict							     =  decoder_ffn_dim
       lowercase_						:     Optional[Any]							     =  decoder_layers
       lowercase_						:     Optional[int]							     =  decoder_attention_heads
       lowercase_						:     Dict							     =  dropout
       lowercase_						:     Union[str, Any]							     =  attention_dropout
       lowercase_						:     str							     =  activation_dropout
       lowercase_						:     Optional[int]							     =  activation_function
       lowercase_						:     str							     =  init_std
       lowercase_						:     Union[str, Any]							     =  init_xavier_std
       lowercase_						:     Union[str, Any]							     =  encoder_layerdrop
       lowercase_						:     Any							     =  auxiliary_loss
       lowercase_						:     Dict							     =  position_embedding_type
       lowercase_						:     Dict							     =  backbone
       lowercase_						:     str							     =  use_pretrained_backbone
       lowercase_						:     Any							     =  dilation
       # deformable attributes
       lowercase_						:     Any							     =  num_feature_levels
       lowercase_						:     str							     =  encoder_n_points
       lowercase_						:     Tuple							     =  decoder_n_points
       lowercase_						:     Tuple							     =  two_stage
       lowercase_						:     str							     =  two_stage_num_proposals
       lowercase_						:     Tuple							     =  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
       lowercase_						:     Optional[int]							     =  class_cost
       lowercase_						:     Tuple							     =  bbox_cost
       lowercase_						:     Union[str, Any]							     =  giou_cost
       # Loss coefficients
       lowercase_						:     Optional[Any]							     =  mask_loss_coefficient
       lowercase_						:     Any							     =  dice_loss_coefficient
       lowercase_						:     Optional[int]							     =  bbox_loss_coefficient
       lowercase_						:     Optional[Any]							     =  giou_loss_coefficient
       lowercase_						:     Dict							     =  eos_coefficient
       lowercase_						:     Tuple							     =  focal_alpha
       lowercase_						:     Dict							     =  disable_custom_kernels
       super().__init__(is_encoder_decoder=a	,  **a      )




    @property
    def 					lowerCAmelCase__					(      self	:							List[Any]      ):






       '''simple docstring'''






       return self.encoder_attention_heads




    @property
    def 					lowerCAmelCase__					(      self	:							List[Any]      ):






       '''simple docstring'''






       return self.d_model





    def 					lowerCAmelCase__					(      self	:							List[Any]      ):






       '''simple docstring'''






       lowercase_						:     Optional[int]							     =  copy.deepcopy(self.__dict__      )
       if self.backbone_config is not None:
          lowercase_						:     Optional[int]							     =  self.backbone_config.to_dict()
       lowercase_						:     List[str]							     =  self.__class__.model_type
       return output












'''simple docstring'''
import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


UpperCamelCase__			=      False
try:
 UpperCamelCase__			=      _is_package_available('google.colab')
except ModuleNotFoundError:
 pass


@input.register
class 							_UpperCAmelCase    :




    def __init__(      self	:							List[Any]	,  a	:							str = None	,  a	:							list = []      ):






       '''simple docstring'''






       lowercase_						:     Optional[Any]							     =  0
       lowercase_						:     Dict							     =  choices
       lowercase_						:     List[str]							     =  prompt
       if sys.platform == "win32":
          lowercase_						:     List[Any]							     =  "*"
       else:
          lowercase_						:     Union[str, Any]							     =  "➔ "




    def 					lowerCAmelCase__					(      self	:							int	,  a	:							Optional[int]	,  a	:							str = ""      ):






       '''simple docstring'''






       if sys.platform != "win32":
          writeColor(self.choices[index]	,  3_2	,  a      )
       else:
          forceWrite(self.choices[index]	,  a      )




    def 					lowerCAmelCase__					(      self	:							List[Any]	,  a	:							int      ):






       '''simple docstring'''






       if index == self.position:
          forceWrite(f""" {self.arrow_char} """      )
          self.write_choice(a      )
       else:
          forceWrite(f"""    {self.choices[index]}"""      )
       reset_cursor()




    def 					lowerCAmelCase__					(      self	:							str	,  a	:							Direction	,  a	:							int = 1      ):






       '''simple docstring'''






       lowercase_						:     Optional[int]							     =  self.position
       if direction == Direction.DOWN:
          if self.position + 1 >= len(self.choices      ):
             return
          self.position += num_spaces
       else:
          if self.position - 1 < 0:
             return
          self.position -= num_spaces
       clear_line()
       self.print_choice(a      )
       move_cursor(a	,  direction.name      )
       self.print_choice(self.position      )




    @input.mark(KEYMAP["up"]      )
    def 					lowerCAmelCase__					(      self	:							Dict      ):






       '''simple docstring'''






       self.move_direction(Direction.UP      )




    @input.mark(KEYMAP["down"]      )
    def 					lowerCAmelCase__					(      self	:							List[Any]      ):






       '''simple docstring'''






       self.move_direction(Direction.DOWN      )




    @input.mark(KEYMAP["newline"]      )
    def 					lowerCAmelCase__					(      self	:							Any      ):






       '''simple docstring'''






       move_cursor(len(self.choices      ) - self.position	,  "DOWN"      )
       return self.position




    @input.mark(KEYMAP["interrupt"]      )
    def 					lowerCAmelCase__					(      self	:							str      ):






       '''simple docstring'''






       move_cursor(len(self.choices      ) - self.position	,  "DOWN"      )
       raise KeyboardInterrupt




    @input.mark_multiple(*[KEYMAP[str(a      )] for number in range(1_0      )]      )
    def 					lowerCAmelCase__					(      self	:							int      ):






       '''simple docstring'''






       lowercase_						:     str							     =  int(chr(self.current_selection      )      )
       lowercase_						:     Tuple							     =  index - self.position
       if index == self.position:
          return
       if index < len(self.choices      ):
          if self.position > index:
             self.move_direction(Direction.UP	,  -movement      )
          elif self.position < index:
             self.move_direction(Direction.DOWN	,  a      )
          else:
             return
       else:
          return





    def 					lowerCAmelCase__					(      self	:							Tuple	,  a	:							int = 0      ):






       '''simple docstring'''






       if self.prompt:
          linebreak()
          forceWrite(self.prompt	,  "\n"      )
          if in_colab:
             forceWrite("Please input a choice index (starting from 0), and press enter"	,  "\n"      )
          else:
             forceWrite("Please select a choice using the arrow or number keys, and selecting with enter"	,  "\n"      )
       lowercase_						:     Dict							     =  default_choice
       for i in range(len(self.choices      )      ):
          self.print_choice(a      )
          forceWrite("\n"      )
       move_cursor(len(self.choices      ) - self.position	,  "UP"      )
       with cursor.hide():
          while True:
             if in_colab:
                try:
                   lowercase_						:     List[str]							     =  int(builtins.input()      )
                except ValueError:
                   lowercase_						:     List[Any]							     =  default_choice
             else:
                lowercase_						:     Dict							     =  self.handle_input()
             if choice is not None:
                reset_cursor()
                for _ in range(len(self.choices      ) + 1      ):
                   move_cursor(1	,  "UP"      )
                   clear_line()
                self.write_choice(a	,  "\n"      )
                return choice




