

"""simple docstring"""





from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
							    TFDebertaVaForMaskedLM,
							    TFDebertaVaForQuestionAnswering,
							    TFDebertaVaForSequenceClassification,
							    TFDebertaVaForTokenClassification,
							    TFDebertaVaModel,
							)







class 							SCREAMING_SNAKE_CASE   :






					"""simple docstring"""



					def __init__(			self     :							Optional[Any]  ,lowercase_     :							Tuple  ,lowercase_     :							List[Any]=1_3  ,lowercase_     :							Any=7  ,lowercase_     :							Optional[Any]=True  ,lowercase_     :							Optional[Any]=True  ,lowercase_     :							str=True  ,lowercase_     :							Optional[int]=True  ,lowercase_     :							List[str]=9_9  ,lowercase_     :							Dict=3_2  ,lowercase_     :							Union[str, Any]=2  ,lowercase_     :							str=4  ,lowercase_     :							Tuple=3_7  ,lowercase_     :							Optional[int]="gelu"  ,lowercase_     :							int=0.1  ,lowercase_     :							Dict=0.1  ,lowercase_     :							Tuple=5_1_2  ,lowercase_     :							Optional[int]=1_6  ,lowercase_     :							List[str]=2  ,lowercase_     :							Optional[int]=0.02  ,lowercase_     :							str=False  ,lowercase_     :							int=True  ,lowercase_     :							Tuple="None"  ,lowercase_     :							Union[str, Any]=3  ,lowercase_     :							Any=4  ,lowercase_     :							Dict=None  ,):
						lowerCAmelCase__      :		Union[str, Any]    							=      parent
						lowerCAmelCase__      :		Any    							=      batch_size
						lowerCAmelCase__      :		Optional[int]    							=      seq_length
						lowerCAmelCase__      :		Optional[Any]    							=      is_training
						lowerCAmelCase__      :		Optional[int]    							=      use_input_mask
						lowerCAmelCase__      :		str    							=      use_token_type_ids
						lowerCAmelCase__      :		Optional[Any]    							=      use_labels
						lowerCAmelCase__      :		Any    							=      vocab_size
						lowerCAmelCase__      :		Any    							=      hidden_size
						lowerCAmelCase__      :		Union[str, Any]    							=      num_hidden_layers
						lowerCAmelCase__      :		List[str]    							=      num_attention_heads
						lowerCAmelCase__      :		Tuple    							=      intermediate_size
						lowerCAmelCase__      :		List[str]    							=      hidden_act
						lowerCAmelCase__      :		List[Any]    							=      hidden_dropout_prob
						lowerCAmelCase__      :		Optional[int]    							=      attention_probs_dropout_prob
						lowerCAmelCase__      :		List[Any]    							=      max_position_embeddings
						lowerCAmelCase__      :		Dict    							=      type_vocab_size
						lowerCAmelCase__      :		List[Any]    							=      type_sequence_label_size
						lowerCAmelCase__      :		str    							=      initializer_range
						lowerCAmelCase__      :		str    							=      num_labels
						lowerCAmelCase__      :		List[str]    							=      num_choices
						lowerCAmelCase__      :		Optional[Any]    							=      relative_attention
						lowerCAmelCase__      :		Union[str, Any]    							=      position_biased_input
						lowerCAmelCase__      :		Any    							=      pos_att_type
						lowerCAmelCase__      :		int    							=      scope







					def 			__lowerCAmelCase					(			self     :							str						):
						lowerCAmelCase__      :		Dict    							=      ids_tensor([self.batch_size, self.seq_length]  ,self.vocab_size						)

						lowerCAmelCase__      :		Optional[Any]    							=      None
						if self.use_input_mask:
							lowerCAmelCase__      :		List[Any]    							=      random_attention_mask([self.batch_size, self.seq_length]						)

						lowerCAmelCase__      :		int    							=      None
						if self.use_token_type_ids:
							lowerCAmelCase__      :		List[Any]    							=      ids_tensor([self.batch_size, self.seq_length]  ,self.type_vocab_size						)

						lowerCAmelCase__      :		str    							=      None
						lowerCAmelCase__      :		Optional[Any]    							=      None
						lowerCAmelCase__      :		str    							=      None
						if self.use_labels:
							lowerCAmelCase__      :		Dict    							=      ids_tensor([self.batch_size]  ,self.type_sequence_label_size						)
							lowerCAmelCase__      :		Optional[Any]    							=      ids_tensor([self.batch_size, self.seq_length]  ,self.num_labels						)

						lowerCAmelCase__      :		Optional[int]    							=      DebertaVaConfig(
						    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  ,relative_attention=self.relative_attention  ,position_biased_input=self.position_biased_input  ,initializer_range=self.initializer_range  ,return_dict=lowercase_  ,)

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







					def 			__lowerCAmelCase					(			self     :							List[str]  ,lowercase_     :							Dict  ,lowercase_     :							str  ,lowercase_     :							List[str]  ,lowercase_     :							Optional[int]  ,lowercase_     :							List[str]  ,lowercase_     :							List[str]  ,lowercase_     :							Tuple						):
						lowerCAmelCase__      :		List[str]    							=      TFDebertaVaModel(config=lowercase_						)
						lowerCAmelCase__      :		List[str]    							=      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

						lowerCAmelCase__      :		Tuple    							=      [input_ids, input_mask]
						lowerCAmelCase__      :		Any    							=      model(lowercase_						)

						lowerCAmelCase__      :		Dict    							=      model(lowercase_						)

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







					def 			__lowerCAmelCase					(			self     :							List[str]  ,lowercase_     :							Optional[Any]  ,lowercase_     :							int  ,lowercase_     :							Optional[Any]  ,lowercase_     :							Union[str, Any]  ,lowercase_     :							str  ,lowercase_     :							List[str]  ,lowercase_     :							Any						):
						lowerCAmelCase__      :		str    							=      TFDebertaVaForMaskedLM(config=lowercase_						)
						lowerCAmelCase__      :		str    							=      {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}
						lowerCAmelCase__      :		Union[str, Any]    							=      model(lowercase_						)
						self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.vocab_size)						)







					def 			__lowerCAmelCase					(			self     :							List[Any]  ,lowercase_     :							Dict  ,lowercase_     :							Union[str, Any]  ,lowercase_     :							Any  ,lowercase_     :							int  ,lowercase_     :							Tuple  ,lowercase_     :							Tuple  ,lowercase_     :							List[str]						):
						lowerCAmelCase__      :		Optional[int]    							=      self.num_labels
						lowerCAmelCase__      :		int    							=      TFDebertaVaForSequenceClassification(config=lowercase_						)
						lowerCAmelCase__      :		Tuple    							=      {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}

						lowerCAmelCase__      :		List[str]    							=      model(lowercase_						)
						self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.num_labels)						)







					def 			__lowerCAmelCase					(			self     :							Any  ,lowercase_     :							str  ,lowercase_     :							Dict  ,lowercase_     :							str  ,lowercase_     :							str  ,lowercase_     :							Optional[Any]  ,lowercase_     :							Union[str, Any]  ,lowercase_     :							List[Any]						):
						lowerCAmelCase__      :		Optional[Any]    							=      self.num_labels
						lowerCAmelCase__      :		str    							=      TFDebertaVaForTokenClassification(config=lowercase_						)
						lowerCAmelCase__      :		Union[str, Any]    							=      {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}
						lowerCAmelCase__      :		Union[str, Any]    							=      model(lowercase_						)
						self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.num_labels)						)







					def 			__lowerCAmelCase					(			self     :							List[str]  ,lowercase_     :							int  ,lowercase_     :							Optional[int]  ,lowercase_     :							Union[str, Any]  ,lowercase_     :							Union[str, Any]  ,lowercase_     :							List[Any]  ,lowercase_     :							Dict  ,lowercase_     :							int						):
						lowerCAmelCase__      :		Optional[Any]    							=      TFDebertaVaForQuestionAnswering(config=lowercase_						)
						lowerCAmelCase__      :		List[Any]    							=      {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}

						lowerCAmelCase__      :		Dict    							=      model(lowercase_						)
						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 			__lowerCAmelCase					(			self     :							Optional[int]						):
						lowerCAmelCase__      :		Tuple    							=      self.prepare_config_and_inputs()
						(
						    (
						    lowerCAmelCase__
						)							,(
						    lowerCAmelCase__
						)							,(
						    lowerCAmelCase__
						)							,(
						    lowerCAmelCase__
						)							,(
						    lowerCAmelCase__
						)							,(
						    lowerCAmelCase__
						)							,(
						    lowerCAmelCase__
						)							,
						)      :		List[Any]    							=      config_and_inputs
						lowerCAmelCase__      :		Any    							=      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
						return config, inputs_dict







