



import inspect
import tempfile
import unittest

from huggingface_hub import hf_hub_download

from transformers import is_torch_available
from transformers.testing_utils import is_flaky, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


_lowercase: Union[str, Any]      			=		1E-4

if is_torch_available():
				import torch

				from transformers import AutoformerConfig, AutoformerForPrediction, AutoformerModel
				from transformers.models.autoformer.modeling_autoformer import AutoformerDecoder, AutoformerEncoder



@require_torch
class 	_lowercase							:





	"""simple docstring"""




	def __init__(self		,       lowerCamelCase_		,       lowerCamelCase_=16		,       lowerCamelCase_=13		,       lowerCamelCase_=7		,       lowerCamelCase_=14		,       lowerCamelCase_=10		,       lowerCamelCase_=19		,       lowerCamelCase_=5		,       lowerCamelCase_=4		,       lowerCamelCase_=True		,       lowerCamelCase_=16		,       lowerCamelCase_=2		,       lowerCamelCase_=4		,       lowerCamelCase_=4		,       lowerCamelCase_="gelu"		,       lowerCamelCase_=0.1		,       lowerCamelCase_=0.1		,       lowerCamelCase_=[1, 2, 3, 4, 5]		,       lowerCamelCase_=25		,       lowerCamelCase_=5		,       ):
						"""simple docstring"""

						a					     =   d_model
						a					     =   parent
						a					     =   batch_size
						a					     =   prediction_length
						a					     =   context_length
						a					     =   cardinality
						a					     =   num_time_features
						a					     =   lags_sequence
						a					     =   embedding_dimension
						a					     =   is_training
						a					     =   hidden_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					     =   context_length
						a					     =   prediction_length + label_length
						a					     =   label_length

						a					     =   moving_average
						a					     =   autocorrelation_factor




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						return AutoformerConfig(
						    d_model=self.d_model		,       encoder_layers=self.num_hidden_layers		,       decoder_layers=self.num_hidden_layers		,       encoder_attention_heads=self.num_attention_heads		,       decoder_attention_heads=self.num_attention_heads		,       encoder_ffn_dim=self.intermediate_size		,       decoder_ffn_dim=self.intermediate_size		,       dropout=self.hidden_dropout_prob		,       attention_dropout=self.attention_probs_dropout_prob		,       prediction_length=self.prediction_length		,       context_length=self.context_length		,       label_length=self.label_length		,       lags_sequence=self.lags_sequence		,       num_time_features=self.num_time_features		,       num_static_categorical_features=1		,       cardinality=[self.cardinality]		,       embedding_dimension=[self.embedding_dimension]		,       moving_average=self.moving_average		,       )




	def      UpperCamelCase_       (self		,       lowerCamelCase_		):
						"""simple docstring"""

						a					     =   config.context_length + max(config.lags_sequence		)

						a					     =   ids_tensor([self.batch_size, 1]		,       config.cardinality[0]		)
						a					     =   floats_tensor([self.batch_size, _past_length, config.num_time_features]		)
						a					     =   floats_tensor([self.batch_size, _past_length]		)
						a					     =   floats_tensor([self.batch_size, _past_length]		) > 0.5

						# decoder inputs
						a					     =   floats_tensor([self.batch_size, config.prediction_length, config.num_time_features]		)
						a					     =   floats_tensor([self.batch_size, config.prediction_length]		)

						a					     =   {
						    "past_values": past_values,
						    "static_categorical_features": static_categorical_features,
						    "past_time_features": past_time_features,
						    "past_observed_mask": past_observed_mask,
						    "future_time_features": future_time_features,
						    "future_values": future_values,
						}
						return inputs_dict




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a					     =   self.get_config()
						a					     =   self.prepare_autoformer_inputs_dict(lowerCamelCase_		)
						return config, inputs_dict




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a     ,				a					     =   self.prepare_config_and_inputs()
						return config, inputs_dict




	def      UpperCamelCase_       (self		,       lowerCamelCase_		,       lowerCamelCase_		):
						"""simple docstring"""

						a					     =   AutoformerModel(config=lowerCamelCase_		).to(lowerCamelCase_		).eval()
						a					     =   model(**lowerCamelCase_		)

						a					     =   outputs.encoder_last_hidden_state
						a					     =   outputs.last_hidden_state

						with tempfile.TemporaryDirectory() as tmpdirname:
											a					     =   model.get_encoder()
											encoder.save_pretrained(lowerCamelCase_		)
											a					     =   AutoformerEncoder.from_pretrained(lowerCamelCase_		).to(lowerCamelCase_		)

						a     ,				a     ,				a     ,				a     ,				a					     =   model.create_network_inputs(**lowerCamelCase_		)
						a     ,				a					     =   model.decomposition_layer(transformer_inputs[:, : config.context_length, ...]		)

						a					     =   torch.cat(
						    (transformer_inputs[:, : config.context_length, ...], feature[:, : config.context_length, ...])		,       dim=-1		,       )
						a					     =   encoder(inputs_embeds=lowerCamelCase_		)[0]
						self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1E-3		)

						a					     =   (
						    torch.mean(transformer_inputs[:, : config.context_length, ...]		,       dim=1		)
						    .unsqueeze(1		)
						    .repeat(1		,       config.prediction_length		,       1		)
						)
						a					     =   torch.zeros(
						    [transformer_inputs.shape[0], config.prediction_length, transformer_inputs.shape[2]]		,       device=enc_input.device		,       )

						a					     =   torch.cat(
						    (
						        torch.cat((seasonal_input[:, -config.label_length :, ...], zeros)		,       dim=1		),
						        feature[:, config.context_length - config.label_length :, ...],
						    )		,       dim=-1		,       )
						a					     =   torch.cat(
						    (
						        torch.cat((trend_input[:, -config.label_length :, ...], mean)		,       dim=1		),
						        feature[:, config.context_length - config.label_length :, ...],
						    )		,       dim=-1		,       )

						with tempfile.TemporaryDirectory() as tmpdirname:
											a					     =   model.get_decoder()
											decoder.save_pretrained(lowerCamelCase_		)
											a					     =   AutoformerDecoder.from_pretrained(lowerCamelCase_		).to(lowerCamelCase_		)

						a					     =   decoder(
						    trend=lowerCamelCase_		,       inputs_embeds=lowerCamelCase_		,       encoder_hidden_states=lowerCamelCase_		,       )[0]

						self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1E-3		)




