import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import 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,
         AlbertForMaskedLM,
         AlbertForMultipleChoice,
         AlbertForPreTraining,
         AlbertForQuestionAnswering,
         AlbertForSequenceClassification,
         AlbertForTokenClassification,
         AlbertModel,
     )
     from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST


class 			lowerCamelCase_  :






    '''simple docstring'''






    def __init__(			self				,				__lowercase				,				__lowercase=13				,				__lowercase=7				,				__lowercase=True				,				__lowercase=True				,				__lowercase=True				,				__lowercase=True				,				__lowercase=99				,				__lowercase=16				,				__lowercase=36				,				__lowercase=6				,				__lowercase=6				,				__lowercase=6				,				__lowercase=37				,				__lowercase="gelu"				,				__lowercase=0.1				,				__lowercase=0.1				,				__lowercase=512				,				__lowercase=16				,				__lowercase=2				,				__lowercase=0.02				,				__lowercase=3				,				__lowercase=4				,				__lowercase=None				,				) ->			str:
        __UpperCamelCase  :Tuple    						=	parent
        __UpperCamelCase  :Union[str, Any]    						=	batch_size
        __UpperCamelCase  :Any    						=	seq_length
        __UpperCamelCase  :str    						=	is_training
        __UpperCamelCase  :int    						=	use_input_mask
        __UpperCamelCase  :List[Any]    						=	use_token_type_ids
        __UpperCamelCase  :Dict    						=	use_labels
        __UpperCamelCase  :List[Any]    						=	vocab_size
        __UpperCamelCase  :Union[str, Any]    						=	embedding_size
        __UpperCamelCase  :Any    						=	hidden_size
        __UpperCamelCase  :Dict    						=	num_hidden_layers
        __UpperCamelCase  :Any    						=	num_hidden_groups
        __UpperCamelCase  :List[str]    						=	num_attention_heads
        __UpperCamelCase  :List[str]    						=	intermediate_size
        __UpperCamelCase  :Union[str, Any]    						=	hidden_act
        __UpperCamelCase  :Dict    						=	hidden_dropout_prob
        __UpperCamelCase  :List[Any]    						=	attention_probs_dropout_prob
        __UpperCamelCase  :Optional[int]    						=	max_position_embeddings
        __UpperCamelCase  :Optional[int]    						=	type_vocab_size
        __UpperCamelCase  :str    						=	type_sequence_label_size
        __UpperCamelCase  :Dict    						=	initializer_range
        __UpperCamelCase  :List[str]    						=	num_labels
        __UpperCamelCase  :List[Any]    						=	num_choices
        __UpperCamelCase  :Any    						=	scope







    def     UpperCamelCase__     (			self) ->			int:
        __UpperCamelCase  :Optional[Any]    						=	ids_tensor([self.batch_size, self.seq_length]				,				self.vocab_size)

        __UpperCamelCase  :Union[str, Any]    						=	None
        if self.use_input_mask:
            __UpperCamelCase  :Any    						=	random_attention_mask([self.batch_size, self.seq_length])

        __UpperCamelCase  :Optional[int]    						=	None
        if self.use_token_type_ids:
            __UpperCamelCase  :List[str]    						=	ids_tensor([self.batch_size, self.seq_length]				,				self.type_vocab_size)

        __UpperCamelCase  :Optional[int]    						=	None
        __UpperCamelCase  :Tuple    						=	None
        __UpperCamelCase  :int    						=	None
        if self.use_labels:
            __UpperCamelCase  :Tuple    						=	ids_tensor([self.batch_size]				,				self.type_sequence_label_size)
            __UpperCamelCase  :Dict    						=	ids_tensor([self.batch_size, self.seq_length]				,				self.num_labels)
            __UpperCamelCase  :List[Any]    						=	ids_tensor([self.batch_size]				,				self.num_choices)

        __UpperCamelCase  :Any    						=	self.get_config()

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







    def     UpperCamelCase__     (			self) ->			int:
        return AlbertConfig(
            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				,				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				,				initializer_range=self.initializer_range				,				num_hidden_groups=self.num_hidden_groups				,				)







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase) ->			Optional[Any]:
        __UpperCamelCase  :Optional[Any]    						=	AlbertModel(config=__A)
        model.to(__A)
        model.eval()
        __UpperCamelCase  :Dict    						=	model(__A				,				attention_mask=__A				,				token_type_ids=__A)
        __UpperCamelCase  :List[Any]    						=	model(__A				,				token_type_ids=__A)
        __UpperCamelCase  :Tuple    						=	model(__A)
        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				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase) ->			Optional[Any]:
        __UpperCamelCase  :Optional[Any]    						=	AlbertForPreTraining(config=__A)
        model.to(__A)
        model.eval()
        __UpperCamelCase  :Optional[Any]    						=	model(
            __A				,				attention_mask=__A				,				token_type_ids=__A				,				labels=__A				,				sentence_order_label=__A				,				)
        self.parent.assertEqual(result.prediction_logits.shape				,				(self.batch_size, self.seq_length, self.vocab_size))
        self.parent.assertEqual(result.sop_logits.shape				,				(self.batch_size, config.num_labels))







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase) ->			List[str]:
        __UpperCamelCase  :Tuple    						=	AlbertForMaskedLM(config=__A)
        model.to(__A)
        model.eval()
        __UpperCamelCase  :int    						=	model(__A				,				attention_mask=__A				,				token_type_ids=__A				,				labels=__A)
        self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.seq_length, self.vocab_size))







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase) ->			Tuple:
        __UpperCamelCase  :Optional[int]    						=	AlbertForQuestionAnswering(config=__A)
        model.to(__A)
        model.eval()
        __UpperCamelCase  :Dict    						=	model(
            __A				,				attention_mask=__A				,				token_type_ids=__A				,				start_positions=__A				,				end_positions=__A				,				)
        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				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase) ->			int:
        __UpperCamelCase  :Union[str, Any]    						=	self.num_labels
        __UpperCamelCase  :List[Any]    						=	AlbertForSequenceClassification(__A)
        model.to(__A)
        model.eval()
        __UpperCamelCase  :Dict    						=	model(__A				,				attention_mask=__A				,				token_type_ids=__A				,				labels=__A)
        self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.num_labels))







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase) ->			List[Any]:
        __UpperCamelCase  :Union[str, Any]    						=	self.num_labels
        __UpperCamelCase  :Dict    						=	AlbertForTokenClassification(config=__A)
        model.to(__A)
        model.eval()
        __UpperCamelCase  :List[Any]    						=	model(__A				,				attention_mask=__A				,				token_type_ids=__A				,				labels=__A)
        self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.seq_length, self.num_labels))







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase				,				__lowercase) ->			Dict:
        __UpperCamelCase  :Any    						=	self.num_choices
        __UpperCamelCase  :str    						=	AlbertForMultipleChoice(config=__A)
        model.to(__A)
        model.eval()
        __UpperCamelCase  :Union[str, Any]    						=	input_ids.unsqueeze(1).expand(-1				,				self.num_choices				,				-1).contiguous()
        __UpperCamelCase  :Dict    						=	token_type_ids.unsqueeze(1).expand(-1				,				self.num_choices				,				-1).contiguous()
        __UpperCamelCase  :Optional[Any]    						=	input_mask.unsqueeze(1).expand(-1				,				self.num_choices				,				-1).contiguous()
        __UpperCamelCase  :Any    						=	model(
            __A				,				attention_mask=__A				,				token_type_ids=__A				,				labels=__A				,				)
        self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.num_choices))







    def     UpperCamelCase__     (			self) ->			List[Any]:
        __UpperCamelCase  :List[Any]    						=	self.prepare_config_and_inputs()
        (
            __UpperCamelCase		
        )  :str    						=	config_and_inputs
        __UpperCamelCase  :Optional[Any]    						=	{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
        return config, inputs_dict


@require_torch
class 			lowerCamelCase_  (     UpperCAmelCase_		,			UpperCAmelCase_		,			unittest.TestCase				):






    '''simple docstring'''






    a__			:		Any      			=   (
        (
            AlbertModel,
            AlbertForPreTraining,
            AlbertForMaskedLM,
            AlbertForMultipleChoice,
            AlbertForSequenceClassification,
            AlbertForTokenClassification,
            AlbertForQuestionAnswering,
        )
        if is_torch_available()
        else ()
    )
    a__			:		List[str]      			=   (
        {
            """feature-extraction""": AlbertModel,
            """fill-mask""": AlbertForMaskedLM,
            """question-answering""": AlbertForQuestionAnswering,
            """text-classification""": AlbertForSequenceClassification,
            """token-classification""": AlbertForTokenClassification,
            """zero-shot""": AlbertForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    a__			:		Dict      			=   True







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase=False) ->			Optional[Any]:
        __UpperCamelCase  :int    						=	super()._prepare_for_class(__A				,				__A				,				return_labels=__A)

        if return_labels:
            if model_class in get_values(__A):
                __UpperCamelCase  :str    						=	torch.zeros(
                    (self.model_tester.batch_size, self.model_tester.seq_length)				,				dtype=torch.long				,				device=__A)
                __UpperCamelCase  :List[Any]    						=	torch.zeros(
                    self.model_tester.batch_size				,				dtype=torch.long				,				device=__A)
        return inputs_dict







    def     UpperCamelCase__     (			self) ->			Dict:
        __UpperCamelCase  :Dict    						=	AlbertModelTester(self)
        __UpperCamelCase  :Dict    						=	ConfigTester(self				,				config_class=__A				,				hidden_size=37)







    def     UpperCamelCase__     (			self) ->			Dict:
        self.config_tester.run_common_tests()







    def     UpperCamelCase__     (			self) ->			int:
        __UpperCamelCase  :Dict    						=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__A)







    def     UpperCamelCase__     (			self) ->			List[str]:
        __UpperCamelCase  :List[Any]    						=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*__A)







    def     UpperCamelCase__     (			self) ->			Dict:
        __UpperCamelCase  :Union[str, Any]    						=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*__A)







    def     UpperCamelCase__     (			self) ->			Dict:
        __UpperCamelCase  :List[str]    						=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*__A)







    def     UpperCamelCase__     (			self) ->			str:
        __UpperCamelCase  :List[Any]    						=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*__A)







    def     UpperCamelCase__     (			self) ->			List[str]:
        __UpperCamelCase  :Tuple    						=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*__A)







    def     UpperCamelCase__     (			self) ->			List[Any]:
        __UpperCamelCase  :Dict    						=	self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
            __UpperCamelCase  :List[str]    						=	type
            self.model_tester.create_and_check_model(*__A)







    @slow
    def     UpperCamelCase__     (			self) ->			Tuple:
        for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            __UpperCamelCase  :Dict    						=	AlbertModel.from_pretrained(__A)
            self.assertIsNotNone(__A)


