





'''simple docstring'''




import inspect
import unittest

from transformers import BitConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch
  from torch import nn

  from transformers import BitBackbone, BitForImageClassification, BitImageProcessor, BitModel
  from transformers.models.bit.modeling_bit import BIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image


class  SCREAMING_SNAKE_CASE    :


     def __init__(						self						,	_UpperCAmelCase						,	_UpperCAmelCase=3						,	_UpperCAmelCase=32						,	_UpperCAmelCase=3						,	_UpperCAmelCase=10						,	_UpperCAmelCase=[8, 16, 32, 64]						,	_UpperCAmelCase=[1, 1, 2, 1]						,	_UpperCAmelCase=True						,	_UpperCAmelCase=True						,	_UpperCAmelCase="relu"						,	_UpperCAmelCase=3						,	_UpperCAmelCase=None						,	_UpperCAmelCase=["stage2", "stage3", "stage4"]						,	_UpperCAmelCase=[2, 3, 4]						,	_UpperCAmelCase=1						,	):

          '''simple docstring'''






          __A						: Dict      =       parent
          __A						: List[Any]      =       batch_size
          __A						: Optional[Any]      =       image_size
          __A						: List[Any]      =       num_channels
          __A						: int      =       embeddings_size
          __A						: Tuple      =       hidden_sizes
          __A						: List[Any]      =       depths
          __A						: int      =       is_training
          __A						: int      =       use_labels
          __A						: List[Any]      =       hidden_act
          __A						: List[Any]      =       num_labels
          __A						: Optional[Any]      =       scope
          __A						: int      =       len(_UpperCAmelCase)
          __A						: Optional[int]      =       out_features
          __A						: Dict      =       out_indices
          __A						: Dict      =       num_groups


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: List[Any]      =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

          __A						: str      =       None
          if self.use_labels:
               __A						: Optional[Any]      =       ids_tensor([self.batch_size]						,	self.num_labels)

          __A						: Tuple      =       self.get_config()

          return config, pixel_values, labels


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return BitConfig(
              num_channels=self.num_channels						,	embeddings_size=self.embeddings_size						,	hidden_sizes=self.hidden_sizes						,	depths=self.depths						,	hidden_act=self.hidden_act						,	num_labels=self.num_labels						,	out_features=self.out_features						,	out_indices=self.out_indices						,	num_groups=self.num_groups						,	)


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase):

          '''simple docstring'''






          __A						: Dict      =       BitModel(config=_UpperCAmelCase)
          model.to(_UpperCAmelCase)
          model.eval()
          __A						: int      =       model(_UpperCAmelCase)
          self.parent.assertEqual(
              result.last_hidden_state.shape						,	(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)						,	)


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase):

          '''simple docstring'''






          __A						: Union[str, Any]      =       self.num_labels
          __A						: List[Any]      =       BitForImageClassification(_UpperCAmelCase)
          model.to(_UpperCAmelCase)
          model.eval()
          __A						: Tuple      =       model(_UpperCAmelCase						,	labels=_UpperCAmelCase)
          self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.num_labels))


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase):

          '''simple docstring'''






          __A						: Optional[int]      =       BitBackbone(config=_UpperCAmelCase)
          model.to(_UpperCAmelCase)
          model.eval()
          __A						: Union[str, Any]      =       model(_UpperCAmelCase)

          # verify feature maps
          self.parent.assertEqual(len(result.feature_maps)						,	len(config.out_features))
          self.parent.assertListEqual(list(result.feature_maps[0].shape)						,	[self.batch_size, self.hidden_sizes[1], 4, 4])

          # verify channels
          self.parent.assertEqual(len(model.channels)						,	len(config.out_features))
          self.parent.assertListEqual(model.channels						,	config.hidden_sizes[1:])

          # verify backbone works with out_features=None
          __A						: Optional[int]      =       None
          __A						: Optional[Any]      =       BitBackbone(config=_UpperCAmelCase)
          model.to(_UpperCAmelCase)
          model.eval()
          __A						: Optional[Any]      =       model(_UpperCAmelCase)

          # verify feature maps
          self.parent.assertEqual(len(result.feature_maps)						,	1)
          self.parent.assertListEqual(list(result.feature_maps[0].shape)						,	[self.batch_size, self.hidden_sizes[-1], 1, 1])

          # verify channels
          self.parent.assertEqual(len(model.channels)						,	1)
          self.parent.assertListEqual(model.channels						,	[config.hidden_sizes[-1]])


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Optional[Any]      =       self.prepare_config_and_inputs()
          __A ,__A ,__A						: List[str]      =       config_and_inputs
          __A						: Optional[int]      =       {'pixel_values': pixel_values}
          return config, inputs_dict




