



from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import (
	    TFConvBertForMaskedLM,
	    TFConvBertForMultipleChoice,
	    TFConvBertForQuestionAnswering,
	    TFConvBertForSequenceClassification,
	    TFConvBertForTokenClassification,
	    TFConvBertModel,
	)






class 						lowercase		:






	"""simple docstring"""


	def __init__(      self      :		Any		,    __UpperCAmelCase      :		Optional[int]		,    __UpperCAmelCase      :		List[str]=13		,    __UpperCAmelCase      :		str=7		,    __UpperCAmelCase      :		List[str]=True		,    __UpperCAmelCase      :		List[Any]=True		,    __UpperCAmelCase      :		Optional[int]=True		,    __UpperCAmelCase      :		List[str]=True		,    __UpperCAmelCase      :		Optional[int]=99		,    __UpperCAmelCase      :		Any=32		,    __UpperCAmelCase      :		Union[str, Any]=2		,    __UpperCAmelCase      :		Tuple=4		,    __UpperCAmelCase      :		List[str]=37		,    __UpperCAmelCase      :		Union[str, Any]="gelu"		,    __UpperCAmelCase      :		Optional[Any]=0.1		,    __UpperCAmelCase      :		Optional[Any]=0.1		,    __UpperCAmelCase      :		str=512		,    __UpperCAmelCase      :		List[str]=16		,    __UpperCAmelCase      :		Dict=2		,    __UpperCAmelCase      :		Union[str, Any]=0.02		,    __UpperCAmelCase      :		Any=3		,    __UpperCAmelCase      :		Tuple=4		,    __UpperCAmelCase      :		Tuple=None		,    )     ->					List[Any]:
							UpperCAmelCase_=  parent
							UpperCAmelCase_=  13
							UpperCAmelCase_=  7
							UpperCAmelCase_=  True
							UpperCAmelCase_=  True
							UpperCAmelCase_=  True
							UpperCAmelCase_=  True
							UpperCAmelCase_=  99
							UpperCAmelCase_=  384
							UpperCAmelCase_=  2
							UpperCAmelCase_=  4
							UpperCAmelCase_=  37
							UpperCAmelCase_=  'gelu'
							UpperCAmelCase_=  0.1
							UpperCAmelCase_=  0.1
							UpperCAmelCase_=  512
							UpperCAmelCase_=  16
							UpperCAmelCase_=  2
							UpperCAmelCase_=  0.02
							UpperCAmelCase_=  3
							UpperCAmelCase_=  4
							UpperCAmelCase_=  128
							UpperCAmelCase_=  2
							UpperCAmelCase_=  9
							UpperCAmelCase_=  1
							UpperCAmelCase_=  None




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

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

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

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

							UpperCAmelCase_=  ConvBertConfig(
							    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		,    return_dict=__UpperCAmelCase		,    )

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




	def     _SCREAMING_SNAKE_CASE						(      self      :		Optional[int]		,    __UpperCAmelCase      :		Any		,    __UpperCAmelCase      :		List[Any]		,    __UpperCAmelCase      :		Optional[Any]		,    __UpperCAmelCase      :		Any		,    __UpperCAmelCase      :		Any		,    __UpperCAmelCase      :		Any		,    __UpperCAmelCase      :		int	)     ->					str:
							UpperCAmelCase_=  TFConvBertModel(config=__UpperCAmelCase	)
							UpperCAmelCase_=  {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

							UpperCAmelCase_=  [input_ids, input_mask]
							UpperCAmelCase_=  model(__UpperCAmelCase	)

							UpperCAmelCase_=  model(__UpperCAmelCase	)

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




	def     _SCREAMING_SNAKE_CASE						(      self      :		List[Any]		,    __UpperCAmelCase      :		int		,    __UpperCAmelCase      :		Tuple		,    __UpperCAmelCase      :		Dict		,    __UpperCAmelCase      :		List[str]		,    __UpperCAmelCase      :		Tuple		,    __UpperCAmelCase      :		List[str]		,    __UpperCAmelCase      :		Dict	)     ->					int:
							UpperCAmelCase_=  TFConvBertForMaskedLM(config=__UpperCAmelCase	)
							UpperCAmelCase_=  {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							UpperCAmelCase_=  model(__UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape		,    (self.batch_size, self.seq_length, self.vocab_size)	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		Tuple		,    __UpperCAmelCase      :		Optional[Any]		,    __UpperCAmelCase      :		Optional[Any]		,    __UpperCAmelCase      :		List[Any]		,    __UpperCAmelCase      :		Tuple		,    __UpperCAmelCase      :		Optional[int]		,    __UpperCAmelCase      :		Optional[int]		,    __UpperCAmelCase      :		Optional[Any]	)     ->					Optional[Any]:
							UpperCAmelCase_=  self.num_labels
							UpperCAmelCase_=  TFConvBertForSequenceClassification(config=__UpperCAmelCase	)
							UpperCAmelCase_=  {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}

							UpperCAmelCase_=  model(__UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape		,    (self.batch_size, self.num_labels)	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		str		,    __UpperCAmelCase      :		List[str]		,    __UpperCAmelCase      :		Optional[Any]		,    __UpperCAmelCase      :		List[str]		,    __UpperCAmelCase      :		Dict		,    __UpperCAmelCase      :		Dict		,    __UpperCAmelCase      :		Optional[int]		,    __UpperCAmelCase      :		Optional[int]	)     ->					Dict:
							UpperCAmelCase_=  self.num_choices
							UpperCAmelCase_=  TFConvBertForMultipleChoice(config=__UpperCAmelCase	)
							UpperCAmelCase_=  tf.tile(tf.expand_dims(__UpperCAmelCase		,    1	)		,    (1, self.num_choices, 1)	)
							UpperCAmelCase_=  tf.tile(tf.expand_dims(__UpperCAmelCase		,    1	)		,    (1, self.num_choices, 1)	)
							UpperCAmelCase_=  tf.tile(tf.expand_dims(__UpperCAmelCase		,    1	)		,    (1, self.num_choices, 1)	)
							UpperCAmelCase_=  {
							    'input_ids': multiple_choice_inputs_ids,
							    'attention_mask': multiple_choice_input_mask,
							    'token_type_ids': multiple_choice_token_type_ids,
							}
							UpperCAmelCase_=  model(__UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape		,    (self.batch_size, self.num_choices)	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		List[str]		,    __UpperCAmelCase      :		List[str]		,    __UpperCAmelCase      :		Dict		,    __UpperCAmelCase      :		Optional[int]		,    __UpperCAmelCase      :		Any		,    __UpperCAmelCase      :		Any		,    __UpperCAmelCase      :		List[Any]		,    __UpperCAmelCase      :		Union[str, Any]	)     ->					List[str]:
							UpperCAmelCase_=  self.num_labels
							UpperCAmelCase_=  TFConvBertForTokenClassification(config=__UpperCAmelCase	)
							UpperCAmelCase_=  {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							UpperCAmelCase_=  model(__UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape		,    (self.batch_size, self.seq_length, self.num_labels)	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		Union[str, Any]		,    __UpperCAmelCase      :		int		,    __UpperCAmelCase      :		int		,    __UpperCAmelCase      :		Dict		,    __UpperCAmelCase      :		Dict		,    __UpperCAmelCase      :		Optional[int]		,    __UpperCAmelCase      :		Optional[int]		,    __UpperCAmelCase      :		Tuple	)     ->					Optional[int]:
							UpperCAmelCase_=  TFConvBertForQuestionAnswering(config=__UpperCAmelCase	)
							UpperCAmelCase_=  {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}

							UpperCAmelCase_=  model(__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     _SCREAMING_SNAKE_CASE						(      self      :		Any	)     ->					Optional[int]:
							UpperCAmelCase_=  self.prepare_config_and_inputs()
							(
							    UpperCAmelCase_			
							)=  config_and_inputs
							UpperCAmelCase_=  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_tf
class 						lowercase		(					snake_case__					,       snake_case__					,       unittest.TestCase):






	"""simple docstring"""


	a__ :   List[str]						  =				(
	    (
	        TFConvBertModel,
	        TFConvBertForMaskedLM,
	        TFConvBertForQuestionAnswering,
	        TFConvBertForSequenceClassification,
	        TFConvBertForTokenClassification,
	        TFConvBertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	a__ :   Dict						  =				(
	    {
	        "feature-extraction": TFConvBertModel,
	        "fill-mask": TFConvBertForMaskedLM,
	        "question-answering": TFConvBertForQuestionAnswering,
	        "text-classification": TFConvBertForSequenceClassification,
	        "token-classification": TFConvBertForTokenClassification,
	        "zero-shot": TFConvBertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	a__ :   Union[str, Any]						  =				False
	a__ :   Optional[int]						  =				False
	a__ :   Tuple						  =				False




	def     _SCREAMING_SNAKE_CASE						(      self      :		Optional[Any]	)     ->					Optional[Any]:
							UpperCAmelCase_=  TFConvBertModelTester(self	)
							UpperCAmelCase_=  ConfigTester(self		,    config_class=__UpperCAmelCase		,    hidden_size=37	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		Union[str, Any]	)     ->					List[Any]:
							self.config_tester.run_common_tests()




	def     _SCREAMING_SNAKE_CASE						(      self      :		List[str]	)     ->					List[str]:
							UpperCAmelCase_=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__UpperCAmelCase	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		Union[str, Any]	)     ->					Optional[int]:
							UpperCAmelCase_=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		int	)     ->					List[str]:
							UpperCAmelCase_=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*__UpperCAmelCase	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		Dict	)     ->					List[str]:
							UpperCAmelCase_=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		Tuple	)     ->					Union[str, Any]:
							UpperCAmelCase_=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		Any	)     ->					Optional[Any]:
							UpperCAmelCase_=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase	)




	@slow
	def     _SCREAMING_SNAKE_CASE						(      self      :		Union[str, Any]	)     ->					Union[str, Any]:
							UpperCAmelCase_=  self.model_tester.prepare_config_and_inputs_for_common()
							UpperCAmelCase_=  True
							UpperCAmelCase_=  True

							if hasattr(__UpperCAmelCase		,    """use_cache"""	):
													UpperCAmelCase_=  True

							UpperCAmelCase_=  getattr(self.model_tester		,    """encoder_seq_length"""		,    self.model_tester.seq_length	)
							UpperCAmelCase_=  getattr(self.model_tester		,    """key_length"""		,    __UpperCAmelCase	)

							for model_class in self.all_model_classes:
													UpperCAmelCase_=  self._prepare_for_class(__UpperCAmelCase		,    __UpperCAmelCase	)
													UpperCAmelCase_=  model_class(__UpperCAmelCase	)
													UpperCAmelCase_=  len(model(__UpperCAmelCase	)	)

													with tempfile.TemporaryDirectory() as tmpdirname:
																			model.save_pretrained(__UpperCAmelCase		,    saved_model=__UpperCAmelCase	)
																			UpperCAmelCase_=  os.path.join(__UpperCAmelCase		,    """saved_model"""		,    """1"""	)
																			UpperCAmelCase_=  tf.keras.models.load_model(__UpperCAmelCase	)
																			UpperCAmelCase_=  model(__UpperCAmelCase	)

																			if self.is_encoder_decoder:
																									UpperCAmelCase_=  outputs['encoder_hidden_states']
																									UpperCAmelCase_=  outputs['encoder_attentions']
																			else:
																									UpperCAmelCase_=  outputs['hidden_states']
																									UpperCAmelCase_=  outputs['attentions']

																			self.assertEqual(len(__UpperCAmelCase	)		,    __UpperCAmelCase	)

																			UpperCAmelCase_=  getattr(
																			    self.model_tester		,    """expected_num_hidden_layers"""		,    self.model_tester.num_hidden_layers + 1	)

																			self.assertEqual(len(__UpperCAmelCase	)		,    __UpperCAmelCase	)
																			self.assertListEqual(
																			    list(output_hidden_states[0].shape[-2:]	)		,    [self.model_tester.seq_length, self.model_tester.hidden_size]		,    )

																			self.assertEqual(len(__UpperCAmelCase	)		,    self.model_tester.num_hidden_layers	)
																			self.assertListEqual(
																			    list(output_attentions[0].shape[-3:]	)		,    [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]		,    )




	@slow
	def     _SCREAMING_SNAKE_CASE						(      self      :		Optional[Any]	)     ->					Union[str, Any]:
							UpperCAmelCase_=  TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""	)
							self.assertIsNotNone(__UpperCAmelCase	)




	def     _SCREAMING_SNAKE_CASE						(      self      :		Optional[Any]	)     ->					Union[str, Any]:
							UpperCAmelCase_=  self.model_tester.prepare_config_and_inputs_for_common()
							UpperCAmelCase_=  True
							UpperCAmelCase_=  getattr(self.model_tester		,    """decoder_seq_length"""		,    self.model_tester.seq_length	)
							UpperCAmelCase_=  getattr(self.model_tester		,    """encoder_seq_length"""		,    self.model_tester.seq_length	)
							UpperCAmelCase_=  getattr(self.model_tester		,    """key_length"""		,    __UpperCAmelCase	)
							UpperCAmelCase_=  getattr(self.model_tester		,    """key_length"""		,    __UpperCAmelCase	)

							def check_decoder_attentions_output(__UpperCAmelCase      :		Optional[Any]	):
													UpperCAmelCase_=  len(__UpperCAmelCase	)
													self.assertEqual(out_len % 2		,    0	)
													UpperCAmelCase_=  outputs.decoder_attentions
													self.assertEqual(len(__UpperCAmelCase	)		,    self.model_tester.num_hidden_layers	)
													self.assertListEqual(
													    list(decoder_attentions[0].shape[-3:]	)		,    [self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]		,    )

							def check_encoder_attentions_output(__UpperCAmelCase      :		Tuple	):
													UpperCAmelCase_=  [
													    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
													]
													self.assertEqual(len(__UpperCAmelCase	)		,    self.model_tester.num_hidden_layers	)
													self.assertListEqual(
													    list(attentions[0].shape[-3:]	)		,    [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]		,    )

							for model_class in self.all_model_classes:
													UpperCAmelCase_=  True
													UpperCAmelCase_=  False
													UpperCAmelCase_=  model_class(__UpperCAmelCase	)
													UpperCAmelCase_=  model(self._prepare_for_class(__UpperCAmelCase		,    __UpperCAmelCase	)	)
													UpperCAmelCase_=  len(__UpperCAmelCase	)
													self.assertEqual(config.output_hidden_states		,    __UpperCAmelCase	)
													check_encoder_attentions_output(__UpperCAmelCase	)

													if self.is_encoder_decoder:
																			UpperCAmelCase_=  model_class(__UpperCAmelCase	)
																			UpperCAmelCase_=  model(self._prepare_for_class(__UpperCAmelCase		,    __UpperCAmelCase	)	)
																			self.assertEqual(config.output_hidden_states		,    __UpperCAmelCase	)
																			check_decoder_attentions_output(__UpperCAmelCase	)

													# Check that output attentions can also be changed via the config
													del inputs_dict["output_attentions"]
													UpperCAmelCase_=  True
													UpperCAmelCase_=  model_class(__UpperCAmelCase	)
													UpperCAmelCase_=  model(self._prepare_for_class(__UpperCAmelCase		,    __UpperCAmelCase	)	)
													self.assertEqual(config.output_hidden_states		,    __UpperCAmelCase	)
													check_encoder_attentions_output(__UpperCAmelCase	)

													# Check attention is always last and order is fine
													UpperCAmelCase_=  True
													UpperCAmelCase_=  True
													UpperCAmelCase_=  model_class(__UpperCAmelCase	)
													UpperCAmelCase_=  model(self._prepare_for_class(__UpperCAmelCase		,    __UpperCAmelCase	)	)

													self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)		,    len(__UpperCAmelCase	)	)
													self.assertEqual(model.config.output_hidden_states		,    __UpperCAmelCase	)
													check_encoder_attentions_output(__UpperCAmelCase	)






