





"""simple docstring"""





import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
  import torch

  from transformers import ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
  from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import AutoImageProcessor






class 					_lowerCAmelCase   :
       """simple docstring"""




       def __init__(    self    , __UpperCAmelCase    , __UpperCAmelCase=1_3    , __UpperCAmelCase=3_2    , __UpperCAmelCase=3    , __UpperCAmelCase=4    , __UpperCAmelCase=[1_0, 2_0, 3_0, 4_0]    , __UpperCAmelCase=[2, 2, 3, 2]    , __UpperCAmelCase=True    , __UpperCAmelCase=True    , __UpperCAmelCase=3_7    , __UpperCAmelCase="gelu"    , __UpperCAmelCase=1_0    , __UpperCAmelCase=0.02    , __UpperCAmelCase=["stage2", "stage3", "stage4"]    , __UpperCAmelCase=[2, 3, 4]    , __UpperCAmelCase=None    , ):



         '''simple docstring'''

         lowerCAmelCase__			:Union[str, Any]											=							parent
         lowerCAmelCase__			:Dict											=							batch_size
         lowerCAmelCase__			:List[str]											=							image_size
         lowerCAmelCase__			:str											=							num_channels
         lowerCAmelCase__			:str											=							num_stages
         lowerCAmelCase__			:Dict											=							hidden_sizes
         lowerCAmelCase__			:Tuple											=							depths
         lowerCAmelCase__			:Any											=							is_training
         lowerCAmelCase__			:Optional[int]											=							use_labels
         lowerCAmelCase__			:Optional[Any]											=							intermediate_size
         lowerCAmelCase__			:List[str]											=							hidden_act
         lowerCAmelCase__			:Optional[int]											=							num_labels
         lowerCAmelCase__			:str											=							initializer_range
         lowerCAmelCase__			:List[Any]											=							out_features
         lowerCAmelCase__			:Union[str, Any]											=							out_indices
         lowerCAmelCase__			:Any											=							scope






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Tuple											=							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

         lowerCAmelCase__			:List[str]											=							None
         if self.use_labels:
           lowerCAmelCase__			:Tuple											=							ids_tensor([self.batch_size]    , self.num_labels      )

         lowerCAmelCase__			:List[Any]											=							self.get_config()

         return config, pixel_values, labels






       def      snake_case						(    self      ):



         '''simple docstring'''

         return ConvNextVaConfig(
             num_channels=self.num_channels    , hidden_sizes=self.hidden_sizes    , depths=self.depths    , num_stages=self.num_stages    , hidden_act=self.hidden_act    , is_decoder=lowerCAmelCase__    , initializer_range=self.initializer_range    , out_features=self.out_features    , out_indices=self.out_indices    , num_labels=self.num_labels    , )






       def      snake_case						(    self    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:Any											=							ConvNextVaModel(config=lowerCAmelCase__      )
         model.to(lowerCAmelCase__      )
         model.eval()
         lowerCAmelCase__			:Dict											=							model(lowerCAmelCase__      )
         # expected last hidden states: B, C, H // 32, W // 32
         self.parent.assertEqual(
             result.last_hidden_state.shape    , (self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)    , )






       def      snake_case						(    self    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:Optional[Any]											=							ConvNextVaForImageClassification(lowerCAmelCase__      )
         model.to(lowerCAmelCase__      )
         model.eval()
         lowerCAmelCase__			:int											=							model(lowerCAmelCase__    , labels=lowerCAmelCase__      )
         self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.num_labels)      )






       def      snake_case						(    self    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:List[str]											=							ConvNextVaBackbone(config=lowerCAmelCase__      )
         model.to(lowerCAmelCase__      )
         model.eval()
         lowerCAmelCase__			:Dict											=							model(lowerCAmelCase__      )

         # verify hidden states
         self.parent.assertEqual(len(result.feature_maps      )    , len(config.out_features      )      )
         self.parent.assertListEqual(list(result.feature_maps[0].shape      )    , [self.batch_size, self.hidden_sizes[1], 4, 4]      )

         # verify channels
         self.parent.assertEqual(len(model.channels      )    , len(config.out_features      )      )
         self.parent.assertListEqual(model.channels    , config.hidden_sizes[1:]      )

         # verify backbone works with out_features=None
         lowerCAmelCase__			:Dict											=							None
         lowerCAmelCase__			:Any											=							ConvNextVaBackbone(config=lowerCAmelCase__      )
         model.to(lowerCAmelCase__      )
         model.eval()
         lowerCAmelCase__			:int											=							model(lowerCAmelCase__      )

         # verify feature maps
         self.parent.assertEqual(len(result.feature_maps      )    , 1      )
         self.parent.assertListEqual(list(result.feature_maps[0].shape      )    , [self.batch_size, self.hidden_sizes[-1], 1, 1]      )

         # verify channels
         self.parent.assertEqual(len(model.channels      )    , 1      )
         self.parent.assertListEqual(model.channels    , [config.hidden_sizes[-1]]      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Any											=							self.prepare_config_and_inputs()
         lowerCAmelCase__			:Union[str, Any]											=							config_and_inputs
         lowerCAmelCase__			:List[str]											=							{"""pixel_values""": pixel_values}
         return config, inputs_dict






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:str											=							self.prepare_config_and_inputs()
         lowerCAmelCase__			:Optional[Any]											=							config_and_inputs
         lowerCAmelCase__			:Tuple											=							{"""pixel_values""": pixel_values, """labels""": labels}
         return config, inputs_dict






@require_torch
class 					_lowerCAmelCase   (     lowerCamelCase__  ,   lowerCamelCase__  ,   unittest.TestCase       ):
       """simple docstring"""




       __magic_name__     :Any		  =					(
           (
               ConvNextVaModel,
               ConvNextVaForImageClassification,
               ConvNextVaBackbone,
           )
           if is_torch_available()
           else ()
       )
       __magic_name__     :Optional[int]		  =					(
           {'''feature-extraction''': ConvNextVaModel, '''image-classification''': ConvNextVaForImageClassification}
           if is_torch_available()
           else {}
       )

       __magic_name__     :Union[str, Any]		  =					False
       __magic_name__     :int		  =					False
       __magic_name__     :List[str]		  =					False
       __magic_name__     :List[str]		  =					False
       __magic_name__     :List[str]		  =					False






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Union[str, Any]											=							ConvNextVaModelTester(self      )
         lowerCAmelCase__			:Optional[int]											=							ConfigTester(self    , config_class=lowerCAmelCase__    , has_text_modality=lowerCAmelCase__    , hidden_size=3_7      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         self.create_and_test_config_common_properties()
         self.config_tester.create_and_test_config_to_json_string()
         self.config_tester.create_and_test_config_to_json_file()
         self.config_tester.create_and_test_config_from_and_save_pretrained()
         self.config_tester.create_and_test_config_with_num_labels()
         self.config_tester.check_config_can_be_init_without_params()
         self.config_tester.check_config_arguments_init()






       def      snake_case						(    self      ):



         '''simple docstring'''

         return






       @unittest.skip(reason='ConvNextV2 does not use inputs_embeds'      )
       def      snake_case						(    self      ):



         '''simple docstring'''

         pass






       @unittest.skip(reason='ConvNextV2 does not support input and output embeddings'      )
       def      snake_case						(    self      ):



         '''simple docstring'''

         pass






       @unittest.skip(reason='ConvNextV2 does not use feedforward chunking'      )
       def      snake_case						(    self      ):



         '''simple docstring'''

         pass






       def      snake_case						(    self      ):



         '''simple docstring'''

         if not self.model_tester.is_training:
           return

         for model_class in self.all_model_classes:
           lowerCAmelCase__			:Dict											=							self.model_tester.prepare_config_and_inputs_with_labels()
           lowerCAmelCase__			:List[Any]											=							True

           if model_class.__name__ in [
               *get_values(lowerCAmelCase__      ),
               *get_values(lowerCAmelCase__      ),
           ]:
             continue

           lowerCAmelCase__			:Tuple											=							model_class(lowerCAmelCase__      )
           model.to(lowerCAmelCase__      )
           model.train()
           lowerCAmelCase__			:Optional[Any]											=							self._prepare_for_class(lowerCAmelCase__    , lowerCAmelCase__    , return_labels=lowerCAmelCase__      )
           lowerCAmelCase__			:List[Any]											=							model(**lowerCAmelCase__      ).loss
           loss.backward()






       def      snake_case						(    self      ):



         '''simple docstring'''

         if not self.model_tester.is_training:
           return

         for model_class in self.all_model_classes:
           lowerCAmelCase__			:int											=							self.model_tester.prepare_config_and_inputs_with_labels()
           lowerCAmelCase__			:Union[str, Any]											=							False
           lowerCAmelCase__			:int											=							True

           if (
               model_class.__name__
               in [*get_values(lowerCAmelCase__      ), *get_values(lowerCAmelCase__      )]
               or not model_class.supports_gradient_checkpointing
           ):
             continue

           lowerCAmelCase__			:Optional[Any]											=							model_class(lowerCAmelCase__      )
           model.to(lowerCAmelCase__      )
           model.gradient_checkpointing_enable()
           model.train()
           lowerCAmelCase__			:Dict											=							self._prepare_for_class(lowerCAmelCase__    , lowerCAmelCase__    , return_labels=lowerCAmelCase__      )
           lowerCAmelCase__			:Optional[Any]											=							model(**lowerCAmelCase__      ).loss
           loss.backward()






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:int											=							self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           lowerCAmelCase__			:Optional[int]											=							model_class(lowerCAmelCase__      )
           lowerCAmelCase__			:Dict											=							inspect.signature(model.forward      )
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           lowerCAmelCase__			:List[str]											=							[*signature.parameters.keys()]

           lowerCAmelCase__			:List[Any]											=							["""pixel_values"""]
           self.assertListEqual(arg_names[:1]    , lowerCAmelCase__      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Optional[int]											=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*lowerCAmelCase__      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         def check_hidden_states_output(__UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase      ):
           lowerCAmelCase__			:Optional[int]											=							model_class(lowerCAmelCase__      )
           model.to(lowerCAmelCase__      )
           model.eval()

           with torch.no_grad():
             lowerCAmelCase__			:Union[str, Any]											=							model(**self._prepare_for_class(lowerCAmelCase__    , lowerCAmelCase__      )      )

           lowerCAmelCase__			:List[str]											=							outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

           lowerCAmelCase__			:Union[str, Any]											=							self.model_tester.num_stages
           self.assertEqual(len(lowerCAmelCase__      )    , expected_num_stages + 1      )

           # ConvNextV2's feature maps are of shape (batch_size, num_channels, height, width)
           self.assertListEqual(
               list(hidden_states[0].shape[-2:]      )    , [self.model_tester.image_size // 4, self.model_tester.image_size // 4]    , )

         lowerCAmelCase__			:Optional[int]											=							self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           lowerCAmelCase__			:str											=							True
           check_hidden_states_output(lowerCAmelCase__    , lowerCAmelCase__    , lowerCAmelCase__      )

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           lowerCAmelCase__			:str											=							True

           check_hidden_states_output(lowerCAmelCase__    , lowerCAmelCase__    , lowerCAmelCase__      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Dict											=							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase__      )






       @slow
       def      snake_case						(    self      ):



         '''simple docstring'''

         for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowerCAmelCase__			:List[Any]											=							ConvNextVaModel.from_pretrained(lowerCAmelCase__      )
           self.assertIsNotNone(lowerCAmelCase__      )






def  __A   ()					->Any:





  """simple docstring"""


  lowerCAmelCase__			:Dict											=							Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'			)
  return image






@require_torch
@require_vision
class 					_lowerCAmelCase   (     unittest.TestCase       ):
       """simple docstring"""




       @cached_property
       def      snake_case						(    self      ):



         '''simple docstring'''

         return AutoImageProcessor.from_pretrained('facebook/convnextv2-tiny-1k-224'      ) if is_vision_available() else None






       @slow
       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Dict											=							ConvNextVaForImageClassification.from_pretrained('facebook/convnextv2-tiny-1k-224'      ).to(lowerCAmelCase__      )

         lowerCAmelCase__			:Tuple											=							self.default_image_processor
         lowerCAmelCase__			:Dict											=							prepare_img()
         lowerCAmelCase__			:List[str]											=							preprocessor(images=lowerCAmelCase__    , return_tensors='pt'      ).to(lowerCAmelCase__      )

         # forward pass
         with torch.no_grad():
           lowerCAmelCase__			:str											=							model(**lowerCAmelCase__      )

         # verify the logits
         lowerCAmelCase__			:List[str]											=							torch.Size((1, 1_0_0_0)      )
         self.assertEqual(outputs.logits.shape    , lowerCAmelCase__      )

         lowerCAmelCase__			:int											=							torch.tensor([0.99_96, 0.19_66, -0.43_86]      ).to(lowerCAmelCase__      )
         self.assertTrue(torch.allclose(outputs.logits[0, :3]    , lowerCAmelCase__    , atol=1E-4      )      )





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


									'''simple docstring'''

									@staticmethod
									def UpperCamelCase__					(							*lowerCAmelCase__     : Any							,     **lowerCAmelCase__     : Any						):





											"""simple docstring"""






											pass






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


			'''simple docstring'''

			_A      :		Optional[int]			    =		MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING

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





					"""simple docstring"""






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

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

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





					"""simple docstring"""






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

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

			@require_tf
			@unittest.skip("""Zero Shot Object Detection not implemented in TF"""						)
			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					pass

			@require_torch
			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






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

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

					self.assertEqual(
					    nested_simplify(lowerCAmelCase__							,     decimals=4						)							,     [
					        {"""score""": 0.72_35, """label""": """cat""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
					        {"""score""": 0.72_18, """label""": """remote""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
					        {"""score""": 0.71_84, """label""": """couch""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
					        {"""score""": 0.67_48, """label""": """remote""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
					        {"""score""": 0.66_56, """label""": """cat""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
					        {"""score""": 0.66_14, """label""": """couch""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
					        {"""score""": 0.64_56, """label""": """remote""", """box""": {"""xmin""": 4_9_4, """ymin""": 1_0_5, """xmax""": 5_2_1, """ymax""": 1_2_7}},
					        {"""score""": 0.6_42, """label""": """remote""", """box""": {"""xmin""": 6_7, """ymin""": 2_7_4, """xmax""": 9_3, """ymax""": 2_9_7}},
					        {"""score""": 0.64_19, """label""": """cat""", """box""": {"""xmin""": 4_9_4, """ymin""": 1_0_5, """xmax""": 5_2_1, """ymax""": 1_2_7}},
					    ]							,     )

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

					self.assertEqual(
					    nested_simplify(lowerCAmelCase__							,     decimals=4						)							,     [
					        [
					            {"""score""": 0.72_35, """label""": """cat""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
					            {"""score""": 0.72_18, """label""": """remote""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
					            {"""score""": 0.71_84, """label""": """couch""", """box""": {"""xmin""": 2_0_4, """ymin""": 1_6_7, """xmax""": 2_3_2, """ymax""": 1_9_0}},
					            {"""score""": 0.67_48, """label""": """remote""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
					            {"""score""": 0.66_56, """label""": """cat""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
					            {"""score""": 0.66_14, """label""": """couch""", """box""": {"""xmin""": 5_7_1, """ymin""": 8_3, """xmax""": 5_9_8, """ymax""": 1_0_3}},
					            {"""score""": 0.64_56, """label""": """remote""", """box""": {"""xmin""": 4_9_4, """ymin""": 1_0_5, """xmax""": 5_2_1, """ymax""": 1_2_7}},
					            {"""score""": 0.6_42, """label""": """remote""", """box""": {"""xmin""": 6_7, """ymin""": 2_7_4, """xmax""": 9_3, """ymax""": 2_9_7}},
					            {"""score""": 0.64_19, """label""": """cat""", """box""": {"""xmin""": 4_9_4, """ymin""": 1_0_5, """xmax""": 5_2_1, """ymax""": 1_2_7}},
					        ]
					    ]							,     )

			@require_torch
			@slow
			def UpperCamelCase__					(							self     : str						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		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"""]							,     )
					self.assertEqual(
					    nested_simplify(lowerCAmelCase__							,     decimals=4						)							,     [
					        {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
					        {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
					        {"""score""": 0.25_37, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 5_5, """xmax""": 3_1_5, """ymax""": 4_7_2}},
					        {"""score""": 0.14_74, """label""": """remote""", """box""": {"""xmin""": 3_3_5, """ymin""": 7_4, """xmax""": 3_7_1, """ymax""": 1_8_7}},
					        {"""score""": 0.12_08, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_4_2, """ymax""": 4_7_6}},
					    ]							,     )

					__SCREAMING_SNAKE_CASE       :		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(lowerCAmelCase__							,     decimals=4						)							,     [
					        [
					            {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
					            {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
					            {"""score""": 0.25_37, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 5_5, """xmax""": 3_1_5, """ymax""": 4_7_2}},
					            {"""score""": 0.14_74, """label""": """remote""", """box""": {"""xmin""": 3_3_5, """ymin""": 7_4, """xmax""": 3_7_1, """ymax""": 1_8_7}},
					            {"""score""": 0.12_08, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_4_2, """ymax""": 4_7_6}},
					        ],
					        [
					            {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
					            {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
					            {"""score""": 0.25_37, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 5_5, """xmax""": 3_1_5, """ymax""": 4_7_2}},
					            {"""score""": 0.14_74, """label""": """remote""", """box""": {"""xmin""": 3_3_5, """ymin""": 7_4, """xmax""": 3_7_1, """ymax""": 1_8_7}},
					            {"""score""": 0.12_08, """label""": """couch""", """box""": {"""xmin""": 4, """ymin""": 0, """xmax""": 6_4_2, """ymax""": 4_7_6}},
					        ],
					    ]							,     )

			@require_tf
			@unittest.skip("""Zero Shot Object Detection not implemented in TF"""						)
			def UpperCamelCase__					(							self     : Any						):





					"""simple docstring"""






					pass

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





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Dict           =		0.2
					__SCREAMING_SNAKE_CASE       :		Dict           =		pipeline("""zero-shot-object-detection"""						)

					__SCREAMING_SNAKE_CASE       :		Any           =		object_detector(
					    """http://images.cocodataset.org/val2017/000000039769.jpg"""							,     candidate_labels=["""cat""", """remote""", """couch"""]							,     threshold=lowerCAmelCase__							,     )
					self.assertEqual(
					    nested_simplify(lowerCAmelCase__							,     decimals=4						)							,     [
					        {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
					        {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
					        {"""score""": 0.25_37, """label""": """cat""", """box""": {"""xmin""": 1, """ymin""": 5_5, """xmax""": 3_1_5, """ymax""": 4_7_2}},
					    ]							,     )



			@require_torch
			@slow
			def UpperCamelCase__					(							self     : int						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		str           =		2
					__SCREAMING_SNAKE_CASE       :		int           =		pipeline("""zero-shot-object-detection"""						)

					__SCREAMING_SNAKE_CASE       :		int           =		object_detector(
					    """http://images.cocodataset.org/val2017/000000039769.jpg"""							,     candidate_labels=["""cat""", """remote""", """couch"""]							,     top_k=lowerCAmelCase__							,     )
					self.assertEqual(
					    nested_simplify(lowerCAmelCase__							,     decimals=4						)							,     [
					        {"""score""": 0.28_68, """label""": """cat""", """box""": {"""xmin""": 3_2_4, """ymin""": 2_0, """xmax""": 6_4_0, """ymax""": 3_7_3}},
					        {"""score""": 0.2_77, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_2, """xmax""": 1_7_7, """ymax""": 1_1_5}},
					    ]							,     )