


"""simple docstring"""
from typing import List, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE :    Optional[int]									=				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE :    List[str]									=				{
    """huggingface/time-series-transformer-tourism-monthly""": (
        """https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json"""
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}



class 			_UpperCAmelCase (							__snake_case				):






		'''simple docstring'''

		lowerCamelCase__				='time_series_transformer'
		lowerCamelCase__				={
		    'hidden_size': 'd_model',
		    'num_attention_heads': 'encoder_attention_heads',
		    'num_hidden_layers': 'encoder_layers',
		}



		def __init__(self				,       a_ = None				,       a_ = None				,       a_ = "student_t"				,       a_ = "nll"				,       a_ = 1				,       a_ = [1, 2, 3, 4, 5, 6, 7]				,       a_ = "mean"				,       a_ = 0				,       a_ = 0				,       a_ = 0				,       a_ = 0				,       a_ = None				,       a_ = None				,       a_ = 32				,       a_ = 32				,       a_ = 2				,       a_ = 2				,       a_ = 2				,       a_ = 2				,       a_ = True				,       a_ = "gelu"				,       a_ = 64				,       a_ = 0.1				,       a_ = 0.1				,       a_ = 0.1				,       a_ = 0.1				,       a_ = 0.1				,       a_ = 1_00				,       a_ = 0.02				,       a_=True				,       **a_				,       ):





			'''simple docstring'''

			__snake_case	:						Union[str, Any]						=				prediction_length
			__snake_case	:						List[str]						=				context_length or prediction_length
			__snake_case	:						Tuple						=				distribution_output
			__snake_case	:						Union[str, Any]						=				loss
			__snake_case	:						Tuple						=				input_size
			__snake_case	:						Optional[Any]						=				num_time_features
			__snake_case	:						Tuple						=				lags_sequence
			__snake_case	:						Optional[int]						=				scaling
			__snake_case	:						Optional[Any]						=				num_dynamic_real_features
			__snake_case	:						Optional[Any]						=				num_static_real_features
			__snake_case	:						List[str]						=				num_static_categorical_features
			if cardinality and num_static_categorical_features > 0:
				if len(a_					) != num_static_categorical_features:
					raise ValueError(
					    '''The cardinality should be a list of the same length as `num_static_categorical_features`'''					)
				__snake_case	:						Dict						=				cardinality
			else:
				__snake_case	:						Optional[int]						=				[0]
			if embedding_dimension and num_static_categorical_features > 0:
				if len(a_					) != num_static_categorical_features:
					raise ValueError(
					    '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''					)
				__snake_case	:						Dict						=				embedding_dimension
			else:
				__snake_case	:						int						=				[min(50				,       (cat + 1) // 2					) for cat in self.cardinality]
			__snake_case	:						int						=				num_parallel_samples

			# Transformer architecture configuration
			__snake_case	:						Union[str, Any]						=				input_size * len(a_					) + self._number_of_features
			__snake_case	:						Any						=				d_model
			__snake_case	:						Union[str, Any]						=				encoder_attention_heads
			__snake_case	:						Any						=				decoder_attention_heads
			__snake_case	:						Any						=				encoder_ffn_dim
			__snake_case	:						List[Any]						=				decoder_ffn_dim
			__snake_case	:						Tuple						=				encoder_layers
			__snake_case	:						Union[str, Any]						=				decoder_layers

			__snake_case	:						int						=				dropout
			__snake_case	:						List[str]						=				attention_dropout
			__snake_case	:						Optional[int]						=				activation_dropout
			__snake_case	:						Dict						=				encoder_layerdrop
			__snake_case	:						Optional[Any]						=				decoder_layerdrop

			__snake_case	:						int						=				activation_function
			__snake_case	:						Union[str, Any]						=				init_std

			__snake_case	:						int						=				use_cache

			super().__init__(is_encoder_decoder=a_				,       **a_					)



		@property
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return (
			    sum(self.embedding_dimension					)
			    + self.num_dynamic_real_features
			    + self.num_time_features
			    + self.num_static_real_features
			    + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
			)









import unittest

from transformers import MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING, is_vision_available, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
						from PIL import Image
else:







						class  snake_case__:







												'''simple docstring'''




												@staticmethod
												def   lowercase_       ( *__lowercase      ,  **__lowercase							)    ->			Union[str, Any]:
																pass







@is_pipeline_test
@require_vision
@require_torch
class  snake_case__(							unittest.TestCase							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__					:     Union[str, Any]    =							MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING




						def   lowercase_       ( self      ,  __lowercase      ,  __lowercase      ,  __lowercase							)    ->			List[str]:
										lowerCAmelCase_       :					Union[str, Any]			 = pipeline(
										    '''zero-shot-object-detection'''      ,  model='''hf-internal-testing/tiny-random-owlvit-object-detection'''							)

										lowerCAmelCase_       :					str			 = [
										    {
										        '''image''': '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
										        '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
										    }
										]
										return object_detector, examples




						def   lowercase_       ( self      ,  __lowercase      ,  __lowercase							)    ->			str:
										lowerCAmelCase_       :					Tuple			 = object_detector(examples[0]      ,  threshold=0.0							)

										lowerCAmelCase_       :					Dict			 = len(__lowercase							)
										self.assertGreater(__lowercase      ,  0							)
										self.assertEqual(
										    __lowercase      ,  [
										        {
										            '''score''': ANY(__lowercase							),
										            '''label''': ANY(__lowercase							),
										            '''box''': {'''xmin''': ANY(__lowercase							), '''ymin''': ANY(__lowercase							), '''xmax''': ANY(__lowercase							), '''ymax''': ANY(__lowercase							)},
										        }
										        for i in range(__lowercase							)
										    ]      ,  )




						@require_tf
						@unittest.skip('''Zero Shot Object Detection not implemented in TF'''							)
						def   lowercase_       ( self							)    ->			List[str]:
										pass




						@require_torch
						def   lowercase_       ( self							)    ->			int:
										lowerCAmelCase_       :					Union[str, Any]			 = pipeline(
										    '''zero-shot-object-detection'''      ,  model='''hf-internal-testing/tiny-random-owlvit-object-detection'''							)

										lowerCAmelCase_       :					Union[str, Any]			 = object_detector(
										    '''./tests/fixtures/tests_samples/COCO/000000039769.png'''      ,  candidate_labels=['''cat''', '''remote''', '''couch''']      ,  threshold=0.64      ,  )

										self.assertEqual(
										    nested_simplify(__lowercase      ,  decimals=4							)      ,  [
										        {'''score''': 0.72_35, '''label''': '''cat''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										        {'''score''': 0.72_18, '''label''': '''remote''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										        {'''score''': 0.71_84, '''label''': '''couch''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										        {'''score''': 0.67_48, '''label''': '''remote''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										        {'''score''': 0.66_56, '''label''': '''cat''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										        {'''score''': 0.66_14, '''label''': '''couch''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										        {'''score''': 0.64_56, '''label''': '''remote''', '''box''': {'''xmin''': 4_9_4, '''ymin''': 1_0_5, '''xmax''': 5_2_1, '''ymax''': 1_2_7}},
										        {'''score''': 0.6_42, '''label''': '''remote''', '''box''': {'''xmin''': 6_7, '''ymin''': 2_7_4, '''xmax''': 9_3, '''ymax''': 2_9_7}},
										        {'''score''': 0.64_19, '''label''': '''cat''', '''box''': {'''xmin''': 4_9_4, '''ymin''': 1_0_5, '''xmax''': 5_2_1, '''ymax''': 1_2_7}},
										    ]      ,  )

										lowerCAmelCase_       :					Union[str, Any]			 = object_detector(
										    [
										        {
										            '''image''': '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
										            '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
										        }
										    ]      ,  threshold=0.64      ,  )

										self.assertEqual(
										    nested_simplify(__lowercase      ,  decimals=4							)      ,  [
										        [
										            {'''score''': 0.72_35, '''label''': '''cat''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										            {'''score''': 0.72_18, '''label''': '''remote''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										            {'''score''': 0.71_84, '''label''': '''couch''', '''box''': {'''xmin''': 2_0_4, '''ymin''': 1_6_7, '''xmax''': 2_3_2, '''ymax''': 1_9_0}},
										            {'''score''': 0.67_48, '''label''': '''remote''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										            {'''score''': 0.66_56, '''label''': '''cat''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										            {'''score''': 0.66_14, '''label''': '''couch''', '''box''': {'''xmin''': 5_7_1, '''ymin''': 8_3, '''xmax''': 5_9_8, '''ymax''': 1_0_3}},
										            {'''score''': 0.64_56, '''label''': '''remote''', '''box''': {'''xmin''': 4_9_4, '''ymin''': 1_0_5, '''xmax''': 5_2_1, '''ymax''': 1_2_7}},
										            {'''score''': 0.6_42, '''label''': '''remote''', '''box''': {'''xmin''': 6_7, '''ymin''': 2_7_4, '''xmax''': 9_3, '''ymax''': 2_9_7}},
										            {'''score''': 0.64_19, '''label''': '''cat''', '''box''': {'''xmin''': 4_9_4, '''ymin''': 1_0_5, '''xmax''': 5_2_1, '''ymax''': 1_2_7}},
										        ]
										    ]      ,  )




						@require_torch
						@slow
						def   lowercase_       ( self							)    ->			Union[str, Any]:
										lowerCAmelCase_       :					Any			 = pipeline('''zero-shot-object-detection'''							)

										lowerCAmelCase_       :					Dict			 = object_detector(
										    '''http://images.cocodataset.org/val2017/000000039769.jpg'''      ,  candidate_labels=['''cat''', '''remote''', '''couch''']      ,  )
										self.assertEqual(
										    nested_simplify(__lowercase      ,  decimals=4							)      ,  [
										        {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 3_2_4, '''ymin''': 2_0, '''xmax''': 6_4_0, '''ymax''': 3_7_3}},
										        {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_2, '''xmax''': 1_7_7, '''ymax''': 1_1_5}},
										        {'''score''': 0.25_37, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 5_5, '''xmax''': 3_1_5, '''ymax''': 4_7_2}},
										        {'''score''': 0.14_74, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_5, '''ymin''': 7_4, '''xmax''': 3_7_1, '''ymax''': 1_8_7}},
										        {'''score''': 0.12_08, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_4_2, '''ymax''': 4_7_6}},
										    ]      ,  )

										lowerCAmelCase_       :					Tuple			 = object_detector(
										    [
										        {
										            '''image''': '''http://images.cocodataset.org/val2017/000000039769.jpg''',
										            '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
										        },
										        {
										            '''image''': '''http://images.cocodataset.org/val2017/000000039769.jpg''',
										            '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
										        },
										    ]      ,  )
										self.assertEqual(
										    nested_simplify(__lowercase      ,  decimals=4							)      ,  [
										        [
										            {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 3_2_4, '''ymin''': 2_0, '''xmax''': 6_4_0, '''ymax''': 3_7_3}},
										            {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_2, '''xmax''': 1_7_7, '''ymax''': 1_1_5}},
										            {'''score''': 0.25_37, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 5_5, '''xmax''': 3_1_5, '''ymax''': 4_7_2}},
										            {'''score''': 0.14_74, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_5, '''ymin''': 7_4, '''xmax''': 3_7_1, '''ymax''': 1_8_7}},
										            {'''score''': 0.12_08, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_4_2, '''ymax''': 4_7_6}},
										        ],
										        [
										            {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 3_2_4, '''ymin''': 2_0, '''xmax''': 6_4_0, '''ymax''': 3_7_3}},
										            {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_2, '''xmax''': 1_7_7, '''ymax''': 1_1_5}},
										            {'''score''': 0.25_37, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 5_5, '''xmax''': 3_1_5, '''ymax''': 4_7_2}},
										            {'''score''': 0.14_74, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_5, '''ymin''': 7_4, '''xmax''': 3_7_1, '''ymax''': 1_8_7}},
										            {'''score''': 0.12_08, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_4_2, '''ymax''': 4_7_6}},
										        ],
										    ]      ,  )




						@require_tf
						@unittest.skip('''Zero Shot Object Detection not implemented in TF'''							)
						def   lowercase_       ( self							)    ->			List[str]:
										pass




						@require_torch
						@slow
						def   lowercase_       ( self							)    ->			Optional[int]:
										lowerCAmelCase_       :					Any			 = 0.2
										lowerCAmelCase_       :					List[Any]			 = pipeline('''zero-shot-object-detection'''							)

										lowerCAmelCase_       :					Optional[Any]			 = object_detector(
										    '''http://images.cocodataset.org/val2017/000000039769.jpg'''      ,  candidate_labels=['''cat''', '''remote''', '''couch''']      ,  threshold=__lowercase      ,  )
										self.assertEqual(
										    nested_simplify(__lowercase      ,  decimals=4							)      ,  [
										        {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 3_2_4, '''ymin''': 2_0, '''xmax''': 6_4_0, '''ymax''': 3_7_3}},
										        {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_2, '''xmax''': 1_7_7, '''ymax''': 1_1_5}},
										        {'''score''': 0.25_37, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 5_5, '''xmax''': 3_1_5, '''ymax''': 4_7_2}},
										    ]      ,  )




						@require_torch
						@slow
						def   lowercase_       ( self							)    ->			Optional[int]:
										lowerCAmelCase_       :					Dict			 = 2
										lowerCAmelCase_       :					Union[str, Any]			 = pipeline('''zero-shot-object-detection'''							)

										lowerCAmelCase_       :					Optional[Any]			 = object_detector(
										    '''http://images.cocodataset.org/val2017/000000039769.jpg'''      ,  candidate_labels=['''cat''', '''remote''', '''couch''']      ,  top_k=__lowercase      ,  )
										self.assertEqual(
										    nested_simplify(__lowercase      ,  decimals=4							)      ,  [
										        {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 3_2_4, '''ymin''': 2_0, '''xmax''': 6_4_0, '''ymax''': 3_7_3}},
										        {'''score''': 0.2_77, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_2, '''xmax''': 1_7_7, '''ymax''': 1_1_5}},
										    ]      ,  )