@require_tf
class 						lowercase		(					unittest.TestCase):






	"""simple docstring"""


	@slow
	def     _SCREAMING_SNAKE_CASE						(      self      :		Tuple	)     ->					Tuple:
							UpperCAmelCase_=  TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""	)
							UpperCAmelCase_=  tf.constant([[0, 1, 2, 3, 4, 5]]	)
							UpperCAmelCase_=  model(__UpperCAmelCase	)[0]

							UpperCAmelCase_=  [1, 6, 768]
							self.assertEqual(output.shape		,    __UpperCAmelCase	)

							UpperCAmelCase_=  tf.constant(
							    [
							        [
							            [-0.03_475_493, -0.4_686_034, -0.30_638_832],
							            [0.22_637_248, -0.26_988_646, -0.7_423_424],
							            [0.10_324_868, -0.45_013_508, -0.58_280_784],
							        ]
							    ]	)
							tf.debugging.assert_near(output[:, :3, :3]		,    __UpperCAmelCase		,    atol=1E-4	)








'''simple docstring'''






import hashlib
import unittest
from typing import Dict

import numpy as np

from transformers import (
    MODEL_FOR_MASK_GENERATION_MAPPING,
    TF_MODEL_FOR_MASK_GENERATION_MAPPING,
    is_vision_available,
    pipeline,
)
from transformers.pipelines import MaskGenerationPipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)