@require_tf
class 							SCREAMING_SNAKE_CASE   (						a_       ,				a_       ,				unittest.TestCase			):






					"""simple docstring"""



					lowercase__												=			(
					    (
					        TFDebertaVaModel,
					        TFDebertaVaForMaskedLM,
					        TFDebertaVaForQuestionAnswering,
					        TFDebertaVaForSequenceClassification,
					        TFDebertaVaForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					lowercase__												=			(
					    {
					        "feature-extraction": TFDebertaVaModel,
					        "fill-mask": TFDebertaVaForMaskedLM,
					        "question-answering": TFDebertaVaForQuestionAnswering,
					        "text-classification": TFDebertaVaForSequenceClassification,
					        "token-classification": TFDebertaVaForTokenClassification,
					        "zero-shot": TFDebertaVaForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)

					lowercase__												=			False
					lowercase__												=			False







					def 			__lowerCAmelCase					(			self     :							int						):
						lowerCAmelCase__      :		str    							=      TFDebertaVaModelTester(self						)
						lowerCAmelCase__      :		Union[str, Any]    							=      ConfigTester(self  ,config_class=lowercase_  ,hidden_size=3_7						)







					def 			__lowerCAmelCase					(			self     :							str						):
						self.config_tester.run_common_tests()







					def 			__lowerCAmelCase					(			self     :							Tuple						):
						lowerCAmelCase__      :		Tuple    							=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowercase_						)







					def 			__lowerCAmelCase					(			self     :							Optional[int]						):
						lowerCAmelCase__      :		Union[str, Any]    							=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*lowercase_						)







					def 			__lowerCAmelCase					(			self     :							int						):
						lowerCAmelCase__      :		Dict    							=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*lowercase_						)







					def 			__lowerCAmelCase					(			self     :							Optional[int]						):
						lowerCAmelCase__      :		Union[str, Any]    							=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*lowercase_						)







					def 			__lowerCAmelCase					(			self     :							Tuple						):
						lowerCAmelCase__      :		Optional[int]    							=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*lowercase_						)







					@slow
					def 			__lowerCAmelCase					(			self     :							List[str]						):
						lowerCAmelCase__      :		Any    							=      TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''						)
						self.assertIsNotNone(lowercase_						)







