



from scipy.stats import spearmanr

import datasets


__A   			="\nThe Spearman rank-order correlation coefficient is a measure of the\nrelationship between two datasets. Like other correlation coefficients,\nthis one varies between -1 and +1 with 0 implying no correlation.\nPositive correlations imply that as data in dataset x increases, so\ndoes data in dataset y. Negative correlations imply that as x increases,\ny decreases. Correlations of -1 or +1 imply an exact monotonic relationship.\n\nUnlike the Pearson correlation, the Spearman correlation does not\nassume that both datasets are normally distributed.\n\nThe p-value roughly indicates the probability of an uncorrelated system\nproducing datasets that have a Spearman correlation at least as extreme\nas the one computed from these datasets. The p-values are not entirely\nreliable but are probably reasonable for datasets larger than 500 or so.\n"

__A   			="\nArgs:\n    predictions (`List[float]`): Predicted labels, as returned by a model.\n    references (`List[float]`): Ground truth labels.\n    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns\n            only the spearmanr score. Defaults to `False`.\nReturns:\n    spearmanr (`float`): Spearman correlation coefficient.\n    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.\nExamples:\n    Example 1:\n        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")\n        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])\n        >>> print(results)\n        {'spearmanr': -0.7}\n\n    Example 2:\n        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")\n        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],\n        ...                                     predictions=[10, 9, 2.5, 6, 4],\n        ...                                     return_pvalue=True)\n        >>> print(results['spearmanr'])\n        -0.7\n        >>> print(round(results['spearmanr_pvalue'], 2))\n        0.19\n"

__A   			=R"\\n@book{kokoska2000crc,\n  title={CRC standard probability and statistics tables and formulae},\n  author={Kokoska, Stephen and Zwillinger, Daniel},\n  year={2000},\n  publisher={Crc Press}\n}\n@article{2020SciPy-NMeth,\n  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and\n            Haberland, Matt and Reddy, Tyler and Cournapeau, David and\n            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and\n            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and\n            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and\n            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and\n            Kern, Robert and Larson, Eric and Carey, C J and\n            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and\n            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and\n            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and\n            Harris, Charles R. and Archibald, Anne M. and\n            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and\n            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},\n  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific\n            Computing in Python}},\n  journal = {Nature Methods},\n  year    = {2020},\n  volume  = {17},\n  pages   = {261--272},\n  adsurl  = {https://rdcu.be/b08Wh},\n  doi     = {10.1038/s41592-019-0686-2},\n}\n"

@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,_KWARGS_DESCRIPTION   )
class 		UpperCAmelCase__			(			datasets.Metric   ):




			'''simple docstring'''






			def  snake_case__     (   self							: str ):
					'''simple docstring'''





					return datasets.MetricInfo(
					    description=_DESCRIPTION       ,       citation=_CITATION       ,       inputs_description=_KWARGS_DESCRIPTION       ,       features=datasets.Features(
					        {
					            '''predictions''': datasets.Value('''float''' ),
					            '''references''': datasets.Value('''float''' ),
					        } )       ,       reference_urls=['''https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html''']       ,       )




			def  snake_case__     (   self							: Dict       ,       a_							: Tuple       ,       a_							: Union[str, Any]       ,       a_							: List[Any]=False ):
					'''simple docstring'''





					__UpperCAmelCase    :     Union[str, Any]													=	spearmanr(a_       ,       a_ )
					if return_pvalue:
							return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
					else:
							return {"spearmanr": results[0]}










import argparse
import json
from pathlib import Path

import requests
import torch
from huggingface_hub import cached_download, hf_hub_download, hf_hub_url
from PIL import Image

from transformers import DetaConfig, DetaForObjectDetection, DetaImageProcessor, SwinConfig
from transformers.utils import logging


logging.set_verbosity_info()
__A   			=logging.get_logger(__name__)

