




'''simple docstring'''


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


UpperCAmelCase_ 		=      logging.get_logger(__name__)

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





class    __lowercase						(  __magic_name__ ):
   _a							=      """conditional_detr"""
   _a							=      ["""past_key_values"""]
   _a							=      {
       """hidden_size""": """d_model""",
       """num_attention_heads""": """encoder_attention_heads""",
   }







   def __init__(	self      ,							UpperCamelCase=True      ,							UpperCamelCase=None      ,							UpperCamelCase=3      ,							UpperCamelCase=300      ,							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=2      ,							UpperCamelCase=5      ,							UpperCamelCase=2      ,							UpperCamelCase=1      ,							UpperCamelCase=1      ,							UpperCamelCase=2      ,							UpperCamelCase=5      ,							UpperCamelCase=2      ,							UpperCamelCase=0.25      ,							**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.'      )
         __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      )

     __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			=					cls_loss_coefficient
     __a			=					bbox_loss_coefficient
     __a			=					giou_loss_coefficient
     __a			=					focal_alpha
     super().__init__(is_encoder_decoder=UpperCamelCase      ,							**UpperCamelCase      )







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







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







   def 		UpperCamelCase__			(	self      )				->    Dict:
     __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





class    __lowercase						(  __magic_name__ ):
   _a							=      version.parse("""1.11""" )







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







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









'''simple docstring'''


from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


UpperCAmelCase_ 		=      logging.get_logger(__name__)


UpperCAmelCase_ 		=      TypeVar("DatasetType", Dataset, IterableDataset)


def 						SCREAMING_SNAKE_CASE       (      a_	:							List[DatasetType]				,					a_	:							Optional[List[float]] = None				,					a_	:							Optional[int] = None				,					a_	:							Optional[DatasetInfo] = None				,					a_	:							Optional[NamedSplit] = None				,					a_	:							Literal["first_exhausted", "all_exhausted"] = "first_exhausted"				,					):
  from .arrow_dataset import Dataset
  from .iterable_dataset import IterableDataset

  if not datasets:
    raise ValueError('Unable to interleave an empty list of datasets.'			)
  for i, dataset in enumerate(a_			):
    if not isinstance(a_				,					(Dataset, IterableDataset)			):
      if isinstance(a_				,					(DatasetDict, IterableDatasetDict)			):
        if not dataset:
          raise ValueError(
              f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
              'is an empty dataset dictionary.'			)
        raise ValueError(
            f"Dataset at position {i} has at least one split: {list(a_			)}\n"
            f"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(a_			)			)}']"			)
      raise ValueError(
          f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(a_			).__name__}."			)
    if i == 0:
      __a	,       __a			=					(
          (Dataset, IterableDataset) if isinstance(a_				,					a_			) else (IterableDataset, Dataset)
      )
    elif not isinstance(a_				,					a_			):
      raise ValueError(
          f"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."			)
  if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
    raise ValueError(f"{stopping_strategy} is not supported. Please enter a valid stopping_strategy."			)
  if dataset_type is Dataset:
    return _interleave_map_style_datasets(
        a_				,					a_				,					a_				,					info=a_				,					split=a_				,					stopping_strategy=a_			)
  else:
    return _interleave_iterable_datasets(
        a_				,					a_				,					a_				,					info=a_				,					split=a_				,					stopping_strategy=a_			)


def 						SCREAMING_SNAKE_CASE       (      a_	:							List[DatasetType]				,					a_	:							Optional[DatasetInfo] = None				,					a_	:							Optional[NamedSplit] = None				,					a_	:							int = 0				,					):

  if not dsets:
    raise ValueError('Unable to concatenate an empty list of datasets.'			)
  for i, dataset in enumerate(a_			):
    if not isinstance(a_				,					(Dataset, IterableDataset)			):
      if isinstance(a_				,					(DatasetDict, IterableDatasetDict)			):
        if not dataset:
          raise ValueError(
              f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
              'is an empty dataset dictionary.'			)
        raise ValueError(
            f"Dataset at position {i} has at least one split: {list(a_			)}\n"
            f"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(a_			)			)}']"			)
      raise ValueError(
          f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(a_			).__name__}."			)
    if i == 0:
      __a	,       __a			=					(
          (Dataset, IterableDataset) if isinstance(a_				,					a_			) else (IterableDataset, Dataset)
      )
    elif not isinstance(a_				,					a_			):
      raise ValueError(
          f"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."			)
  if dataset_type is Dataset:
    return _concatenate_map_style_datasets(a_				,					info=a_				,					split=a_				,					axis=a_			)
  else:
    return _concatenate_iterable_datasets(a_				,					info=a_				,					split=a_				,					axis=a_			)