@require_tf
class 							SCREAMING_SNAKE_CASE   (						unittest.TestCase			):






					"""simple docstring"""



					@unittest.skip(reason='''Model not available yet'''						)
					def 			__lowerCAmelCase					(			self     :							Union[str, Any]						):
						pass







					@slow
					def 			__lowerCAmelCase					(			self     :							int						):
						lowerCAmelCase__      :		str    							=      TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''						)
						lowerCAmelCase__      :		str    							=      tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]						)
						lowerCAmelCase__      :		Tuple    							=      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
						lowerCAmelCase__      :		Optional[int]    							=      model(lowercase_  ,attention_mask=lowercase_						)[0]

						lowerCAmelCase__      :		Tuple    							=      tf.constant(
						    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]						)
						tf.debugging.assert_near(output[:, 1:4, 1:4]  ,lowercase_  ,atol=1E-4						)







"""simple docstring"""





import unittest

from transformers import (
    MODEL_FOR_OBJECT_DETECTION_MAPPING,
    AutoFeatureExtractor,
    AutoModelForObjectDetection,
    ObjectDetectionPipeline,
    is_vision_available,
    pipeline,
)
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_pytesseract,
    require_tf,
    require_timm,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
							from PIL import Image
else:







							class 							SCREAMING_SNAKE_CASE   :






												"""simple docstring"""



												@staticmethod
												def 			__lowerCAmelCase					(			*lowercase_     :							Dict  ,**lowercase_     :							str						):
													pass







