

'''simple docstring'''

import random
import unittest

import numpy as np

import transformers
from transformers import is_flax_available, is_torch_available
from transformers.testing_utils import is_pt_flax_cross_test, require_flax


if is_flax_available():
							import os

							import jax.numpy as jnp
							from jax import jit

							from transformers import AutoTokenizer, FlaxAutoModelForCausalLM
							from transformers.modeling_flax_pytorch_utils import load_flax_weights_in_pytorch_model

							SCREAMING_SNAKE_CASE							:				List[Any]     	=			"0.12"  # assumed parallelism: 8


if is_torch_available():
							import torch




def 							_UpperCamelCase				(   lowerCAmelCase__:					Dict		,lowerCAmelCase__:					int		,lowerCAmelCase__:					Tuple=None   )      -> Union[str, Any]:
							if rng is None:
														SCREAMING_SNAKE_CASE_				=				random.Random()

							SCREAMING_SNAKE_CASE_				=				1
							for dim in shape:
														total_dims *= dim

							SCREAMING_SNAKE_CASE_				=				[]
							for _ in range(lowerCAmelCase__   ):
														values.append(rng.randint(0		,vocab_size - 1   )   )

							SCREAMING_SNAKE_CASE_				=				np.array(lowerCAmelCase__		,dtype=jnp.intaa   ).reshape(lowerCAmelCase__   )

							return output




def 							_UpperCamelCase				(   lowerCAmelCase__:					Tuple		,lowerCAmelCase__:					str=None   )      -> Optional[int]:
							SCREAMING_SNAKE_CASE_				=				ids_tensor(lowerCAmelCase__		,vocab_size=2		,rng=lowerCAmelCase__   )
							# make sure that at least one token is attended to for each batch
							SCREAMING_SNAKE_CASE_				=				1
							return attn_mask