if is_vision_available():
 from PIL import Image
else:






 class    __magic_name__				:






        @staticmethod
        def      lowerCAmelCase						(     *snake_case    ,				**snake_case)		->    str:




           '''simple docstring'''
           pass





def lowerCamelCase__     (		__lowerCamelCase			:				Image				):







   '''simple docstring'''




   _UpperCAmelCase  :  Optional[Any]				       =hashlib.mda(image.tobytes()				)
   return m.hexdigest()[:1_0]





def lowerCamelCase__     (		__lowerCamelCase			:				Image				):







   '''simple docstring'''




   _UpperCAmelCase  :  List[str]				       =np.array(__lowerCamelCase				)
   _UpperCAmelCase  :  List[str]				       =npimg.shape
   return {"hash": hashimage(__lowerCamelCase				), "shape": shape}






@is_pipeline_test
@require_vision
@require_torch
class    __magic_name__				(						unittest.TestCase							):
       UpperCAmelCase		 =dict(
           (list(MODEL_FOR_MASK_GENERATION_MAPPING.items()							) if MODEL_FOR_MASK_GENERATION_MAPPING else [])							)
       UpperCAmelCase		 =dict(
           (list(TF_MODEL_FOR_MASK_GENERATION_MAPPING.items()							) if TF_MODEL_FOR_MASK_GENERATION_MAPPING else [])							)






       def      lowerCAmelCase						(     self    ,				snake_case    ,				snake_case    ,				snake_case)		->    str:




          '''simple docstring'''
          _UpperCAmelCase  :  List[str]				       =MaskGenerationPipeline(model=snake_case    ,				image_processor=snake_case)
          return image_segmenter, [
              "./tests/fixtures/tests_samples/COCO/000000039769.png",
              "./tests/fixtures/tests_samples/COCO/000000039769.png",
          ]






       def      lowerCAmelCase						(     self    ,				snake_case    ,				snake_case)		->    Optional[Any]:




          '''simple docstring'''
          pass






       @require_tf
       @unittest.skip('Image segmentation not implemented in TF')
       def      lowerCAmelCase						(     self)		->    Union[str, Any]:




          '''simple docstring'''
          pass






       @slow
       @require_torch
       def      lowerCAmelCase						(     self)		->    str:




          '''simple docstring'''
          _UpperCAmelCase  :  Any				       =pipeline('mask-generation'    ,				model='facebook/sam-vit-huge')

          _UpperCAmelCase  :  Union[str, Any]				       =image_segmenter('http://images.cocodataset.org/val2017/000000039769.jpg'    ,				points_per_batch=2_5_6)

          # Shortening by hashing
          _UpperCAmelCase  :  str				       =[]
          for i, o in enumerate(outputs['masks']):
             new_outupt += [{"mask": mask_to_test_readable(snake_case), "scores": outputs["scores"][i]}]

          # fmt: off
          self.assertEqual(
              nested_simplify(snake_case    ,				decimals=4)    ,				[
                  {'mask': {'hash': '115ad19f5f', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.04_44},
                  {'mask': {'hash': '6affa964c6', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.0_21},
                  {'mask': {'hash': 'dfe28a0388', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.01_67},
                  {'mask': {'hash': 'c0a5f4a318', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.01_32},
                  {'mask': {'hash': 'fe8065c197', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.00_53},
                  {'mask': {'hash': 'e2d0b7a0b7', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.99_67},
                  {'mask': {'hash': '453c7844bd', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.9_93},
                  {'mask': {'hash': '3d44f2926d', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.99_09},
                  {'mask': {'hash': '64033ddc3f', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.98_79},
                  {'mask': {'hash': '801064ff79', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.98_34},
                  {'mask': {'hash': '6172f276ef', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.97_16},
                  {'mask': {'hash': 'b49e60e084', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.96_12},
                  {'mask': {'hash': 'a811e775fd', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.95_99},
                  {'mask': {'hash': 'a6a8ebcf4b', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.95_52},
                  {'mask': {'hash': '9d8257e080', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.95_32},
                  {'mask': {'hash': '32de6454a8', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.95_16},
                  {'mask': {'hash': 'af3d4af2c8', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.94_99},
                  {'mask': {'hash': '3c6db475fb', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.94_83},
                  {'mask': {'hash': 'c290813fb9', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.94_64},
                  {'mask': {'hash': 'b6f0b8f606', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.9_43},
                  {'mask': {'hash': '92ce16bfdf', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.9_43},
                  {'mask': {'hash': 'c749b25868', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.94_08},
                  {'mask': {'hash': 'efb6cab859', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.93_35},
                  {'mask': {'hash': '1ff2eafb30', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.93_26},
                  {'mask': {'hash': '788b798e24', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.92_62},
                  {'mask': {'hash': 'abea804f0e', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.89_99},
                  {'mask': {'hash': '7b9e8ddb73', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.89_86},
                  {'mask': {'hash': 'cd24047c8a', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.89_84},
                  {'mask': {'hash': '6943e6bcbd', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.88_73},
                  {'mask': {'hash': 'b5f47c9191', 'shape': (4_8_0, 6_4_0)}, 'scores': 0.88_71}
              ]    ,				)
          # fmt: on






       @require_torch
       @slow
       def      lowerCAmelCase						(     self)		->    Optional[Any]:




          '''simple docstring'''
          _UpperCAmelCase  :  List[str]				       ='facebook/sam-vit-huge'
          _UpperCAmelCase  :  Optional[int]				       =pipeline('mask-generation'    ,				model=snake_case)

          _UpperCAmelCase  :  str				       =image_segmenter(
              'http://images.cocodataset.org/val2017/000000039769.jpg'    ,				pred_iou_thresh=1    ,				points_per_batch=2_5_6)

          # Shortening by hashing
          _UpperCAmelCase  :  Tuple				       =[]
          for i, o in enumerate(outputs['masks']):
             new_outupt += [{"mask": mask_to_test_readable(snake_case), "scores": outputs["scores"][i]}]

          self.assertEqual(
              nested_simplify(snake_case    ,				decimals=4)    ,				[
                  {'mask': {'hash': '115ad19f5f', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.04_44},
                  {'mask': {'hash': '6affa964c6', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.02_10},
                  {'mask': {'hash': 'dfe28a0388', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.01_67},
                  {'mask': {'hash': 'c0a5f4a318', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.01_32},
                  {'mask': {'hash': 'fe8065c197', 'shape': (4_8_0, 6_4_0)}, 'scores': 1.00_53},
              ]    ,				)