@require_torch
class 	_lowercase							(   lowerCAmelCase,      lowerCAmelCase,      unittest.TestCase	):





	"""simple docstring"""
	__A							=							(AutoformerModel, AutoformerForPrediction) if is_torch_available() else ()
	__A							=							(AutoformerForPrediction,) if is_torch_available() else ()
	__A							=							{"feature-extraction": AutoformerModel} if is_torch_available() else {}
	__A							=							False
	__A							=							False
	__A							=							False
	__A							=							False
	__A							=							False
	__A							=							False




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a					     =   AutoformerModelTester(self		)
						a					     =   ConfigTester(self		,       config_class=lowerCamelCase_		,       has_text_modality=lowerCamelCase_		)




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						self.config_tester.run_common_tests()




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a     ,				a					     =   self.model_tester.prepare_config_and_inputs()
						for model_class in self.all_model_classes:
											a					     =   model_class(lowerCamelCase_		)

											with tempfile.TemporaryDirectory() as tmpdirname:
																model.save_pretrained(lowerCamelCase_		)
																a     ,				a					     =   model_class.from_pretrained(lowerCamelCase_		,       output_loading_info=lowerCamelCase_		)
											self.assertEqual(info["missing_keys"]		,       []		)




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a					     =   self.model_tester.prepare_config_and_inputs_for_common()
						self.model_tester.check_encoder_decoder_model_standalone(*lowerCamelCase_		)




	@unittest.skip(reason="Model has no tokens embeddings"		)
	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						pass




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a					     =   inspect.signature(getattr(lowerCamelCase_		,       "forward"		)		)
						# The main input is the name of the argument after `self`
						a					     =   list(model_signature.parameters.keys()		)[1]
						self.assertEqual(AutoformerModel.main_input_name		,       lowerCamelCase_		)




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a     ,				a					     =   self.model_tester.prepare_config_and_inputs_for_common()

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

											a					     =   [
											    "past_values",
											    "past_time_features",
											    "past_observed_mask",
											    "static_categorical_features",
											    "static_real_features",
											    "future_values",
											    "future_time_features",
											]

											if model.__class__.__name__ in ["AutoformerForPrediction"]:
																expected_arg_names.append("future_observed_mask"		)

											expected_arg_names.extend(
											    [
											        "decoder_attention_mask",
											        "head_mask",
											        "decoder_head_mask",
											        "cross_attn_head_mask",
											        "encoder_outputs",
											        "past_key_values",
											        "output_hidden_states",
											        "output_attentions",
											        "use_cache",
											        "return_dict",
											    ]		)

											self.assertListEqual(arg_names[: len(lowerCamelCase_		)]		,       lowerCamelCase_		)




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a     ,				a					     =   self.model_tester.prepare_config_and_inputs_for_common()
						a					     =   True

						a					     =   getattr(self.model_tester		,       "seq_length"		,       lowerCamelCase_		)
						a					     =   getattr(self.model_tester		,       "decoder_seq_length"		,       lowerCamelCase_		)
						a					     =   getattr(self.model_tester		,       "encoder_seq_length"		,       lowerCamelCase_		)
						a					     =   getattr(self.model_tester		,       "d_model"		,       lowerCamelCase_		)
						a					     =   getattr(self.model_tester		,       "num_attention_heads"		,       lowerCamelCase_		)
						a					     =   d_model // num_attention_heads

						for model_class in self.all_model_classes:
											a					     =   True
											a					     =   False
											a					     =   True
											a					     =   model_class(lowerCamelCase_		)
											model.to(lowerCamelCase_		)
											model.eval()
											with torch.no_grad():
																a					     =   model(**self._prepare_for_class(lowerCamelCase_		,       lowerCamelCase_		)		)
											a					     =   outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
											self.assertEqual(len(lowerCamelCase_		)		,       self.model_tester.num_hidden_layers		)

											# check that output_attentions also work using config
											del inputs_dict["output_attentions"]
											a					     =   True
											a					     =   model_class(lowerCamelCase_		)
											model.to(lowerCamelCase_		)
											model.eval()
											with torch.no_grad():
																a					     =   model(**self._prepare_for_class(lowerCamelCase_		,       lowerCamelCase_		)		)
											a					     =   outputs.encoder_attentions
											self.assertEqual(len(lowerCamelCase_		)		,       self.model_tester.num_hidden_layers		)

											self.assertListEqual(
											    list(attentions[0].shape[-3:]		)		,       [self.model_tester.num_attention_heads, encoder_seq_length, dim]		,       )
											a					     =   len(lowerCamelCase_		)

											a					     =   7

											if "last_hidden_state" in outputs:
																correct_outlen += 1

											if "trend" in outputs:
																correct_outlen += 1

											if "past_key_values" in outputs:
																correct_outlen += 1  # past_key_values have been returned

											if "loss" in outputs:
																correct_outlen += 1

											if "params" in outputs:
																correct_outlen += 1

											self.assertEqual(lowerCamelCase_		,       lowerCamelCase_		)

											# decoder attentions
											a					     =   outputs.decoder_attentions
											self.assertIsInstance(lowerCamelCase_		,       (list, tuple)		)
											self.assertEqual(len(lowerCamelCase_		)		,       self.model_tester.num_hidden_layers		)
											self.assertListEqual(
											    list(decoder_attentions[0].shape[-3:]		)		,       [self.model_tester.num_attention_heads, decoder_seq_length, dim]		,       )

											# cross attentions
											a					     =   outputs.cross_attentions
											self.assertIsInstance(lowerCamelCase_		,       (list, tuple)		)
											self.assertEqual(len(lowerCamelCase_		)		,       self.model_tester.num_hidden_layers		)
											self.assertListEqual(
											    list(cross_attentions[0].shape[-3:]		)		,       [self.model_tester.num_attention_heads, decoder_seq_length, dim]		,       )

						# Check attention is always last and order is fine
						a					     =   True
						a					     =   True
						a					     =   model_class(lowerCamelCase_		)
						model.to(lowerCamelCase_		)
						model.eval()
						with torch.no_grad():
											a					     =   model(**self._prepare_for_class(lowerCamelCase_		,       lowerCamelCase_		)		)

						self.assertEqual(out_len + 2		,       len(lowerCamelCase_		)		)

						a					     =   outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions

						self.assertEqual(len(lowerCamelCase_		)		,       self.model_tester.num_hidden_layers		)
						self.assertListEqual(
						    list(self_attentions[0].shape[-3:]		)		,       [self.model_tester.num_attention_heads, encoder_seq_length, dim]		,       )




	@is_flaky()
	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						super().test_retain_grad_hidden_states_attentions()






