





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


lowercase_					     =	logging.get_logger(__name__)

lowercase_					     =	{
    """microsoft/conditional-detr-resnet-50""": (
        """https://huggingface.co/microsoft/conditional-detr-resnet-50/resolve/main/config.json"""
    ),
}
class        SCREAMING_SNAKE_CASE     (UpperCAmelCase   ):
   _UpperCamelCase					:	List[str]				      = 'conditional_detr'
   _UpperCamelCase					:	Union[str, Any]				      = ['past_key_values']
   _UpperCamelCase					:	List[str]				      = {
       'hidden_size': 'd_model',
       'num_attention_heads': 'encoder_attention_heads',
   }


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

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


   @property
   def  SCREAMING_SNAKE_CASE_							(					self    :       Optional[int] )->     int:





     """simple docstring"""







     return self.encoder_attention_heads


   @property
   def  SCREAMING_SNAKE_CASE_							(					self    :       Tuple )->     int:





     """simple docstring"""







     return self.d_model


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





     """simple docstring"""







     lowercase__			    =						copy.deepcopy(self.__dict__ )
     if self.backbone_config is not None:
       lowercase__			    =						self.backbone_config.to_dict()
     lowercase__			    =						self.__class__.model_type
     return output






class        SCREAMING_SNAKE_CASE     (UpperCAmelCase   ):
   _UpperCamelCase					:	Optional[int]				      = version.parse('1.11'   )


   @property
   def  SCREAMING_SNAKE_CASE_							(					self    :       List[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    :       Any )->     float:





     """simple docstring"""







     return 1E-5


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





     """simple docstring"""







     return 12









from scipy.stats import spearmanr

import datasets


lowercase_					     =	"""
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
"""

lowercase_					     =	"""
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {'spearmanr': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results['spearmanr'])
        -0.7
        >>> print(round(results['spearmanr_pvalue'], 2))
        0.19
"""

lowercase_					     =	R"""\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
"""
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION    ,			_KWARGS_DESCRIPTION   )
class        SCREAMING_SNAKE_CASE     (datasets.Metric   ):


   def  SCREAMING_SNAKE_CASE_							(					self    :       Union[str, Any] )->     Tuple:





     """simple docstring"""







     return datasets.MetricInfo(
         description=_DESCRIPTION    ,  citation=_CITATION    ,  inputs_description=_KWARGS_DESCRIPTION    ,  features=datasets.Features(
             {
                 'predictions': datasets.Value('float' ),
                 'references': datasets.Value('float' ),
             } )    ,  reference_urls=['https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html']    ,  )


   def  SCREAMING_SNAKE_CASE_							(					self    :       int    ,  a    :       str    ,  a    :       Any    ,  a    :       str=False )->     Optional[int]:





     """simple docstring"""







     lowercase__			    =						spearmanr(a    ,  a )
     if return_pvalue:
       return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
     else:
       return {"spearmanr": results[0]}