def        a						(      _UpperCAmelCase							:					int						):







		'''simple docstring'''





		__UpperCAmelCase    :     Optional[Any]													=	SwinConfig(
		    embed_dim=1_92 ,   depths=(2, 2, 18, 2) ,   num_heads=(6, 12, 24, 48) ,   window_size=12 ,   out_features=['''stage2''', '''stage3''', '''stage4'''] ,   )

		__UpperCAmelCase    :     Optional[int]													=	DetaConfig(
		    backbone_config=_UpperCAmelCase ,   num_queries=9_00 ,   encoder_ffn_dim=20_48 ,   decoder_ffn_dim=20_48 ,   num_feature_levels=5 ,   assign_first_stage=_UpperCAmelCase ,   with_box_refine=_UpperCAmelCase ,   two_stage=_UpperCAmelCase ,   )

		# set labels
		__UpperCAmelCase    :     Optional[int]													=	'''huggingface/label-files'''
		if "o365" in model_name:
				__UpperCAmelCase    :     Tuple													=	3_66
				__UpperCAmelCase    :     List[str]													=	'''object365-id2label.json'''
		else:
				__UpperCAmelCase    :     Any													=	91
				__UpperCAmelCase    :     int													=	'''coco-detection-id2label.json'''

		__UpperCAmelCase    :     Optional[int]													=	num_labels
		__UpperCAmelCase    :     List[str]													=	json.load(open(cached_download(hf_hub_url(_UpperCAmelCase ,   _UpperCAmelCase ,   repo_type='''dataset'''						)						) ,   '''r'''						)						)
		__UpperCAmelCase    :     str													=	{int(_UpperCAmelCase						): v for k, v in idalabel.items()}
		__UpperCAmelCase    :     Optional[int]													=	idalabel
		__UpperCAmelCase    :     Tuple													=	{v: k for k, v in idalabel.items()}

		return config

