

"""simple docstring"""





import inspect
import unittest

from transformers import MobileNetVaConfig
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_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 transformers import MobileNetVaForImageClassification, MobileNetVaModel
							from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import MobileNetVaImageProcessor







class 							SCREAMING_SNAKE_CASE   (						a_			):






					"""simple docstring"""



					def 			__lowerCAmelCase					(			self     :							Union[str, Any]						):
						lowerCAmelCase__      :		Optional[int]    							=      self.config_class(**self.inputs_dict						)
						self.parent.assertTrue(hasattr(lowercase_  ,'''tf_padding'''						)						)
						self.parent.assertTrue(hasattr(lowercase_  ,'''depth_multiplier'''						)						)







class 							SCREAMING_SNAKE_CASE   :






					"""simple docstring"""



					def __init__(			self     :							Optional[Any]  ,lowercase_     :							Dict  ,lowercase_     :							Any=1_3  ,lowercase_     :							Optional[Any]=3  ,lowercase_     :							int=3_2  ,lowercase_     :							Tuple=0.25  ,lowercase_     :							Optional[Any]=8  ,lowercase_     :							Any=True  ,lowercase_     :							Dict=1_0_2_4  ,lowercase_     :							Tuple=3_2  ,lowercase_     :							Optional[int]="relu6"  ,lowercase_     :							Optional[int]=0.1  ,lowercase_     :							int=0.02  ,lowercase_     :							Optional[int]=True  ,lowercase_     :							List[Any]=True  ,lowercase_     :							Optional[int]=1_0  ,lowercase_     :							Union[str, Any]=None  ,):
						lowerCAmelCase__      :		Union[str, Any]    							=      parent
						lowerCAmelCase__      :		Optional[int]    							=      batch_size
						lowerCAmelCase__      :		Optional[Any]    							=      num_channels
						lowerCAmelCase__      :		List[Any]    							=      image_size
						lowerCAmelCase__      :		int    							=      depth_multiplier
						lowerCAmelCase__      :		Tuple    							=      min_depth
						lowerCAmelCase__      :		str    							=      tf_padding
						lowerCAmelCase__      :		Optional[Any]    							=      int(last_hidden_size * depth_multiplier						)
						lowerCAmelCase__      :		Union[str, Any]    							=      output_stride
						lowerCAmelCase__      :		Optional[int]    							=      hidden_act
						lowerCAmelCase__      :		Optional[Any]    							=      classifier_dropout_prob
						lowerCAmelCase__      :		List[str]    							=      use_labels
						lowerCAmelCase__      :		Dict    							=      is_training
						lowerCAmelCase__      :		List[Any]    							=      num_labels
						lowerCAmelCase__      :		Any    							=      initializer_range
						lowerCAmelCase__      :		Union[str, Any]    							=      scope







					def 			__lowerCAmelCase					(			self     :							str						):
						lowerCAmelCase__      :		Union[str, Any]    							=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

						lowerCAmelCase__      :		List[str]    							=      None
						lowerCAmelCase__      :		str    							=      None
						if self.use_labels:
							lowerCAmelCase__      :		List[Any]    							=      ids_tensor([self.batch_size]  ,self.num_labels						)
							lowerCAmelCase__      :		int    							=      ids_tensor([self.batch_size, self.image_size, self.image_size]  ,self.num_labels						)

						lowerCAmelCase__      :		List[str]    							=      self.get_config()

						return config, pixel_values, labels, pixel_labels







					def 			__lowerCAmelCase					(			self     :							str						):
						return MobileNetVaConfig(
						    num_channels=self.num_channels  ,image_size=self.image_size  ,depth_multiplier=self.depth_multiplier  ,min_depth=self.min_depth  ,tf_padding=self.tf_padding  ,hidden_act=self.hidden_act  ,classifier_dropout_prob=self.classifier_dropout_prob  ,initializer_range=self.initializer_range  ,)







					def 			__lowerCAmelCase					(			self     :							Tuple  ,lowercase_     :							List[Any]  ,lowercase_     :							int  ,lowercase_     :							int  ,lowercase_     :							str						):
						lowerCAmelCase__      :		Dict    							=      MobileNetVaModel(config=lowercase_						)
						model.to(lowercase_						)
						model.eval()
						lowerCAmelCase__      :		Union[str, Any]    							=      model(lowercase_						)
						self.parent.assertEqual(
						    result.last_hidden_state.shape  ,(
						        self.batch_size,
						        self.last_hidden_size,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    )  ,)







					def 			__lowerCAmelCase					(			self     :							int  ,lowercase_     :							Tuple  ,lowercase_     :							str  ,lowercase_     :							Dict  ,lowercase_     :							Dict						):
						lowerCAmelCase__      :		Optional[Any]    							=      self.num_labels
						lowerCAmelCase__      :		Tuple    							=      MobileNetVaForImageClassification(lowercase_						)
						model.to(lowercase_						)
						model.eval()
						lowerCAmelCase__      :		Dict    							=      model(lowercase_  ,labels=lowercase_						)
						self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.num_labels)						)







					def 			__lowerCAmelCase					(			self     :							str						):
						lowerCAmelCase__      :		List[Any]    							=      self.prepare_config_and_inputs()
						lowerCAmelCase__							,lowerCAmelCase__							,lowerCAmelCase__							,lowerCAmelCase__      :		Dict    							=      config_and_inputs
						lowerCAmelCase__      :		Dict    							=      {'''pixel_values''': pixel_values}
						return config, inputs_dict







