
import collections
import inspect
import unittest

from transformers import FocalNetConfig
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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch
			from torch import nn

			from transformers import (
			    FocalNetBackbone,
			    FocalNetForImageClassification,
			    FocalNetForMaskedImageModeling,
			    FocalNetModel,
			)
			from transformers.models.focalnet.modeling_focalnet import FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor





class 	_lowerCAmelCase					:




				def __init__(					self				,				_UpperCamelCase				,				_UpperCamelCase=13				,				_UpperCamelCase=32				,				_UpperCamelCase=2				,				_UpperCamelCase=3				,				_UpperCamelCase=16				,				_UpperCamelCase=[32, 64, 128]				,				_UpperCamelCase=[1, 2, 1]				,				_UpperCamelCase=[2, 2, 4]				,				_UpperCamelCase=2				,				_UpperCamelCase=2.0				,				_UpperCamelCase=True				,				_UpperCamelCase=0.0				,				_UpperCamelCase=0.0				,				_UpperCamelCase=0.1				,				_UpperCamelCase="gelu"				,				_UpperCamelCase=False				,				_UpperCamelCase=True				,				_UpperCamelCase=0.02				,				_UpperCamelCase=1e-5				,				_UpperCamelCase=True				,				_UpperCamelCase=None				,				_UpperCamelCase=True				,				_UpperCamelCase=10				,				_UpperCamelCase=8				,				_UpperCamelCase=["stage1", "stage2"]				,				_UpperCamelCase=[1, 2]				,				)				->      Any:
							lowerCAmelCase_						=	parent
							lowerCAmelCase_						=	batch_size
							lowerCAmelCase_						=	image_size
							lowerCAmelCase_						=	patch_size
							lowerCAmelCase_						=	num_channels
							lowerCAmelCase_						=	embed_dim
							lowerCAmelCase_						=	hidden_sizes
							lowerCAmelCase_						=	depths
							lowerCAmelCase_						=	num_heads
							lowerCAmelCase_						=	window_size
							lowerCAmelCase_						=	mlp_ratio
							lowerCAmelCase_						=	qkv_bias
							lowerCAmelCase_						=	hidden_dropout_prob
							lowerCAmelCase_						=	attention_probs_dropout_prob
							lowerCAmelCase_						=	drop_path_rate
							lowerCAmelCase_						=	hidden_act
							lowerCAmelCase_						=	use_absolute_embeddings
							lowerCAmelCase_						=	patch_norm
							lowerCAmelCase_						=	layer_norm_eps
							lowerCAmelCase_						=	initializer_range
							lowerCAmelCase_						=	is_training
							lowerCAmelCase_						=	scope
							lowerCAmelCase_						=	use_labels
							lowerCAmelCase_						=	type_sequence_label_size
							lowerCAmelCase_						=	encoder_stride
							lowerCAmelCase_						=	out_features
							lowerCAmelCase_						=	out_indices




				def      __a						(					self     )				->      Tuple:
							lowerCAmelCase_						=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

							lowerCAmelCase_						=	None
							if self.use_labels:
										lowerCAmelCase_						=	ids_tensor([self.batch_size]				,				self.type_sequence_label_size     )

							lowerCAmelCase_						=	self.get_config()

							return config, pixel_values, labels




				def      __a						(					self     )				->      List[str]:
							return FocalNetConfig(
							    image_size=self.image_size				,				patch_size=self.patch_size				,				num_channels=self.num_channels				,				embed_dim=self.embed_dim				,				hidden_sizes=self.hidden_sizes				,				depths=self.depths				,				num_heads=self.num_heads				,				window_size=self.window_size				,				mlp_ratio=self.mlp_ratio				,				qkv_bias=self.qkv_bias				,				hidden_dropout_prob=self.hidden_dropout_prob				,				attention_probs_dropout_prob=self.attention_probs_dropout_prob				,				drop_path_rate=self.drop_path_rate				,				hidden_act=self.hidden_act				,				use_absolute_embeddings=self.use_absolute_embeddings				,				path_norm=self.patch_norm				,				layer_norm_eps=self.layer_norm_eps				,				initializer_range=self.initializer_range				,				encoder_stride=self.encoder_stride				,				out_features=self.out_features				,				out_indices=self.out_indices				,				)




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      List[str]:
							lowerCAmelCase_						=	FocalNetModel(config=_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	model(_UpperCamelCase     )

							lowerCAmelCase_						=	((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths     ) - 1))
							lowerCAmelCase_						=	int(config.embed_dim * 2 ** (len(config.depths     ) - 1)     )

							self.parent.assertEqual(result.last_hidden_state.shape				,				(self.batch_size, expected_seq_len, expected_dim)     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      int:
							lowerCAmelCase_						=	FocalNetBackbone(config=_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	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.image_size, 8, 8]     )

							# 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
							lowerCAmelCase_						=	None
							lowerCAmelCase_						=	FocalNetBackbone(config=_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	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.image_size * 2, 4, 4]     )

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




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      Dict:
							lowerCAmelCase_						=	FocalNetForMaskedImageModeling(config=_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	model(_UpperCamelCase     )
							self.parent.assertEqual(
							    result.reconstruction.shape				,				(self.batch_size, self.num_channels, self.image_size, self.image_size)     )

							# test greyscale images
							lowerCAmelCase_						=	1
							lowerCAmelCase_						=	FocalNetForMaskedImageModeling(_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()

							lowerCAmelCase_						=	floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
							lowerCAmelCase_						=	model(_UpperCamelCase     )
							self.parent.assertEqual(result.reconstruction.shape				,				(self.batch_size, 1, self.image_size, self.image_size)     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      Tuple:
							lowerCAmelCase_						=	self.type_sequence_label_size
							lowerCAmelCase_						=	FocalNetForImageClassification(_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()
							lowerCAmelCase_						=	model(_UpperCamelCase				,				labels=_UpperCamelCase     )
							self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.type_sequence_label_size)     )

							# test greyscale images
							lowerCAmelCase_						=	1
							lowerCAmelCase_						=	FocalNetForImageClassification(_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()

							lowerCAmelCase_						=	floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
							lowerCAmelCase_						=	model(_UpperCamelCase     )
							self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.type_sequence_label_size)     )




				def      __a						(					self     )				->      int:
							lowerCAmelCase_						=	self.prepare_config_and_inputs()

							lowerCAmelCase_	,  lowerCAmelCase_	,  lowerCAmelCase_						=	config_and_inputs
							lowerCAmelCase_						=	{"pixel_values": pixel_values}
							return config, inputs_dict





@require_torch
class 	_lowerCAmelCase					(	__a					,      __a					,      unittest.TestCase       ):
				_lowercase					=(
				    (
				        FocalNetModel,
				        FocalNetForImageClassification,
				        FocalNetForMaskedImageModeling,
				        FocalNetBackbone,
				    )
				    if is_torch_available()
				    else ()
				)
				_lowercase					=(
				    {'''feature-extraction''': FocalNetModel, '''image-classification''': FocalNetForImageClassification}
				    if is_torch_available()
				    else {}
				)
				_lowercase					=False

				_lowercase					=False
				_lowercase					=False
				_lowercase					=False
				_lowercase					=False




				def      __a						(					self     )				->      str:
							lowerCAmelCase_						=	FocalNetModelTester(self     )
							lowerCAmelCase_						=	ConfigTester(self				,				config_class=_UpperCamelCase				,				embed_dim=37				,				has_text_modality=_UpperCamelCase     )




				def      __a						(					self     )				->      Tuple:
							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      __a						(					self     )				->      Dict:
							return




				def      __a						(					self     )				->      int:
							lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_UpperCamelCase     )




				def      __a						(					self     )				->      int:
							lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_backbone(*_UpperCamelCase     )




				def      __a						(					self     )				->      Tuple:
							lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_image_modeling(*_UpperCamelCase     )




				def      __a						(					self     )				->      Union[str, Any]:
							lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*_UpperCamelCase     )




				@unittest.skip(reason="FocalNet does not use inputs_embeds"     )
				def      __a						(					self     )				->      Optional[Any]:
							pass




				@unittest.skip(reason="FocalNet does not use feedforward chunking"     )
				def      __a						(					self     )				->      List[str]:
							pass




				def      __a						(					self     )				->      str:
							lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes[:-1]:
										lowerCAmelCase_						=	model_class(_UpperCamelCase     )
										self.assertIsInstance(model.get_input_embeddings()				,				(nn.Module)     )
										lowerCAmelCase_						=	model.get_output_embeddings()
										self.assertTrue(x is None or isinstance(_UpperCamelCase				,				nn.Linear     )     )




				def      __a						(					self     )				->      List[str]:
							lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes[:-1]:
										lowerCAmelCase_						=	model_class(_UpperCamelCase     )
										lowerCAmelCase_						=	inspect.signature(model.forward     )
										# signature.parameters is an OrderedDict => so arg_names order is deterministic
										lowerCAmelCase_						=	[*signature.parameters.keys()]

										lowerCAmelCase_						=	["pixel_values"]
										self.assertListEqual(arg_names[:1]				,				_UpperCamelCase     )




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      Dict:
							lowerCAmelCase_						=	model_class(_UpperCamelCase     )
							model.to(_UpperCamelCase     )
							model.eval()

							with torch.no_grad():
										lowerCAmelCase_						=	model(**self._prepare_for_class(_UpperCamelCase				,				_UpperCamelCase     )     )

							lowerCAmelCase_						=	outputs.hidden_states

							lowerCAmelCase_						=	getattr(
							    self.model_tester				,				"expected_num_hidden_layers"				,				len(self.model_tester.depths     ) + 1     )
							self.assertEqual(len(_UpperCamelCase     )				,				_UpperCamelCase     )

							# FocalNet has a different seq_length
							lowerCAmelCase_						=	(
							    config.patch_size
							    if isinstance(config.patch_size				,				collections.abc.Iterable     )
							    else (config.patch_size, config.patch_size)
							)

							lowerCAmelCase_						=	(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

							self.assertListEqual(
							    list(hidden_states[0].shape[-2:]     )				,				[num_patches, self.model_tester.embed_dim]				,				)

							lowerCAmelCase_						=	outputs.reshaped_hidden_states
							self.assertEqual(len(_UpperCamelCase     )				,				_UpperCamelCase     )

							lowerCAmelCase_	,  lowerCAmelCase_	,  lowerCAmelCase_	,  lowerCAmelCase_						=	reshaped_hidden_states[0].shape
							lowerCAmelCase_						=	(
							    reshaped_hidden_states[0].view(_UpperCamelCase				,				_UpperCamelCase				,				height * width     ).permute(0				,				2				,				1     )
							)
							self.assertListEqual(
							    list(reshaped_hidden_states.shape[-2:]     )				,				[num_patches, self.model_tester.embed_dim]				,				)




				def      __a						(					self     )				->      Optional[int]:
							lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_for_common()

							lowerCAmelCase_						=	(
							    self.model_tester.image_size
							    if isinstance(self.model_tester.image_size				,				collections.abc.Iterable     )
							    else (self.model_tester.image_size, self.model_tester.image_size)
							)

							for model_class in self.all_model_classes[:-1]:
										lowerCAmelCase_						=	True
										self.check_hidden_states_output(_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )

										# check that output_hidden_states also work using config
										del inputs_dict["output_hidden_states"]
										lowerCAmelCase_						=	True

										self.check_hidden_states_output(_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )




				def      __a						(					self     )				->      Optional[Any]:
							lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_for_common()
							lowerCAmelCase_						=	3

							lowerCAmelCase_						=	(
							    self.model_tester.image_size
							    if isinstance(self.model_tester.image_size				,				collections.abc.Iterable     )
							    else (self.model_tester.image_size, self.model_tester.image_size)
							)
							lowerCAmelCase_						=	(
							    config.patch_size
							    if isinstance(config.patch_size				,				collections.abc.Iterable     )
							    else (config.patch_size, config.patch_size)
							)

							lowerCAmelCase_						=	image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
							lowerCAmelCase_						=	image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

							for model_class in self.all_model_classes[:-1]:
										lowerCAmelCase_						=	True
										self.check_hidden_states_output(_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase				,				(padded_height, padded_width)     )

										# check that output_hidden_states also work using config
										del inputs_dict["output_hidden_states"]
										lowerCAmelCase_						=	True
										self.check_hidden_states_output(_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase				,				(padded_height, padded_width)     )




				@slow
				def      __a						(					self     )				->      Any:
							for model_name in FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowerCAmelCase_						=	FocalNetModel.from_pretrained(_UpperCamelCase     )
										self.assertIsNotNone(_UpperCamelCase     )




				def      __a						(					self     )				->      Optional[int]:
							lowerCAmelCase_	,  lowerCAmelCase_						=	self.model_tester.prepare_config_and_inputs_for_common()

							lowerCAmelCase_						=	_config_zero_init(_UpperCamelCase     )
							for model_class in self.all_model_classes:
										lowerCAmelCase_						=	model_class(config=_UpperCamelCase     )
										for name, param in model.named_parameters():
													if "embeddings" not in name and param.requires_grad:
																self.assertIn(
																    ((param.data.mean() * 1e9).round() / 1e9).item()				,				[0.0, 1.0]				,				msg=f"""Parameter {name} of model {model_class} seems not properly initialized"""				,				)





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




				@cached_property
				def      __a						(					self     )				->      Union[str, Any]:
							# TODO update organization
							return AutoImageProcessor.from_pretrained("microsoft/focalnet-tiny"     ) if is_vision_available() else None




				@slow
				def      __a						(					self     )				->      Optional[int]:
							lowerCAmelCase_						=	FocalNetForImageClassification.from_pretrained("microsoft/focalnet-tiny"     ).to(_UpperCamelCase     )
							lowerCAmelCase_						=	self.default_image_processor

							lowerCAmelCase_						=	Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
							lowerCAmelCase_						=	image_processor(images=_UpperCamelCase				,				return_tensors="pt"     ).to(_UpperCamelCase     )

							# forward pass
							with torch.no_grad():
										lowerCAmelCase_						=	model(**_UpperCamelCase     )

							# verify the logits
							lowerCAmelCase_						=	torch.Size((1, 1_000)     )
							self.assertEqual(outputs.logits.shape				,				_UpperCamelCase     )
							lowerCAmelCase_						=	torch.tensor([0.2166, -0.4368, 0.2191]     ).to(_UpperCamelCase     )
							self.assertTrue(torch.allclose(outputs.logits[0, :3]				,				_UpperCamelCase				,				atol=1e-4     )     )
							self.assertTrue(outputs.logits.argmax(dim=-1     ).item()				,				281     )





@require_torch
class 	_lowerCAmelCase					(	__a					,      unittest.TestCase       ):
				_lowercase					=(FocalNetBackbone,) if is_torch_available() else ()
				_lowercase					=FocalNetConfig

				_lowercase					=False




				def      __a						(					self     )				->      Tuple:
							lowerCAmelCase_						=	FocalNetModelTester(self     )





import unittest

from transformers import (
    MODEL_FOR_OBJECT_DETECTION_MAPPING,
    AutoFeatureExtractor,
    AutoModelForObjectDetection,
    ObjectDetectionPipeline,
    is_vision_available,
    pipeline,
)
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_pytesseract,
    require_tf,
    require_timm,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
			from PIL import Image
else:





			class 	_lowerCAmelCase					:




							@staticmethod
							def      __a						(					*_UpperCamelCase				,				**_UpperCamelCase     )				->      str:
										pass





@is_pipeline_test
@require_vision
@require_timm
@require_torch
class 	_lowerCAmelCase					(	unittest.TestCase       ):
				_lowercase					=MODEL_FOR_OBJECT_DETECTION_MAPPING




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase				,				_UpperCamelCase     )				->      str:
							lowerCAmelCase_						=	ObjectDetectionPipeline(model=_UpperCamelCase				,				image_processor=_UpperCamelCase     )
							return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase     )				->      Any:
							lowerCAmelCase_						=	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

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

							lowerCAmelCase_						=	[
							    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_						=	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      __a						(					self     )				->      Optional[int]:
							pass




				@require_torch
				def      __a						(					self     )				->      str:
							lowerCAmelCase_						=	"hf-internal-testing/tiny-detr-mobilenetsv3"

							lowerCAmelCase_						=	AutoModelForObjectDetection.from_pretrained(_UpperCamelCase     )
							lowerCAmelCase_						=	AutoFeatureExtractor.from_pretrained(_UpperCamelCase     )
							lowerCAmelCase_						=	ObjectDetectionPipeline(model=_UpperCamelCase				,				feature_extractor=_UpperCamelCase     )

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

							lowerCAmelCase_						=	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      __a						(					self     )				->      Optional[Any]:
							lowerCAmelCase_						=	"facebook/detr-resnet-50"

							lowerCAmelCase_						=	AutoModelForObjectDetection.from_pretrained(_UpperCamelCase     )
							lowerCAmelCase_						=	AutoFeatureExtractor.from_pretrained(_UpperCamelCase     )
							lowerCAmelCase_						=	ObjectDetectionPipeline(model=_UpperCamelCase				,				feature_extractor=_UpperCamelCase     )

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

							lowerCAmelCase_						=	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      __a						(					self     )				->      str:
							lowerCAmelCase_						=	"facebook/detr-resnet-50"

							lowerCAmelCase_						=	pipeline("object-detection"				,				model=_UpperCamelCase     )

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

							lowerCAmelCase_						=	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      __a						(					self     )				->      Optional[Any]:
							lowerCAmelCase_						=	0.9985
							lowerCAmelCase_						=	"facebook/detr-resnet-50"

							lowerCAmelCase_						=	pipeline("object-detection"				,				model=_UpperCamelCase     )

							lowerCAmelCase_						=	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      __a						(					self     )				->      List[str]:
							lowerCAmelCase_						=	"Narsil/layoutlmv3-finetuned-funsd"
							lowerCAmelCase_						=	0.9993

							lowerCAmelCase_						=	pipeline("object-detection"				,				model=_UpperCamelCase				,				threshold=_UpperCamelCase     )

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



