


'''simple docstring'''

import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     MODEL_FOR_PRETRAINING_MAPPING,
     MobileBertForMaskedLM,
     MobileBertForMultipleChoice,
     MobileBertForNextSentencePrediction,
     MobileBertForPreTraining,
     MobileBertForQuestionAnswering,
     MobileBertForSequenceClassification,
     MobileBertForTokenClassification,
     MobileBertModel,
 )
class   __lowerCAmelCase						:





      '''simple docstring'''






      def __init__(self    :    int   ,						UpperCamelCase    :    Optional[int]   ,						UpperCamelCase    :    Any=13   ,						UpperCamelCase    :    List[Any]=7   ,						UpperCamelCase    :    Optional[int]=True   ,						UpperCamelCase    :    List[str]=True   ,						UpperCamelCase    :    List[Any]=True   ,						UpperCamelCase    :    Optional[Any]=True   ,						UpperCamelCase    :    Union[str, Any]=99   ,						UpperCamelCase    :    List[str]=64   ,						UpperCamelCase    :    List[str]=32   ,						UpperCamelCase    :    Optional[int]=5   ,						UpperCamelCase    :    Any=4   ,						UpperCamelCase    :    Union[str, Any]=37   ,						UpperCamelCase    :    Dict="gelu"   ,						UpperCamelCase    :    int=0.1   ,						UpperCamelCase    :    List[Any]=0.1   ,						UpperCamelCase    :    List[Any]=512   ,						UpperCamelCase    :    Union[str, Any]=16   ,						UpperCamelCase    :    int=2   ,						UpperCamelCase    :    Tuple=0.02   ,						UpperCamelCase    :    Optional[int]=3   ,						UpperCamelCase    :    Optional[Any]=4   ,						UpperCamelCase    :    str=None   ,						):

             '''simple docstring'''







             lowercase__      			= parent
             lowercase__      			= batch_size
             lowercase__      			= seq_length
             lowercase__      			= is_training
             lowercase__      			= use_input_mask
             lowercase__      			= use_token_type_ids
             lowercase__      			= use_labels
             lowercase__      			= vocab_size
             lowercase__      			= hidden_size
             lowercase__      			= embedding_size
             lowercase__      			= num_hidden_layers
             lowercase__      			= num_attention_heads
             lowercase__      			= intermediate_size
             lowercase__      			= hidden_act
             lowercase__      			= hidden_dropout_prob
             lowercase__      			= attention_probs_dropout_prob
             lowercase__      			= max_position_embeddings
             lowercase__      			= type_vocab_size
             lowercase__      			= type_sequence_label_size
             lowercase__      			= initializer_range
             lowercase__      			= num_labels
             lowercase__      			= num_choices
             lowercase__      			= scope



      def       UpperCamelCase__		(self    :    str ):

             '''simple docstring'''







             lowercase__      			= ids_tensor([self.batch_size, self.seq_length]   ,						self.vocab_size )

             lowercase__      			= None
             if self.use_input_mask:
                    lowercase__      			= random_attention_mask([self.batch_size, self.seq_length] )

             lowercase__      			= None
             if self.use_token_type_ids:
                    lowercase__      			= ids_tensor([self.batch_size, self.seq_length]   ,						self.type_vocab_size )

             lowercase__      			= None
             lowercase__      			= None
             lowercase__      			= None
             if self.use_labels:
                    lowercase__      			= ids_tensor([self.batch_size]   ,						self.type_sequence_label_size )
                    lowercase__      			= ids_tensor([self.batch_size, self.seq_length]   ,						self.num_labels )
                    lowercase__      			= ids_tensor([self.batch_size]   ,						self.num_choices )

             lowercase__      			= self.get_config()

             return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



      def       UpperCamelCase__		(self    :    Dict ):

             '''simple docstring'''







             return MobileBertConfig(
                 vocab_size=self.vocab_size   ,						hidden_size=self.hidden_size   ,						num_hidden_layers=self.num_hidden_layers   ,						num_attention_heads=self.num_attention_heads   ,						intermediate_size=self.intermediate_size   ,						embedding_size=self.embedding_size   ,						hidden_act=self.hidden_act   ,						hidden_dropout_prob=self.hidden_dropout_prob   ,						attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,						max_position_embeddings=self.max_position_embeddings   ,						type_vocab_size=self.type_vocab_size   ,						is_decoder=UpperCamelCase   ,						initializer_range=self.initializer_range   ,						)



      def       UpperCamelCase__		(self    :    Optional[Any]   ,						UpperCamelCase    :    Any   ,						UpperCamelCase    :    Optional[int]   ,						UpperCamelCase    :    List[str]   ,						UpperCamelCase    :    int   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    Union[str, Any]   ,						UpperCamelCase    :    Optional[Any] ):

             '''simple docstring'''







             lowercase__      			= MobileBertModel(config=UpperCamelCase )
             model.to(UpperCamelCase )
             model.eval()
             lowercase__      			= model(UpperCamelCase   ,						attention_mask=UpperCamelCase   ,						token_type_ids=UpperCamelCase )
             lowercase__      			= model(UpperCamelCase   ,						token_type_ids=UpperCamelCase )
             lowercase__      			= model(UpperCamelCase )

             self.parent.assertEqual(result.last_hidden_state.shape   ,						(self.batch_size, self.seq_length, self.hidden_size) )
             self.parent.assertEqual(result.pooler_output.shape   ,						(self.batch_size, self.hidden_size) )



      def       UpperCamelCase__		(self    :    str   ,						UpperCamelCase    :    str   ,						UpperCamelCase    :    Optional[Any]   ,						UpperCamelCase    :    str   ,						UpperCamelCase    :    Optional[Any]   ,						UpperCamelCase    :    Optional[int]   ,						UpperCamelCase    :    List[str]   ,						UpperCamelCase    :    List[Any] ):

             '''simple docstring'''







             lowercase__      			= MobileBertForMaskedLM(config=UpperCamelCase )
             model.to(UpperCamelCase )
             model.eval()
             lowercase__      			= model(UpperCamelCase   ,						attention_mask=UpperCamelCase   ,						token_type_ids=UpperCamelCase   ,						labels=UpperCamelCase )
             self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.seq_length, self.vocab_size) )



      def       UpperCamelCase__		(self    :    Optional[Any]   ,						UpperCamelCase    :    Optional[int]   ,						UpperCamelCase    :    str   ,						UpperCamelCase    :    Any   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    Union[str, Any]   ,						UpperCamelCase    :    str ):

             '''simple docstring'''







             lowercase__      			= MobileBertForNextSentencePrediction(config=UpperCamelCase )
             model.to(UpperCamelCase )
             model.eval()
             lowercase__      			= model(
                 UpperCamelCase   ,						attention_mask=UpperCamelCase   ,						token_type_ids=UpperCamelCase   ,						labels=UpperCamelCase   ,						)
             self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, 2) )



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

             '''simple docstring'''







             lowercase__      			= MobileBertForPreTraining(config=UpperCamelCase )
             model.to(UpperCamelCase )
             model.eval()
             lowercase__      			= model(
                 UpperCamelCase   ,						attention_mask=UpperCamelCase   ,						token_type_ids=UpperCamelCase   ,						labels=UpperCamelCase   ,						next_sentence_label=UpperCamelCase   ,						)
             self.parent.assertEqual(result.prediction_logits.shape   ,						(self.batch_size, self.seq_length, self.vocab_size) )
             self.parent.assertEqual(result.seq_relationship_logits.shape   ,						(self.batch_size, 2) )



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

             '''simple docstring'''







             lowercase__      			= MobileBertForQuestionAnswering(config=UpperCamelCase )
             model.to(UpperCamelCase )
             model.eval()
             lowercase__      			= model(
                 UpperCamelCase   ,						attention_mask=UpperCamelCase   ,						token_type_ids=UpperCamelCase   ,						start_positions=UpperCamelCase   ,						end_positions=UpperCamelCase   ,						)
             self.parent.assertEqual(result.start_logits.shape   ,						(self.batch_size, self.seq_length) )
             self.parent.assertEqual(result.end_logits.shape   ,						(self.batch_size, self.seq_length) )



      def       UpperCamelCase__		(self    :    List[str]   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    List[Any]   ,						UpperCamelCase    :    Union[str, Any]   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    str   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    Any ):

             '''simple docstring'''







             lowercase__      			= self.num_labels
             lowercase__      			= MobileBertForSequenceClassification(UpperCamelCase )
             model.to(UpperCamelCase )
             model.eval()
             lowercase__      			= model(UpperCamelCase   ,						attention_mask=UpperCamelCase   ,						token_type_ids=UpperCamelCase   ,						labels=UpperCamelCase )
             self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.num_labels) )



      def       UpperCamelCase__		(self    :    List[str]   ,						UpperCamelCase    :    List[str]   ,						UpperCamelCase    :    Optional[Any]   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    Dict   ,						UpperCamelCase    :    Tuple   ,						UpperCamelCase    :    List[str] ):

             '''simple docstring'''







             lowercase__      			= self.num_labels
             lowercase__      			= MobileBertForTokenClassification(config=UpperCamelCase )
             model.to(UpperCamelCase )
             model.eval()
             lowercase__      			= model(UpperCamelCase   ,						attention_mask=UpperCamelCase   ,						token_type_ids=UpperCamelCase   ,						labels=UpperCamelCase )
             self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.seq_length, self.num_labels) )



      def       UpperCamelCase__		(self    :    List[str]   ,						UpperCamelCase    :    Union[str, Any]   ,						UpperCamelCase    :    int   ,						UpperCamelCase    :    List[str]   ,						UpperCamelCase    :    Union[str, Any]   ,						UpperCamelCase    :    Any   ,						UpperCamelCase    :    Any   ,						UpperCamelCase    :    Dict ):

             '''simple docstring'''







             lowercase__      			= self.num_choices
             lowercase__      			= MobileBertForMultipleChoice(config=UpperCamelCase )
             model.to(UpperCamelCase )
             model.eval()
             lowercase__      			= input_ids.unsqueeze(1 ).expand(-1   ,						self.num_choices   ,						-1 ).contiguous()
             lowercase__      			= token_type_ids.unsqueeze(1 ).expand(-1   ,						self.num_choices   ,						-1 ).contiguous()
             lowercase__      			= input_mask.unsqueeze(1 ).expand(-1   ,						self.num_choices   ,						-1 ).contiguous()
             lowercase__      			= model(
                 UpperCamelCase   ,						attention_mask=UpperCamelCase   ,						token_type_ids=UpperCamelCase   ,						labels=UpperCamelCase   ,						)
             self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.num_choices) )






      def       UpperCamelCase__		(self    :    Dict ):

             '''simple docstring'''







             lowercase__      			= self.prepare_config_and_inputs()
             (
                 (
                 lowercase__
             )			,(
                 lowercase__
             )			,(
                 lowercase__
             )			,(
                 lowercase__
             )			,(
                 lowercase__
             )			,(
                 lowercase__
             )			,(
                 lowercase__
             )			,
             )      			= config_and_inputs
             lowercase__      			= {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
             return config, inputs_dict






@require_torch
class   __lowerCAmelCase						(lowercase_  ,     lowercase_  ,     unittest.TestCase     ):





      '''simple docstring'''






      lowerCAmelCase__					:     Tuple  					=							(
          (
              MobileBertModel,
              MobileBertForMaskedLM,
              MobileBertForMultipleChoice,
              MobileBertForNextSentencePrediction,
              MobileBertForPreTraining,
              MobileBertForQuestionAnswering,
              MobileBertForSequenceClassification,
              MobileBertForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      lowerCAmelCase__					:     Tuple  					=							(
          {
              """feature-extraction""": MobileBertModel,
              """fill-mask""": MobileBertForMaskedLM,
              """question-answering""": MobileBertForQuestionAnswering,
              """text-classification""": MobileBertForSequenceClassification,
              """token-classification""": MobileBertForTokenClassification,
              """zero-shot""": MobileBertForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      lowerCAmelCase__					:     str  					=							True



      def       UpperCamelCase__		(self    :    List[str]   ,						UpperCamelCase    :    List[str]   ,						UpperCamelCase    :    Any   ,						UpperCamelCase    :    Any=False ):

             '''simple docstring'''







             lowercase__      			= super()._prepare_for_class(UpperCamelCase   ,						UpperCamelCase   ,						return_labels=UpperCamelCase )

             if return_labels:
                    if model_class in get_values(UpperCamelCase ):
                           lowercase__      			= torch.zeros(
                               (self.model_tester.batch_size, self.model_tester.seq_length)   ,						dtype=torch.long   ,						device=UpperCamelCase )
                           lowercase__      			= torch.zeros(
                               self.model_tester.batch_size   ,						dtype=torch.long   ,						device=UpperCamelCase )
             return inputs_dict



      def       UpperCamelCase__		(self    :    Optional[Any] ):

             '''simple docstring'''







             lowercase__      			= MobileBertModelTester(self )
             lowercase__      			= ConfigTester(self   ,						config_class=UpperCamelCase   ,						hidden_size=37 )



      def       UpperCamelCase__		(self    :    Any ):

             '''simple docstring'''







             self.config_tester.run_common_tests()



      def       UpperCamelCase__		(self    :    Any ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_model(*UpperCamelCase )



      def       UpperCamelCase__		(self    :    Optional[int] ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_masked_lm(*UpperCamelCase )



      def       UpperCamelCase__		(self    :    Optional[Any] ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_multiple_choice(*UpperCamelCase )



      def       UpperCamelCase__		(self    :    List[str] ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*UpperCamelCase )



      def       UpperCamelCase__		(self    :    Dict ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_pretraining(*UpperCamelCase )



      def       UpperCamelCase__		(self    :    List[str] ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_question_answering(*UpperCamelCase )



      def       UpperCamelCase__		(self    :    Dict ):

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_sequence_classification(*UpperCamelCase )






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

             '''simple docstring'''







             lowercase__      			= self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_token_classification(*UpperCamelCase )






def _SCREAMING_SNAKE_CASE      (A       )       ->       Optional[int]:






       """simple docstring"""







       return torch.tensor(
           A  , dtype=torch.long  , device=A  , )


lowerCamelCase							:   str  						=	1e-3

@require_torch
@require_sentencepiece
@require_tokenizers
class   __lowerCAmelCase						(unittest.TestCase     ):





      '''simple docstring'''






      @slow
      def       UpperCamelCase__		(self    :    int ):

             '''simple docstring'''







             lowercase__      			= MobileBertModel.from_pretrained('''google/mobilebert-uncased''' ).to(UpperCamelCase )
             lowercase__      			= _long_tensor([[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]] )
             with torch.no_grad():
                    lowercase__      			= model(UpperCamelCase )[0]
             lowercase__      			= torch.Size((1, 9, 512) )
             self.assertEqual(output.shape   ,						UpperCamelCase )
             lowercase__      			= torch.tensor(
                 [
                     [
                         [-2.4_73_65_26E07, 8.2_69_16_56E04, 1.6_52_18_38E05],
                         [-5.7_54_17_04E-01, 3.9_05_60_22E00, 4.4_01_15_07E00],
                         [2.6_04_73_59E00, 1.5_67_76_52E00, -1.7_32_41_88E-01],
                     ]
                 ]   ,						device=UpperCamelCase   ,						)

             # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
             # ~1 difference, it's therefore not a good idea to measure using addition.
             # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
             # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
             lowercase__      			= torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE )
             lowercase__      			= torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE )

             self.assertTrue(lower_bound and upper_bound )





"""simple docstring"""







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 			_UpperCAmelCase   (			*__UpperCamelCase     ,**__UpperCamelCase			)	->      Union[str, Any]:


               '''simple docstring'''


               pass







@is_pipeline_test
@require_vision
@require_torch
class        UpperCamelCase		(			unittest.TestCase  ):
   lowercase							=  MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING
   def 			_UpperCAmelCase   (			self     ,__UpperCamelCase     ,__UpperCamelCase     ,__UpperCamelCase			)	->      Tuple:


        '''simple docstring'''


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

        lowercase_	:				Optional[int]													=	[
            {
                'image': './tests/fixtures/tests_samples/COCO/000000039769.png',
                'candidate_labels': ['cat', 'remote', 'couch'],
            }
        ]
        return object_detector, examples
   def 			_UpperCAmelCase   (			self     ,__UpperCamelCase     ,__UpperCamelCase			)	->      str:


        '''simple docstring'''


        lowercase_	:				Tuple													=	object_detector(examples[0]     ,threshold=0.0			)

        lowercase_	:				Any													=	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 			_UpperCAmelCase   (			self			)	->      Optional[Any]:


        '''simple docstring'''


        pass
   @require_torch
   def 			_UpperCAmelCase   (			self			)	->      int:


        '''simple docstring'''


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

        lowercase_	:				Optional[int]													=	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}},
            ]     ,)

        lowercase_	:				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(__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 			_UpperCAmelCase   (			self			)	->      Tuple:


        '''simple docstring'''


        lowercase_	:				Any													=	pipeline('zero-shot-object-detection'			)

        lowercase_	:				List[str]													=	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}},
            ]     ,)

        lowercase_	:				Union[str, Any]													=	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 			_UpperCAmelCase   (			self			)	->      Union[str, Any]:


        '''simple docstring'''


        pass
   @require_torch
   @slow
   def 			_UpperCAmelCase   (			self			)	->      Optional[int]:


        '''simple docstring'''


        lowercase_	:				Union[str, Any]													=	0.2
        lowercase_	:				Any													=	pipeline('zero-shot-object-detection'			)

        lowercase_	:				str													=	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 			_UpperCAmelCase   (			self			)	->      Any:


        '''simple docstring'''


        lowercase_	:				Tuple													=	2
        lowercase_	:				Optional[Any]													=	pipeline('zero-shot-object-detection'			)

        lowercase_	:				List[Any]													=	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}},
            ]     ,)

