



'''simple docstring'''





import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

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


if is_torch_available():
   import torch

   from transformers import EsmForMaskedLM, EsmForSequenceClassification, EsmForTokenClassification, EsmModel
   from transformers.models.esm.modeling_esm import (
       ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
       EsmEmbeddings,
       create_position_ids_from_input_ids,
   )






class    lowerCamelCase_       :
  """simple docstring"""




  def __init__(					self :      str     ,      _a :      List[Any]     ,      _a :      Optional[int]=13     ,      _a :      Optional[Any]=7     ,      _a :      List[str]=False     ,      _a :      Dict=True     ,      _a :      Optional[Any]=False     ,      _a :      Tuple=True     ,      _a :      List[Any]=33     ,      _a :      int=32     ,      _a :      int=5     ,      _a :      int=4     ,      _a :      List[str]=37     ,      _a :      str="gelu"     ,      _a :      Union[str, Any]=0.1     ,      _a :      Any=0.1     ,      _a :      str=512     ,      _a :      List[str]=16     ,      _a :      Dict=2     ,      _a :      Any=0.02     ,      _a :      int=3     ,      _a :      str=4     ,      _a :      Any=None     ,      )   ->   List[str]:
    __lowerCamelCase			:			Union[str, Any]       			=					parent
    __lowerCamelCase			:			Optional[Any]       			=					batch_size
    __lowerCamelCase			:			int       			=					seq_length
    __lowerCamelCase			:			List[Any]       			=					is_training
    __lowerCamelCase			:			List[str]       			=					use_input_mask
    __lowerCamelCase			:			str       			=					use_token_type_ids
    __lowerCamelCase			:			List[str]       			=					use_labels
    __lowerCamelCase			:			str       			=					vocab_size
    __lowerCamelCase			:			Optional[int]       			=					hidden_size
    __lowerCamelCase			:			Optional[int]       			=					num_hidden_layers
    __lowerCamelCase			:			Optional[int]       			=					num_attention_heads
    __lowerCamelCase			:			int       			=					intermediate_size
    __lowerCamelCase			:			Any       			=					hidden_act
    __lowerCamelCase			:			Any       			=					hidden_dropout_prob
    __lowerCamelCase			:			Optional[Any]       			=					attention_probs_dropout_prob
    __lowerCamelCase			:			List[str]       			=					max_position_embeddings
    __lowerCamelCase			:			List[Any]       			=					type_vocab_size
    __lowerCamelCase			:			Dict       			=					type_sequence_label_size
    __lowerCamelCase			:			List[Any]       			=					initializer_range
    __lowerCamelCase			:			Union[str, Any]       			=					num_labels
    __lowerCamelCase			:			str       			=					num_choices
    __lowerCamelCase			:			Tuple       			=					scope




  def 		_lowercase	(					self :      Tuple  )   ->   Union[str, Any]:
    __lowerCamelCase			:			Tuple       			=					ids_tensor([self.batch_size, self.seq_length]     ,      self.vocab_size  )

    __lowerCamelCase			:			List[str]       			=					None
    if self.use_input_mask:
      __lowerCamelCase			:			Union[str, Any]       			=					random_attention_mask([self.batch_size, self.seq_length]  )

    __lowerCamelCase			:			Tuple       			=					None
    __lowerCamelCase			:			Union[str, Any]       			=					None
    __lowerCamelCase			:			Any       			=					None
    if self.use_labels:
      __lowerCamelCase			:			Any       			=					ids_tensor([self.batch_size]     ,      self.type_sequence_label_size  )
      __lowerCamelCase			:			int       			=					ids_tensor([self.batch_size, self.seq_length]     ,      self.num_labels  )
      __lowerCamelCase			:			List[str]       			=					ids_tensor([self.batch_size]     ,      self.num_choices  )

    __lowerCamelCase			:			Tuple       			=					self.get_config()

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




  def 		_lowercase	(					self :      str  )   ->   List[str]:
    return EsmConfig(
        vocab_size=self.vocab_size     ,      hidden_size=self.hidden_size     ,      pad_token_id=1     ,      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     ,      )




  def 		_lowercase	(					self :      str     ,      _a :      List[Any]     ,      _a :      str     ,      _a :      Optional[int]     ,      _a :      Any     ,      _a :      Tuple     ,      _a :      Optional[int]  )   ->   Any:
    __lowerCamelCase			:			List[str]       			=					EsmModel(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			List[str]       			=					model(_a     ,      attention_mask=_a  )
    __lowerCamelCase			:			Tuple       			=					model(_a  )
    __lowerCamelCase			:			Dict       			=					model(_a  )

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




  def 		_lowercase	(					self :      Any     ,      _a :      Optional[int]     ,      _a :      Any     ,      _a :      List[str]     ,      _a :      Dict     ,      _a :      List[str]     ,      _a :      int  )   ->   Optional[Any]:
    __lowerCamelCase			:			Optional[Any]       			=					EsmForMaskedLM(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			List[str]       			=					model(_a     ,      attention_mask=_a     ,      labels=_a  )
    self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.seq_length, self.vocab_size)  )




  def 		_lowercase	(					self :      str     ,      _a :      str     ,      _a :      Union[str, Any]     ,      _a :      Dict     ,      _a :      List[Any]     ,      _a :      Any     ,      _a :      str  )   ->   Dict:
    __lowerCamelCase			:			str       			=					self.num_labels
    __lowerCamelCase			:			Tuple       			=					EsmForTokenClassification(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			List[Any]       			=					model(_a     ,      attention_mask=_a     ,      labels=_a  )
    self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.seq_length, self.num_labels)  )




  def 		_lowercase	(					self :      Dict  )   ->   Tuple:
    __lowerCamelCase			:			Tuple       			=					self.prepare_config_and_inputs()
    (
        (
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,
    )			:			List[str]       			=					config_and_inputs
    __lowerCamelCase			:			Dict       			=					{'input_ids': input_ids, 'attention_mask': input_mask}
    return config, inputs_dict






@require_torch
class    lowerCamelCase_       (							SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_  ,  unittest.TestCase	):
  """simple docstring"""




  a_				   =False

  a_				   =(
      (
          EsmForMaskedLM,
          EsmModel,
          EsmForSequenceClassification,
          EsmForTokenClassification,
      )
      if is_torch_available()
      else ()
  )
  a_				   =()
  a_				   =(
      {
          """feature-extraction""": EsmModel,
          """fill-mask""": EsmForMaskedLM,
          """text-classification""": EsmForSequenceClassification,
          """token-classification""": EsmForTokenClassification,
          """zero-shot""": EsmForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  a_				   =True




  def 		_lowercase	(					self :      Any  )   ->   Tuple:
    __lowerCamelCase			:			Union[str, Any]       			=					EsmModelTester(self  )
    __lowerCamelCase			:			Tuple       			=					ConfigTester(self     ,      config_class=_a     ,      hidden_size=37  )




  def 		_lowercase	(					self :      Optional[Any]  )   ->   Tuple:
    self.config_tester.run_common_tests()




  def 		_lowercase	(					self :      Any  )   ->   Tuple:
    __lowerCamelCase			:			List[str]       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*_a  )




  def 		_lowercase	(					self :      Any  )   ->   Dict:
    __lowerCamelCase			:			Dict       			=					self.model_tester.prepare_config_and_inputs()
    for type in ["absolute", "relative_key", "relative_key_query"]:
      __lowerCamelCase			:			Optional[Any]       			=					type
      self.model_tester.create_and_check_model(*_a  )




  def 		_lowercase	(					self :      List[Any]  )   ->   Union[str, Any]:
    __lowerCamelCase			:			List[Any]       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*_a  )




  def 		_lowercase	(					self :      Tuple  )   ->   int:
    __lowerCamelCase			:			Dict       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_token_classification(*_a  )




  @slow
  def 		_lowercase	(					self :      Optional[int]  )   ->   int:
    for model_name in ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      __lowerCamelCase			:			Tuple       			=					EsmModel.from_pretrained(_a  )
      self.assertIsNotNone(_a  )




  def 		_lowercase	(					self :      Any  )   ->   Union[str, Any]:
    __lowerCamelCase			:			Union[str, Any]       			=					self.model_tester.prepare_config_and_inputs()[0]
    __lowerCamelCase			:			Union[str, Any]       			=					EsmEmbeddings(config=_a  )

    __lowerCamelCase			:			int       			=					torch.as_tensor([[12, 31, 13, model.padding_idx]]  )
    __lowerCamelCase			:			str       			=					torch.as_tensor(
        [
            [
                0 + model.padding_idx + 1,
                1 + model.padding_idx + 1,
                2 + model.padding_idx + 1,
                model.padding_idx,
            ]
        ]  )
    __lowerCamelCase			:			Optional[Any]       			=					create_position_ids_from_input_ids(_a     ,      model.padding_idx  )
    self.assertEqual(position_ids.shape     ,      expected_positions.shape  )
    self.assertTrue(torch.all(torch.eq(_a     ,      _a  )  )  )




  def 		_lowercase	(					self :      List[Any]  )   ->   Dict:
    __lowerCamelCase			:			int       			=					self.model_tester.prepare_config_and_inputs()[0]
    __lowerCamelCase			:			int       			=					EsmEmbeddings(config=_a  )

    __lowerCamelCase			:			Union[str, Any]       			=					torch.empty(2     ,      4     ,      30  )
    __lowerCamelCase			:			List[Any]       			=					[
        0 + embeddings.padding_idx + 1,
        1 + embeddings.padding_idx + 1,
        2 + embeddings.padding_idx + 1,
        3 + embeddings.padding_idx + 1,
    ]
    __lowerCamelCase			:			Optional[Any]       			=					torch.as_tensor([expected_single_positions, expected_single_positions]  )
    __lowerCamelCase			:			Tuple       			=					embeddings.create_position_ids_from_inputs_embeds(_a  )
    self.assertEqual(position_ids.shape     ,      expected_positions.shape  )
    self.assertTrue(torch.all(torch.eq(_a     ,      _a  )  )  )




  @unittest.skip('Esm does not support embedding resizing'  )
  def 		_lowercase	(					self :      str  )   ->   Tuple:
    pass




  @unittest.skip('Esm does not support embedding resizing'  )
  def 		_lowercase	(					self :      List[Any]  )   ->   Optional[int]:
    pass




  @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'  )
  def 		_lowercase	(					self :      Optional[Any]  )   ->   List[str]:
    pass






@require_torch
class    lowerCamelCase_       (							SCREAMING_SNAKE_CASE_	):
  """simple docstring"""




  @slow
  def 		_lowercase	(					self :      Union[str, Any]  )   ->   Tuple:
    with torch.no_grad():
      __lowerCamelCase			:			List[str]       			=					EsmForMaskedLM.from_pretrained('facebook/esm2_t6_8M_UR50D'  )
      model.eval()
      __lowerCamelCase			:			Any       			=					torch.tensor([[0, 1, 2, 3, 4, 5]]  )
      __lowerCamelCase			:			List[Any]       			=					model(_a  )[0]

      __lowerCamelCase			:			Dict       			=					33

      __lowerCamelCase			:			Tuple       			=					torch.Size((1, 6, vocab_size)  )
      self.assertEqual(output.shape     ,      _a  )

      __lowerCamelCase			:			Optional[int]       			=					torch.tensor(
          [[[8.9215, -10.5898, -6.4671], [-6.3967, -13.9114, -1.1212], [-7.7812, -13.9516, -3.7406]]]  )
      self.assertTrue(torch.allclose(output[:, :3, :3]     ,      _a     ,      atol=1e-4  )  )




  @slow
  def 		_lowercase	(					self :      int  )   ->   List[Any]:
    with torch.no_grad():
      __lowerCamelCase			:			Optional[int]       			=					EsmModel.from_pretrained('facebook/esm2_t6_8M_UR50D'  )
      model.eval()

      __lowerCamelCase			:			Tuple       			=					torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]  )
      __lowerCamelCase			:			List[str]       			=					model(_a  )[0]
      # compare the actual values for a slice.
      __lowerCamelCase			:			Optional[Any]       			=					torch.tensor(
          [[[0.1444, 0.5413, 0.3248], [0.3034, 0.0053, 0.3108], [0.3228, -0.2499, 0.3415]]]  )
      self.assertTrue(torch.allclose(output[:, :3, :3]     ,      _a     ,      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    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}},
        ]     ,      )






