import os
import unittest

from transformers import MobileBertTokenizer, MobileBertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english





@require_tokenizers
class 					lowercase__						(   UpperCamelCase_	,							unittest.TestCase):
						UpperCamelCase_     =		MobileBertTokenizer
						UpperCamelCase_     =		MobileBertTokenizerFast
						UpperCamelCase_     =		True
						UpperCamelCase_     =		True
						UpperCamelCase_     =		filter_non_english
						UpperCamelCase_     =		"""google/mobilebert-uncased"""


						def        __A       (       self	:				Tuple						):





												'''simple docstring'''





												super().setUp()

												SCREAMING_SNAKE_CASE							:    int							=							[
												    '''[UNK]''',
												    '''[CLS]''',
												    '''[SEP]''',
												    '''[PAD]''',
												    '''[MASK]''',
												    '''want''',
												    '''##want''',
												    '''##ed''',
												    '''wa''',
												    '''un''',
												    '''runn''',
												    '''##ing''',
												    ''',''',
												    '''low''',
												    '''lowest''',
												]
												SCREAMING_SNAKE_CASE							:    Tuple							=							os.path.join(self.tmpdirname    ,		VOCAB_FILES_NAMES['''vocab_file''']						)
												with open(self.vocab_file    ,		'''w'''    ,		encoding='''utf-8'''						) as vocab_writer:
																		vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]						)						)

												SCREAMING_SNAKE_CASE							:    Dict							=							[
												    (tokenizer_def[0], self.pre_trained_model_path, tokenizer_def[2])  # else the 'google/' prefix is stripped
												    for tokenizer_def in self.tokenizers_list
												]


						def        __A       (       self	:				List[Any]    ,		UpperCamelCase__	:				int						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							'''UNwant\u00E9d,running'''
												SCREAMING_SNAKE_CASE							:    Any							=							'''unwanted, running'''
												return input_text, output_text


						def        __A       (       self	:				List[Any]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    List[Any]							=							self.tokenizer_class(self.vocab_file						)

												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							tokenizer.tokenize('''UNwant\u00E9d,running'''						)
												self.assertListEqual(UpperCamelCase__    ,		['''un''', '''##want''', '''##ed''', ''',''', '''runn''', '''##ing''']						)
												self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase__						)    ,		[9, 6, 7, 12, 10, 11]						)


						def        __A       (       self	:				Optional[int]						):





												'''simple docstring'''





												if not self.test_rust_tokenizer:
																		return

												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							self.get_tokenizer()
												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							self.get_rust_tokenizer()

												SCREAMING_SNAKE_CASE							:    Tuple							=							'''UNwant\u00E9d,running'''

												SCREAMING_SNAKE_CASE							:    int							=							tokenizer.tokenize(UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    List[Any]							=							rust_tokenizer.tokenize(UpperCamelCase__						)
												self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)

												SCREAMING_SNAKE_CASE							:    str							=							tokenizer.encode(UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    List[str]							=							rust_tokenizer.encode(UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__						)
												self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)

												SCREAMING_SNAKE_CASE							:    Any							=							self.get_rust_tokenizer()
												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							tokenizer.encode(UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    List[str]							=							rust_tokenizer.encode(UpperCamelCase__						)
												self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)

												# With lower casing
												SCREAMING_SNAKE_CASE							:    int							=							self.get_tokenizer(do_lower_case=UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    int							=							self.get_rust_tokenizer(do_lower_case=UpperCamelCase__						)

												SCREAMING_SNAKE_CASE							:    List[Any]							=							'''UNwant\u00E9d,running'''

												SCREAMING_SNAKE_CASE							:    int							=							tokenizer.tokenize(UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    List[str]							=							rust_tokenizer.tokenize(UpperCamelCase__						)
												self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)

												SCREAMING_SNAKE_CASE							:    Dict							=							tokenizer.encode(UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							rust_tokenizer.encode(UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__						)
												self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)

												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							self.get_rust_tokenizer()
												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							tokenizer.encode(UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    Dict							=							rust_tokenizer.encode(UpperCamelCase__						)
												self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)


						def        __A       (       self	:				Any						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    str							=							BasicTokenizer()

												self.assertListEqual(tokenizer.tokenize('''ah\u535A\u63A8zz'''						)    ,		['''ah''', '''\u535A''', '''\u63A8''', '''zz''']						)


						def        __A       (       self	:				Any						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Dict							=							BasicTokenizer(do_lower_case=UpperCamelCase__						)

												self.assertListEqual(
												    tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU?  '''						)    ,		['''hello''', '''!''', '''how''', '''are''', '''you''', '''?''']						)
												self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''						)    ,		['''hello''']						)


						def        __A       (       self	:				Optional[int]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							BasicTokenizer(do_lower_case=UpperCamelCase__    ,		strip_accents=UpperCamelCase__						)

												self.assertListEqual(
												    tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''						)    ,		['''hällo''', '''!''', '''how''', '''are''', '''you''', '''?''']						)
												self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''						)    ,		['''h\u00E9llo''']						)


						def        __A       (       self	:				Tuple						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							BasicTokenizer(do_lower_case=UpperCamelCase__    ,		strip_accents=UpperCamelCase__						)

												self.assertListEqual(
												    tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''						)    ,		['''hallo''', '''!''', '''how''', '''are''', '''you''', '''?''']						)
												self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''						)    ,		['''hello''']						)


						def        __A       (       self	:				Tuple						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							BasicTokenizer(do_lower_case=UpperCamelCase__						)

												self.assertListEqual(
												    tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''						)    ,		['''hallo''', '''!''', '''how''', '''are''', '''you''', '''?''']						)
												self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''						)    ,		['''hello''']						)


						def        __A       (       self	:				List[Any]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    List[Any]							=							BasicTokenizer(do_lower_case=UpperCamelCase__						)

												self.assertListEqual(
												    tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU?  '''						)    ,		['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']						)


						def        __A       (       self	:				Optional[int]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    str							=							BasicTokenizer(do_lower_case=UpperCamelCase__    ,		strip_accents=UpperCamelCase__						)

												self.assertListEqual(
												    tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''						)    ,		['''HäLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']						)


						def        __A       (       self	:				Dict						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Tuple							=							BasicTokenizer(do_lower_case=UpperCamelCase__    ,		strip_accents=UpperCamelCase__						)

												self.assertListEqual(
												    tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''						)    ,		['''HaLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']						)


						def        __A       (       self	:				Optional[Any]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    int							=							BasicTokenizer(do_lower_case=UpperCamelCase__    ,		never_split=['''[UNK]''']						)

												self.assertListEqual(
												    tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU? [UNK]'''						)    ,		['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''', '''[UNK]''']						)


						def        __A       (       self	:				List[str]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Optional[int]							=							['''[UNK]''', '''[CLS]''', '''[SEP]''', '''want''', '''##want''', '''##ed''', '''wa''', '''un''', '''runn''', '''##ing''']

												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							{}
												for i, token in enumerate(UpperCamelCase__						):
																		SCREAMING_SNAKE_CASE							:    Tuple							=							i
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							WordpieceTokenizer(vocab=UpperCamelCase__    ,		unk_token='''[UNK]'''						)

												self.assertListEqual(tokenizer.tokenize(''''''						)    ,		[]						)

												self.assertListEqual(tokenizer.tokenize('''unwanted running'''						)    ,		['''un''', '''##want''', '''##ed''', '''runn''', '''##ing''']						)

												self.assertListEqual(tokenizer.tokenize('''unwantedX running'''						)    ,		['''[UNK]''', '''runn''', '''##ing''']						)


						def        __A       (       self	:				str						):





												'''simple docstring'''





												self.assertTrue(_is_whitespace(''' '''						)						)
												self.assertTrue(_is_whitespace('''\t'''						)						)
												self.assertTrue(_is_whitespace('''\r'''						)						)
												self.assertTrue(_is_whitespace('''\n'''						)						)
												self.assertTrue(_is_whitespace('''\u00A0'''						)						)

												self.assertFalse(_is_whitespace('''A'''						)						)
												self.assertFalse(_is_whitespace('''-'''						)						)


						def        __A       (       self	:				Dict						):





												'''simple docstring'''





												self.assertTrue(_is_control('''\u0005'''						)						)

												self.assertFalse(_is_control('''A'''						)						)
												self.assertFalse(_is_control(''' '''						)						)
												self.assertFalse(_is_control('''\t'''						)						)
												self.assertFalse(_is_control('''\r'''						)						)


						def        __A       (       self	:				Dict						):





												'''simple docstring'''





												self.assertTrue(_is_punctuation('''-'''						)						)
												self.assertTrue(_is_punctuation('''$'''						)						)
												self.assertTrue(_is_punctuation('''`'''						)						)
												self.assertTrue(_is_punctuation('''.'''						)						)

												self.assertFalse(_is_punctuation('''A'''						)						)
												self.assertFalse(_is_punctuation(''' '''						)						)


						def        __A       (       self	:				Tuple						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    List[Any]							=							self.get_tokenizer()
												SCREAMING_SNAKE_CASE							:    Tuple							=							self.get_rust_tokenizer()

												# Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
												self.assertListEqual([tokenizer.tokenize(UpperCamelCase__						) for t in ['''Test''', '''\xad''', '''test''']]    ,		[['''[UNK]'''], [], ['''[UNK]''']]						)

												self.assertListEqual(
												    [rust_tokenizer.tokenize(UpperCamelCase__						) for t in ['''Test''', '''\xad''', '''test''']]    ,		[['''[UNK]'''], [], ['''[UNK]''']]						)


						@slow
						def        __A       (       self	:				Any						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    List[str]							=							self.tokenizer_class.from_pretrained('''google/mobilebert-uncased'''						)

												SCREAMING_SNAKE_CASE							:    List[str]							=							tokenizer.encode('''sequence builders'''    ,		add_special_tokens=UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    Dict							=							tokenizer.encode('''multi-sequence build'''    ,		add_special_tokens=UpperCamelCase__						)

												SCREAMING_SNAKE_CASE							:    Optional[int]							=							tokenizer.build_inputs_with_special_tokens(UpperCamelCase__						)
												SCREAMING_SNAKE_CASE							:    int							=							tokenizer.build_inputs_with_special_tokens(UpperCamelCase__    ,		UpperCamelCase__						)

												assert encoded_sentence == [101] + text + [102]
												assert encoded_pair == [101] + text + [102] + text_a + [102]


						def        __A       (       self	:				Any						):





												'''simple docstring'''





												for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																		with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""						):
																								SCREAMING_SNAKE_CASE							:    int							=							self.rust_tokenizer_class.from_pretrained(UpperCamelCase__    ,		**UpperCamelCase__						)

																								SCREAMING_SNAKE_CASE							:    Tuple							=							f"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
																								SCREAMING_SNAKE_CASE							:    Dict							=							tokenizer_r.encode_plus(
																								    UpperCamelCase__    ,		return_attention_mask=UpperCamelCase__    ,		return_token_type_ids=UpperCamelCase__    ,		return_offsets_mapping=UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__    ,		)

																								SCREAMING_SNAKE_CASE							:    Optional[Any]							=							tokenizer_r.do_lower_case if hasattr(UpperCamelCase__    ,		'''do_lower_case'''						) else False
																								SCREAMING_SNAKE_CASE							:    int							=							(
																								    [
																								        ((0, 0), tokenizer_r.cls_token),
																								        ((0, 1), '''A'''),
																								        ((1, 2), ''','''),
																								        ((3, 5), '''na'''),
																								        ((5, 6), '''##ï'''),
																								        ((6, 8), '''##ve'''),
																								        ((9, 15), tokenizer_r.mask_token),
																								        ((16, 21), '''Allen'''),
																								        ((21, 23), '''##NL'''),
																								        ((23, 24), '''##P'''),
																								        ((25, 33), '''sentence'''),
																								        ((33, 34), '''.'''),
																								        ((0, 0), tokenizer_r.sep_token),
																								    ]
																								    if not do_lower_case
																								    else [
																								        ((0, 0), tokenizer_r.cls_token),
																								        ((0, 1), '''a'''),
																								        ((1, 2), ''','''),
																								        ((3, 8), '''naive'''),
																								        ((9, 15), tokenizer_r.mask_token),
																								        ((16, 21), '''allen'''),
																								        ((21, 23), '''##nl'''),
																								        ((23, 24), '''##p'''),
																								        ((25, 33), '''sentence'''),
																								        ((33, 34), '''.'''),
																								        ((0, 0), tokenizer_r.sep_token),
																								    ]
																								)

																								self.assertEqual(
																								    [e[1] for e in expected_results]    ,		tokenizer_r.convert_ids_to_tokens(tokens['''input_ids''']						)						)
																								self.assertEqual([e[0] for e in expected_results]    ,		tokens['''offset_mapping''']						)



						def        __A       (       self	:				int						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Any							=							['''的''', '''人''', '''有''']
												SCREAMING_SNAKE_CASE							:    Any							=							''''''.join(UpperCamelCase__						)
												for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																		with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""						):
																								SCREAMING_SNAKE_CASE							:    Optional[Any]							=							True
																								SCREAMING_SNAKE_CASE							:    Tuple							=							self.tokenizer_class.from_pretrained(UpperCamelCase__    ,		**UpperCamelCase__						)
																								SCREAMING_SNAKE_CASE							:    Any							=							self.rust_tokenizer_class.from_pretrained(UpperCamelCase__    ,		**UpperCamelCase__						)

																								SCREAMING_SNAKE_CASE							:    Dict							=							tokenizer_p.encode(UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__						)
																								SCREAMING_SNAKE_CASE							:    List[Any]							=							tokenizer_r.encode(UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__						)

																								SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							tokenizer_r.convert_ids_to_tokens(UpperCamelCase__						)
																								SCREAMING_SNAKE_CASE							:    Tuple							=							tokenizer_p.convert_ids_to_tokens(UpperCamelCase__						)

																								# it is expected that each Chinese character is not preceded by "##"
																								self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)
																								self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)

																								SCREAMING_SNAKE_CASE							:    Optional[Any]							=							False
																								SCREAMING_SNAKE_CASE							:    Tuple							=							self.rust_tokenizer_class.from_pretrained(UpperCamelCase__    ,		**UpperCamelCase__						)
																								SCREAMING_SNAKE_CASE							:    int							=							self.tokenizer_class.from_pretrained(UpperCamelCase__    ,		**UpperCamelCase__						)

																								SCREAMING_SNAKE_CASE							:    str							=							tokenizer_r.encode(UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__						)
																								SCREAMING_SNAKE_CASE							:    Tuple							=							tokenizer_p.encode(UpperCamelCase__    ,		add_special_tokens=UpperCamelCase__						)

																								SCREAMING_SNAKE_CASE							:    List[Any]							=							tokenizer_r.convert_ids_to_tokens(UpperCamelCase__						)
																								SCREAMING_SNAKE_CASE							:    str							=							tokenizer_p.convert_ids_to_tokens(UpperCamelCase__						)

																								# it is expected that only the first Chinese character is not preceded by "##".
																								SCREAMING_SNAKE_CASE							:    Tuple							=							[
																								    f"""##{token}""" if idx != 0 else token for idx, token in enumerate(UpperCamelCase__						)
																								]
																								self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)
																								self.assertListEqual(UpperCamelCase__    ,		UpperCamelCase__						)






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


											@staticmethod
											def        __A       (       *UpperCamelCase__	:				Union[str, Any]    ,		**UpperCamelCase__	:				Optional[Any]						):





																	'''simple docstring'''





																	pass





@is_pipeline_test
@require_vision
@require_torch
class 					lowercase__						(   unittest.TestCase):
						UpperCamelCase_     =		MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING


						def        __A       (       self	:				Union[str, Any]    ,		UpperCamelCase__	:				Tuple    ,		UpperCamelCase__	:				List[Any]    ,		UpperCamelCase__	:				int						):





												'''simple docstring'''





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

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


						def        __A       (       self	:				Union[str, Any]    ,		UpperCamelCase__	:				Any    ,		UpperCamelCase__	:				Optional[Any]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Optional[int]							=							object_detector(examples[0]    ,		threshold=0.0						)

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


						@require_tf
						@unittest.skip('''Zero Shot Object Detection not implemented in TF'''						)
						def        __A       (       self	:				Optional[Any]						):





												'''simple docstring'''





												pass


						@require_torch
						def        __A       (       self	:				Dict						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Tuple							=							pipeline(
												    '''zero-shot-object-detection'''    ,		model='''hf-internal-testing/tiny-random-owlvit-object-detection'''						)

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

												self.assertEqual(
												    nested_simplify(UpperCamelCase__    ,		decimals=4						)    ,		[
												        {'''score''': 0.7235, '''label''': '''cat''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
												        {'''score''': 0.7218, '''label''': '''remote''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
												        {'''score''': 0.7184, '''label''': '''couch''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
												        {'''score''': 0.6748, '''label''': '''remote''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
												        {'''score''': 0.6656, '''label''': '''cat''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
												        {'''score''': 0.6614, '''label''': '''couch''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
												        {'''score''': 0.6456, '''label''': '''remote''', '''box''': {'''xmin''': 494, '''ymin''': 105, '''xmax''': 521, '''ymax''': 127}},
												        {'''score''': 0.642, '''label''': '''remote''', '''box''': {'''xmin''': 67, '''ymin''': 274, '''xmax''': 93, '''ymax''': 297}},
												        {'''score''': 0.6419, '''label''': '''cat''', '''box''': {'''xmin''': 494, '''ymin''': 105, '''xmax''': 521, '''ymax''': 127}},
												    ]    ,		)

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

												self.assertEqual(
												    nested_simplify(UpperCamelCase__    ,		decimals=4						)    ,		[
												        [
												            {'''score''': 0.7235, '''label''': '''cat''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
												            {'''score''': 0.7218, '''label''': '''remote''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
												            {'''score''': 0.7184, '''label''': '''couch''', '''box''': {'''xmin''': 204, '''ymin''': 167, '''xmax''': 232, '''ymax''': 190}},
												            {'''score''': 0.6748, '''label''': '''remote''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
												            {'''score''': 0.6656, '''label''': '''cat''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
												            {'''score''': 0.6614, '''label''': '''couch''', '''box''': {'''xmin''': 571, '''ymin''': 83, '''xmax''': 598, '''ymax''': 103}},
												            {'''score''': 0.6456, '''label''': '''remote''', '''box''': {'''xmin''': 494, '''ymin''': 105, '''xmax''': 521, '''ymax''': 127}},
												            {'''score''': 0.642, '''label''': '''remote''', '''box''': {'''xmin''': 67, '''ymin''': 274, '''xmax''': 93, '''ymax''': 297}},
												            {'''score''': 0.6419, '''label''': '''cat''', '''box''': {'''xmin''': 494, '''ymin''': 105, '''xmax''': 521, '''ymax''': 127}},
												        ]
												    ]    ,		)


						@require_torch
						@slow
						def        __A       (       self	:				Tuple						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    int							=							pipeline('''zero-shot-object-detection'''						)

												SCREAMING_SNAKE_CASE							:    Optional[int]							=							object_detector(
												    '''http://images.cocodataset.org/val2017/000000039769.jpg'''    ,		candidate_labels=['''cat''', '''remote''', '''couch''']    ,		)
												self.assertEqual(
												    nested_simplify(UpperCamelCase__    ,		decimals=4						)    ,		[
												        {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
												        {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
												        {'''score''': 0.2537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 315, '''ymax''': 472}},
												        {'''score''': 0.1474, '''label''': '''remote''', '''box''': {'''xmin''': 335, '''ymin''': 74, '''xmax''': 371, '''ymax''': 187}},
												        {'''score''': 0.1208, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 642, '''ymax''': 476}},
												    ]    ,		)

												SCREAMING_SNAKE_CASE							:    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(UpperCamelCase__    ,		decimals=4						)    ,		[
												        [
												            {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
												            {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
												            {'''score''': 0.2537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 315, '''ymax''': 472}},
												            {'''score''': 0.1474, '''label''': '''remote''', '''box''': {'''xmin''': 335, '''ymin''': 74, '''xmax''': 371, '''ymax''': 187}},
												            {'''score''': 0.1208, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 642, '''ymax''': 476}},
												        ],
												        [
												            {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
												            {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
												            {'''score''': 0.2537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 315, '''ymax''': 472}},
												            {'''score''': 0.1474, '''label''': '''remote''', '''box''': {'''xmin''': 335, '''ymin''': 74, '''xmax''': 371, '''ymax''': 187}},
												            {'''score''': 0.1208, '''label''': '''couch''', '''box''': {'''xmin''': 4, '''ymin''': 0, '''xmax''': 642, '''ymax''': 476}},
												        ],
												    ]    ,		)


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





												'''simple docstring'''





												pass


						@require_torch
						@slow
						def        __A       (       self	:				List[str]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Tuple							=							0.2
												SCREAMING_SNAKE_CASE							:    Optional[int]							=							pipeline('''zero-shot-object-detection'''						)

												SCREAMING_SNAKE_CASE							:    Dict							=							object_detector(
												    '''http://images.cocodataset.org/val2017/000000039769.jpg'''    ,		candidate_labels=['''cat''', '''remote''', '''couch''']    ,		threshold=UpperCamelCase__    ,		)
												self.assertEqual(
												    nested_simplify(UpperCamelCase__    ,		decimals=4						)    ,		[
												        {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
												        {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
												        {'''score''': 0.2537, '''label''': '''cat''', '''box''': {'''xmin''': 1, '''ymin''': 55, '''xmax''': 315, '''ymax''': 472}},
												    ]    ,		)



						@require_torch
						@slow
						def        __A       (       self	:				List[Any]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    List[str]							=							2
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							pipeline('''zero-shot-object-detection'''						)

												SCREAMING_SNAKE_CASE							:    List[str]							=							object_detector(
												    '''http://images.cocodataset.org/val2017/000000039769.jpg'''    ,		candidate_labels=['''cat''', '''remote''', '''couch''']    ,		top_k=UpperCamelCase__    ,		)
												self.assertEqual(
												    nested_simplify(UpperCamelCase__    ,		decimals=4						)    ,		[
												        {'''score''': 0.2868, '''label''': '''cat''', '''box''': {'''xmin''': 324, '''ymin''': 20, '''xmax''': 640, '''ymax''': 373}},
												        {'''score''': 0.277, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 72, '''xmax''': 177, '''ymax''': 115}},
												    ]    ,		)