@is_pipeline_test
@require_vision
@require_timm
@require_torch
class 							SCREAMING_SNAKE_CASE   (						unittest.TestCase			):






					"""simple docstring"""



					lowercase__												=			MODEL_FOR_OBJECT_DETECTION_MAPPING







					def 			__lowerCAmelCase					(			self     :							str  ,lowercase_     :							int  ,lowercase_     :							str  ,lowercase_     :							List[str]						):
						lowerCAmelCase__      :		int    							=      ObjectDetectionPipeline(model=lowercase_  ,image_processor=lowercase_						)
						return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]







					def 			__lowerCAmelCase					(			self     :							int  ,lowercase_     :							str  ,lowercase_     :							str						):
						lowerCAmelCase__      :		List[str]    							=      object_detector('''./tests/fixtures/tests_samples/COCO/000000039769.png'''  ,threshold=0.0						)

						self.assertGreater(len(lowercase_						)  ,0						)
						for detected_object in outputs:
							self.assertEqual(
							    lowercase_  ,{
							        '''score''': ANY(lowercase_						),
							        '''label''': ANY(lowercase_						),
							        '''box''': {'''xmin''': ANY(lowercase_						), '''ymin''': ANY(lowercase_						), '''xmax''': ANY(lowercase_						), '''ymax''': ANY(lowercase_						)},
							    }  ,)

						import datasets

						lowerCAmelCase__      :		str    							=      datasets.load_dataset('''hf-internal-testing/fixtures_image_utils'''  ,'''image'''  ,split='''test'''						)

						lowerCAmelCase__      :		Dict    							=      [
						    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''						),
						    '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						    # RGBA
						    dataset[0]['''file'''],
						    # LA
						    dataset[1]['''file'''],
						    # L
						    dataset[2]['''file'''],
						]
						lowerCAmelCase__      :		Optional[Any]    							=      object_detector(lowercase_  ,threshold=0.0						)

						self.assertEqual(len(lowercase_						)  ,len(lowercase_						)						)
						for outputs in batch_outputs:
							self.assertGreater(len(lowercase_						)  ,0						)
							for detected_object in outputs:
								self.assertEqual(
								    lowercase_  ,{
								        '''score''': ANY(lowercase_						),
								        '''label''': ANY(lowercase_						),
								        '''box''': {'''xmin''': ANY(lowercase_						), '''ymin''': ANY(lowercase_						), '''xmax''': ANY(lowercase_						), '''ymax''': ANY(lowercase_						)},
								    }  ,)







					@require_tf
					@unittest.skip('''Object detection not implemented in TF'''						)
					def 			__lowerCAmelCase					(			self     :							Optional[int]						):
						pass







					@require_torch
					def 			__lowerCAmelCase					(			self     :							Optional[int]						):
						lowerCAmelCase__      :		Optional[Any]    							=      '''hf-internal-testing/tiny-detr-mobilenetsv3'''

						lowerCAmelCase__      :		Union[str, Any]    							=      AutoModelForObjectDetection.from_pretrained(lowercase_						)
						lowerCAmelCase__      :		Any    							=      AutoFeatureExtractor.from_pretrained(lowercase_						)
						lowerCAmelCase__      :		Optional[int]    							=      ObjectDetectionPipeline(model=lowercase_  ,feature_extractor=lowercase_						)

						lowerCAmelCase__      :		Any    							=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''  ,threshold=0.0						)

						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						        {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						    ]  ,)

						lowerCAmelCase__      :		List[Any]    							=      object_detector(
						    [
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						    ]  ,threshold=0.0  ,)

						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        [
						            {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						            {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						        ],
						        [
						            {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						            {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						        ],
						    ]  ,)







					@require_torch
					@slow
					def 			__lowerCAmelCase					(			self     :							Any						):
						lowerCAmelCase__      :		List[Any]    							=      '''facebook/detr-resnet-50'''

						lowerCAmelCase__      :		Any    							=      AutoModelForObjectDetection.from_pretrained(lowercase_						)
						lowerCAmelCase__      :		Dict    							=      AutoFeatureExtractor.from_pretrained(lowercase_						)
						lowerCAmelCase__      :		Any    							=      ObjectDetectionPipeline(model=lowercase_  ,feature_extractor=lowercase_						)

						lowerCAmelCase__      :		Tuple    							=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						        {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						        {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						        {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						        {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						    ]  ,)

						lowerCAmelCase__      :		List[Any]    							=      object_detector(
						    [
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						    ]						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        [
						            {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						            {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						            {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						            {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						            {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						        ],
						        [
						            {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						            {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						            {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						            {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						            {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						        ],
						    ]  ,)







					@require_torch
					@slow
					def 			__lowerCAmelCase					(			self     :							Tuple						):
						lowerCAmelCase__      :		Tuple    							=      '''facebook/detr-resnet-50'''

						lowerCAmelCase__      :		Tuple    							=      pipeline('''object-detection'''  ,model=lowercase_						)

						lowerCAmelCase__      :		Optional[int]    							=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						        {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						        {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						        {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						        {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						    ]  ,)

						lowerCAmelCase__      :		Any    							=      object_detector(
						    [
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						    ]						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        [
						            {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						            {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						            {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						            {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						            {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						        ],
						        [
						            {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						            {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						            {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						            {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						            {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						        ],
						    ]  ,)







					@require_torch
					@slow
					def 			__lowerCAmelCase					(			self     :							Any						):
						lowerCAmelCase__      :		List[Any]    							=      0.9985
						lowerCAmelCase__      :		Dict    							=      '''facebook/detr-resnet-50'''

						lowerCAmelCase__      :		List[Any]    							=      pipeline('''object-detection'''  ,model=lowercase_						)

						lowerCAmelCase__      :		int    							=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''  ,threshold=lowercase_						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						        {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						    ]  ,)







					@require_torch
					@require_pytesseract
					@slow
					def 			__lowerCAmelCase					(			self     :							str						):
						lowerCAmelCase__      :		Optional[Any]    							=      '''Narsil/layoutlmv3-finetuned-funsd'''
						lowerCAmelCase__      :		List[Any]    							=      0.9993

						lowerCAmelCase__      :		Any    							=      pipeline('''object-detection'''  ,model=lowercase_  ,threshold=lowercase_						)

						lowerCAmelCase__      :		List[str]    							=      object_detector(
						    '''https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png'''						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.9993, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 2_9_4, '''ymin''': 2_5_4, '''xmax''': 3_4_3, '''ymax''': 2_6_4}},
						        {'''score''': 0.9993, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 2_9_4, '''ymin''': 2_5_4, '''xmax''': 3_4_3, '''ymax''': 2_6_4}},
						    ]  ,)