@require_torch
class 							SCREAMING_SNAKE_CASE   (						a_       ,				a_       ,				unittest.TestCase			):






					"""simple docstring"""



					lowercase__												=			(MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
					lowercase__												=			(
					    {"feature-extraction": MobileNetVaModel, "image-classification": MobileNetVaForImageClassification}
					    if is_torch_available()
					    else {}
					)

					lowercase__												=			False
					lowercase__												=			False
					lowercase__												=			False
					lowercase__												=			False







					def 			__lowerCAmelCase					(			self     :							Dict						):
						lowerCAmelCase__      :		str    							=      MobileNetVaModelTester(self						)
						lowerCAmelCase__      :		int    							=      MobileNetVaConfigTester(self  ,config_class=lowercase_  ,has_text_modality=lowercase_						)







					def 			__lowerCAmelCase					(			self     :							Any						):
						self.config_tester.run_common_tests()







					@unittest.skip(reason='''MobileNetV1 does not use inputs_embeds'''						)
					def 			__lowerCAmelCase					(			self     :							int						):
						pass







					@unittest.skip(reason='''MobileNetV1 does not support input and output embeddings'''						)
					def 			__lowerCAmelCase					(			self     :							Union[str, Any]						):
						pass







					@unittest.skip(reason='''MobileNetV1 does not output attentions'''						)
					def 			__lowerCAmelCase					(			self     :							int						):
						pass







					def 			__lowerCAmelCase					(			self     :							int						):
						lowerCAmelCase__							,lowerCAmelCase__      :		int    							=      self.model_tester.prepare_config_and_inputs_for_common()

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

							lowerCAmelCase__      :		Tuple    							=      ['''pixel_values''']
							self.assertListEqual(arg_names[:1]  ,lowercase_						)







					def 			__lowerCAmelCase					(			self     :							List[str]						):
						lowerCAmelCase__      :		int    							=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowercase_						)







					def 			__lowerCAmelCase					(			self     :							Tuple						):
						def check_hidden_states_output(lowercase_     :							List[str]  ,lowercase_     :							Union[str, Any]  ,lowercase_     :							List[Any]						):
							lowerCAmelCase__      :		Optional[int]    							=      model_class(lowercase_						)
							model.to(lowercase_						)
							model.eval()

							with torch.no_grad():
								lowerCAmelCase__      :		Dict    							=      model(**self._prepare_for_class(lowercase_  ,lowercase_						)						)

							lowerCAmelCase__      :		List[Any]    							=      outputs.hidden_states

							lowerCAmelCase__      :		str    							=      2_6
							self.assertEqual(len(lowercase_						)  ,lowercase_						)

						lowerCAmelCase__							,lowerCAmelCase__      :		int    							=      self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
							lowerCAmelCase__      :		Dict    							=      True
							check_hidden_states_output(lowercase_  ,lowercase_  ,lowercase_						)

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							lowerCAmelCase__      :		Tuple    							=      True

							check_hidden_states_output(lowercase_  ,lowercase_  ,lowercase_						)







					def 			__lowerCAmelCase					(			self     :							int						):
						lowerCAmelCase__      :		int    							=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*lowercase_						)







					@slow
					def 			__lowerCAmelCase					(			self     :							List[str]						):
						for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							lowerCAmelCase__      :		Optional[int]    							=      MobileNetVaModel.from_pretrained(lowercase_						)
							self.assertIsNotNone(lowercase_						)