def     a(      A       :    int="train-batch.pt"       )		->       Dict:
					"""simple docstring"""





					a					     =   hf_hub_download(repo_id="hf-internal-testing/tourism-monthly-batch" ,     filename=A ,     repo_type="dataset"       )
					a					     =   torch.load(A ,     map_location=A       )
					return batch







@require_torch
@slow
class 	_lowercase							(   unittest.TestCase	):





	"""simple docstring"""




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a					     =   AutoformerModel.from_pretrained("huggingface/autoformer-tourism-monthly"		).to(lowerCamelCase_		)
						a					     =   prepare_batch()

						with torch.no_grad():
											a					     =   model(
											    past_values=batch["past_values"]		,       past_time_features=batch["past_time_features"]		,       past_observed_mask=batch["past_observed_mask"]		,       static_categorical_features=batch["static_categorical_features"]		,       future_values=batch["future_values"]		,       future_time_features=batch["future_time_features"]		,       )[0]

						a					     =   torch.Size(
						    (64, model.config.prediction_length + model.config.label_length, model.config.feature_size)		)
						self.assertEqual(output.shape		,       lowerCamelCase_		)

						a					     =   torch.tensor(
						    [[0.3593, -1.3398, 0.6330], [0.2279, 1.5396, -0.1792], [0.0450, 1.3225, -0.2335]]		,       device=lowerCamelCase_		)
						self.assertTrue(torch.allclose(output[0, :3, :3]		,       lowerCamelCase_		,       atol=lowerCamelCase_		)		)




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a					     =   AutoformerForPrediction.from_pretrained("huggingface/autoformer-tourism-monthly"		).to(lowerCamelCase_		)
						a					     =   prepare_batch("val-batch.pt"		)
						with torch.no_grad():
											a					     =   model(
											    past_values=batch["past_values"]		,       past_time_features=batch["past_time_features"]		,       past_observed_mask=batch["past_observed_mask"]		,       static_categorical_features=batch["static_categorical_features"]		,       ).encoder_last_hidden_state
						a					     =   torch.Size((64, model.config.context_length, model.config.d_model)		)
						self.assertEqual(output.shape		,       lowerCamelCase_		)

						a					     =   torch.tensor(
						    [[-0.0734, -0.9036, 0.8358], [4.7186, 2.4113, 1.9581], [1.7953, 2.3558, 1.2970]]		,       device=lowerCamelCase_		)
						self.assertTrue(torch.allclose(output[0, :3, :3]		,       lowerCamelCase_		,       atol=lowerCamelCase_		)		)




	def      UpperCamelCase_       (self		):
						"""simple docstring"""

						a					     =   AutoformerForPrediction.from_pretrained("huggingface/autoformer-tourism-monthly"		).to(lowerCamelCase_		)
						a					     =   prepare_batch("val-batch.pt"		)
						with torch.no_grad():
											a					     =   model.generate(
											    static_categorical_features=batch["static_categorical_features"]		,       past_time_features=batch["past_time_features"]		,       past_values=batch["past_values"]		,       future_time_features=batch["future_time_features"]		,       past_observed_mask=batch["past_observed_mask"]		,       )
						a					     =   torch.Size((64, model.config.num_parallel_samples, model.config.prediction_length)		)
						self.assertEqual(outputs.sequences.shape		,       lowerCamelCase_		)

						a					     =   torch.tensor([3130.6763, 4056.5293, 7053.0786]		,       device=lowerCamelCase_		)
						a					     =   outputs.sequences.mean(dim=1		)
						self.assertTrue(torch.allclose(mean_prediction[0, -3:]		,       lowerCamelCase_		,       rtol=1E-1		)		)





