



import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
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, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import (
	    MODEL_FOR_PRETRAINING_MAPPING,
	    MegatronBertForCausalLM,
	    MegatronBertForMaskedLM,
	    MegatronBertForMultipleChoice,
	    MegatronBertForNextSentencePrediction,
	    MegatronBertForPreTraining,
	    MegatronBertForQuestionAnswering,
	    MegatronBertForSequenceClassification,
	    MegatronBertForTokenClassification,
	    MegatronBertModel,
	)

class  __snake_case      :







							'''simple docstring'''






							def __init__(							self  ,  a_  ,  a_=13  ,  a_=7  ,  a_=True  ,  a_=True  ,  a_=True  ,  a_=True  ,  a_=99  ,  a_=64  ,  a_=32  ,  a_=5  ,  a_=4  ,  a_=37  ,  a_="gelu"  ,  a_=0.1  ,  a_=0.1  ,  a_=512  ,  a_=16  ,  a_=2  ,  a_=0.02  ,  a_=3  ,  a_=4  ,  a_=None  ,  ):
											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__				      =		embedding_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__				      =		scope


							def _a      (							self		):
											a__				      =		ids_tensor([self.batch_size, self.seq_length]  ,  self.vocab_size		)

											a__				      =		None
											if self.use_input_mask:
															a__				      =		random_attention_mask([self.batch_size, self.seq_length]		)

											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 _a      (							self		):
											return MegatronBertConfig(
											    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  ,  embedding_size=self.embedding_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=a_  ,  initializer_range=self.initializer_range  ,  )


							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		MegatronBertModel(config=a_		)
											model.to(a_		)
											model.eval()
											a__				      =		model(a_  ,  attention_mask=a_  ,  token_type_ids=a_		)
											a__				      =		model(a_  ,  token_type_ids=a_		)
											a__				      =		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 _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		MegatronBertForMaskedLM(config=a_		)
											model.to(a_		)
											model.eval()
											a__				      =		model(a_  ,  attention_mask=a_  ,  token_type_ids=a_  ,  labels=a_		)
											self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.seq_length, self.vocab_size)		)


							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		MegatronBertForCausalLM(config=a_		)
											model.to(a_		)
											model.eval()
											a__				      =		model(a_  ,  attention_mask=a_  ,  token_type_ids=a_  ,  labels=a_		)
											self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.seq_length, self.vocab_size)		)


							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		MegatronBertForNextSentencePrediction(config=a_		)
											model.to(a_		)
											model.eval()
											a__				      =		model(
											    a_  ,  attention_mask=a_  ,  token_type_ids=a_  ,  labels=a_  ,  )
											self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, 2)		)


							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		MegatronBertForPreTraining(config=a_		)
											model.to(a_		)
											model.eval()
											a__				      =		model(
											    a_  ,  attention_mask=a_  ,  token_type_ids=a_  ,  labels=a_  ,  next_sentence_label=a_  ,  )
											self.parent.assertEqual(result.prediction_logits.shape  ,  (self.batch_size, self.seq_length, self.vocab_size)		)
											self.parent.assertEqual(result.seq_relationship_logits.shape  ,  (self.batch_size, 2)		)


							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		MegatronBertForQuestionAnswering(config=a_		)
											model.to(a_		)
											model.eval()
											a__				      =		model(
											    a_  ,  attention_mask=a_  ,  token_type_ids=a_  ,  start_positions=a_  ,  end_positions=a_  ,  )
											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 _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		self.num_labels
											a__				      =		MegatronBertForSequenceClassification(a_		)
											model.to(a_		)
											model.eval()
											a__				      =		model(a_  ,  attention_mask=a_  ,  token_type_ids=a_  ,  labels=a_		)
											self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.num_labels)		)


							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		self.num_labels
											a__				      =		MegatronBertForTokenClassification(config=a_		)
											model.to(a_		)
											model.eval()
											a__				      =		model(a_  ,  attention_mask=a_  ,  token_type_ids=a_  ,  labels=a_		)
											self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.seq_length, self.num_labels)		)


							def _a      (							self  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_  ,  a_		):
											a__				      =		self.num_choices
											a__				      =		MegatronBertForMultipleChoice(config=a_		)
											model.to(a_		)
											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(
											    a_  ,  attention_mask=a_  ,  token_type_ids=a_  ,  labels=a_  ,  )
											self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.num_choices)		)







							def _a      (							self		):
											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  __snake_case      (   SCREAMING_SNAKE_CASE			,SCREAMING_SNAKE_CASE			,unittest.TestCase):







							'''simple docstring'''






							UpperCamelCase__				:      Optional[Any]         =					(
							    (
							        MegatronBertModel,
							        MegatronBertForMaskedLM,
							        MegatronBertForCausalLM,
							        MegatronBertForMultipleChoice,
							        MegatronBertForNextSentencePrediction,
							        MegatronBertForPreTraining,
							        MegatronBertForQuestionAnswering,
							        MegatronBertForSequenceClassification,
							        MegatronBertForTokenClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							UpperCamelCase__				:      Union[str, Any]         =					(
							    {
							        """feature-extraction""": MegatronBertModel,
							        """fill-mask""": MegatronBertForMaskedLM,
							        """question-answering""": MegatronBertForQuestionAnswering,
							        """text-classification""": MegatronBertForSequenceClassification,
							        """text-generation""": MegatronBertForCausalLM,
							        """token-classification""": MegatronBertForTokenClassification,
							        """zero-shot""": MegatronBertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							UpperCamelCase__				:      str         =					True
							# test_resize_embeddings = False
							UpperCamelCase__				:      str         =					False


							def _a      (							self  ,  a_  ,  a_  ,  a_=False		):
											a__				      =		super()._prepare_for_class(a_  ,  a_  ,  return_labels=a_		)

											if return_labels:
															if model_class in get_values(a_		):
																			a__				      =		torch.zeros(
																			    (self.model_tester.batch_size, self.model_tester.seq_length)  ,  dtype=torch.long  ,  device=a_		)
																			a__				      =		torch.zeros(
																			    self.model_tester.batch_size  ,  dtype=torch.long  ,  device=a_		)
											return inputs_dict


							def _a      (							self		):
											a__				      =		MegatronBertModelTester(self		)
											a__				      =		ConfigTester(self  ,  config_class=a_  ,  hidden_size=37		)


							def _a      (							self		):
											self.config_tester.run_common_tests()


							def _a      (							self		):
											a__				      =		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_megatron_bert_model(*a_		)


							def _a      (							self		):
											a__				      =		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_megatron_bert_for_masked_lm(*a_		)


							def _a      (							self		):
											a__				      =		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*a_		)


							def _a      (							self		):
											a__				      =		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*a_		)


							def _a      (							self		):
											a__				      =		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_megatron_bert_for_pretraining(*a_		)


							def _a      (							self		):
											a__				      =		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_megatron_bert_for_question_answering(*a_		)


							def _a      (							self		):
											a__				      =		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*a_		)







							def _a      (							self		):
											a__				      =		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_megatron_bert_for_token_classification(*a_		)




def 			A_      (	__a     :				Any		):

				"""simple docstring"""
				return torch.tensor(
				    __a ,		dtype=torch.long ,		device=__a ,		)


UpperCAmelCase							 =					1E-4




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







							'''simple docstring'''






							@slow
							@unittest.skip("""Model is not available."""		)
							def _a      (							self		):
											a__				      =		"""nvidia/megatron-bert-uncased-345m"""
											if "MYDIR" in os.environ:
															a__				      =		os.path.join(os.environ["""MYDIR"""]  ,  a_		)
											a__				      =		MegatronBertModel.from_pretrained(a_		)
											model.to(a_		)
											model.half()
											a__				      =		_long_tensor([[101, 7_110, 1_005, 1_056, 2_023, 11_333, 17_413, 1_029, 102]]		)
											with torch.no_grad():
															a__				      =		model(a_		)[0]
											a__				      =		torch.Size((1, 9, 1_024)		)
											self.assertEqual(output.shape  ,  a_		)

											a__				      =		[-0.6_040, -0.2_517, -0.1_025, 0.3_420, -0.6_758, -0.0_017, -0.1_089, -0.1_990, 0.5_728]
											for ii in range(3		):
															for jj in range(3		):
																			a__				      =		output[0, ii, jj]
																			a__				      =		expected[3 * ii + jj]
																			a__				      =		"""ii={} jj={} a={} b={}""".format(a_  ,  a_  ,  a_  ,  a_		)
																			self.assertTrue(math.isclose(a_  ,  a_  ,  rel_tol=a_  ,  abs_tol=a_		)  ,  msg=a_		)






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







								'''simple docstring'''






								@staticmethod
								def _a      (							*a_  ,  **a_		):
												pass

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







							'''simple docstring'''






							UpperCamelCase__				:      Dict         =					MODEL_FOR_OBJECT_DETECTION_MAPPING


							def _a      (							self  ,  a_  ,  a_  ,  a_		):
											a__				      =		ObjectDetectionPipeline(model=a_  ,  image_processor=a_		)
											return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]


							def _a      (							self  ,  a_  ,  a_		):
											a__				      =		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

											a__				      =		datasets.load_dataset("""hf-internal-testing/fixtures_image_utils"""  ,  """image"""  ,  split="""test"""		)

											a__				      =		[
											    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__				      =		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 _a      (							self		):
											pass


							@require_torch
							def _a      (							self		):
											a__				      =		"""hf-internal-testing/tiny-detr-mobilenetsv3"""

											a__				      =		AutoModelForObjectDetection.from_pretrained(a_		)
											a__				      =		AutoFeatureExtractor.from_pretrained(a_		)
											a__				      =		ObjectDetectionPipeline(model=a_  ,  feature_extractor=a_		)

											a__				      =		object_detector("""http://images.cocodataset.org/val2017/000000039769.jpg"""  ,  threshold=0.0		)

											self.assertEqual(
											    nested_simplify(a_  ,  decimals=4		)  ,  [
											        {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 159, """ymin""": 120, """xmax""": 480, """ymax""": 359}},
											        {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 159, """ymin""": 120, """xmax""": 480, """ymax""": 359}},
											    ]  ,  )

											a__				      =		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.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 159, """ymin""": 120, """xmax""": 480, """ymax""": 359}},
											            {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 159, """ymin""": 120, """xmax""": 480, """ymax""": 359}},
											        ],
											        [
											            {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 159, """ymin""": 120, """xmax""": 480, """ymax""": 359}},
											            {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 159, """ymin""": 120, """xmax""": 480, """ymax""": 359}},
											        ],
											    ]  ,  )


							@require_torch
							@slow
							def _a      (							self		):
											a__				      =		"""facebook/detr-resnet-50"""

											a__				      =		AutoModelForObjectDetection.from_pretrained(a_		)
											a__				      =		AutoFeatureExtractor.from_pretrained(a_		)
											a__				      =		ObjectDetectionPipeline(model=a_  ,  feature_extractor=a_		)

											a__				      =		object_detector("""http://images.cocodataset.org/val2017/000000039769.jpg"""		)
											self.assertEqual(
											    nested_simplify(a_  ,  decimals=4		)  ,  [
											        {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 70, """xmax""": 175, """ymax""": 117}},
											        {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 333, """ymin""": 72, """xmax""": 368, """ymax""": 187}},
											        {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 639, """ymax""": 473}},
											        {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 13, """ymin""": 52, """xmax""": 314, """ymax""": 470}},
											        {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 345, """ymin""": 23, """xmax""": 640, """ymax""": 368}},
											    ]  ,  )

											a__				      =		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.9_982, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 70, """xmax""": 175, """ymax""": 117}},
											            {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 333, """ymin""": 72, """xmax""": 368, """ymax""": 187}},
											            {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 639, """ymax""": 473}},
											            {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 13, """ymin""": 52, """xmax""": 314, """ymax""": 470}},
											            {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 345, """ymin""": 23, """xmax""": 640, """ymax""": 368}},
											        ],
											        [
											            {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 70, """xmax""": 175, """ymax""": 117}},
											            {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 333, """ymin""": 72, """xmax""": 368, """ymax""": 187}},
											            {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 639, """ymax""": 473}},
											            {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 13, """ymin""": 52, """xmax""": 314, """ymax""": 470}},
											            {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 345, """ymin""": 23, """xmax""": 640, """ymax""": 368}},
											        ],
											    ]  ,  )


							@require_torch
							@slow
							def _a      (							self		):
											a__				      =		"""facebook/detr-resnet-50"""

											a__				      =		pipeline("""object-detection"""  ,  model=a_		)

											a__				      =		object_detector("""http://images.cocodataset.org/val2017/000000039769.jpg"""		)
											self.assertEqual(
											    nested_simplify(a_  ,  decimals=4		)  ,  [
											        {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 70, """xmax""": 175, """ymax""": 117}},
											        {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 333, """ymin""": 72, """xmax""": 368, """ymax""": 187}},
											        {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 639, """ymax""": 473}},
											        {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 13, """ymin""": 52, """xmax""": 314, """ymax""": 470}},
											        {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 345, """ymin""": 23, """xmax""": 640, """ymax""": 368}},
											    ]  ,  )

											a__				      =		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.9_982, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 70, """xmax""": 175, """ymax""": 117}},
											            {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 333, """ymin""": 72, """xmax""": 368, """ymax""": 187}},
											            {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 639, """ymax""": 473}},
											            {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 13, """ymin""": 52, """xmax""": 314, """ymax""": 470}},
											            {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 345, """ymin""": 23, """xmax""": 640, """ymax""": 368}},
											        ],
											        [
											            {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 40, """ymin""": 70, """xmax""": 175, """ymax""": 117}},
											            {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 333, """ymin""": 72, """xmax""": 368, """ymax""": 187}},
											            {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 639, """ymax""": 473}},
											            {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 13, """ymin""": 52, """xmax""": 314, """ymax""": 470}},
											            {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 345, """ymin""": 23, """xmax""": 640, """ymax""": 368}},
											        ],
											    ]  ,  )


							@require_torch
							@slow
							def _a      (							self		):
											a__				      =		0.9_985
											a__				      =		"""facebook/detr-resnet-50"""

											a__				      =		pipeline("""object-detection"""  ,  model=a_		)

											a__				      =		object_detector("""http://images.cocodataset.org/val2017/000000039769.jpg"""  ,  threshold=a_		)
											self.assertEqual(
											    nested_simplify(a_  ,  decimals=4		)  ,  [
											        {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 13, """ymin""": 52, """xmax""": 314, """ymax""": 470}},
											        {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 345, """ymin""": 23, """xmax""": 640, """ymax""": 368}},
											    ]  ,  )







							@require_torch
							@require_pytesseract
							@slow
							def _a      (							self		):
											a__				      =		"""Narsil/layoutlmv3-finetuned-funsd"""
											a__				      =		0.9_993

											a__				      =		pipeline("""object-detection"""  ,  model=a_  ,  threshold=a_		)

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

