


import unittest

from transformers import DebertaVaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
	import torch

	from transformers import (
	    DebertaVaForMaskedLM,
	    DebertaVaForMultipleChoice,
	    DebertaVaForQuestionAnswering,
	    DebertaVaForSequenceClassification,
	    DebertaVaForTokenClassification,
	    DebertaVaModel,
	)
	from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST




class       lowercase_					(lowercase__   ):





				def __init__(				self       ,  lowercase_       ,  lowercase_=13       ,  lowercase_=7       ,  lowercase_=True       ,  lowercase_=True       ,  lowercase_=True       ,  lowercase_=True       ,  lowercase_=99       ,  lowercase_=32       ,  lowercase_=5       ,  lowercase_=4       ,  lowercase_=37       ,  lowercase_="gelu"       ,  lowercase_=0.1       ,  lowercase_=0.1       ,  lowercase_=512       ,  lowercase_=16       ,  lowercase_=2       ,  lowercase_=0.02       ,  lowercase_=False       ,  lowercase_=True       ,  lowercase_="None"       ,  lowercase_=3       ,  lowercase_=4       ,  lowercase_=None       ,  )  -> Any:
											a__      =parent
											a__      =batch_size
											a__      =seq_length
											a__      =is_training
											a__      =use_input_mask
											a__      =use_token_type_ids
											a__      =use_labels
											a__      =vocab_size
											a__      =hidden_size
											a__      =num_hidden_layers
											a__      =num_attention_heads
											a__      =intermediate_size
											a__      =hidden_act
											a__      =hidden_dropout_prob
											a__      =attention_probs_dropout_prob
											a__      =max_position_embeddings
											a__      =type_vocab_size
											a__      =type_sequence_label_size
											a__      =initializer_range
											a__      =num_labels
											a__      =num_choices
											a__      =relative_attention
											a__      =position_biased_input
											a__      =pos_att_type
											a__      =scope





				def 						__UpperCamelCase    (				self)  -> List[str]:
											a__      =ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size)

											a__      =None
											if self.use_input_mask:
																		a__      =ids_tensor([self.batch_size, self.seq_length]       ,  vocab_size=2)

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

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

											a__      =self.get_config()

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





				def 						__UpperCamelCase    (				self)  -> Any:
											return 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       ,  initializer_range=self.initializer_range       ,  relative_attention=self.relative_attention       ,  position_biased_input=self.position_biased_input       ,  pos_att_type=self.pos_att_type       ,  )





				def 						__UpperCamelCase    (				self       ,  lowercase_)  -> Tuple:
											self.parent.assertListEqual(list(result.loss.size())       ,  [])





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_)  -> Any:
											a__      =DebertaVaModel(config=lowercase_)
											model.to(lowercase_)
											model.eval()
											a__      =model(lowercase_       ,  attention_mask=lowercase_       ,  token_type_ids=lowercase_)[0]
											a__      =model(lowercase_       ,  token_type_ids=lowercase_)[0]
											a__      =model(lowercase_)[0]

											self.parent.assertListEqual(list(sequence_output.size())       ,  [self.batch_size, self.seq_length, self.hidden_size])





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_)  -> Any:
											a__      =DebertaVaForMaskedLM(config=lowercase_)
											model.to(lowercase_)
											model.eval()
											a__      =model(lowercase_       ,  attention_mask=lowercase_       ,  token_type_ids=lowercase_       ,  labels=lowercase_)

											self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size))





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_)  -> Dict:
											a__      =self.num_labels
											a__      =DebertaVaForSequenceClassification(lowercase_)
											model.to(lowercase_)
											model.eval()
											a__      =model(lowercase_       ,  attention_mask=lowercase_       ,  token_type_ids=lowercase_       ,  labels=lowercase_)
											self.parent.assertListEqual(list(result.logits.size())       ,  [self.batch_size, self.num_labels])
											self.check_loss_output(lowercase_)





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_)  -> int:
											a__      =self.num_labels
											a__      =DebertaVaForTokenClassification(config=lowercase_)
											model.to(lowercase_)
											model.eval()
											a__      =model(lowercase_       ,  attention_mask=lowercase_       ,  token_type_ids=lowercase_       ,  labels=lowercase_)
											self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.num_labels))





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_)  -> List[Any]:
											a__      =DebertaVaForQuestionAnswering(config=lowercase_)
											model.to(lowercase_)
											model.eval()
											a__      =model(
											    lowercase_       ,  attention_mask=lowercase_       ,  token_type_ids=lowercase_       ,  start_positions=lowercase_       ,  end_positions=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 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_)  -> Tuple:
											a__      =DebertaVaForMultipleChoice(config=lowercase_)
											model.to(lowercase_)
											model.eval()
											a__      =input_ids.unsqueeze(1).expand(-1       ,  self.num_choices       ,  -1).contiguous()
											a__      =token_type_ids.unsqueeze(1).expand(-1       ,  self.num_choices       ,  -1).contiguous()
											a__      =input_mask.unsqueeze(1).expand(-1       ,  self.num_choices       ,  -1).contiguous()
											a__      =model(
											    lowercase_       ,  attention_mask=lowercase_       ,  token_type_ids=lowercase_       ,  labels=lowercase_       ,  )
											self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_choices))





				def 						__UpperCamelCase    (				self)  -> Tuple:
											a__      =self.prepare_config_and_inputs()
											(
											    (
											    a__
											)    ,     (
											    a__
											)    ,     (
											    a__
											)    ,     (
											    a__
											)    ,     (
											    a__
											)    ,     (
											    a__
											)    ,     (
											    a__
											)    ,     
											)      =config_and_inputs
											a__      ={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
											return config, inputs_dict







@require_torch
class       lowercase_					(lowercase__      ,					lowercase__      ,					unittest.TestCase   ):
				snake_case	    =(
				    (
				        DebertaVaModel,
				        DebertaVaForMaskedLM,
				        DebertaVaForSequenceClassification,
				        DebertaVaForTokenClassification,
				        DebertaVaForQuestionAnswering,
				        DebertaVaForMultipleChoice,
				    )
				    if is_torch_available()
				    else ()
				)
				snake_case	    =(
				    {
				        'feature-extraction': DebertaVaModel,
				        'fill-mask': DebertaVaForMaskedLM,
				        'question-answering': DebertaVaForQuestionAnswering,
				        'text-classification': DebertaVaForSequenceClassification,
				        'token-classification': DebertaVaForTokenClassification,
				        'zero-shot': DebertaVaForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)

				snake_case	    =True
				snake_case	    =False
				snake_case	    =False
				snake_case	    =False
				snake_case	    =False





				def 						__UpperCamelCase    (				self)  -> List[Any]:
											a__      =DebertaVaModelTester(self)
											a__      =ConfigTester(self       ,  config_class=lowercase_       ,  hidden_size=37)





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





				def 						__UpperCamelCase    (				self)  -> int:
											a__      =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_model(*lowercase_)





				def 						__UpperCamelCase    (				self)  -> Dict:
											a__      =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_sequence_classification(*lowercase_)





				def 						__UpperCamelCase    (				self)  -> str:
											a__      =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_masked_lm(*lowercase_)





				def 						__UpperCamelCase    (				self)  -> Dict:
											a__      =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_question_answering(*lowercase_)





				def 						__UpperCamelCase    (				self)  -> Optional[Any]:
											a__      =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_token_classification(*lowercase_)





				def 						__UpperCamelCase    (				self)  -> Dict:
											a__      =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_multiple_choice(*lowercase_)





				@slow
				def 						__UpperCamelCase    (				self)  -> Union[str, Any]:
											for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		a__      =DebertaVaModel.from_pretrained(lowercase_)
																		self.assertIsNotNone(lowercase_)







@require_torch
@require_sentencepiece
@require_tokenizers
class       lowercase_					(unittest.TestCase   ):





				@unittest.skip(reason='Model not available yet')
				def 						__UpperCamelCase    (				self)  -> Optional[int]:
											pass





				@slow
				def 						__UpperCamelCase    (				self)  -> List[str]:
											a__      =DebertaVaModel.from_pretrained('microsoft/deberta-v2-xlarge')

											a__      =torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]])
											a__      =torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
											with torch.no_grad():
																		a__      =model(lowercase_       ,  attention_mask=lowercase_)[0]
											# compare the actual values for a slice.
											a__      =torch.tensor(
											    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]])
											self.assertTrue(torch.allclose(output[:, 1:4, 1:4]       ,  lowercase_       ,  atol=1e-4)       ,  F"""{output[:, 1:4, 1: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    lowerCamelCase_       :
     """simple docstring"""




     @staticmethod
     def 		_lowercase	(					*_a :      Optional[Any]     ,      **_a :      Optional[Any]  )   ->   Tuple:
       pass






@is_pipeline_test
@require_vision
@require_timm
@require_torch
class    lowerCamelCase_       (							unittest.TestCase	):
  """simple docstring"""




  a_				   =MODEL_FOR_OBJECT_DETECTION_MAPPING




  def 		_lowercase	(					self :      List[Any]     ,      _a :      int     ,      _a :      str     ,      _a :      Tuple  )   ->   List[Any]:
    __lowerCamelCase			:			List[str]       			=					ObjectDetectionPipeline(model=_a     ,      image_processor=_a  )
    return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]




  def 		_lowercase	(					self :      Optional[int]     ,      _a :      int     ,      _a :      Optional[Any]  )   ->   Any:
    __lowerCamelCase			:			int       			=					object_detector('./tests/fixtures/tests_samples/COCO/000000039769.png'     ,      threshold=0.0  )

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

    import datasets

    __lowerCamelCase			:			Optional[int]       			=					datasets.load_dataset('hf-internal-testing/fixtures_image_utils'     ,      'image'     ,      split='test'  )

    __lowerCamelCase			:			List[str]       			=					[
        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			:			Dict       			=					object_detector(_a     ,      threshold=0.0  )

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




  @require_tf
  @unittest.skip('Object detection not implemented in TF'  )
  def 		_lowercase	(					self :      Optional[Any]  )   ->   Dict:
    pass




  @require_torch
  def 		_lowercase	(					self :      int  )   ->   Optional[int]:
    __lowerCamelCase			:			Dict       			=					'hf-internal-testing/tiny-detr-mobilenetsv3'

    __lowerCamelCase			:			str       			=					AutoModelForObjectDetection.from_pretrained(_a  )
    __lowerCamelCase			:			Optional[Any]       			=					AutoFeatureExtractor.from_pretrained(_a  )
    __lowerCamelCase			:			str       			=					ObjectDetectionPipeline(model=_a     ,      feature_extractor=_a  )

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

    self.assertEqual(
        nested_simplify(_a     ,      decimals=4  )     ,      [
            {'score': 0.3376, 'label': 'LABEL_0', 'box': {'xmin': 159, 'ymin': 120, 'xmax': 480, 'ymax': 359}},
            {'score': 0.3376, 'label': 'LABEL_0', 'box': {'xmin': 159, 'ymin': 120, 'xmax': 480, 'ymax': 359}},
        ]     ,      )

    __lowerCamelCase			:			Optional[int]       			=					object_detector(
        [
            'http://images.cocodataset.org/val2017/000000039769.jpg',
            'http://images.cocodataset.org/val2017/000000039769.jpg',
        ]     ,      threshold=0.0     ,      )

    self.assertEqual(
        nested_simplify(_a     ,      decimals=4  )     ,      [
            [
                {'score': 0.3376, 'label': 'LABEL_0', 'box': {'xmin': 159, 'ymin': 120, 'xmax': 480, 'ymax': 359}},
                {'score': 0.3376, 'label': 'LABEL_0', 'box': {'xmin': 159, 'ymin': 120, 'xmax': 480, 'ymax': 359}},
            ],
            [
                {'score': 0.3376, 'label': 'LABEL_0', 'box': {'xmin': 159, 'ymin': 120, 'xmax': 480, 'ymax': 359}},
                {'score': 0.3376, 'label': 'LABEL_0', 'box': {'xmin': 159, 'ymin': 120, 'xmax': 480, 'ymax': 359}},
            ],
        ]     ,      )




  @require_torch
  @slow
  def 		_lowercase	(					self :      Union[str, Any]  )   ->   Dict:
    __lowerCamelCase			:			Tuple       			=					'facebook/detr-resnet-50'

    __lowerCamelCase			:			Optional[int]       			=					AutoModelForObjectDetection.from_pretrained(_a  )
    __lowerCamelCase			:			List[str]       			=					AutoFeatureExtractor.from_pretrained(_a  )
    __lowerCamelCase			:			str       			=					ObjectDetectionPipeline(model=_a     ,      feature_extractor=_a  )

    __lowerCamelCase			:			int       			=					object_detector('http://images.cocodataset.org/val2017/000000039769.jpg'  )
    self.assertEqual(
        nested_simplify(_a     ,      decimals=4  )     ,      [
            {'score': 0.9982, 'label': 'remote', 'box': {'xmin': 40, 'ymin': 70, 'xmax': 175, 'ymax': 117}},
            {'score': 0.9960, 'label': 'remote', 'box': {'xmin': 333, 'ymin': 72, 'xmax': 368, 'ymax': 187}},
            {'score': 0.9955, 'label': 'couch', 'box': {'xmin': 0, 'ymin': 1, 'xmax': 639, 'ymax': 473}},
            {'score': 0.9988, 'label': 'cat', 'box': {'xmin': 13, 'ymin': 52, 'xmax': 314, 'ymax': 470}},
            {'score': 0.9987, 'label': 'cat', 'box': {'xmin': 345, 'ymin': 23, 'xmax': 640, 'ymax': 368}},
        ]     ,      )

    __lowerCamelCase			:			List[Any]       			=					object_detector(
        [
            'http://images.cocodataset.org/val2017/000000039769.jpg',
            'http://images.cocodataset.org/val2017/000000039769.jpg',
        ]  )
    self.assertEqual(
        nested_simplify(_a     ,      decimals=4  )     ,      [
            [
                {'score': 0.9982, 'label': 'remote', 'box': {'xmin': 40, 'ymin': 70, 'xmax': 175, 'ymax': 117}},
                {'score': 0.9960, 'label': 'remote', 'box': {'xmin': 333, 'ymin': 72, 'xmax': 368, 'ymax': 187}},
                {'score': 0.9955, 'label': 'couch', 'box': {'xmin': 0, 'ymin': 1, 'xmax': 639, 'ymax': 473}},
                {'score': 0.9988, 'label': 'cat', 'box': {'xmin': 13, 'ymin': 52, 'xmax': 314, 'ymax': 470}},
                {'score': 0.9987, 'label': 'cat', 'box': {'xmin': 345, 'ymin': 23, 'xmax': 640, 'ymax': 368}},
            ],
            [
                {'score': 0.9982, 'label': 'remote', 'box': {'xmin': 40, 'ymin': 70, 'xmax': 175, 'ymax': 117}},
                {'score': 0.9960, 'label': 'remote', 'box': {'xmin': 333, 'ymin': 72, 'xmax': 368, 'ymax': 187}},
                {'score': 0.9955, 'label': 'couch', 'box': {'xmin': 0, 'ymin': 1, 'xmax': 639, 'ymax': 473}},
                {'score': 0.9988, 'label': 'cat', 'box': {'xmin': 13, 'ymin': 52, 'xmax': 314, 'ymax': 470}},
                {'score': 0.9987, 'label': 'cat', 'box': {'xmin': 345, 'ymin': 23, 'xmax': 640, 'ymax': 368}},
            ],
        ]     ,      )




  @require_torch
  @slow
  def 		_lowercase	(					self :      Tuple  )   ->   Optional[Any]:
    __lowerCamelCase			:			Any       			=					'facebook/detr-resnet-50'

    __lowerCamelCase			:			List[str]       			=					pipeline('object-detection'     ,      model=_a  )

    __lowerCamelCase			:			int       			=					object_detector('http://images.cocodataset.org/val2017/000000039769.jpg'  )
    self.assertEqual(
        nested_simplify(_a     ,      decimals=4  )     ,      [
            {'score': 0.9982, 'label': 'remote', 'box': {'xmin': 40, 'ymin': 70, 'xmax': 175, 'ymax': 117}},
            {'score': 0.9960, 'label': 'remote', 'box': {'xmin': 333, 'ymin': 72, 'xmax': 368, 'ymax': 187}},
            {'score': 0.9955, 'label': 'couch', 'box': {'xmin': 0, 'ymin': 1, 'xmax': 639, 'ymax': 473}},
            {'score': 0.9988, 'label': 'cat', 'box': {'xmin': 13, 'ymin': 52, 'xmax': 314, 'ymax': 470}},
            {'score': 0.9987, 'label': 'cat', 'box': {'xmin': 345, 'ymin': 23, 'xmax': 640, 'ymax': 368}},
        ]     ,      )

    __lowerCamelCase			:			List[Any]       			=					object_detector(
        [
            'http://images.cocodataset.org/val2017/000000039769.jpg',
            'http://images.cocodataset.org/val2017/000000039769.jpg',
        ]  )
    self.assertEqual(
        nested_simplify(_a     ,      decimals=4  )     ,      [
            [
                {'score': 0.9982, 'label': 'remote', 'box': {'xmin': 40, 'ymin': 70, 'xmax': 175, 'ymax': 117}},
                {'score': 0.9960, 'label': 'remote', 'box': {'xmin': 333, 'ymin': 72, 'xmax': 368, 'ymax': 187}},
                {'score': 0.9955, 'label': 'couch', 'box': {'xmin': 0, 'ymin': 1, 'xmax': 639, 'ymax': 473}},
                {'score': 0.9988, 'label': 'cat', 'box': {'xmin': 13, 'ymin': 52, 'xmax': 314, 'ymax': 470}},
                {'score': 0.9987, 'label': 'cat', 'box': {'xmin': 345, 'ymin': 23, 'xmax': 640, 'ymax': 368}},
            ],
            [
                {'score': 0.9982, 'label': 'remote', 'box': {'xmin': 40, 'ymin': 70, 'xmax': 175, 'ymax': 117}},
                {'score': 0.9960, 'label': 'remote', 'box': {'xmin': 333, 'ymin': 72, 'xmax': 368, 'ymax': 187}},
                {'score': 0.9955, 'label': 'couch', 'box': {'xmin': 0, 'ymin': 1, 'xmax': 639, 'ymax': 473}},
                {'score': 0.9988, 'label': 'cat', 'box': {'xmin': 13, 'ymin': 52, 'xmax': 314, 'ymax': 470}},
                {'score': 0.9987, 'label': 'cat', 'box': {'xmin': 345, 'ymin': 23, 'xmax': 640, 'ymax': 368}},
            ],
        ]     ,      )




  @require_torch
  @slow
  def 		_lowercase	(					self :      int  )   ->   Tuple:
    __lowerCamelCase			:			Optional[Any]       			=					0.9985
    __lowerCamelCase			:			Optional[Any]       			=					'facebook/detr-resnet-50'

    __lowerCamelCase			:			Optional[int]       			=					pipeline('object-detection'     ,      model=_a  )

    __lowerCamelCase			:			Dict       			=					object_detector('http://images.cocodataset.org/val2017/000000039769.jpg'     ,      threshold=_a  )
    self.assertEqual(
        nested_simplify(_a     ,      decimals=4  )     ,      [
            {'score': 0.9988, 'label': 'cat', 'box': {'xmin': 13, 'ymin': 52, 'xmax': 314, 'ymax': 470}},
            {'score': 0.9987, 'label': 'cat', 'box': {'xmin': 345, 'ymin': 23, 'xmax': 640, 'ymax': 368}},
        ]     ,      )




  @require_torch
  @require_pytesseract
  @slow
  def 		_lowercase	(					self :      int  )   ->   Any:
    __lowerCamelCase			:			Optional[int]       			=					'Narsil/layoutlmv3-finetuned-funsd'
    __lowerCamelCase			:			Tuple       			=					0.9993

    __lowerCamelCase			:			List[str]       			=					pipeline('object-detection'     ,      model=_a     ,      threshold=_a  )

    __lowerCamelCase			:			Tuple       			=					object_detector(
        'https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png'  )
    self.assertEqual(
        nested_simplify(_a     ,      decimals=4  )     ,      [
            {'score': 0.9993, 'label': 'I-ANSWER', 'box': {'xmin': 294, 'ymin': 254, 'xmax': 343, 'ymax': 264}},
            {'score': 0.9993, 'label': 'I-ANSWER', 'box': {'xmin': 294, 'ymin': 254, 'xmax': 343, 'ymax': 264}},
        ]     ,      )