def        a						(      _UpperCAmelCase							:					Dict						):







		'''simple docstring'''





		__UpperCAmelCase    :     List[str]													=	[]

		# stem
		# fmt: off
		rename_keys.append(('''backbone.0.body.patch_embed.proj.weight''', '''model.backbone.model.embeddings.patch_embeddings.projection.weight''')						)
		rename_keys.append(('''backbone.0.body.patch_embed.proj.bias''', '''model.backbone.model.embeddings.patch_embeddings.projection.bias''')						)
		rename_keys.append(('''backbone.0.body.patch_embed.norm.weight''', '''model.backbone.model.embeddings.norm.weight''')						)
		rename_keys.append(('''backbone.0.body.patch_embed.norm.bias''', '''model.backbone.model.embeddings.norm.bias''')						)
		# stages
		for i in range(len(config.backbone_config.depths						)						):
				for j in range(config.backbone_config.depths[i]						):
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.norm1.weight', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.layernorm_before.weight')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.norm1.bias', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.layernorm_before.bias')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.attn.relative_position_bias_table', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.attention.self.relative_position_bias_table')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.attn.relative_position_index', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.attention.self.relative_position_index')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.attn.proj.weight', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.attention.output.dense.weight')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.attn.proj.bias', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.attention.output.dense.bias')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.norm2.weight', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.layernorm_after.weight')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.norm2.bias', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.layernorm_after.bias')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.mlp.fc1.weight', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.intermediate.dense.weight')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.mlp.fc1.bias', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.intermediate.dense.bias')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.mlp.fc2.weight', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.output.dense.weight')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.blocks.{j}.mlp.fc2.bias', f'model.backbone.model.encoder.layers.{i}.blocks.{j}.output.dense.bias')						)

				if i < 3:
						rename_keys.append((f'backbone.0.body.layers.{i}.downsample.reduction.weight', f'model.backbone.model.encoder.layers.{i}.downsample.reduction.weight')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.downsample.norm.weight', f'model.backbone.model.encoder.layers.{i}.downsample.norm.weight')						)
						rename_keys.append((f'backbone.0.body.layers.{i}.downsample.norm.bias', f'model.backbone.model.encoder.layers.{i}.downsample.norm.bias')						)

		rename_keys.append(('''backbone.0.body.norm1.weight''', '''model.backbone.model.hidden_states_norms.stage2.weight''')						)
		rename_keys.append(('''backbone.0.body.norm1.bias''', '''model.backbone.model.hidden_states_norms.stage2.bias''')						)
		rename_keys.append(('''backbone.0.body.norm2.weight''', '''model.backbone.model.hidden_states_norms.stage3.weight''')						)
		rename_keys.append(('''backbone.0.body.norm2.bias''', '''model.backbone.model.hidden_states_norms.stage3.bias''')						)
		rename_keys.append(('''backbone.0.body.norm3.weight''', '''model.backbone.model.hidden_states_norms.stage4.weight''')						)
		rename_keys.append(('''backbone.0.body.norm3.bias''', '''model.backbone.model.hidden_states_norms.stage4.bias''')						)

		# transformer encoder
		for i in range(config.encoder_layers						):
				rename_keys.append((f'transformer.encoder.layers.{i}.self_attn.sampling_offsets.weight', f'model.encoder.layers.{i}.self_attn.sampling_offsets.weight')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.self_attn.sampling_offsets.bias', f'model.encoder.layers.{i}.self_attn.sampling_offsets.bias')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.self_attn.attention_weights.weight', f'model.encoder.layers.{i}.self_attn.attention_weights.weight')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.self_attn.attention_weights.bias', f'model.encoder.layers.{i}.self_attn.attention_weights.bias')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.self_attn.value_proj.weight', f'model.encoder.layers.{i}.self_attn.value_proj.weight')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.self_attn.value_proj.bias', f'model.encoder.layers.{i}.self_attn.value_proj.bias')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.self_attn.output_proj.weight', f'model.encoder.layers.{i}.self_attn.output_proj.weight')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.self_attn.output_proj.bias', f'model.encoder.layers.{i}.self_attn.output_proj.bias')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.norm1.weight', f'model.encoder.layers.{i}.self_attn_layer_norm.weight')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.norm1.bias', f'model.encoder.layers.{i}.self_attn_layer_norm.bias')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.linear1.weight', f'model.encoder.layers.{i}.fc1.weight')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.linear1.bias', f'model.encoder.layers.{i}.fc1.bias')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.linear2.weight', f'model.encoder.layers.{i}.fc2.weight')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.linear2.bias', f'model.encoder.layers.{i}.fc2.bias')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.norm2.weight', f'model.encoder.layers.{i}.final_layer_norm.weight')						)
				rename_keys.append((f'transformer.encoder.layers.{i}.norm2.bias', f'model.encoder.layers.{i}.final_layer_norm.bias')						)

		# transformer decoder
		for i in range(config.decoder_layers						):
				rename_keys.append((f'transformer.decoder.layers.{i}.cross_attn.sampling_offsets.weight', f'model.decoder.layers.{i}.encoder_attn.sampling_offsets.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.cross_attn.sampling_offsets.bias', f'model.decoder.layers.{i}.encoder_attn.sampling_offsets.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.cross_attn.attention_weights.weight', f'model.decoder.layers.{i}.encoder_attn.attention_weights.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.cross_attn.attention_weights.bias', f'model.decoder.layers.{i}.encoder_attn.attention_weights.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.cross_attn.value_proj.weight', f'model.decoder.layers.{i}.encoder_attn.value_proj.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.cross_attn.value_proj.bias', f'model.decoder.layers.{i}.encoder_attn.value_proj.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.cross_attn.output_proj.weight', f'model.decoder.layers.{i}.encoder_attn.output_proj.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.cross_attn.output_proj.bias', f'model.decoder.layers.{i}.encoder_attn.output_proj.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.norm1.weight', f'model.decoder.layers.{i}.encoder_attn_layer_norm.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.norm1.bias', f'model.decoder.layers.{i}.encoder_attn_layer_norm.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.self_attn.out_proj.weight', f'model.decoder.layers.{i}.self_attn.out_proj.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.self_attn.out_proj.bias', f'model.decoder.layers.{i}.self_attn.out_proj.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.norm2.weight', f'model.decoder.layers.{i}.self_attn_layer_norm.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.norm2.bias', f'model.decoder.layers.{i}.self_attn_layer_norm.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.linear1.weight', f'model.decoder.layers.{i}.fc1.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.linear1.bias', f'model.decoder.layers.{i}.fc1.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.linear2.weight', f'model.decoder.layers.{i}.fc2.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.linear2.bias', f'model.decoder.layers.{i}.fc2.bias')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.norm3.weight', f'model.decoder.layers.{i}.final_layer_norm.weight')						)
				rename_keys.append((f'transformer.decoder.layers.{i}.norm3.bias', f'model.decoder.layers.{i}.final_layer_norm.bias')						)

		# fmt: on

		return rename_keys

def        a						(      _UpperCAmelCase							:					Tuple ,   _UpperCAmelCase							:					str ,   _UpperCAmelCase							:					Union[str, Any]						):







		'''simple docstring'''





		__UpperCAmelCase    :     Optional[int]													=	dct.pop(_UpperCAmelCase						)
		__UpperCAmelCase    :     List[Any]													=	val

def        a						(      _UpperCAmelCase							:					Dict ,   _UpperCAmelCase							:					List[Any]						):







		'''simple docstring'''





		__UpperCAmelCase    :     List[str]													=	[int(backbone_config.embed_dim * 2**i						) for i in range(len(backbone_config.depths						)						)]
		for i in range(len(backbone_config.depths						)						):
				__UpperCAmelCase    :     str													=	num_features[i]
				for j in range(backbone_config.depths[i]						):
						# fmt: off
						# read in weights + bias of input projection layer (in original implementation, this is a single matrix + bias)
						__UpperCAmelCase    :     List[str]													=	state_dict.pop(f'backbone.0.body.layers.{i}.blocks.{j}.attn.qkv.weight'						)
						__UpperCAmelCase    :     List[Any]													=	state_dict.pop(f'backbone.0.body.layers.{i}.blocks.{j}.attn.qkv.bias'						)
						# next, add query, keys and values (in that order) to the state dict
						__UpperCAmelCase    :     Dict													=	in_proj_weight[:dim, :]
						__UpperCAmelCase    :     List[str]													=	in_proj_bias[: dim]
						__UpperCAmelCase    :     str													=	in_proj_weight[
						    dim : dim * 2, :
						]
						__UpperCAmelCase    :     Any													=	in_proj_bias[
						    dim : dim * 2
						]
						__UpperCAmelCase    :     Tuple													=	in_proj_weight[
						    -dim :, :
						]
						__UpperCAmelCase    :     int													=	in_proj_bias[-dim :]
						# fmt: on

def        a						(      _UpperCAmelCase							:					Optional[int] ,   _UpperCAmelCase							:					Any						):







		'''simple docstring'''





		__UpperCAmelCase    :     int													=	config.d_model
		for i in range(config.decoder_layers						):
				# read in weights + bias of input projection layer of self-attention
				__UpperCAmelCase    :     List[str]													=	state_dict.pop(f'transformer.decoder.layers.{i}.self_attn.in_proj_weight'						)
				__UpperCAmelCase    :     Tuple													=	state_dict.pop(f'transformer.decoder.layers.{i}.self_attn.in_proj_bias'						)
				# next, add query, keys and values (in that order) to the state dict
				__UpperCAmelCase    :     Union[str, Any]													=	in_proj_weight[:hidden_size, :]
				__UpperCAmelCase    :     List[Any]													=	in_proj_bias[:hidden_size]
				__UpperCAmelCase    :     int													=	in_proj_weight[
				    hidden_size : hidden_size * 2, :
				]
				__UpperCAmelCase    :     str													=	in_proj_bias[hidden_size : hidden_size * 2]
				__UpperCAmelCase    :     Tuple													=	in_proj_weight[-hidden_size:, :]
				__UpperCAmelCase    :     Optional[Any]													=	in_proj_bias[-hidden_size:]

def        a						(      ):







		'''simple docstring'''





		__UpperCAmelCase    :     Union[str, Any]													=	'''http://images.cocodataset.org/val2017/000000039769.jpg'''
		__UpperCAmelCase    :     int													=	Image.open(requests.get(_UpperCAmelCase ,   stream=_UpperCAmelCase						).raw						)

		return im

@torch.no_grad()
def        a						(      _UpperCAmelCase							:					str ,   _UpperCAmelCase							:					List[Any] ,   _UpperCAmelCase							:					List[str]						):







		'''simple docstring'''





		__UpperCAmelCase    :     Tuple													=	get_deta_config(_UpperCAmelCase						)

		# load original state dict
		if model_name == "deta-swin-large":
				__UpperCAmelCase    :     Dict													=	hf_hub_download(repo_id='''nielsr/deta-checkpoints''' ,   filename='''adet_swin_ft.pth'''						)
		elif model_name == "deta-swin-large-o365":
				__UpperCAmelCase    :     Any													=	hf_hub_download(repo_id='''jozhang97/deta-swin-l-o365''' ,   filename='''deta_swin_pt_o365.pth'''						)
		else:
				raise ValueError(f'Model name {model_name} not supported'						)

		__UpperCAmelCase    :     str													=	torch.load(_UpperCAmelCase ,   map_location='''cpu'''						)['''model''']

		# original state dict
		for name, param in state_dict.items():
				print(_UpperCAmelCase ,   param.shape						)

		# rename keys
		__UpperCAmelCase    :     int													=	create_rename_keys(_UpperCAmelCase						)
		for src, dest in rename_keys:
				rename_key(_UpperCAmelCase ,   _UpperCAmelCase ,   _UpperCAmelCase						)
		read_in_swin_q_k_v(_UpperCAmelCase ,   config.backbone_config						)
		read_in_decoder_q_k_v(_UpperCAmelCase ,   _UpperCAmelCase						)

		# fix some prefixes
		for key in state_dict.copy().keys():
				if "transformer.decoder.class_embed" in key or "transformer.decoder.bbox_embed" in key:
						__UpperCAmelCase    :     Optional[Any]													=	state_dict.pop(_UpperCAmelCase						)
						__UpperCAmelCase    :     Union[str, Any]													=	val
				if "input_proj" in key:
						__UpperCAmelCase    :     Union[str, Any]													=	state_dict.pop(_UpperCAmelCase						)
						__UpperCAmelCase    :     List[str]													=	val
				if "level_embed" in key or "pos_trans" in key or "pix_trans" in key or "enc_output" in key:
						__UpperCAmelCase    :     Union[str, Any]													=	state_dict.pop(_UpperCAmelCase						)
						__UpperCAmelCase    :     Union[str, Any]													=	val

    # finally, create HuggingFace model and load state dict
		__UpperCAmelCase    :     Union[str, Any]													=	DetaForObjectDetection(_UpperCAmelCase						)
		model.load_state_dict(_UpperCAmelCase						)
		model.eval()

		__UpperCAmelCase    :     Optional[int]													=	'''cuda''' if torch.cuda.is_available() else '''cpu'''
		model.to(_UpperCAmelCase						)

		# load image processor
		__UpperCAmelCase    :     str													=	DetaImageProcessor(format='''coco_detection'''						)

		# verify our conversion on image
		__UpperCAmelCase    :     str													=	prepare_img()
		__UpperCAmelCase    :     Optional[int]													=	processor(images=_UpperCAmelCase ,   return_tensors='''pt'''						)
		__UpperCAmelCase    :     List[Any]													=	encoding['''pixel_values''']
		__UpperCAmelCase    :     List[str]													=	model(pixel_values.to(_UpperCAmelCase						)						)

		# verify logits
		print('''Logits:''' ,   outputs.logits[0, :3, :3]						)
		print('''Boxes:''' ,   outputs.pred_boxes[0, :3, :3]						)
		if model_name == "deta-swin-large":
				__UpperCAmelCase    :     str													=	torch.tensor(
				    [[-7.63_08, -2.84_85, -5.37_37], [-7.20_37, -4.55_05, -4.80_27], [-7.29_43, -4.26_11, -4.66_17]]						)
				__UpperCAmelCase    :     Union[str, Any]													=	torch.tensor([[0.49_87, 0.49_69, 0.99_99], [0.25_49, 0.54_98, 0.48_05], [0.54_98, 0.27_57, 0.05_69]]						)
		elif model_name == "deta-swin-large-o365":
				__UpperCAmelCase    :     Optional[Any]													=	torch.tensor(
				    [[-8.01_22, -3.57_20, -4.97_17], [-8.15_47, -3.68_86, -4.63_89], [-7.66_10, -3.61_94, -5.01_34]]						)
				__UpperCAmelCase    :     str													=	torch.tensor([[0.25_23, 0.55_49, 0.48_81], [0.77_15, 0.41_49, 0.46_01], [0.55_03, 0.27_53, 0.05_75]]						)
		assert torch.allclose(outputs.logits[0, :3, :3] ,   expected_logits.to(_UpperCAmelCase						) ,   atol=1e-4						)
		assert torch.allclose(outputs.pred_boxes[0, :3, :3] ,   expected_boxes.to(_UpperCAmelCase						) ,   atol=1e-4						)
		print('''Everything ok!'''						)

		if pytorch_dump_folder_path:
				# Save model and processor
				logger.info(f'Saving PyTorch model and processor to {pytorch_dump_folder_path}...'						)
				Path(_UpperCAmelCase						).mkdir(exist_ok=_UpperCAmelCase						)
				model.save_pretrained(_UpperCAmelCase						)
				processor.save_pretrained(_UpperCAmelCase						)

		# Push to hub
		if push_to_hub:
				print('''Pushing model and processor to hub...'''						)
				model.push_to_hub(f'jozhang97/{model_name}'						)
				processor.push_to_hub(f'jozhang97/{model_name}'						)


if __name__ == "__main__":
				__A   			=argparse.ArgumentParser()

				parser.add_argument(
				    "--model_name",
				    type=str,
				    default="deta-swin-large",
				    choices=["deta-swin-large", "deta-swin-large-o365"],
				    help="Name of the model you'd like to convert.",
				)
				parser.add_argument(
				    "--pytorch_dump_folder_path",
				    default=None,
				    type=str,
				    help="Path to the folder to output PyTorch model.",
				)
				parser.add_argument(
				    "--push_to_hub", action="store_true", help="Whether or not to push the converted model to the 🤗 hub."
				)
				__A   			=parser.parse_args()
				convert_deta_checkpoint(args.model_name, args.pytorch_dump_folder_path, args.push_to_hub)