@require_flax
class    snake_case     :






				"""simple docstring"""
				_a    	=     None
				_a    	=     ()



				def   a__					(    self       )     ->							List[str]:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self.model_tester.prepare_config_and_inputs_for_common()

											# cut to half length & take max batch_size 3
											SCREAMING_SNAKE_CASE_				=				2
											SCREAMING_SNAKE_CASE_				=				inputs['input_ids'].shape[-1] // 2
											SCREAMING_SNAKE_CASE_				=				inputs['input_ids'][:max_batch_size, :sequence_length]

											SCREAMING_SNAKE_CASE_				=				jnp.ones_like(_lowercase       )
											SCREAMING_SNAKE_CASE_				=				attention_mask[:max_batch_size, :sequence_length]

											# generate max 5 tokens
											SCREAMING_SNAKE_CASE_				=				input_ids.shape[-1] + 5
											if config.eos_token_id is not None and config.pad_token_id is None:
																		# hack to allow generate for models such as GPT2 as is done in `generate()`
																		SCREAMING_SNAKE_CASE_				=				config.eos_token_id
											return config, input_ids, attention_mask, max_length



				@is_pt_flax_cross_test
				def   a__					(    self       )     ->							Dict:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()
											SCREAMING_SNAKE_CASE_				=				False
											SCREAMING_SNAKE_CASE_				=				max_length
											SCREAMING_SNAKE_CASE_				=				0

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model_class.__name__[4:]  # Skip the "Flax" at the beginning
																		SCREAMING_SNAKE_CASE_				=				getattr(_lowercase,     _lowercase       )
																		SCREAMING_SNAKE_CASE_				=				pt_model_class(_lowercase       ).eval()
																		SCREAMING_SNAKE_CASE_				=				load_flax_weights_in_pytorch_model(_lowercase,     flax_model.params       )

																		SCREAMING_SNAKE_CASE_				=				flax_model.generate(_lowercase       ).sequences
																		SCREAMING_SNAKE_CASE_				=				pt_model.generate(torch.tensor(_lowercase,     dtype=torch.long       )       )

																		if flax_generation_outputs.shape[-1] > pt_generation_outputs.shape[-1]:
																									SCREAMING_SNAKE_CASE_				=				flax_generation_outputs[:, : pt_generation_outputs.shape[-1]]

																		self.assertListEqual(pt_generation_outputs.numpy().tolist(),     flax_generation_outputs.tolist()       )



				def   a__					(    self       )     ->							Any:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()
											SCREAMING_SNAKE_CASE_				=				False
											SCREAMING_SNAKE_CASE_				=				max_length

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )



				def   a__					(    self       )     ->							int:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()
											SCREAMING_SNAKE_CASE_				=				True
											SCREAMING_SNAKE_CASE_				=				max_length

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )



				def   a__					(    self       )     ->							Any:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()
											SCREAMING_SNAKE_CASE_				=				False
											SCREAMING_SNAKE_CASE_				=				max_length
											SCREAMING_SNAKE_CASE_				=				2

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )



				def   a__					(    self       )     ->							Optional[Any]:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()
											SCREAMING_SNAKE_CASE_				=				False
											SCREAMING_SNAKE_CASE_				=				max_length
											SCREAMING_SNAKE_CASE_				=				2
											SCREAMING_SNAKE_CASE_				=				2

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[0],     input_ids.shape[0] * config.num_return_sequences       )



				def   a__					(    self       )     ->							Tuple:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()
											SCREAMING_SNAKE_CASE_				=				True
											SCREAMING_SNAKE_CASE_				=				max_length
											SCREAMING_SNAKE_CASE_				=				0.8
											SCREAMING_SNAKE_CASE_				=				10
											SCREAMING_SNAKE_CASE_				=				0.3
											SCREAMING_SNAKE_CASE_				=				1
											SCREAMING_SNAKE_CASE_				=				8
											SCREAMING_SNAKE_CASE_				=				9

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )



				def   a__					(    self       )     ->							List[str]:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()
											SCREAMING_SNAKE_CASE_				=				max_length
											SCREAMING_SNAKE_CASE_				=				1
											SCREAMING_SNAKE_CASE_				=				8
											SCREAMING_SNAKE_CASE_				=				9

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )



				def   a__					(    self       )     ->							Dict:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()
											SCREAMING_SNAKE_CASE_				=				max_length
											SCREAMING_SNAKE_CASE_				=				2
											SCREAMING_SNAKE_CASE_				=				1
											SCREAMING_SNAKE_CASE_				=				8
											SCREAMING_SNAKE_CASE_				=				9

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )



				def   a__					(    self       )     ->							Optional[int]:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()

											# pad attention mask on the left
											SCREAMING_SNAKE_CASE_				=				attention_mask.at[(0, 0)].set(0       )

											SCREAMING_SNAKE_CASE_				=				False
											SCREAMING_SNAKE_CASE_				=				max_length

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase,     attention_mask=_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase,     attention_mask=_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )



				def   a__					(    self       )     ->							List[Any]:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()

											# pad attention mask on the left
											SCREAMING_SNAKE_CASE_				=				attention_mask.at[(0, 0)].set(0       )

											SCREAMING_SNAKE_CASE_				=				True
											SCREAMING_SNAKE_CASE_				=				max_length

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase,     attention_mask=_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase,     attention_mask=_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )





				def   a__					(    self       )     ->							int:
											SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				,    SCREAMING_SNAKE_CASE_				=				self._get_input_ids_and_config()

											# pad attention mask on the left
											SCREAMING_SNAKE_CASE_				=				attention_mask.at[(0, 0)].set(0       )

											SCREAMING_SNAKE_CASE_				=				2
											SCREAMING_SNAKE_CASE_				=				max_length

											for model_class in self.all_generative_model_classes:
																		SCREAMING_SNAKE_CASE_				=				model_class(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				model.generate(_lowercase,     attention_mask=_lowercase       ).sequences
																		self.assertEqual(generation_outputs.shape[-1],     _lowercase       )

																		SCREAMING_SNAKE_CASE_				=				jit(model.generate       )
																		SCREAMING_SNAKE_CASE_				=				jit_generate(_lowercase,     attention_mask=_lowercase       ).sequences

																		self.assertListEqual(generation_outputs.tolist(),     jit_generation_outputs.tolist()       )






@require_flax
class    snake_case     (      unittest.TestCase		):






				"""simple docstring"""



				def   a__					(    self       )     ->							Optional[int]:
											SCREAMING_SNAKE_CASE_				=				AutoTokenizer.from_pretrained('hf-internal-testing/tiny-bert'       )
											SCREAMING_SNAKE_CASE_				=				FlaxAutoModelForCausalLM.from_pretrained('hf-internal-testing/tiny-bert-flax-only'       )

											SCREAMING_SNAKE_CASE_				=				'Hello world'
											SCREAMING_SNAKE_CASE_				=				tokenizer(_lowercase,     return_tensors='np'       ).input_ids

											# typos are quickly detected (the correct argument is `do_sample`)
											with self.assertRaisesRegex(_lowercase,     'do_samples'       ):
																		model.generate(_lowercase,     do_samples=_lowercase       )

											# arbitrary arguments that will not be used anywhere are also not accepted
											with self.assertRaisesRegex(_lowercase,     'foo'       ):
																		SCREAMING_SNAKE_CASE_				=				{'foo': 'bar'}
																		model.generate(_lowercase,     **_lowercase       )








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






											"""simple docstring"""



											@staticmethod
											def   a__					(    *_lowercase,     **_lowercase       )     ->							Tuple:
																		pass






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






				"""simple docstring"""
				_a    	=     MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING



				def   a__					(    self,     _lowercase,     _lowercase,     _lowercase       )     ->							Tuple:
											SCREAMING_SNAKE_CASE_				=				pipeline(
											    'zero-shot-object-detection',     model='hf-internal-testing/tiny-random-owlvit-object-detection'       )

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



				def   a__					(    self,     _lowercase,     _lowercase       )     ->							str:
											SCREAMING_SNAKE_CASE_				=				object_detector(examples[0],     threshold=0.0       )

											SCREAMING_SNAKE_CASE_				=				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   a__					(    self       )     ->							Union[str, Any]:
											pass



				@require_torch
				def   a__					(    self       )     ->							str:
											SCREAMING_SNAKE_CASE_				=				pipeline(
											    'zero-shot-object-detection',     model='hf-internal-testing/tiny-random-owlvit-object-detection'       )

											SCREAMING_SNAKE_CASE_				=				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.7_235, 'label': 'cat', 'box': {'xmin': 204, 'ymin': 167, 'xmax': 232, 'ymax': 190}},
											        {'score': 0.7_218, 'label': 'remote', 'box': {'xmin': 204, 'ymin': 167, 'xmax': 232, 'ymax': 190}},
											        {'score': 0.7_184, 'label': 'couch', 'box': {'xmin': 204, 'ymin': 167, 'xmax': 232, 'ymax': 190}},
											        {'score': 0.6_748, 'label': 'remote', 'box': {'xmin': 571, 'ymin': 83, 'xmax': 598, 'ymax': 103}},
											        {'score': 0.6_656, 'label': 'cat', 'box': {'xmin': 571, 'ymin': 83, 'xmax': 598, 'ymax': 103}},
											        {'score': 0.6_614, 'label': 'couch', 'box': {'xmin': 571, 'ymin': 83, 'xmax': 598, 'ymax': 103}},
											        {'score': 0.6_456, '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.6_419, 'label': 'cat', 'box': {'xmin': 494, 'ymin': 105, 'xmax': 521, 'ymax': 127}},
											    ],     )

											SCREAMING_SNAKE_CASE_				=				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.7_235, 'label': 'cat', 'box': {'xmin': 204, 'ymin': 167, 'xmax': 232, 'ymax': 190}},
											            {'score': 0.7_218, 'label': 'remote', 'box': {'xmin': 204, 'ymin': 167, 'xmax': 232, 'ymax': 190}},
											            {'score': 0.7_184, 'label': 'couch', 'box': {'xmin': 204, 'ymin': 167, 'xmax': 232, 'ymax': 190}},
											            {'score': 0.6_748, 'label': 'remote', 'box': {'xmin': 571, 'ymin': 83, 'xmax': 598, 'ymax': 103}},
											            {'score': 0.6_656, 'label': 'cat', 'box': {'xmin': 571, 'ymin': 83, 'xmax': 598, 'ymax': 103}},
											            {'score': 0.6_614, 'label': 'couch', 'box': {'xmin': 571, 'ymin': 83, 'xmax': 598, 'ymax': 103}},
											            {'score': 0.6_456, '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.6_419, 'label': 'cat', 'box': {'xmin': 494, 'ymin': 105, 'xmax': 521, 'ymax': 127}},
											        ]
											    ],     )



				@require_torch
				@slow
				def   a__					(    self       )     ->							Optional[int]:
											SCREAMING_SNAKE_CASE_				=				pipeline('zero-shot-object-detection'       )

											SCREAMING_SNAKE_CASE_				=				object_detector(
											    'http://images.cocodataset.org/val2017/000000039769.jpg',     candidate_labels=['cat', 'remote', 'couch'],     )
											self.assertEqual(
											    nested_simplify(_lowercase,     decimals=4       ),     [
											        {'score': 0.2_868, '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.2_537, 'label': 'cat', 'box': {'xmin': 1, 'ymin': 55, 'xmax': 315, 'ymax': 472}},
											        {'score': 0.1_474, 'label': 'remote', 'box': {'xmin': 335, 'ymin': 74, 'xmax': 371, 'ymax': 187}},
											        {'score': 0.1_208, 'label': 'couch', 'box': {'xmin': 4, 'ymin': 0, 'xmax': 642, 'ymax': 476}},
											    ],     )

											SCREAMING_SNAKE_CASE_				=				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.2_868, '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.2_537, 'label': 'cat', 'box': {'xmin': 1, 'ymin': 55, 'xmax': 315, 'ymax': 472}},
											            {'score': 0.1_474, 'label': 'remote', 'box': {'xmin': 335, 'ymin': 74, 'xmax': 371, 'ymax': 187}},
											            {'score': 0.1_208, 'label': 'couch', 'box': {'xmin': 4, 'ymin': 0, 'xmax': 642, 'ymax': 476}},
											        ],
											        [
											            {'score': 0.2_868, '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.2_537, 'label': 'cat', 'box': {'xmin': 1, 'ymin': 55, 'xmax': 315, 'ymax': 472}},
											            {'score': 0.1_474, 'label': 'remote', 'box': {'xmin': 335, 'ymin': 74, 'xmax': 371, 'ymax': 187}},
											            {'score': 0.1_208, 'label': 'couch', 'box': {'xmin': 4, 'ymin': 0, 'xmax': 642, 'ymax': 476}},
											        ],
											    ],     )



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



				@require_torch
				@slow
				def   a__					(    self       )     ->							Any:
											SCREAMING_SNAKE_CASE_				=				0.2
											SCREAMING_SNAKE_CASE_				=				pipeline('zero-shot-object-detection'       )

											SCREAMING_SNAKE_CASE_				=				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.2_868, '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.2_537, 'label': 'cat', 'box': {'xmin': 1, 'ymin': 55, 'xmax': 315, 'ymax': 472}},
											    ],     )





				@require_torch
				@slow
				def   a__					(    self       )     ->							int:
											SCREAMING_SNAKE_CASE_				=				2
											SCREAMING_SNAKE_CASE_				=				pipeline('zero-shot-object-detection'       )

											SCREAMING_SNAKE_CASE_				=				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.2_868, '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}},
											    ],     )





