



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  lowerCamelCase__    :




									'''simple docstring'''



									@staticmethod
									def 	lowerCAmelCase__   (*__lowerCamelCase	,**__lowerCamelCase				)  ->    Optional[Any]:

													"""simple docstring"""






													pass



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




		'''simple docstring'''



		snake_case_			=MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)  ->    List[str]:

						"""simple docstring"""






						lowerCAmelCase__  :       Optional[int]				=  pipeline(
						    '''zero-shot-object-detection'''	,model='''hf-internal-testing/tiny-random-owlvit-object-detection'''				)

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



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase				)  ->    Dict:

						"""simple docstring"""






						lowerCAmelCase__  :       Union[str, Any]				=  object_detector(examples[0]	,threshold=0.0				)

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



		@require_tf
		@unittest.skip('''Zero Shot Object Detection not implemented in TF'''				)
		def 	lowerCAmelCase__   (self				)  ->    str:

						"""simple docstring"""






						pass



		@require_torch
		def 	lowerCAmelCase__   (self				)  ->    int:

						"""simple docstring"""






						lowerCAmelCase__  :       Union[str, Any]				=  pipeline(
						    '''zero-shot-object-detection'''	,model='''hf-internal-testing/tiny-random-owlvit-object-detection'''				)

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

						self.assertEqual(
						    nested_simplify(__lowerCamelCase	,decimals=4				)	,[
						        {'''score''': 0.7235, '''label''': '''cat''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
						        {'''score''': 0.7218, '''label''': '''remote''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
						        {'''score''': 0.7184, '''label''': '''couch''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
						        {'''score''': 0.6748, '''label''': '''remote''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
						        {'''score''': 0.6656, '''label''': '''cat''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
						        {'''score''': 0.6614, '''label''': '''couch''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
						        {'''score''': 0.6456, '''label''': '''remote''', '''box''': {'''xmin''': 4_94, '''ymin''': 1_05, '''xmax''': 5_21, '''ymax''': 1_27}},
						        {'''score''': 0.642, '''label''': '''remote''', '''box''': {'''xmin''': 67, '''ymin''': 2_74, '''xmax''': 93, '''ymax''': 2_97}},
						        {'''score''': 0.6419, '''label''': '''cat''', '''box''': {'''xmin''': 4_94, '''ymin''': 1_05, '''xmax''': 5_21, '''ymax''': 1_27}},
						    ]	,)

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

						self.assertEqual(
						    nested_simplify(__lowerCamelCase	,decimals=4				)	,[
						        [
						            {'''score''': 0.7235, '''label''': '''cat''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
						            {'''score''': 0.7218, '''label''': '''remote''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
						            {'''score''': 0.7184, '''label''': '''couch''', '''box''': {'''xmin''': 2_04, '''ymin''': 1_67, '''xmax''': 2_32, '''ymax''': 1_90}},
						            {'''score''': 0.6748, '''label''': '''remote''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
						            {'''score''': 0.6656, '''label''': '''cat''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
						            {'''score''': 0.6614, '''label''': '''couch''', '''box''': {'''xmin''': 5_71, '''ymin''': 83, '''xmax''': 5_98, '''ymax''': 1_03}},
						            {'''score''': 0.6456, '''label''': '''remote''', '''box''': {'''xmin''': 4_94, '''ymin''': 1_05, '''xmax''': 5_21, '''ymax''': 1_27}},
						            {'''score''': 0.642, '''label''': '''remote''', '''box''': {'''xmin''': 67, '''ymin''': 2_74, '''xmax''': 93, '''ymax''': 2_97}},
						            {'''score''': 0.6419, '''label''': '''cat''', '''box''': {'''xmin''': 4_94, '''ymin''': 1_05, '''xmax''': 5_21, '''ymax''': 1_27}},
						        ]
						    ]	,)



		@require_torch
		@slow
		def 	lowerCAmelCase__   (self				)  ->    Any:

						"""simple docstring"""






						lowerCAmelCase__  :       List[str]				=  pipeline('''zero-shot-object-detection'''				)

						lowerCAmelCase__  :       str				=  object_detector(
						    '''http://images.cocodataset.org/val2017/000000039769.jpg'''	,candidate_labels=['''cat''', '''remote''', '''couch''']	,)
						self.assertEqual(
						    nested_simplify(__lowerCamelCase	,decimals=4				)	,[
						        {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
						        {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
						        {'''score''': 0.2537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 3_15, '''ymax''': 4_72}},
						        {'''score''': 0.1474, '''label''': '''remote''', '''box''': {'''xmin''': 3_35, '''ymin''': 74, '''xmax''': 3_71, '''ymax''': 1_87}},
						        {'''score''': 0.1208, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_42, '''ymax''': 4_76}},
						    ]	,)

						lowerCAmelCase__  :       int				=  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(__lowerCamelCase	,decimals=4				)	,[
						        [
						            {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
						            {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
						            {'''score''': 0.2537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 3_15, '''ymax''': 4_72}},
						            {'''score''': 0.1474, '''label''': '''remote''', '''box''': {'''xmin''': 3_35, '''ymin''': 74, '''xmax''': 3_71, '''ymax''': 1_87}},
						            {'''score''': 0.1208, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_42, '''ymax''': 4_76}},
						        ],
						        [
						            {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
						            {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
						            {'''score''': 0.2537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 3_15, '''ymax''': 4_72}},
						            {'''score''': 0.1474, '''label''': '''remote''', '''box''': {'''xmin''': 3_35, '''ymin''': 74, '''xmax''': 3_71, '''ymax''': 1_87}},
						            {'''score''': 0.1208, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 6_42, '''ymax''': 4_76}},
						        ],
						    ]	,)



		@require_tf
		@unittest.skip('''Zero Shot Object Detection not implemented in TF'''				)
		def 	lowerCAmelCase__   (self				)  ->    Dict:

						"""simple docstring"""






						pass



		@require_torch
		@slow
		def 	lowerCAmelCase__   (self				)  ->    Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__  :       Dict				=  0.2
						lowerCAmelCase__  :       int				=  pipeline('''zero-shot-object-detection'''				)

						lowerCAmelCase__  :       List[str]				=  object_detector(
						    '''http://images.cocodataset.org/val2017/000000039769.jpg'''	,candidate_labels=['''cat''', '''remote''', '''couch''']	,threshold=__lowerCamelCase	,)
						self.assertEqual(
						    nested_simplify(__lowerCamelCase	,decimals=4				)	,[
						        {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
						        {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
						        {'''score''': 0.2537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 3_15, '''ymax''': 4_72}},
						    ]	,)



		@require_torch
		@slow
		def 	lowerCAmelCase__   (self				)  ->    Dict:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  2
						lowerCAmelCase__  :       Dict				=  pipeline('''zero-shot-object-detection'''				)

						lowerCAmelCase__  :       str				=  object_detector(
						    '''http://images.cocodataset.org/val2017/000000039769.jpg'''	,candidate_labels=['''cat''', '''remote''', '''couch''']	,top_k=__lowerCamelCase	,)
						self.assertEqual(
						    nested_simplify(__lowerCamelCase	,decimals=4				)	,[
						        {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 3_24, '''ymin''': 20, '''xmax''': 6_40, '''ymax''': 3_73}},
						        {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 1_77, '''ymax''': 1_15}},
						    ]	,)






def 			lowerCAmelCase__	(					lowerCamelCase_	:	int):





				'''simple docstring'''

				if not isinstance(lowerCamelCase_ ,lowerCamelCase_):
								lowerCAmelCase__  :       Dict				=  f"""Input value of [number={number}] must be an integer"""
								raise TypeError(lowerCamelCase_)

				if number < 1:
								lowerCAmelCase__  :       Any				=  f"""Input value of [number={number}] must be > 0"""
								raise ValueError(lowerCamelCase_)

				lowerCAmelCase__  :       List[str]				=  1

				for i in range(1 ,lowerCamelCase_):
								current_number *= 4 * i - 2
								current_number //= i + 1

				return current_number


if __name__ == "__main__":
							import doctest

							doctest.testmod()

