




import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

	if is_vision_available():
		from transformers import MaskFormerImageProcessor

if is_vision_available():
	from PIL import Image
class        __snake_case  :



				def __init__(      self      :		Optional[int]		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Optional[int]=2		,	_UpperCAmelCase      :		Any=True		,	_UpperCAmelCase      :		Tuple=False		,	_UpperCAmelCase      :		Any=10		,	_UpperCAmelCase      :		str=3		,	_UpperCAmelCase      :		List[str]=32 * 4		,	_UpperCAmelCase      :		List[Any]=32 * 6		,	_UpperCAmelCase      :		str=4		,	_UpperCAmelCase      :		Any=32		,	)  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[int]										=      parent
								_lowerCAmelCase    :    List[Any]										=      batch_size
								_lowerCAmelCase    :    Dict										=      is_training
								_lowerCAmelCase    :    int										=      use_auxiliary_loss
								_lowerCAmelCase    :    Optional[Any]										=      num_queries
								_lowerCAmelCase    :    List[Any]										=      num_channels
								_lowerCAmelCase    :    int										=      min_size
								_lowerCAmelCase    :    Dict										=      max_size
								_lowerCAmelCase    :    Optional[Any]										=      num_labels
								_lowerCAmelCase    :    Any										=      mask_feature_size



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]      )  ->    Tuple:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[int]										=      floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]      ).to(
								    _UpperCAmelCase      )

								_lowerCAmelCase    :    Any										=      torch.ones([self.batch_size, self.min_size, self.max_size]		,	device=_UpperCAmelCase      )

								_lowerCAmelCase    :    Union[str, Any]										=      (
								    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]		,	device=_UpperCAmelCase      ) > 0.5
								).float()
								_lowerCAmelCase    :    Any										=      (torch.rand((self.batch_size, self.num_labels)		,	device=_UpperCAmelCase      ) > 0.5).long()

								_lowerCAmelCase    :    List[str]										=      self.get_config()
								return config, pixel_values, pixel_mask, mask_labels, class_labels



				def       SCREAMING_SNAKE_CASE       (      self      :		Any      )  ->    List[Any]:





								'''simple docstring'''




								return MaskFormerConfig.from_backbone_and_decoder_configs(
								    backbone_config=SwinConfig(
								        depths=[1, 1, 1, 1]		,	)		,	decoder_config=DetrConfig(
								        decoder_ffn_dim=128		,	num_queries=self.num_queries		,	decoder_attention_heads=2		,	d_model=self.mask_feature_size		,	)		,	mask_feature_size=self.mask_feature_size		,	fpn_feature_size=self.mask_feature_size		,	num_channels=self.num_channels		,	num_labels=self.num_labels		,	)



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    Dict:





								'''simple docstring'''




								_lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase    :    int										=      self.prepare_config_and_inputs()
								_lowerCAmelCase    :    List[Any]										=      {"""pixel_values""": pixel_values, """pixel_mask""": pixel_mask}
								return config, inputs_dict



				def       SCREAMING_SNAKE_CASE       (      self      :		Any		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		str      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      output.encoder_hidden_states
								_lowerCAmelCase    :    int										=      output.pixel_decoder_hidden_states
								_lowerCAmelCase    :    Any										=      output.transformer_decoder_hidden_states

								self.parent.assertTrue(len(_UpperCAmelCase      )		,	len(config.backbone_config.depths      )      )
								self.parent.assertTrue(len(_UpperCAmelCase      )		,	len(config.backbone_config.depths      )      )
								self.parent.assertTrue(len(_UpperCAmelCase      )		,	config.decoder_config.decoder_layers      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		int=False      )  ->    Tuple:





								'''simple docstring'''




								with torch.no_grad():
												_lowerCAmelCase    :    Union[str, Any]										=      MaskFormerModel(config=_UpperCAmelCase      )
												model.to(_UpperCAmelCase      )
												model.eval()

												_lowerCAmelCase    :    Optional[int]										=      model(pixel_values=_UpperCAmelCase		,	pixel_mask=_UpperCAmelCase      )
												_lowerCAmelCase    :    Optional[Any]										=      model(_UpperCAmelCase		,	output_hidden_states=_UpperCAmelCase      )
								# the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
								# encoder and pixel decoder
								self.parent.assertEqual(
								    output.transformer_decoder_last_hidden_state.shape		,	(self.batch_size, self.num_queries, self.mask_feature_size)		,	)
								# let's ensure the other two hidden state exists
								self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None      )
								self.parent.assertTrue(output.encoder_last_hidden_state is not None      )

								if output_hidden_states:
												self.check_output_hidden_state(_UpperCAmelCase		,	_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		List[Any]		,	_UpperCAmelCase      :		Optional[int]      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      MaskFormerForInstanceSegmentation(config=_UpperCAmelCase      )
								model.to(_UpperCAmelCase      )
								model.eval()

								def comm_check_on_output(_UpperCAmelCase      :		Dict      ):
												# let's still check that all the required stuff is there
												self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None      )
												self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None      )
												self.parent.assertTrue(result.encoder_last_hidden_state is not None      )
												# okay, now we need to check the logits shape
												# due to the encoder compression, masks have a //4 spatial size
												self.parent.assertEqual(
												    result.masks_queries_logits.shape		,	(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)		,	)
												# + 1 for null class
												self.parent.assertEqual(
												    result.class_queries_logits.shape		,	(self.batch_size, self.num_queries, self.num_labels + 1)      )

								with torch.no_grad():
												_lowerCAmelCase    :    List[str]										=      model(pixel_values=_UpperCAmelCase		,	pixel_mask=_UpperCAmelCase      )
												_lowerCAmelCase    :    Optional[Any]										=      model(_UpperCAmelCase      )

												comm_check_on_output(_UpperCAmelCase      )

												_lowerCAmelCase    :    Optional[Any]										=      model(
												    pixel_values=_UpperCAmelCase		,	pixel_mask=_UpperCAmelCase		,	mask_labels=_UpperCAmelCase		,	class_labels=_UpperCAmelCase      )

								comm_check_on_output(_UpperCAmelCase      )

								self.parent.assertTrue(result.loss is not None      )
								self.parent.assertEqual(result.loss.shape		,	torch.Size([1]      )      )