def     __SCREAMING_SNAKE_CASE    ( ):
	lowerCAmelCase__      :		str    							=      Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''					)
	return image







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






					"""simple docstring"""



					@cached_property
					def 			__lowerCAmelCase					(			self     :							Optional[Any]						):
						return (
						    MobileNetVaImageProcessor.from_pretrained('''google/mobilenet_v1_1.0_224'''						) if is_vision_available() else None
						)







					@slow
					def 			__lowerCAmelCase					(			self     :							int						):
						lowerCAmelCase__      :		Optional[Any]    							=      MobileNetVaForImageClassification.from_pretrained('''google/mobilenet_v1_1.0_224'''						).to(lowercase_						)

						lowerCAmelCase__      :		List[str]    							=      self.default_image_processor
						lowerCAmelCase__      :		Dict    							=      prepare_img()
						lowerCAmelCase__      :		str    							=      image_processor(images=lowercase_  ,return_tensors='''pt'''						).to(lowercase_						)

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

						# verify the logits
						lowerCAmelCase__      :		Dict    							=      torch.Size((1, 1_0_0_1)						)
						self.assertEqual(outputs.logits.shape  ,lowercase_						)

						lowerCAmelCase__      :		List[Any]    							=      torch.tensor([-4.1739, -1.1233, 3.1205]						).to(lowercase_						)

						self.assertTrue(torch.allclose(outputs.logits[0, :3]  ,lowercase_  ,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 							SCREAMING_SNAKE_CASE   :






												"""simple docstring"""



												@staticmethod
												def 			__lowerCAmelCase					(			*lowercase_     :							Dict  ,**lowercase_     :							str						):
													pass







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






					"""simple docstring"""



					lowercase__												=			MODEL_FOR_OBJECT_DETECTION_MAPPING







					def 			__lowerCAmelCase					(			self     :							str  ,lowercase_     :							int  ,lowercase_     :							str  ,lowercase_     :							List[str]						):
						lowerCAmelCase__      :		int    							=      ObjectDetectionPipeline(model=lowercase_  ,image_processor=lowercase_						)
						return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]







					def 			__lowerCAmelCase					(			self     :							int  ,lowercase_     :							str  ,lowercase_     :							str						):
						lowerCAmelCase__      :		List[str]    							=      object_detector('''./tests/fixtures/tests_samples/COCO/000000039769.png'''  ,threshold=0.0						)

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

						import datasets

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

						lowerCAmelCase__      :		Dict    							=      [
						    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__      :		Optional[Any]    							=      object_detector(lowercase_  ,threshold=0.0						)

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







					@require_tf
					@unittest.skip('''Object detection not implemented in TF'''						)
					def 			__lowerCAmelCase					(			self     :							Optional[int]						):
						pass







					@require_torch
					def 			__lowerCAmelCase					(			self     :							Optional[int]						):
						lowerCAmelCase__      :		Optional[Any]    							=      '''hf-internal-testing/tiny-detr-mobilenetsv3'''

						lowerCAmelCase__      :		Union[str, Any]    							=      AutoModelForObjectDetection.from_pretrained(lowercase_						)
						lowerCAmelCase__      :		Any    							=      AutoFeatureExtractor.from_pretrained(lowercase_						)
						lowerCAmelCase__      :		Optional[int]    							=      ObjectDetectionPipeline(model=lowercase_  ,feature_extractor=lowercase_						)

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

						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						        {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						    ]  ,)

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

						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        [
						            {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						            {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						        ],
						        [
						            {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						            {'''score''': 0.3376, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
						        ],
						    ]  ,)







					@require_torch
					@slow
					def 			__lowerCAmelCase					(			self     :							Any						):
						lowerCAmelCase__      :		List[Any]    							=      '''facebook/detr-resnet-50'''

						lowerCAmelCase__      :		Any    							=      AutoModelForObjectDetection.from_pretrained(lowercase_						)
						lowerCAmelCase__      :		Dict    							=      AutoFeatureExtractor.from_pretrained(lowercase_						)
						lowerCAmelCase__      :		Any    							=      ObjectDetectionPipeline(model=lowercase_  ,feature_extractor=lowercase_						)

						lowerCAmelCase__      :		Tuple    							=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						        {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						        {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						        {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						        {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						    ]  ,)

						lowerCAmelCase__      :		List[Any]    							=      object_detector(
						    [
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						    ]						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        [
						            {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						            {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						            {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						            {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						            {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						        ],
						        [
						            {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						            {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						            {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						            {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						            {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						        ],
						    ]  ,)







					@require_torch
					@slow
					def 			__lowerCAmelCase					(			self     :							Tuple						):
						lowerCAmelCase__      :		Tuple    							=      '''facebook/detr-resnet-50'''

						lowerCAmelCase__      :		Tuple    							=      pipeline('''object-detection'''  ,model=lowercase_						)

						lowerCAmelCase__      :		Optional[int]    							=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						        {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						        {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						        {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						        {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						    ]  ,)

						lowerCAmelCase__      :		Any    							=      object_detector(
						    [
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
						    ]						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        [
						            {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						            {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						            {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						            {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						            {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						        ],
						        [
						            {'''score''': 0.9982, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
						            {'''score''': 0.9960, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
						            {'''score''': 0.9955, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
						            {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						            {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						        ],
						    ]  ,)







					@require_torch
					@slow
					def 			__lowerCAmelCase					(			self     :							Any						):
						lowerCAmelCase__      :		List[Any]    							=      0.9985
						lowerCAmelCase__      :		Dict    							=      '''facebook/detr-resnet-50'''

						lowerCAmelCase__      :		List[Any]    							=      pipeline('''object-detection'''  ,model=lowercase_						)

						lowerCAmelCase__      :		int    							=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''  ,threshold=lowercase_						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.9988, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
						        {'''score''': 0.9987, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
						    ]  ,)







					@require_torch
					@require_pytesseract
					@slow
					def 			__lowerCAmelCase					(			self     :							str						):
						lowerCAmelCase__      :		Optional[Any]    							=      '''Narsil/layoutlmv3-finetuned-funsd'''
						lowerCAmelCase__      :		List[Any]    							=      0.9993

						lowerCAmelCase__      :		Any    							=      pipeline('''object-detection'''  ,model=lowercase_  ,threshold=lowercase_						)

						lowerCAmelCase__      :		List[str]    							=      object_detector(
						    '''https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png'''						)
						self.assertEqual(
						    nested_simplify(lowercase_  ,decimals=4						)  ,[
						        {'''score''': 0.9993, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 2_9_4, '''ymin''': 2_5_4, '''xmax''': 3_4_3, '''ymax''': 2_6_4}},
						        {'''score''': 0.9993, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 2_9_4, '''ymin''': 2_5_4, '''xmax''': 3_4_3, '''ymax''': 2_6_4}},
						    ]  ,)




