


import copy
from collections import OrderedDict
from typing import Mapping

from packaging import version

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


_A			=						logging.get_logger(__name__)

_A			=						{
    'microsoft/conditional-detr-resnet-50': (
        'https://huggingface.co/microsoft/conditional-detr-resnet-50/resolve/main/config.json'
    ),
}






class    UpperCAmelCase__	( A_		):



     """simple docstring"""






     UpperCAmelCase__						:		List[str]              =  "conditional_detr"
     UpperCAmelCase__						:		Optional[Any]              =  ["past_key_values"]
     UpperCAmelCase__						:		int              =  {
         "hidden_size": "d_model",
         "num_attention_heads": "encoder_attention_heads",
     }






     def __init__(      self ,       A_=True ,       A_=None ,       A_=3 ,       A_=300 ,       A_=6 ,       A_=2048 ,       A_=8 ,       A_=6 ,       A_=2048 ,       A_=8 ,       A_=0.0 ,       A_=0.0 ,       A_=True ,       A_="relu" ,       A_=256 ,       A_=0.1 ,       A_=0.0 ,       A_=0.0 ,       A_=0.02 ,       A_=1.0 ,       A_=False ,       A_="sine" ,       A_="resnet50" ,       A_=True ,       A_=False ,       A_=2 ,       A_=5 ,       A_=2 ,       A_=1 ,       A_=1 ,       A_=2 ,       A_=5 ,       A_=2 ,       A_=0.25 ,       **A_ ,       )  ->	Union[str, Any]:
          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.'   )
                    __UpperCamelCase   							=CONFIG_MAPPING['resnet'](out_features=['stage4']   )
               elif isinstance(A_ ,       A_   ):
                    __UpperCamelCase   							=backbone_config.get('model_type'   )
                    __UpperCamelCase   							=CONFIG_MAPPING[backbone_model_type]
                    __UpperCamelCase   							=config_class.from_dict(A_   )

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






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






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






     def _a (      self   )  ->	Optional[int]:
          __UpperCamelCase   							=copy.deepcopy(self.__dict__   )
          if self.backbone_config is not None:
               __UpperCamelCase   							=self.backbone_config.to_dict()
          __UpperCamelCase   							=self.__class__.model_type
          return output






class    UpperCAmelCase__	( A_		):



     """simple docstring"""






     UpperCAmelCase__						:		List[str]              =  version.parse("1.11"		)






     @property
     def _a (      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 _a (      self   )  ->	float:
          return 1E-5






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









import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin






class    UpperCAmelCase__	( A_		):



    """simple docstring"""






    UpperCAmelCase__						:		Optional[int]              =  "MCTCTFeatureExtractor"
    UpperCAmelCase__						:		str              =  "AutoTokenizer"






    def __init__(      self ,       A_ ,       A_   )  ->	Dict:
         super().__init__(A_ ,       A_   )
         __UpperCamelCase   							=self.feature_extractor
         __UpperCamelCase   							=False






    def __call__(      self ,       *A_ ,       **A_   )  ->	Optional[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
              return self.current_processor(*A_ ,       **A_   )

         if "raw_speech" in kwargs:
              warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'   )
              __UpperCamelCase   							=kwargs.pop('raw_speech'   )
         else:
              __UpperCamelCase   							=kwargs.pop('audio' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('sampling_rate' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('text' ,       A_   )
         if len(A_   ) > 0:
              __UpperCamelCase   							=args[0]
              __UpperCamelCase   							=args[1:]

         if audio is None and text is None:
              raise ValueError('You need to specify either an `audio` or `text` input to process.'   )

         if audio is not None:
              __UpperCamelCase   							=self.feature_extractor(A_ ,       *A_ ,       sampling_rate=A_ ,       **A_   )
         if text is not None:
              __UpperCamelCase   							=self.tokenizer(A_ ,       **A_   )

         if text is None:
              return inputs
         elif audio is None:
              return encodings
         else:
              __UpperCamelCase   							=encodings['input_ids']
              return inputs






    def _a (      self ,       *A_ ,       **A_   )  ->	str:
         return self.tokenizer.batch_decode(*A_ ,       **A_   )






    def _a (      self ,       *A_ ,       **A_   )  ->	List[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
              return self.current_processor.pad(*A_ ,       **A_   )

         __UpperCamelCase   							=kwargs.pop('input_features' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('labels' ,       A_   )
         if len(A_   ) > 0:
              __UpperCamelCase   							=args[0]
              __UpperCamelCase   							=args[1:]

         if input_features is not None:
              __UpperCamelCase   							=self.feature_extractor.pad(A_ ,       *A_ ,       **A_   )
         if labels is not None:
              __UpperCamelCase   							=self.tokenizer.pad(A_ ,       **A_   )

         if labels is None:
              return input_features
         elif input_features is None:
              return labels
         else:
              __UpperCamelCase   							=labels['input_ids']
              return input_features






    def _a (      self ,       *A_ ,       **A_   )  ->	Optional[int]:
         return self.tokenizer.decode(*A_ ,       **A_   )






    @contextmanager
    def _a (      self   )  ->	str:
         warnings.warn(
             '`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '
             'labels by using the argument `text` of the regular `__call__` method (either in the same call as '
             'your audio inputs, or in a separate call.'   )
         __UpperCamelCase   							=True
         __UpperCamelCase   							=self.tokenizer
         yield
         __UpperCamelCase   							=self.feature_extractor
         __UpperCamelCase   							=False