from collections import defaultdict
from typing import Optional

from ..image_utils import load_image
from ..utils import (
    add_end_docstrings,
    is_torch_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, ChunkPipeline


if is_torch_available():
				import torch

				from ..models.auto.modeling_auto import MODEL_FOR_MASK_GENERATION_MAPPING

_lowercase: Any      			=		logging.get_logger(__name__)



@add_end_docstrings(lowerCAmelCase	)
class 	_lowercase							(   lowerCAmelCase	):





	"""simple docstring"""




	def __init__(self		,       **lowerCamelCase_		):
						"""simple docstring"""

						super().__init__(**lowerCamelCase_		)
						requires_backends(self		,       "vision"		)
						requires_backends(self		,       "torch"		)

						if self.framework != "pt":
											raise ValueError(F'''The {self.__class__} is only available in PyTorch.'''		)

						self.check_model_type(lowerCamelCase_		)




	def      UpperCamelCase_       (self		,       **lowerCamelCase_		):
						"""simple docstring"""

						a					     =   {}
						a					     =   {}
						a					     =   {}
						# preprocess args
						if "points_per_batch" in kwargs:
											a					     =   kwargs["points_per_batch"]
						if "points_per_crop" in kwargs:
											a					     =   kwargs["points_per_crop"]
						if "crops_n_layers" in kwargs:
											a					     =   kwargs["crops_n_layers"]
						if "crop_overlap_ratio" in kwargs:
											a					     =   kwargs["crop_overlap_ratio"]
						if "crop_n_points_downscale_factor" in kwargs:
											a					     =   kwargs["crop_n_points_downscale_factor"]
						# postprocess args
						if "pred_iou_thresh" in kwargs:
											a					     =   kwargs["pred_iou_thresh"]
						if "stability_score_offset" in kwargs:
											a					     =   kwargs["stability_score_offset"]
						if "mask_threshold" in kwargs:
											a					     =   kwargs["mask_threshold"]
						if "stability_score_thresh" in kwargs:
											a					     =   kwargs["stability_score_thresh"]
						if "crops_nms_thresh" in kwargs:
											a					     =   kwargs["crops_nms_thresh"]
						if "output_rle_mask" in kwargs:
											a					     =   kwargs["output_rle_mask"]
						if "output_bboxes_mask" in kwargs:
											a					     =   kwargs["output_bboxes_mask"]
						return preprocess_kwargs, forward_params, postprocess_kwargs




	def __call__(self		,       lowerCamelCase_		,       *lowerCamelCase_		,       lowerCamelCase_=None		,       lowerCamelCase_=None		,       **lowerCamelCase_		):
						"""simple docstring"""

						return super().__call__(lowerCamelCase_		,       *lowerCamelCase_		,       num_workers=lowerCamelCase_		,       batch_size=lowerCamelCase_		,       **lowerCamelCase_		)




	def      UpperCamelCase_       (self		,       lowerCamelCase_		,       lowerCamelCase_=64		,       lowerCamelCase_ = 0		,       lowerCamelCase_ = 512 / 1500		,       lowerCamelCase_ = 32		,       lowerCamelCase_ = 1		,       ):
						"""simple docstring"""

						a					     =   load_image(lowerCamelCase_		)
						a					     =   self.image_processor.size["longest_edge"]
						a     ,				a     ,				a     ,				a					     =   self.image_processor.generate_crop_boxes(
						    lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		)
						a					     =   self.image_processor(images=lowerCamelCase_		,       return_tensors="pt"		)

						with self.device_placement():
											if self.framework == "pt":
																a					     =   self.get_inference_context()
																with inference_context():
																					a					     =   self._ensure_tensor_on_device(lowerCamelCase_		,       device=self.device		)
																					a					     =   self.model.get_image_embeddings(model_inputs.pop("pixel_values"		)		)
																					a					     =   image_embeddings

						a					     =   grid_points.shape[1]
						a					     =   points_per_batch if points_per_batch is not None else n_points

						if points_per_batch <= 0:
											raise ValueError(
											    "Cannot have points_per_batch<=0. Must be >=1 to returned batched outputs. "
											    "To return all points at once, set points_per_batch to None"		)

						for i in range(0		,       lowerCamelCase_		,       lowerCamelCase_		):
											a					     =   grid_points[:, i : i + points_per_batch, :, :]
											a					     =   input_labels[:, i : i + points_per_batch]
											a					     =   i == n_points - points_per_batch
											yield {
											    "input_points": batched_points,
											    "input_labels": labels,
											    "input_boxes": crop_boxes,
											    "is_last": is_last,
											    **model_inputs,
											}




	def      UpperCamelCase_       (self		,       lowerCamelCase_		,       lowerCamelCase_=0.88		,       lowerCamelCase_=0.95		,       lowerCamelCase_=0		,       lowerCamelCase_=1		,       ):
						"""simple docstring"""

						a					     =   model_inputs.pop("input_boxes"		)
						a					     =   model_inputs.pop("is_last"		)
						a					     =   model_inputs.pop("original_sizes"		).tolist()
						a					     =   model_inputs.pop("reshaped_input_sizes"		).tolist()

						a					     =   self.model(**lowerCamelCase_		)

						# post processing happens here in order to avoid CPU GPU copies of ALL the masks
						a					     =   model_outputs["pred_masks"]
						a					     =   self.image_processor.post_process_masks(
						    lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       binarize=lowerCamelCase_		)
						a					     =   model_outputs["iou_scores"]
						a     ,				a     ,				a					     =   self.image_processor.filter_masks(
						    masks[0]		,       iou_scores[0]		,       original_sizes[0]		,       input_boxes[0]		,       lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       )
						return {
						    "masks": masks,
						    "is_last": is_last,
						    "boxes": boxes,
						    "iou_scores": iou_scores,
						}




	def      UpperCamelCase_       (self		,       lowerCamelCase_		,       lowerCamelCase_=False		,       lowerCamelCase_=False		,       lowerCamelCase_=0.7		,       ):
						"""simple docstring"""

						a					     =   []
						a					     =   []
						a					     =   []
						for model_output in model_outputs:
											all_scores.append(model_output.pop("iou_scores"		)		)
											all_masks.extend(model_output.pop("masks"		)		)
											all_boxes.append(model_output.pop("boxes"		)		)

						a					     =   torch.cat(lowerCamelCase_		)
						a					     =   torch.cat(lowerCamelCase_		)
						a     ,				a     ,				a     ,				a					     =   self.image_processor.post_process_for_mask_generation(
						    lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_		)

						a					     =   defaultdict(lowerCamelCase_		)
						for output in model_outputs:
											for k, v in output.items():
																extra[k].append(lowerCamelCase_		)

						a					     =   {}
						if output_rle_mask:
											a					     =   rle_mask

						if output_bboxes_mask:
											a					     =   bounding_boxes

						return {"masks": output_masks, "scores": iou_scores, **optional, **extra}