@require_torch
class  SCREAMING_SNAKE_CASE    (a__					,		a__					,		unittest.TestCase							):
     lowerCAmelCase					=       (BitModel, BitForImageClassification, BitBackbone) if is_torch_available() else ()
     lowerCAmelCase					=       (
         {'''feature-extraction''': BitModel, '''image-classification''': BitForImageClassification}
         if is_torch_available()
         else {}
     )

     lowerCAmelCase					=       False
     lowerCAmelCase					=       False
     lowerCAmelCase					=       False
     lowerCAmelCase					=       False
     lowerCAmelCase					=       False


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: List[Any]      =       BitModelTester(self)
          __A						: Dict      =       ConfigTester(self						,	config_class=_UpperCAmelCase						,	has_text_modality=_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          self.create_and_test_config_common_properties()
          self.config_tester.create_and_test_config_to_json_string()
          self.config_tester.create_and_test_config_to_json_file()
          self.config_tester.create_and_test_config_from_and_save_pretrained()
          self.config_tester.create_and_test_config_with_num_labels()
          self.config_tester.check_config_can_be_init_without_params()
          self.config_tester.check_config_arguments_init()


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return


     @unittest.skip(reason='Bit does not output attentions')
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          pass


     @unittest.skip(reason='Bit does not use inputs_embeds')
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          pass


     @unittest.skip(reason='Bit does not support input and output embeddings')
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          pass


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: Dict      =       self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __A						: Tuple      =       model_class(_UpperCAmelCase)
               __A						: str      =       inspect.signature(model.forward)
               # signature.parameters is an OrderedDict => so arg_names order is deterministic
               __A						: Optional[Any]      =       [*signature.parameters.keys()]

               __A						: Optional[Any]      =       ['pixel_values']
               self.assertListEqual(arg_names[:1]						,	_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Dict      =       self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: List[str]      =       self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_backbone(*_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: Tuple      =       self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __A						: Union[str, Any]      =       model_class(config=_UpperCAmelCase)
               for name, module in model.named_modules():
                    if isinstance(_UpperCAmelCase						,	(nn.BatchNormad, nn.GroupNorm)):
                         self.assertTrue(
                             torch.all(module.weight == 1)						,	msg=F'Parameter {name} of model {model_class} seems not properly initialized'						,	)
                         self.assertTrue(
                             torch.all(module.bias == 0)						,	msg=F'Parameter {name} of model {model_class} seems not properly initialized'						,	)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          def check_hidden_states_output(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase):
               __A						: str      =       model_class(_UpperCAmelCase)
               model.to(_UpperCAmelCase)
               model.eval()

               with torch.no_grad():
                    __A						: str      =       model(**self._prepare_for_class(_UpperCAmelCase						,	_UpperCAmelCase))

               __A						: int      =       outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

               __A						: Any      =       self.model_tester.num_stages
               self.assertEqual(len(_UpperCAmelCase)						,	expected_num_stages + 1)

               # Bit's feature maps are of shape (batch_size, num_channels, height, width)
               self.assertListEqual(
                   list(hidden_states[0].shape[-2:])						,	[self.model_tester.image_size // 4, self.model_tester.image_size // 4]						,	)

          __A ,__A						: List[Any]      =       self.model_tester.prepare_config_and_inputs_for_common()
          __A						: Dict      =       ['preactivation', 'bottleneck']
          for model_class in self.all_model_classes:
               for layer_type in layers_type:
                    __A						: Dict      =       layer_type
                    __A						: List[Any]      =       True
                    check_hidden_states_output(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase)

                    # check that output_hidden_states also work using config
                    del inputs_dict["output_hidden_states"]
                    __A						: Union[str, Any]      =       True

                    check_hidden_states_output(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase)


     @unittest.skip(reason='Bit does not use feedforward chunking')
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          pass


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Optional[int]      =       self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*_UpperCAmelCase)


     @slow
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          for model_name in BIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __A						: Any      =       BitModel.from_pretrained(_UpperCAmelCase)
               self.assertIsNotNone(_UpperCAmelCase)






def        _lowerCAmelCase			(  )     ->     str:
     __A						: Tuple      =       Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'			)
     return image


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


     @cached_property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return (
              BitImageProcessor.from_pretrained(BIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]) if is_vision_available() else None
          )


     @slow
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Dict      =       BitForImageClassification.from_pretrained(BIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]).to(_UpperCAmelCase)

          __A						: Dict      =       self.default_image_processor
          __A						: Union[str, Any]      =       prepare_img()
          __A						: int      =       image_processor(images=_UpperCAmelCase						,	return_tensors='pt').to(_UpperCAmelCase)

          # forward pass
          with torch.no_grad():
               __A						: List[Any]      =       model(**_UpperCAmelCase)

          # verify the logits
          __A						: str      =       torch.Size((1, 1000))
          self.assertEqual(outputs.logits.shape						,	_UpperCAmelCase)

          __A						: List[Any]      =       torch.tensor([[-0.6526, -0.5263, -1.4398]]).to(_UpperCAmelCase)

          self.assertTrue(torch.allclose(outputs.logits[0, :3]						,	_UpperCAmelCase						,	atol=1e-4))




@require_torch
class  SCREAMING_SNAKE_CASE    (a__					,		unittest.TestCase							):
     lowerCAmelCase					=       (BitBackbone,) if is_torch_available() else ()
     lowerCAmelCase					=       BitConfig

     lowerCAmelCase					=       False


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Optional[Any]      =       BitModelTester(self)






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


       @staticmethod
       def 							SCREAMING_SNAKE_CASE  (						*_UpperCAmelCase						,	**_UpperCAmelCase):

            '''simple docstring'''






            pass


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


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase):

          '''simple docstring'''






          __A						: Dict      =       ObjectDetectionPipeline(model=_UpperCAmelCase						,	image_processor=_UpperCAmelCase)
          return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase):

          '''simple docstring'''






          __A						: str      =       object_detector('./tests/fixtures/tests_samples/COCO/000000039769.png'						,	threshold=0.0)

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

          import datasets

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

          __A						: 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'],
          ]
          __A						: Union[str, Any]      =       object_detector(_UpperCAmelCase						,	threshold=0.0)

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


     @require_tf
     @unittest.skip('Object detection not implemented in TF')
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          pass


     @require_torch
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: List[str]      =       'hf-internal-testing/tiny-detr-mobilenetsv3'

          __A						: Any      =       AutoModelForObjectDetection.from_pretrained(_UpperCAmelCase)
          __A						: int      =       AutoFeatureExtractor.from_pretrained(_UpperCAmelCase)
          __A						: Any      =       ObjectDetectionPipeline(model=_UpperCAmelCase						,	feature_extractor=_UpperCAmelCase)

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

          self.assertEqual(
              nested_simplify(_UpperCAmelCase						,	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}},
              ]						,	)

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

          self.assertEqual(
              nested_simplify(_UpperCAmelCase						,	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 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Optional[Any]      =       'facebook/detr-resnet-50'

          __A						: Union[str, Any]      =       AutoModelForObjectDetection.from_pretrained(_UpperCAmelCase)
          __A						: Tuple      =       AutoFeatureExtractor.from_pretrained(_UpperCAmelCase)
          __A						: List[Any]      =       ObjectDetectionPipeline(model=_UpperCAmelCase						,	feature_extractor=_UpperCAmelCase)

          __A						: Union[str, Any]      =       object_detector('http://images.cocodataset.org/val2017/000000039769.jpg')
          self.assertEqual(
              nested_simplify(_UpperCAmelCase						,	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}},
              ]						,	)

          __A						: Tuple      =       object_detector(
              [
                  'http://images.cocodataset.org/val2017/000000039769.jpg',
                  'http://images.cocodataset.org/val2017/000000039769.jpg',
              ])
          self.assertEqual(
              nested_simplify(_UpperCAmelCase						,	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 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: List[Any]      =       'facebook/detr-resnet-50'

          __A						: str      =       pipeline('object-detection'						,	model=_UpperCAmelCase)

          __A						: Any      =       object_detector('http://images.cocodataset.org/val2017/000000039769.jpg')
          self.assertEqual(
              nested_simplify(_UpperCAmelCase						,	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}},
              ]						,	)

          __A						: str      =       object_detector(
              [
                  'http://images.cocodataset.org/val2017/000000039769.jpg',
                  'http://images.cocodataset.org/val2017/000000039769.jpg',
              ])
          self.assertEqual(
              nested_simplify(_UpperCAmelCase						,	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 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: List[Any]      =       0.9985
          __A						: List[Any]      =       'facebook/detr-resnet-50'

          __A						: List[str]      =       pipeline('object-detection'						,	model=_UpperCAmelCase)

          __A						: List[Any]      =       object_detector('http://images.cocodataset.org/val2017/000000039769.jpg'						,	threshold=_UpperCAmelCase)
          self.assertEqual(
              nested_simplify(_UpperCAmelCase						,	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 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Optional[int]      =       'Narsil/layoutlmv3-finetuned-funsd'
          __A						: Tuple      =       0.9993

          __A						: str      =       pipeline('object-detection'						,	model=_UpperCAmelCase						,	threshold=_UpperCAmelCase)

          __A						: Optional[int]      =       object_detector(
              'https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png')
          self.assertEqual(
              nested_simplify(_UpperCAmelCase						,	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}},
              ]						,	)