@require_torch
class 			lowerCamelCase_  (     unittest.TestCase				):






    '''simple docstring'''






    @slow
    def     UpperCamelCase__     (			self) ->			str:
        __UpperCamelCase  :str    						=	AlbertModel.from_pretrained('''albert-base-v2''')
        __UpperCamelCase  :Any    						=	torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]])
        __UpperCamelCase  :Union[str, Any]    						=	torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
        with torch.no_grad():
            __UpperCamelCase  :Union[str, Any]    						=	model(__A				,				attention_mask=__A)[0]
        __UpperCamelCase  :Optional[int]    						=	torch.Size((1, 11, 768))
        self.assertEqual(output.shape				,				__A)
        __UpperCamelCase  :Dict    						=	torch.tensor(
            [[[-0.65_13, 1.50_35, -0.27_66], [-0.65_15, 1.50_46, -0.27_80], [-0.65_12, 1.50_49, -0.27_84]]])

        self.assertTrue(torch.allclose(output[:, 1:4, 1:4]				,				__A				,				atol=1E-4))






import unittest

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

from .test_pipelines_common import ANY


if is_vision_available():
    from PIL import Image
else:


    class 			lowerCamelCase_  :






        '''simple docstring'''






        @staticmethod
        def     UpperCamelCase__     (			*__lowercase				,				**__lowercase) ->			Dict:
            pass


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






    '''simple docstring'''






    a__			:		str      			=   MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING







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

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







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase) ->			Optional[Any]:
        __UpperCamelCase  :Optional[Any]    						=	object_detector(examples[0]				,				threshold=0.0)

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







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







    @require_torch
    def     UpperCamelCase__     (			self) ->			Any:
        __UpperCamelCase  :Tuple    						=	pipeline(
            '''zero-shot-object-detection'''				,				model='''hf-internal-testing/tiny-random-owlvit-object-detection''')

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

        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                {'''score''': 0.72_35, '''label''': '''cat''', '''box''': {'''xmin''': 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  :str    						=	object_detector(
            [
                {
                    '''image''': '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
                    '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
                }
            ]				,				threshold=0.64				,				)

        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                [
                    {'''score''': 0.72_35, '''label''': '''cat''', '''box''': {'''xmin''': 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     UpperCamelCase__     (			self) ->			Optional[int]:
        __UpperCamelCase  :List[str]    						=	pipeline('''zero-shot-object-detection''')

        __UpperCamelCase  :List[str]    						=	object_detector(
            '''http://images.cocodataset.org/val2017/000000039769.jpg'''				,				candidate_labels=['''cat''', '''remote''', '''couch''']				,				)
        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 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  :Dict    						=	object_detector(
            [
                {
                    '''image''': '''http://images.cocodataset.org/val2017/000000039769.jpg''',
                    '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
                },
                {
                    '''image''': '''http://images.cocodataset.org/val2017/000000039769.jpg''',
                    '''candidate_labels''': ['''cat''', '''remote''', '''couch'''],
                },
            ]				,				)
        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                [
                    {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 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     UpperCamelCase__     (			self) ->			Dict:
        pass







    @require_torch
    @slow
    def     UpperCamelCase__     (			self) ->			str:
        __UpperCamelCase  :Tuple    						=	0.2
        __UpperCamelCase  :str    						=	pipeline('''zero-shot-object-detection''')

        __UpperCamelCase  :Any    						=	object_detector(
            '''http://images.cocodataset.org/val2017/000000039769.jpg'''				,				candidate_labels=['''cat''', '''remote''', '''couch''']				,				threshold=__lowercase				,				)
        self.assertEqual(
            nested_simplify(__lowercase				,				decimals=4)				,				[
                {'''score''': 0.28_68, '''label''': '''cat''', '''box''': {'''xmin''': 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     UpperCamelCase__     (			self) ->			Any:
        __UpperCamelCase  :Optional[int]    						=	2
        __UpperCamelCase  :Union[str, Any]    						=	pipeline('''zero-shot-object-detection''')

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





