






import unittest

from parameterized import parameterized

from transformers import AutoTokenizer, GPTNeoXConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 (
							    GPTNeoXForCausalLM,
							    GPTNeoXForQuestionAnswering,
							    GPTNeoXForSequenceClassification,
							    GPTNeoXForTokenClassification,
							    GPTNeoXModel,
							)




class 				__A     :





				"""simple docstring"""







				def __init__( self							,  lowerCamelCase__							,  lowerCamelCase__=13							,  lowerCamelCase__=7							,  lowerCamelCase__=True							,  lowerCamelCase__=True							,  lowerCamelCase__=True							,  lowerCamelCase__=True							,  lowerCamelCase__=99							,  lowerCamelCase__=64							,  lowerCamelCase__=5							,  lowerCamelCase__=4							,  lowerCamelCase__=37							,  lowerCamelCase__="gelu"							,  lowerCamelCase__=0.1							,  lowerCamelCase__=0.1							,  lowerCamelCase__=512							,  lowerCamelCase__=16							,  lowerCamelCase__=2							,  lowerCamelCase__=0.02							,  lowerCamelCase__=3							,  lowerCamelCase__=4							,  lowerCamelCase__=None							,  ):




									"""simple docstring"""

									__UpperCamelCase      :					Any       		=parent
									__UpperCamelCase      :					Dict       		=batch_size
									__UpperCamelCase      :					Optional[int]       		=seq_length
									__UpperCamelCase      :					List[Any]       		=is_training
									__UpperCamelCase      :					Optional[Any]       		=use_input_mask
									__UpperCamelCase      :					List[str]       		=use_token_type_ids
									__UpperCamelCase      :					List[Any]       		=use_labels
									__UpperCamelCase      :					Union[str, Any]       		=vocab_size
									__UpperCamelCase      :					str       		=hidden_size
									__UpperCamelCase      :					Optional[Any]       		=num_hidden_layers
									__UpperCamelCase      :					Optional[Any]       		=num_attention_heads
									__UpperCamelCase      :					List[Any]       		=intermediate_size
									__UpperCamelCase      :					str       		=hidden_act
									__UpperCamelCase      :					List[str]       		=hidden_dropout_prob
									__UpperCamelCase      :					Optional[int]       		=attention_probs_dropout_prob
									__UpperCamelCase      :					Optional[Any]       		=max_position_embeddings
									__UpperCamelCase      :					List[Any]       		=type_vocab_size
									__UpperCamelCase      :					Tuple       		=type_sequence_label_size
									__UpperCamelCase      :					Union[str, Any]       		=initializer_range
									__UpperCamelCase      :					List[str]       		=num_labels
									__UpperCamelCase      :					Union[str, Any]       		=num_choices
									__UpperCamelCase      :					List[Any]       		=scope
									__UpperCamelCase      :					str       		=vocab_size - 1


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Tuple       		=ids_tensor([self.batch_size, self.seq_length]							,  self.vocab_size    )

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

									__UpperCamelCase      :					Optional[Any]       		=None
									if self.use_labels:
														__UpperCamelCase      :					Optional[int]       		=ids_tensor([self.batch_size, self.seq_length]							,  self.num_labels    )

									__UpperCamelCase      :					str       		=self.get_config()

									return config, input_ids, input_mask, token_labels


				def       __lowercase							( self    ):




									"""simple docstring"""

									return GPTNeoXConfig(
									    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							,  is_decoder=_UpperCAmelCase							,  initializer_range=self.initializer_range							,  pad_token_id=self.pad_token_id							,  )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					List[Any]       		=self.prepare_config_and_inputs()

									__UpperCamelCase      :					str       		=True

									return config, input_ids, input_mask, token_labels


				def       __lowercase							( self							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=GPTNeoXModel(config=_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									__UpperCamelCase      :					Union[str, Any]       		=model(_UpperCAmelCase							,  attention_mask=_UpperCAmelCase    )
									__UpperCamelCase      :					Any       		=model(_UpperCAmelCase    )
									self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.seq_length, self.hidden_size)    )


				def       __lowercase							( self							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=True
									__UpperCamelCase      :					Optional[Any]       		=GPTNeoXModel(_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									__UpperCamelCase      :					Union[str, Any]       		=model(_UpperCAmelCase							,  attention_mask=_UpperCAmelCase    )
									self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.seq_length, self.hidden_size)    )


				def       __lowercase							( self							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=GPTNeoXForCausalLM(config=_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									__UpperCamelCase      :					Union[str, Any]       		=model(_UpperCAmelCase							,  attention_mask=_UpperCAmelCase							,  labels=_UpperCAmelCase    )
									self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size)    )


				def       __lowercase							( self							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					int       		=self.num_labels
									__UpperCamelCase      :					Any       		=GPTNeoXForQuestionAnswering(_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									__UpperCamelCase      :					Any       		=model(_UpperCAmelCase							,  attention_mask=_UpperCAmelCase    )
									self.parent.assertEqual(result.start_logits.shape							,  (self.batch_size, self.seq_length)    )
									self.parent.assertEqual(result.end_logits.shape							,  (self.batch_size, self.seq_length)    )


				def       __lowercase							( self							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					Any       		=self.num_labels
									__UpperCamelCase      :					Optional[Any]       		=GPTNeoXForSequenceClassification(_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									__UpperCamelCase      :					int       		=ids_tensor([self.batch_size]							,  self.type_sequence_label_size    )
									__UpperCamelCase      :					Dict       		=model(_UpperCAmelCase							,  attention_mask=_UpperCAmelCase							,  labels=_UpperCAmelCase    )
									self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.num_labels)    )


				def       __lowercase							( self							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					List[str]       		=self.num_labels
									__UpperCamelCase      :					Union[str, Any]       		=GPTNeoXForTokenClassification(_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									__UpperCamelCase      :					Any       		=model(_UpperCAmelCase							,  attention_mask=_UpperCAmelCase							,  labels=_UpperCAmelCase    )
									self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.num_labels)    )


				def       __lowercase							( self							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					Union[str, Any]       		=True
									__UpperCamelCase      :					str       		=GPTNeoXForCausalLM(config=_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()

									# first forward pass
									__UpperCamelCase      :					Optional[Any]       		=model(_UpperCAmelCase							,  attention_mask=_UpperCAmelCase							,  use_cache=_UpperCAmelCase    )
									__UpperCamelCase      :					str       		=outputs.past_key_values

									# create hypothetical multiple next token and extent to next_input_ids
									__UpperCamelCase      :					int       		=ids_tensor((self.batch_size, 3)							,  config.vocab_size    )
									__UpperCamelCase      :					Optional[Any]       		=ids_tensor((self.batch_size, 3)							,  vocab_size=2    )

									# append to next input_ids and
									__UpperCamelCase      :					List[Any]       		=torch.cat([input_ids, next_tokens]							,  dim=-1    )
									__UpperCamelCase      :					Optional[int]       		=torch.cat([input_mask, next_mask]							,  dim=-1    )

									__UpperCamelCase      :					int       		=model(_UpperCAmelCase							,  attention_mask=_UpperCAmelCase							,  output_hidden_states=_UpperCAmelCase    )
									__UpperCamelCase      :					Tuple       		=output_from_no_past['hidden_states'][0]
									__UpperCamelCase      :					Any       		=model(
									    _UpperCAmelCase							,  attention_mask=_UpperCAmelCase							,  past_key_values=_UpperCAmelCase							,  output_hidden_states=_UpperCAmelCase							,  )['hidden_states'][0]

									# select random slice
									__UpperCamelCase      :					Optional[int]       		=ids_tensor((1,)							,  output_from_past.shape[-1]    ).item()
									__UpperCamelCase      :					Dict       		=output_from_no_past[:, -3:, random_slice_idx].detach()
									__UpperCamelCase      :					Union[str, Any]       		=output_from_past[:, :, random_slice_idx].detach()

									self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]    )

									# test that outputs are equal for slice
									self.parent.assertTrue(torch.allclose(_UpperCAmelCase							,  _UpperCAmelCase							,  atol=1E-3    )    )







				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Optional[Any]       		=self.prepare_config_and_inputs()
									__UpperCamelCase      :					Any       		=config_and_inputs
									__UpperCamelCase      :					str       		={'input_ids': input_ids, 'attention_mask': input_mask}
									return config, inputs_dict




@require_torch
class 				__A     (			a__      ,     a__      ,     a__      ,     unittest.TestCase ):





				"""simple docstring"""







				UpperCamelCase__ :      Optional[int]			 =(
				    (
				        GPTNeoXModel,
				        GPTNeoXForCausalLM,
				        GPTNeoXForQuestionAnswering,
				        GPTNeoXForSequenceClassification,
				        GPTNeoXForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				UpperCamelCase__ :      Any			 =(GPTNeoXForCausalLM,) if is_torch_available() else ()
				UpperCamelCase__ :      Any			 =(
				    {
				        """feature-extraction""": GPTNeoXModel,
				        """question-answering""": GPTNeoXForQuestionAnswering,
				        """text-classification""": GPTNeoXForSequenceClassification,
				        """text-generation""": GPTNeoXForCausalLM,
				        """token-classification""": GPTNeoXForTokenClassification,
				        """zero-shot""": GPTNeoXForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				UpperCamelCase__ :      Optional[Any]			 =False
				UpperCamelCase__ :      List[Any]			 =False
				UpperCamelCase__ :      List[Any]			 =False
				UpperCamelCase__ :      Any			 =False


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=GPTNeoXModelTester(self    )
									__UpperCamelCase      :					Union[str, Any]       		=ConfigTester(self							,  config_class=_UpperCAmelCase							,  hidden_size=64							,  num_attention_heads=8    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									self.config_tester.run_common_tests()


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					int       		=self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(_UpperCAmelCase							,  _UpperCAmelCase							,  _UpperCAmelCase    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Optional[Any]       		=self.model_tester.prepare_config_and_inputs_for_decoder()
									self.model_tester.create_and_check_model_as_decoder(_UpperCAmelCase							,  _UpperCAmelCase							,  _UpperCAmelCase    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=self.model_tester.prepare_config_and_inputs_for_decoder()

									__UpperCamelCase      :					Dict       		=None

									self.model_tester.create_and_check_model_as_decoder(_UpperCAmelCase							,  _UpperCAmelCase							,  _UpperCAmelCase    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Union[str, Any]       		=self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_decoder_model_past_large_inputs(_UpperCAmelCase							,  _UpperCAmelCase							,  _UpperCAmelCase    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Union[str, Any]       		=self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_causal_lm(*_UpperCAmelCase    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Union[str, Any]       		=self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					List[Any]       		=self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					int       		=self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*_UpperCAmelCase    )


				@unittest.skip(reason='Feed forward chunking is not implemented'    )
				def       __lowercase							( self    ):




									"""simple docstring"""

									pass







				@parameterized.expand([('linear',), ('dynamic',)]    )
				def       __lowercase							( self							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					Any       		=self.model_tester.prepare_config_and_inputs_for_common()
									__UpperCamelCase      :					Tuple       		=ids_tensor([1, 10]							,  config.vocab_size    )
									__UpperCamelCase      :					Tuple       		=ids_tensor([1, int(config.max_position_embeddings * 1.5    )]							,  config.vocab_size    )

									set_seed(42    )  # Fixed seed at init time so the two models get the same random weights
									__UpperCamelCase      :					Union[str, Any]       		=GPTNeoXModel(_UpperCAmelCase    )
									original_model.to(_UpperCAmelCase    )
									original_model.eval()
									__UpperCamelCase      :					Tuple       		=original_model(_UpperCAmelCase    ).last_hidden_state
									__UpperCamelCase      :					Optional[int]       		=original_model(_UpperCAmelCase    ).last_hidden_state

									set_seed(42    )  # Fixed seed at init time so the two models get the same random weights
									__UpperCamelCase      :					Union[str, Any]       		={'type': scaling_type, 'factor': 10.0}
									__UpperCamelCase      :					int       		=GPTNeoXModel(_UpperCAmelCase    )
									scaled_model.to(_UpperCAmelCase    )
									scaled_model.eval()
									__UpperCamelCase      :					List[str]       		=scaled_model(_UpperCAmelCase    ).last_hidden_state
									__UpperCamelCase      :					Any       		=scaled_model(_UpperCAmelCase    ).last_hidden_state

									# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
									# maximum sequence length, so the outputs for the short input should match.
									if scaling_type == "dynamic":
														self.assertTrue(torch.allclose(_UpperCAmelCase							,  _UpperCAmelCase							,  atol=1E-5    )    )
									else:
														self.assertFalse(torch.allclose(_UpperCAmelCase							,  _UpperCAmelCase							,  atol=1E-5    )    )

									# The output should be different for long inputs
									self.assertFalse(torch.allclose(_UpperCAmelCase							,  _UpperCAmelCase							,  atol=1E-5    )    )




@require_torch
class 				__A     (			unittest.TestCase ):





				"""simple docstring"""







				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					List[str]       		=AutoTokenizer.from_pretrained('EleutherAI/pythia-410m-deduped'    )
									for checkpointing in [True, False]:
														__UpperCamelCase      :					Dict       		=GPTNeoXForCausalLM.from_pretrained('EleutherAI/pythia-410m-deduped'    )

														if checkpointing:
																			model.gradient_checkpointing_enable()
														else:
																			model.gradient_checkpointing_disable()
														model.to(_UpperCAmelCase    )

														__UpperCamelCase      :					List[str]       		=tokenizer('My favorite food is'							,  return_tensors='pt'    ).to(_UpperCAmelCase    )
														# The hub repo. is updated on 2023-04-04, resulting in poor outputs.
														# See: https://github.com/huggingface/transformers/pull/24193
														__UpperCamelCase      :					Any       		='My favorite food is a good old-fashioned, old-fashioned, old-fashioned.\n\nI\'m not sure'

														__UpperCamelCase      :					Optional[int]       		=model.generate(**_UpperCAmelCase							,  do_sample=_UpperCAmelCase							,  max_new_tokens=20    )
														__UpperCamelCase      :					Tuple       		=tokenizer.batch_decode(_UpperCAmelCase    )[0]

														self.assertEqual(_UpperCAmelCase							,  _UpperCAmelCase    )








'''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}},
              ]						,	)