@require_torch
class        __snake_case  (_a						,	_a						,	unittest.TestCase		):
				lowerCAmelCase__				=     (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
				lowerCAmelCase__				=     (
				    {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation}
				    if is_torch_available()
				    else {}
				)

				lowerCAmelCase__				=     False
				lowerCAmelCase__				=     False
				lowerCAmelCase__				=     False
				lowerCAmelCase__				=     False



				def       SCREAMING_SNAKE_CASE       (      self      :		Any      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[int]										=      MaskFormerModelTester(self      )
								_lowerCAmelCase    :    Tuple										=      ConfigTester(self		,	config_class=_UpperCAmelCase		,	has_text_modality=_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		List[str]      )  ->    Tuple:





								'''simple docstring'''




								self.config_tester.run_common_tests()



				def       SCREAMING_SNAKE_CASE       (      self      :		Union[str, Any]      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase					,    _lowerCAmelCase    :    Any										=      self.model_tester.prepare_config_and_inputs_for_common()
								self.model_tester.create_and_check_maskformer_model(_UpperCAmelCase		,	**_UpperCAmelCase		,	output_hidden_states=_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]      )  ->    Optional[int]:





								'''simple docstring'''




								_lowerCAmelCase    :    Union[str, Any]										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*_UpperCAmelCase      )



				@unittest.skip(reason="""MaskFormer does not use inputs_embeds"""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    Any:





								'''simple docstring'''




								pass



				@unittest.skip(reason="""MaskFormer does not have a get_input_embeddings method"""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple      )  ->    Union[str, Any]:





								'''simple docstring'''




								pass



				@unittest.skip(reason="""MaskFormer is not a generative model"""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple      )  ->    Optional[int]:





								'''simple docstring'''




								pass



				@unittest.skip(reason="""MaskFormer does not use token embeddings"""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple      )  ->    Any:





								'''simple docstring'''




								pass



				@require_torch_multi_gpu
				@unittest.skip(
				    reason="""MaskFormer has some layers using `add_module` which doesn't work well with `nn.DataParallel`"""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]      )  ->    Tuple:





								'''simple docstring'''




								pass



				@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		Any      )  ->    Any:





								'''simple docstring'''




								pass



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase					,    _lowerCAmelCase    :    Any										=      self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
												_lowerCAmelCase    :    Optional[Any]										=      model_class(_UpperCAmelCase      )
												_lowerCAmelCase    :    Optional[Any]										=      inspect.signature(model.forward      )
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												_lowerCAmelCase    :    List[str]										=      [*signature.parameters.keys()]

												_lowerCAmelCase    :    str										=      ["""pixel_values"""]
												self.assertListEqual(arg_names[:1]		,	_UpperCAmelCase      )



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    Optional[Any]:





								'''simple docstring'''




								for model_name in ["facebook/maskformer-swin-small-coco"]:
												_lowerCAmelCase    :    List[Any]										=      MaskFormerModel.from_pretrained(_UpperCAmelCase      )
												self.assertIsNotNone(_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Any      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    str										=      (self.model_tester.min_size,) * 2
								_lowerCAmelCase    :    Union[str, Any]										=      {
								    """pixel_values""": torch.randn((2, 3, *size)		,	device=_UpperCAmelCase      ),
								    """mask_labels""": torch.randn((2, 10, *size)		,	device=_UpperCAmelCase      ),
								    """class_labels""": torch.zeros(2		,	10		,	device=_UpperCAmelCase      ).long(),
								}

								_lowerCAmelCase    :    Any										=      MaskFormerForInstanceSegmentation(MaskFormerConfig()      ).to(_UpperCAmelCase      )
								_lowerCAmelCase    :    Tuple										=      model(**_UpperCAmelCase      )
								self.assertTrue(outputs.loss is not None      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase					,    _lowerCAmelCase    :    Tuple										=      self.model_tester.prepare_config_and_inputs_for_common()
								self.model_tester.create_and_check_maskformer_model(_UpperCAmelCase		,	**_UpperCAmelCase		,	output_hidden_states=_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		List[Any]      )  ->    Tuple:





								'''simple docstring'''




								_lowerCAmelCase					,    _lowerCAmelCase    :    str										=      self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
												_lowerCAmelCase    :    Optional[int]										=      model_class(_UpperCAmelCase      ).to(_UpperCAmelCase      )
												_lowerCAmelCase    :    Union[str, Any]										=      model(**_UpperCAmelCase		,	output_attentions=_UpperCAmelCase      )
												self.assertTrue(outputs.attentions is not None      )



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    int:





								'''simple docstring'''




								if not self.model_tester.is_training:
												return
								# only MaskFormerForInstanceSegmentation has the loss
								_lowerCAmelCase    :    Optional[Any]										=      self.all_model_classes[1]
								_lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase    :    Dict										=      self.model_tester.prepare_config_and_inputs()

								_lowerCAmelCase    :    List[Any]										=      model_class(_UpperCAmelCase      )
								model.to(_UpperCAmelCase      )
								model.train()

								_lowerCAmelCase    :    Any										=      model(_UpperCAmelCase		,	mask_labels=_UpperCAmelCase		,	class_labels=_UpperCAmelCase      ).loss
								loss.backward()



				def       SCREAMING_SNAKE_CASE       (      self      :		Union[str, Any]      )  ->    Dict:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      self.all_model_classes[1]
								_lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase					,    _lowerCAmelCase    :    Optional[int]										=      self.model_tester.prepare_config_and_inputs()
								_lowerCAmelCase    :    int										=      True
								_lowerCAmelCase    :    int										=      True

								_lowerCAmelCase    :    Optional[Any]										=      model_class(_UpperCAmelCase      )
								model.to(_UpperCAmelCase      )
								model.train()

								_lowerCAmelCase    :    Tuple										=      model(_UpperCAmelCase		,	mask_labels=_UpperCAmelCase		,	class_labels=_UpperCAmelCase      )

								_lowerCAmelCase    :    Any										=      outputs.encoder_hidden_states[0]
								encoder_hidden_states.retain_grad()

								_lowerCAmelCase    :    List[Any]										=      outputs.pixel_decoder_hidden_states[0]
								pixel_decoder_hidden_states.retain_grad()
								# we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
								_lowerCAmelCase    :    List[Any]										=      outputs.transformer_decoder_hidden_states[0]
								transformer_decoder_hidden_states.retain_grad()

								_lowerCAmelCase    :    Optional[int]										=      outputs.attentions[0]
								attentions.retain_grad()

								outputs.loss.backward(retain_graph=_UpperCAmelCase      )

								self.assertIsNotNone(encoder_hidden_states.grad      )
								self.assertIsNotNone(pixel_decoder_hidden_states.grad      )
								self.assertIsNotNone(transformer_decoder_hidden_states.grad      )
								self.assertIsNotNone(attentions.grad      )






_lowerCamelCase      :  Optional[int]      						=						1e-4




def 							_UpperCAmelCase  ():
				'''simple docstring'''
				_lowerCAmelCase    :    Dict										=      Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""       )
				return image





@require_vision
@slow
class        __snake_case  (unittest.TestCase		):



				@cached_property
				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    str:





								'''simple docstring'''




								return (
								    MaskFormerImageProcessor.from_pretrained("""facebook/maskformer-swin-small-coco"""      )
								    if is_vision_available()
								    else None
								)



				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    Optional[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[Any]										=      MaskFormerModel.from_pretrained("""facebook/maskformer-swin-small-coco"""      ).to(_UpperCAmelCase      )
								_lowerCAmelCase    :    List[str]										=      self.default_image_processor
								_lowerCAmelCase    :    Any										=      prepare_img()
								_lowerCAmelCase    :    Tuple										=      image_processor(_UpperCAmelCase		,	return_tensors="""pt"""      ).to(_UpperCAmelCase      )
								_lowerCAmelCase    :    List[str]										=      inputs["""pixel_values"""].shape
								# check size is divisible by 32
								self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0      )
								# check size
								self.assertEqual(_UpperCAmelCase		,	(1, 3, 800, 1088)      )

								with torch.no_grad():
												_lowerCAmelCase    :    Optional[int]										=      model(**_UpperCAmelCase      )

								_lowerCAmelCase    :    List[str]										=      torch.tensor(
								    [[-0.0482, 0.9228, 0.4951], [-0.2547, 0.8017, 0.8527], [-0.0069, 0.3385, -0.0089]]      ).to(_UpperCAmelCase      )
								self.assertTrue(
								    torch.allclose(
								        outputs.encoder_last_hidden_state[0, 0, :3, :3]		,	_UpperCAmelCase		,	atol=_UpperCAmelCase      )      )

								_lowerCAmelCase    :    str										=      torch.tensor(
								    [[-0.8422, -0.8434, -0.9718], [-1.0144, -0.5565, -0.4195], [-1.0038, -0.4484, -0.1961]]      ).to(_UpperCAmelCase      )
								self.assertTrue(
								    torch.allclose(
								        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]		,	_UpperCAmelCase		,	atol=_UpperCAmelCase      )      )

								_lowerCAmelCase    :    Union[str, Any]										=      torch.tensor(
								    [[0.2852, -0.0159, 0.9735], [0.6254, 0.1858, 0.8529], [-0.0680, -0.4116, 1.8413]]      ).to(_UpperCAmelCase      )
								self.assertTrue(
								    torch.allclose(
								        outputs.transformer_decoder_last_hidden_state[0, :3, :3]		,	_UpperCAmelCase		,	atol=_UpperCAmelCase      )      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    List[str]										=      (
								    MaskFormerForInstanceSegmentation.from_pretrained("""facebook/maskformer-swin-small-coco"""      )
								    .to(_UpperCAmelCase      )
								    .eval()
								)
								_lowerCAmelCase    :    Optional[Any]										=      self.default_image_processor
								_lowerCAmelCase    :    Tuple										=      prepare_img()
								_lowerCAmelCase    :    str										=      image_processor(_UpperCAmelCase		,	return_tensors="""pt"""      ).to(_UpperCAmelCase      )
								_lowerCAmelCase    :    Dict										=      inputs["""pixel_values"""].shape
								# check size is divisible by 32
								self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0      )
								# check size
								self.assertEqual(_UpperCAmelCase		,	(1, 3, 800, 1088)      )

								with torch.no_grad():
												_lowerCAmelCase    :    List[str]										=      model(**_UpperCAmelCase      )
								# masks_queries_logits
								_lowerCAmelCase    :    Tuple										=      outputs.masks_queries_logits
								self.assertEqual(
								    masks_queries_logits.shape		,	(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)		,	)
								_lowerCAmelCase    :    List[str]										=      [
								    [-1.3737124, -1.7724937, -1.9364233],
								    [-1.5977281, -1.9867939, -2.1523695],
								    [-1.5795398, -1.9269832, -2.093942],
								]
								_lowerCAmelCase    :    Optional[int]										=      torch.tensor(_UpperCAmelCase      ).to(_UpperCAmelCase      )
								self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]		,	_UpperCAmelCase		,	atol=_UpperCAmelCase      )      )
								# class_queries_logits
								_lowerCAmelCase    :    int										=      outputs.class_queries_logits
								self.assertEqual(
								    class_queries_logits.shape		,	(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)      )
								_lowerCAmelCase    :    str										=      torch.tensor(
								    [
								        [1.6_512E00, -5.2_572E00, -3.3_519E00],
								        [3.6_169E-02, -5.9_025E00, -2.9_313E00],
								        [1.0_766E-04, -7.7_630E00, -5.1_263E00],
								    ]      ).to(_UpperCAmelCase      )
								self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]		,	_UpperCAmelCase		,	atol=_UpperCAmelCase      )      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[int]										=      (
								    MaskFormerForInstanceSegmentation.from_pretrained("""facebook/maskformer-resnet101-coco-stuff"""      )
								    .to(_UpperCAmelCase      )
								    .eval()
								)
								_lowerCAmelCase    :    int										=      self.default_image_processor
								_lowerCAmelCase    :    int										=      prepare_img()
								_lowerCAmelCase    :    int										=      image_processor(_UpperCAmelCase		,	return_tensors="""pt"""      ).to(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[Any]										=      inputs["""pixel_values"""].shape
								# check size is divisible by 32
								self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0      )
								# check size
								self.assertEqual(_UpperCAmelCase		,	(1, 3, 800, 1088)      )

								with torch.no_grad():
												_lowerCAmelCase    :    Tuple										=      model(**_UpperCAmelCase      )
								# masks_queries_logits
								_lowerCAmelCase    :    str										=      outputs.masks_queries_logits
								self.assertEqual(
								    masks_queries_logits.shape		,	(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)		,	)
								_lowerCAmelCase    :    List[Any]										=      [[-0.9046, -2.6366, -4.6062], [-3.4179, -5.7890, -8.8057], [-4.9179, -7.6560, -10.7711]]
								_lowerCAmelCase    :    Any										=      torch.tensor(_UpperCAmelCase      ).to(_UpperCAmelCase      )
								self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]		,	_UpperCAmelCase		,	atol=_UpperCAmelCase      )      )
								# class_queries_logits
								_lowerCAmelCase    :    List[Any]										=      outputs.class_queries_logits
								self.assertEqual(
								    class_queries_logits.shape		,	(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)      )
								_lowerCAmelCase    :    Any										=      torch.tensor(
								    [[4.7188, -3.2585, -2.8857], [6.6871, -2.9181, -1.2487], [7.2449, -2.2764, -2.1874]]      ).to(_UpperCAmelCase      )
								self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]		,	_UpperCAmelCase		,	atol=_UpperCAmelCase      )      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Union[str, Any]      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      (
								    MaskFormerForInstanceSegmentation.from_pretrained("""facebook/maskformer-swin-small-coco"""      )
								    .to(_UpperCAmelCase      )
								    .eval()
								)
								_lowerCAmelCase    :    Optional[Any]										=      self.default_image_processor

								_lowerCAmelCase    :    List[Any]										=      image_processor(
								    [np.zeros((3, 800, 1333)      ), np.zeros((3, 800, 1333)      )]		,	segmentation_maps=[np.zeros((384, 384)      ).astype(np.floataa      ), np.zeros((384, 384)      ).astype(np.floataa      )]		,	return_tensors="""pt"""		,	)

								_lowerCAmelCase    :    Any										=      inputs["""pixel_values"""].to(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[Any]										=      [el.to(_UpperCAmelCase      ) for el in inputs["""mask_labels"""]]
								_lowerCAmelCase    :    Optional[int]										=      [el.to(_UpperCAmelCase      ) for el in inputs["""class_labels"""]]

								with torch.no_grad():
												_lowerCAmelCase    :    Tuple										=      model(**_UpperCAmelCase      )

								self.assertTrue(outputs.loss is not None      )







def 							_UpperCAmelCase  (UpperCamelCase_ : str       ):
				'''simple docstring'''
				_lowerCAmelCase    :    List[str]										=      [int(UpperCamelCase_       ) for i in ip_va_address.split("""."""       ) if i.isdigit()]
				return len(UpperCamelCase_       ) == 4 and all(0 <= int(UpperCamelCase_       ) <= 254 for octet in octets       )


if __name__ == "__main__":
	_lowerCamelCase      :  List[str]      						=						input().strip()
	_lowerCamelCase      :  int      						=						"valid" if is_ip_va_address_valid(ip) else "invalid"
	print(F'''{ip} is a {valid_or_invalid} IP v4 address.''')

