





import json
import os
import unittest

from transformers import AutoTokenizer, GPTaTokenizer, GPTaTokenizerFast
from transformers.models.gpta.tokenization_gpta import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin



@require_tokenizers
class 							_UpperCamelCase					(	lowerCAmelCase_  ,						unittest.TestCase     ):
       _UpperCamelCase				:					List[str]         =   GPTaTokenizer
       _UpperCamelCase				:					int         =   GPTaTokenizerFast
       _UpperCamelCase				:					Union[str, Any]         =   True
       _UpperCamelCase				:					int         =   {'''add_prefix_space''': True}
       _UpperCamelCase				:					Optional[int]         =   False

       def lowercase (		self: Tuple		)       -> int:




              """simple docstring"""


              super().setUp()

              # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
              UpperCamelCase_          =  [
                  "l",
                  "o",
                  "w",
                  "e",
                  "r",
                  "s",
                  "t",
                  "i",
                  "d",
                  "n",
                  "\u0120",
                  "\u0120l",
                  "\u0120n",
                  "\u0120lo",
                  "\u0120low",
                  "er",
                  "\u0120lowest",
                  "\u0120newer",
                  "\u0120wider",
                  "<unk>",
                  "<|endoftext|>",
              ]
              UpperCamelCase_          =  dict(zip(_SCREAMING_SNAKE_CASE					,   range(len(_SCREAMING_SNAKE_CASE		)		)		)		)
              UpperCamelCase_          =  ["#version: 0.2", "\u0120 l", "\u0120l o", "\u0120lo w", "e r", ""]
              UpperCamelCase_          =  {"unk_token": "<unk>"}

              UpperCamelCase_          =  os.path.join(self.tmpdirname					,   VOCAB_FILES_NAMES["vocab_file"]		)
              UpperCamelCase_          =  os.path.join(self.tmpdirname					,   VOCAB_FILES_NAMES["merges_file"]		)
              with open(self.vocab_file					,   "w"					,   encoding="utf-8"		) as fp:
                     fp.write(json.dumps(_SCREAMING_SNAKE_CASE		) + "\n"		)
              with open(self.merges_file					,   "w"					,   encoding="utf-8"		) as fp:
                     fp.write("\n".join(_SCREAMING_SNAKE_CASE		)		)

       def lowercase (		self: str					,   **_SCREAMING_SNAKE_CASE: Union[str, Any]		)       -> List[Any]:




              """simple docstring"""


              kwargs.update(self.special_tokens_map		)
              return GPTaTokenizer.from_pretrained(self.tmpdirname					,   **_SCREAMING_SNAKE_CASE		)

       def lowercase (		self: str					,   **_SCREAMING_SNAKE_CASE: int		)       -> Optional[Any]:




              """simple docstring"""


              kwargs.update(self.special_tokens_map		)
              return GPTaTokenizerFast.from_pretrained(self.tmpdirname					,   **_SCREAMING_SNAKE_CASE		)

       def lowercase (		self: int					,   _SCREAMING_SNAKE_CASE: Dict		)       -> List[str]:




              """simple docstring"""


              UpperCamelCase_          =  "lower newer"
              UpperCamelCase_          =  "lower newer"
              return input_text, output_text

       def lowercase (		self: int		)       -> List[str]:




              """simple docstring"""


              UpperCamelCase_          =  GPTaTokenizer(self.vocab_file					,   self.merges_file					,   **self.special_tokens_map		)
              UpperCamelCase_          =  "lower newer"
              UpperCamelCase_          =  ["\u0120low", "er", "\u0120", "n", "e", "w", "er"]
              UpperCamelCase_          =  tokenizer.tokenize(_SCREAMING_SNAKE_CASE					,   add_prefix_space=_SCREAMING_SNAKE_CASE		)
              self.assertListEqual(_SCREAMING_SNAKE_CASE					,   _SCREAMING_SNAKE_CASE		)

              UpperCamelCase_          =  tokens + [tokenizer.unk_token]
              UpperCamelCase_          =  [14, 15, 10, 9, 3, 2, 15, 19]
              self.assertListEqual(tokenizer.convert_tokens_to_ids(_SCREAMING_SNAKE_CASE		)					,   _SCREAMING_SNAKE_CASE		)

       def lowercase (		self: Union[str, Any]		)       -> List[Any]:




              """simple docstring"""


              if not self.test_rust_tokenizer:
                     return

              UpperCamelCase_          =  self.get_tokenizer()
              UpperCamelCase_          =  self.get_rust_tokenizer(add_prefix_space=_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_          =  "lower newer"

              # Testing tokenization
              UpperCamelCase_          =  tokenizer.tokenize(_SCREAMING_SNAKE_CASE					,   add_prefix_space=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  rust_tokenizer.tokenize(_SCREAMING_SNAKE_CASE		)
              self.assertListEqual(_SCREAMING_SNAKE_CASE					,   _SCREAMING_SNAKE_CASE		)

              # Testing conversion to ids without special tokens
              UpperCamelCase_          =  tokenizer.encode(_SCREAMING_SNAKE_CASE					,   add_special_tokens=_SCREAMING_SNAKE_CASE					,   add_prefix_space=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  rust_tokenizer.encode(_SCREAMING_SNAKE_CASE					,   add_special_tokens=_SCREAMING_SNAKE_CASE		)
              self.assertListEqual(_SCREAMING_SNAKE_CASE					,   _SCREAMING_SNAKE_CASE		)

              # Testing conversion to ids with special tokens
              UpperCamelCase_          =  self.get_rust_tokenizer(add_prefix_space=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  tokenizer.encode(_SCREAMING_SNAKE_CASE					,   add_prefix_space=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  rust_tokenizer.encode(_SCREAMING_SNAKE_CASE		)
              self.assertListEqual(_SCREAMING_SNAKE_CASE					,   _SCREAMING_SNAKE_CASE		)

              # Testing the unknown token
              UpperCamelCase_          =  tokens + [rust_tokenizer.unk_token]
              UpperCamelCase_          =  [14, 15, 10, 9, 3, 2, 15, 19]
              self.assertListEqual(rust_tokenizer.convert_tokens_to_ids(_SCREAMING_SNAKE_CASE		)					,   _SCREAMING_SNAKE_CASE		)

       def lowercase (		self: Tuple					,   *_SCREAMING_SNAKE_CASE: str					,   **_SCREAMING_SNAKE_CASE: str		)       -> Optional[Any]:




              """simple docstring"""


              pass

       def lowercase (		self: Any					,   _SCREAMING_SNAKE_CASE: Dict=15		)       -> Tuple:




              """simple docstring"""


              for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
                     with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''		):
                            UpperCamelCase_          =  self.rust_tokenizer_class.from_pretrained(_SCREAMING_SNAKE_CASE					,   **_SCREAMING_SNAKE_CASE		)

                            # Simple input
                            UpperCamelCase_          =  "This is a simple input"
                            UpperCamelCase_          =  ["This is a simple input 1", "This is a simple input 2"]
                            UpperCamelCase_          =  ("This is a simple input", "This is a pair")
                            UpperCamelCase_          =  [
                                ("This is a simple input 1", "This is a simple input 2"),
                                ("This is a simple pair 1", "This is a simple pair 2"),
                            ]

                            # Simple input tests
                            self.assertRaises(_SCREAMING_SNAKE_CASE					,   tokenizer_r.encode					,   _SCREAMING_SNAKE_CASE					,   max_length=_SCREAMING_SNAKE_CASE					,   padding="max_length"		)

                            # Simple input
                            self.assertRaises(_SCREAMING_SNAKE_CASE					,   tokenizer_r.encode_plus					,   _SCREAMING_SNAKE_CASE					,   max_length=_SCREAMING_SNAKE_CASE					,   padding="max_length"		)

                            # Simple input
                            self.assertRaises(
                                _SCREAMING_SNAKE_CASE					,   tokenizer_r.batch_encode_plus					,   _SCREAMING_SNAKE_CASE					,   max_length=_SCREAMING_SNAKE_CASE					,   padding="max_length"					,   )

                            # Pair input
                            self.assertRaises(_SCREAMING_SNAKE_CASE					,   tokenizer_r.encode					,   _SCREAMING_SNAKE_CASE					,   max_length=_SCREAMING_SNAKE_CASE					,   padding="max_length"		)

                            # Pair input
                            self.assertRaises(_SCREAMING_SNAKE_CASE					,   tokenizer_r.encode_plus					,   _SCREAMING_SNAKE_CASE					,   max_length=_SCREAMING_SNAKE_CASE					,   padding="max_length"		)

                            # Pair input
                            self.assertRaises(
                                _SCREAMING_SNAKE_CASE					,   tokenizer_r.batch_encode_plus					,   _SCREAMING_SNAKE_CASE					,   max_length=_SCREAMING_SNAKE_CASE					,   padding="max_length"					,   )

       def lowercase (		self: Dict		)       -> str:




              """simple docstring"""


              UpperCamelCase_          =  GPTaTokenizer.from_pretrained(self.tmpdirname					,   pad_token="<pad>"		)

              # Simple input
              UpperCamelCase_          =  "This is a simple input"
              UpperCamelCase_          =  ["This is a simple input looooooooong", "This is a simple input"]
              UpperCamelCase_          =  ("This is a simple input", "This is a pair")
              UpperCamelCase_          =  [
                  ("This is a simple input loooooong", "This is a simple input"),
                  ("This is a simple pair loooooong", "This is a simple pair"),
              ]

              UpperCamelCase_          =  tokenizer.pad_token_id

              UpperCamelCase_          =  tokenizer(_SCREAMING_SNAKE_CASE					,   padding="max_length"					,   max_length=30					,   return_tensors="np"		)
              UpperCamelCase_          =  tokenizer(_SCREAMING_SNAKE_CASE					,   padding=_SCREAMING_SNAKE_CASE					,   truncate=_SCREAMING_SNAKE_CASE					,   return_tensors="np"		)
              UpperCamelCase_          =  tokenizer(*_SCREAMING_SNAKE_CASE					,   padding="max_length"					,   max_length=60					,   return_tensors="np"		)
              UpperCamelCase_          =  tokenizer(_SCREAMING_SNAKE_CASE					,   padding=_SCREAMING_SNAKE_CASE					,   truncate=_SCREAMING_SNAKE_CASE					,   return_tensors="np"		)

              # s
              # test single string max_length padding
              self.assertEqual(out_s["input_ids"].shape[-1]					,   30		)
              self.assertTrue(pad_token_id in out_s["input_ids"]		)
              self.assertTrue(0 in out_s["attention_mask"]		)

              # s2
              # test automatic padding
              self.assertEqual(out_sa["input_ids"].shape[-1]					,   33		)
              # long slice doesn't have padding
              self.assertFalse(pad_token_id in out_sa["input_ids"][0]		)
              self.assertFalse(0 in out_sa["attention_mask"][0]		)
              # short slice does have padding
              self.assertTrue(pad_token_id in out_sa["input_ids"][1]		)
              self.assertTrue(0 in out_sa["attention_mask"][1]		)

              # p
              # test single pair max_length padding
              self.assertEqual(out_p["input_ids"].shape[-1]					,   60		)
              self.assertTrue(pad_token_id in out_p["input_ids"]		)
              self.assertTrue(0 in out_p["attention_mask"]		)

              # p2
              # test automatic padding pair
              self.assertEqual(out_pa["input_ids"].shape[-1]					,   52		)
              # long slice pair doesn't have padding
              self.assertFalse(pad_token_id in out_pa["input_ids"][0]		)
              self.assertFalse(0 in out_pa["attention_mask"][0]		)
              # short slice pair does have padding
              self.assertTrue(pad_token_id in out_pa["input_ids"][1]		)
              self.assertTrue(0 in out_pa["attention_mask"][1]		)

       def lowercase (		self: List[str]		)       -> Dict:




              """simple docstring"""


              UpperCamelCase_          =  "$$$"
              UpperCamelCase_          =  GPTaTokenizer.from_pretrained(self.tmpdirname					,   bos_token=_SCREAMING_SNAKE_CASE					,   add_bos_token=_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_          =  "This is a simple input"
              UpperCamelCase_          =  ["This is a simple input 1", "This is a simple input 2"]

              UpperCamelCase_          =  tokenizer.bos_token_id

              UpperCamelCase_          =  tokenizer(_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  tokenizer(_SCREAMING_SNAKE_CASE		)

              self.assertEqual(out_s.input_ids[0]					,   _SCREAMING_SNAKE_CASE		)
              self.assertTrue(all(o[0] == bos_token_id for o in out_sa.input_ids		)		)

              UpperCamelCase_          =  tokenizer.decode(out_s.input_ids		)
              UpperCamelCase_          =  tokenizer.batch_decode(out_sa.input_ids		)

              self.assertEqual(decode_s.split()[0]					,   _SCREAMING_SNAKE_CASE		)
              self.assertTrue(all(d.split()[0] == bos_token for d in decode_sa		)		)

       def lowercase (		self: List[str]		)       -> Dict:




              """simple docstring"""


              pass



       def lowercase (		self: int		)       -> Any:




              """simple docstring"""


              UpperCamelCase_          =  [self.get_tokenizer(do_lower_case=_SCREAMING_SNAKE_CASE					,   add_bos_token=_SCREAMING_SNAKE_CASE		)]
              for tokenizer in tokenizers:
                     with self.subTest(f'''{tokenizer.__class__.__name__}'''		):
                            UpperCamelCase_          =  "Encode this."
                            UpperCamelCase_          =  "This one too please."
                            UpperCamelCase_          =  tokenizer.encode(_SCREAMING_SNAKE_CASE					,   add_special_tokens=_SCREAMING_SNAKE_CASE		)
                            encoded_sequence += tokenizer.encode(_SCREAMING_SNAKE_CASE					,   add_special_tokens=_SCREAMING_SNAKE_CASE		)
                            UpperCamelCase_          =  tokenizer.encode_plus(
                                _SCREAMING_SNAKE_CASE					,   _SCREAMING_SNAKE_CASE					,   add_special_tokens=_SCREAMING_SNAKE_CASE					,   return_special_tokens_mask=_SCREAMING_SNAKE_CASE					,   )
                            UpperCamelCase_          =  encoded_sequence_dict["input_ids"]
                            UpperCamelCase_          =  encoded_sequence_dict["special_tokens_mask"]
                            self.assertEqual(len(_SCREAMING_SNAKE_CASE		)					,   len(_SCREAMING_SNAKE_CASE		)		)

                            UpperCamelCase_          =  [
                                (x if not special_tokens_mask[i] else None) for i, x in enumerate(_SCREAMING_SNAKE_CASE		)
                            ]
                            UpperCamelCase_          =  [x for x in filtered_sequence if x is not None]
                            self.assertEqual(_SCREAMING_SNAKE_CASE					,   _SCREAMING_SNAKE_CASE		)



@require_tokenizers
class 							_UpperCamelCase					(	unittest.TestCase     ):

       def lowercase (		self: List[str]		)       -> Dict:




              """simple docstring"""


              UpperCamelCase_          =  AutoTokenizer.from_pretrained("facebook/opt-350m"					,   from_slow=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  "A photo of a cat"

              UpperCamelCase_          =  tokenizer.encode(
                  _SCREAMING_SNAKE_CASE					,   )
              self.assertEqual(_SCREAMING_SNAKE_CASE					,   [2, 250, 1345, 9, 10, 4758]		)
              tokenizer.save_pretrained("test_opt"		)

              UpperCamelCase_          =  AutoTokenizer.from_pretrained("./test_opt"		)
              UpperCamelCase_          =  tokenizer.encode(
                  _SCREAMING_SNAKE_CASE					,   )
              self.assertEqual(_SCREAMING_SNAKE_CASE					,   [2, 250, 1345, 9, 10, 4758]		)

       def lowercase (		self: Tuple		)       -> str:




              """simple docstring"""


              UpperCamelCase_          =  AutoTokenizer.from_pretrained("facebook/opt-350m"					,   use_slow=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  "A photo of a cat"

              UpperCamelCase_          =  tokenizer.encode(
                  _SCREAMING_SNAKE_CASE					,   )
              # Same as above
              self.assertEqual(_SCREAMING_SNAKE_CASE					,   [2, 250, 1345, 9, 10, 4758]		)



       @unittest.skip("This test is failing because of a bug in the fast tokenizer"		)
       def lowercase (		self: Optional[Any]		)       -> Optional[int]:




              """simple docstring"""


              UpperCamelCase_          =  AutoTokenizer.from_pretrained("facebook/opt-350m"					,   from_slow=_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_          =  "bos"
              UpperCamelCase_          =  tokenizer.get_vocab()["bos"]

              UpperCamelCase_          =  "A photo of a cat"
              UpperCamelCase_          =  tokenizer.encode(
                  _SCREAMING_SNAKE_CASE					,   )
              # We changed the bos token
              self.assertEqual(_SCREAMING_SNAKE_CASE					,   [31957, 250, 1345, 9, 10, 4758]		)
              tokenizer.save_pretrained("./tok"		)
              UpperCamelCase_          =  AutoTokenizer.from_pretrained("./tok"		)
              self.assertTrue(tokenizer.is_fast		)
              UpperCamelCase_          =  tokenizer.encode(
                  _SCREAMING_SNAKE_CASE					,   )
              self.assertEqual(_SCREAMING_SNAKE_CASE					,   [31957, 250, 1345, 9, 10, 4758]		)








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

            @staticmethod
            def lowercase (		*_SCREAMING_SNAKE_CASE: Optional[int]					,   **_SCREAMING_SNAKE_CASE: Dict		)       -> Union[str, Any]:




                   """simple docstring"""


                   pass



@is_pipeline_test
@require_vision
@require_torch
class 							_UpperCamelCase					(	unittest.TestCase     ):
       _UpperCamelCase				:					str         =   MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING

       def lowercase (		self: int					,   _SCREAMING_SNAKE_CASE: str					,   _SCREAMING_SNAKE_CASE: int					,   _SCREAMING_SNAKE_CASE: Optional[Any]		)       -> Any:




              """simple docstring"""


              UpperCamelCase_          =  pipeline(
                  "zero-shot-object-detection"					,   model="hf-internal-testing/tiny-random-owlvit-object-detection"		)

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

       def lowercase (		self: Optional[Any]					,   _SCREAMING_SNAKE_CASE: Tuple					,   _SCREAMING_SNAKE_CASE: Tuple		)       -> Optional[int]:




              """simple docstring"""


              UpperCamelCase_          =  object_detector(examples[0]					,   threshold=0.0		)

              UpperCamelCase_          =  len(_SCREAMING_SNAKE_CASE		)
              self.assertGreater(_SCREAMING_SNAKE_CASE					,   0		)
              self.assertEqual(
                  _SCREAMING_SNAKE_CASE					,   [
                      {
                          "score": ANY(_SCREAMING_SNAKE_CASE		),
                          "label": ANY(_SCREAMING_SNAKE_CASE		),
                          "box": {"xmin": ANY(_SCREAMING_SNAKE_CASE		), "ymin": ANY(_SCREAMING_SNAKE_CASE		), "xmax": ANY(_SCREAMING_SNAKE_CASE		), "ymax": ANY(_SCREAMING_SNAKE_CASE		)},
                      }
                      for i in range(_SCREAMING_SNAKE_CASE		)
                  ]					,   )

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




              """simple docstring"""


              pass

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




              """simple docstring"""


              UpperCamelCase_          =  pipeline(
                  "zero-shot-object-detection"					,   model="hf-internal-testing/tiny-random-owlvit-object-detection"		)

              UpperCamelCase_          =  object_detector(
                  "./tests/fixtures/tests_samples/COCO/000000039769.png"					,   candidate_labels=["cat", "remote", "couch"]					,   threshold=0.64					,   )

              self.assertEqual(
                  nested_simplify(_SCREAMING_SNAKE_CASE					,   decimals=4		)					,   [
                      {"score": 0.72_35, "label": "cat", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                      {"score": 0.72_18, "label": "remote", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                      {"score": 0.71_84, "label": "couch", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                      {"score": 0.67_48, "label": "remote", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                      {"score": 0.66_56, "label": "cat", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                      {"score": 0.66_14, "label": "couch", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                      {"score": 0.64_56, "label": "remote", "box": {"xmin": 494, "ymin": 105, "xmax": 521, "ymax": 127}},
                      {"score": 0.6_42, "label": "remote", "box": {"xmin": 67, "ymin": 274, "xmax": 93, "ymax": 297}},
                      {"score": 0.64_19, "label": "cat", "box": {"xmin": 494, "ymin": 105, "xmax": 521, "ymax": 127}},
                  ]					,   )

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

              self.assertEqual(
                  nested_simplify(_SCREAMING_SNAKE_CASE					,   decimals=4		)					,   [
                      [
                          {"score": 0.72_35, "label": "cat", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                          {"score": 0.72_18, "label": "remote", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                          {"score": 0.71_84, "label": "couch", "box": {"xmin": 204, "ymin": 167, "xmax": 232, "ymax": 190}},
                          {"score": 0.67_48, "label": "remote", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                          {"score": 0.66_56, "label": "cat", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                          {"score": 0.66_14, "label": "couch", "box": {"xmin": 571, "ymin": 83, "xmax": 598, "ymax": 103}},
                          {"score": 0.64_56, "label": "remote", "box": {"xmin": 494, "ymin": 105, "xmax": 521, "ymax": 127}},
                          {"score": 0.6_42, "label": "remote", "box": {"xmin": 67, "ymin": 274, "xmax": 93, "ymax": 297}},
                          {"score": 0.64_19, "label": "cat", "box": {"xmin": 494, "ymin": 105, "xmax": 521, "ymax": 127}},
                      ]
                  ]					,   )

       @require_torch
       @slow
       def lowercase (		self: List[str]		)       -> List[str]:




              """simple docstring"""


              UpperCamelCase_          =  pipeline("zero-shot-object-detection"		)

              UpperCamelCase_          =  object_detector(
                  "http://images.cocodataset.org/val2017/000000039769.jpg"					,   candidate_labels=["cat", "remote", "couch"]					,   )
              self.assertEqual(
                  nested_simplify(_SCREAMING_SNAKE_CASE					,   decimals=4		)					,   [
                      {"score": 0.28_68, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                      {"score": 0.2_77, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                      {"score": 0.25_37, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 315, "ymax": 472}},
                      {"score": 0.14_74, "label": "remote", "box": {"xmin": 335, "ymin": 74, "xmax": 371, "ymax": 187}},
                      {"score": 0.12_08, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 642, "ymax": 476}},
                  ]					,   )

              UpperCamelCase_          =  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(_SCREAMING_SNAKE_CASE					,   decimals=4		)					,   [
                      [
                          {"score": 0.28_68, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                          {"score": 0.2_77, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                          {"score": 0.25_37, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 315, "ymax": 472}},
                          {"score": 0.14_74, "label": "remote", "box": {"xmin": 335, "ymin": 74, "xmax": 371, "ymax": 187}},
                          {"score": 0.12_08, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 642, "ymax": 476}},
                      ],
                      [
                          {"score": 0.28_68, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                          {"score": 0.2_77, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                          {"score": 0.25_37, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 315, "ymax": 472}},
                          {"score": 0.14_74, "label": "remote", "box": {"xmin": 335, "ymin": 74, "xmax": 371, "ymax": 187}},
                          {"score": 0.12_08, "label": "couch", "box": {"xmin": 4, "ymin": 0, "xmax": 642, "ymax": 476}},
                      ],
                  ]					,   )

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




              """simple docstring"""


              pass

       @require_torch
       @slow
       def lowercase (		self: Any		)       -> int:




              """simple docstring"""


              UpperCamelCase_          =  0.2
              UpperCamelCase_          =  pipeline("zero-shot-object-detection"		)

              UpperCamelCase_          =  object_detector(
                  "http://images.cocodataset.org/val2017/000000039769.jpg"					,   candidate_labels=["cat", "remote", "couch"]					,   threshold=_SCREAMING_SNAKE_CASE					,   )
              self.assertEqual(
                  nested_simplify(_SCREAMING_SNAKE_CASE					,   decimals=4		)					,   [
                      {"score": 0.28_68, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                      {"score": 0.2_77, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                      {"score": 0.25_37, "label": "cat", "box": {"xmin": 1, "ymin": 55, "xmax": 315, "ymax": 472}},
                  ]					,   )



       @require_torch
       @slow
       def lowercase (		self: Dict		)       -> Tuple:




              """simple docstring"""


              UpperCamelCase_          =  2
              UpperCamelCase_          =  pipeline("zero-shot-object-detection"		)

              UpperCamelCase_          =  object_detector(
                  "http://images.cocodataset.org/val2017/000000039769.jpg"					,   candidate_labels=["cat", "remote", "couch"]					,   top_k=_SCREAMING_SNAKE_CASE					,   )
              self.assertEqual(
                  nested_simplify(_SCREAMING_SNAKE_CASE					,   decimals=4		)					,   [
                      {"score": 0.28_68, "label": "cat", "box": {"xmin": 324, "ymin": 20, "xmax": 640, "ymax": 373}},
                      {"score": 0.2_77, "label": "remote", "box": {"xmin": 40, "ymin": 72, "xmax": 177, "ymax": 115}},
                  ]					,   )

