


'''simple docstring'''






from __future__ import annotations






class        __snake_case	:







    """simple docstring"""



    def __init__(       self   :  Tuple   ,						lowerCamelCase   :  Dict=None		)       ->  List[str]:
      lowerCAmelCase_      :				Optional[Any]      =       data
      lowerCAmelCase_      :				Any      =       None





    def __repr__(       self   :  Dict		)       ->  int:
      lowerCAmelCase_      :				Any      =       []
      lowerCAmelCase_      :				Optional[Any]      =       self
      while temp:
        string_rep.append(F'{temp.data}'		)
        lowerCAmelCase_      :				List[Any]      =       temp.next
      return "->".join(lowerCamelCase		)







def     UpperCamelCase_      (   A__ :       list ):
  '''simple docstring'''





  if not elements_list:
    raise Exception("""The Elements List is empty""" )

  lowerCAmelCase_      :				Union[str, Any]      =       Node(elements_list[0] )
  for i in range(1							,   len(A__ ) ):
    lowerCAmelCase_      :				Optional[int]      =       Node(elements_list[i] )
    lowerCAmelCase_      :				Union[str, Any]      =       current.next
  return head







def     UpperCamelCase_      (   A__ :       Node ):
  '''simple docstring'''





  if head_node is not None and isinstance(A__							,   A__ ):
    print_reverse(head_node.next )
    print(head_node.data )







def     UpperCamelCase_      (   ):
  '''simple docstring'''





  from doctest import testmod

  testmod()

  lowerCAmelCase_      :				Optional[int]      =       make_linked_list([14, 52, 14, 12, 43] )
  print("""Linked List:""" )
  print(A__ )
  print("""Elements in Reverse:""" )
  print_reverse(A__ )


if __name__ == "__main__":
  main()







'''simple docstring'''






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	:







    """simple docstring"""



    def __init__(       self   :  Union[str, Any]   ,						lowerCamelCase   :  List[Any]   ,						lowerCamelCase   :  List[Any]=2   ,						lowerCamelCase   :  int=True   ,						lowerCamelCase   :  str=False   ,						lowerCamelCase   :  List[str]=10   ,						lowerCamelCase   :  Dict=3   ,						lowerCamelCase   :  str=32 * 4   ,						lowerCamelCase   :  Tuple=32 * 6   ,						lowerCamelCase   :  int=4   ,						lowerCamelCase   :  Optional[int]=32   ,						)       ->  List[Any]:
      lowerCAmelCase_      :				Tuple      =       parent
      lowerCAmelCase_      :				int      =       batch_size
      lowerCAmelCase_      :				Tuple      =       is_training
      lowerCAmelCase_      :				str      =       use_auxiliary_loss
      lowerCAmelCase_      :				Optional[Any]      =       num_queries
      lowerCAmelCase_      :				List[str]      =       num_channels
      lowerCAmelCase_      :				Optional[Any]      =       min_size
      lowerCAmelCase_      :				Dict      =       max_size
      lowerCAmelCase_      :				List[Any]      =       num_labels
      lowerCAmelCase_      :				List[Any]      =       mask_feature_size

    def __lowercase       (       self   :  str		)       ->  List[Any]:
      lowerCAmelCase_      :				Union[str, Any]      =       floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]		).to(
          lowerCamelCase		)

      lowerCAmelCase_      :				int      =       torch.ones([self.batch_size, self.min_size, self.max_size]   ,						device=lowerCamelCase		)

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

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

    def __lowercase       (       self   :  Optional[int]		)       ->  Optional[int]:
      return MaskFormerConfig.from_backbone_and_decoder_configs(
          backbone_config=SwinConfig(
              depths=[1, 1, 1, 1]   ,						)   ,						decoder_config=DetrConfig(
              decoder_ffn_dim=1_28   ,						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 __lowercase       (       self   :  Tuple		)       ->  Optional[Any]:
      lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_      :				List[Any]      =       self.prepare_config_and_inputs()
      lowerCAmelCase_      :				Union[str, Any]      =       {"""pixel_values""": pixel_values, """pixel_mask""": pixel_mask}
      return config, inputs_dict

    def __lowercase       (       self   :  Tuple   ,						lowerCamelCase   :  Tuple   ,						lowerCamelCase   :  Optional[Any]		)       ->  Union[str, Any]:
      lowerCAmelCase_      :				Any      =       output.encoder_hidden_states
      lowerCAmelCase_      :				Dict      =       output.pixel_decoder_hidden_states
      lowerCAmelCase_      :				str      =       output.transformer_decoder_hidden_states

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

    def __lowercase       (       self   :  List[Any]   ,						lowerCamelCase   :  Any   ,						lowerCamelCase   :  int   ,						lowerCamelCase   :  Optional[int]   ,						lowerCamelCase   :  Tuple=False		)       ->  List[Any]:
      with torch.no_grad():
        lowerCAmelCase_      :				int      =       MaskFormerModel(config=lowerCamelCase		)
        model.to(lowerCamelCase		)
        model.eval()

        lowerCAmelCase_      :				List[Any]      =       model(pixel_values=lowerCamelCase   ,						pixel_mask=lowerCamelCase		)
        lowerCAmelCase_      :				Union[str, Any]      =       model(lowerCamelCase   ,						output_hidden_states=lowerCamelCase		)
      # 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(lowerCamelCase   ,						lowerCamelCase		)





    def __lowercase       (       self   :  Any   ,						lowerCamelCase   :  Dict   ,						lowerCamelCase   :  Any   ,						lowerCamelCase   :  Optional[int]   ,						lowerCamelCase   :  Tuple   ,						lowerCamelCase   :  Optional[Any]		)       ->  Dict:
      lowerCAmelCase_      :				Tuple      =       MaskFormerForInstanceSegmentation(config=lowerCamelCase		)
      model.to(lowerCamelCase		)
      model.eval()

      def comm_check_on_output(lowerCamelCase   :  Optional[Any]		):
        # 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_      :				Dict      =       model(pixel_values=lowerCamelCase   ,						pixel_mask=lowerCamelCase		)
        lowerCAmelCase_      :				List[str]      =       model(lowerCamelCase		)

        comm_check_on_output(lowerCamelCase		)

        lowerCAmelCase_      :				Union[str, Any]      =       model(
            pixel_values=lowerCamelCase   ,						pixel_mask=lowerCamelCase   ,						mask_labels=lowerCamelCase   ,						class_labels=lowerCamelCase		)

      comm_check_on_output(lowerCamelCase		)

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







@require_torch
class        __snake_case	(       _SCREAMING_SNAKE_CASE     ,_SCREAMING_SNAKE_CASE     ,unittest.TestCase):







    """simple docstring"""



    lowercase       			= (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
    lowercase       			= (
        {'feature-extraction': MaskFormerModel, 'image-segmentation': MaskFormerForInstanceSegmentation}
        if is_torch_available()
        else {}
    )

    lowercase       			= False
    lowercase       			= False
    lowercase       			= False
    lowercase       			= False

    def __lowercase       (       self   :  Dict		)       ->  Optional[Any]:
      lowerCAmelCase_      :				Tuple      =       MaskFormerModelTester(self		)
      lowerCAmelCase_      :				str      =       ConfigTester(self   ,						config_class=lowerCamelCase   ,						has_text_modality=lowerCamelCase		)

    def __lowercase       (       self   :  List[Any]		)       ->  Optional[Any]:
      self.config_tester.run_common_tests()

    def __lowercase       (       self   :  Tuple		)       ->  List[Any]:
      lowerCAmelCase_,							lowerCAmelCase_      :				List[str]      =       self.model_tester.prepare_config_and_inputs_for_common()
      self.model_tester.create_and_check_maskformer_model(lowerCamelCase   ,						**lowerCamelCase   ,						output_hidden_states=lowerCamelCase		)

    def __lowercase       (       self   :  Union[str, Any]		)       ->  str:
      lowerCAmelCase_      :				Dict      =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*lowerCamelCase		)

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

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

    @unittest.skip(reason="""MaskFormer is not a generative model"""		)
    def __lowercase       (       self   :  Any		)       ->  str:
      pass

    @unittest.skip(reason="""MaskFormer does not use token embeddings"""		)
    def __lowercase       (       self   :  List[Any]		)       ->  Any:
      pass

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

    @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""		)
    def __lowercase       (       self   :  str		)       ->  Optional[int]:
      pass

    def __lowercase       (       self   :  Tuple		)       ->  List[str]:
      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(lowerCamelCase		)
        lowerCAmelCase_      :				int      =       inspect.signature(model.forward		)
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        lowerCAmelCase_      :				List[str]      =       [*signature.parameters.keys()]

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

    @slow
    def __lowercase       (       self   :  Optional[int]		)       ->  List[str]:
      for model_name in ["facebook/maskformer-swin-small-coco"]:
        lowerCAmelCase_      :				List[str]      =       MaskFormerModel.from_pretrained(lowerCamelCase		)
        self.assertIsNotNone(lowerCamelCase		)

    def __lowercase       (       self   :  Dict		)       ->  int:
      lowerCAmelCase_      :				Any      =       (self.model_tester.min_size,) * 2
      lowerCAmelCase_      :				Dict      =       {
          """pixel_values""": torch.randn((2, 3, *size)   ,						device=lowerCamelCase		),
          """mask_labels""": torch.randn((2, 10, *size)   ,						device=lowerCamelCase		),
          """class_labels""": torch.zeros(2   ,						10   ,						device=lowerCamelCase		).long(),
      }

      lowerCAmelCase_      :				Dict      =       MaskFormerForInstanceSegmentation(MaskFormerConfig()		).to(lowerCamelCase		)
      lowerCAmelCase_      :				str      =       model(**lowerCamelCase		)
      self.assertTrue(outputs.loss is not None		)

    def __lowercase       (       self   :  int		)       ->  int:
      lowerCAmelCase_,							lowerCAmelCase_      :				Union[str, Any]      =       self.model_tester.prepare_config_and_inputs_for_common()
      self.model_tester.create_and_check_maskformer_model(lowerCamelCase   ,						**lowerCamelCase   ,						output_hidden_states=lowerCamelCase		)

    def __lowercase       (       self   :  Dict		)       ->  List[str]:
      lowerCAmelCase_,							lowerCAmelCase_      :				Union[str, Any]      =       self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        lowerCAmelCase_      :				List[str]      =       model_class(lowerCamelCase		).to(lowerCamelCase		)
        lowerCAmelCase_      :				Tuple      =       model(**lowerCamelCase   ,						output_attentions=lowerCamelCase		)
        self.assertTrue(outputs.attentions is not None		)

    def __lowercase       (       self   :  int		)       ->  Union[str, Any]:
      if not self.model_tester.is_training:
        return
      # only MaskFormerForInstanceSegmentation has the loss
      lowerCAmelCase_      :				Optional[int]      =       self.all_model_classes[1]
      lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_      :				str      =       self.model_tester.prepare_config_and_inputs()

      lowerCAmelCase_      :				Union[str, Any]      =       model_class(lowerCamelCase		)
      model.to(lowerCamelCase		)
      model.train()

      lowerCAmelCase_      :				str      =       model(lowerCamelCase   ,						mask_labels=lowerCamelCase   ,						class_labels=lowerCamelCase		).loss
      loss.backward()





    def __lowercase       (       self   :  Any		)       ->  Union[str, Any]:
      # only MaskFormerForInstanceSegmentation has the loss
      lowerCAmelCase_      :				List[str]      =       self.all_model_classes[1]
      lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_,							lowerCAmelCase_      :				Any      =       self.model_tester.prepare_config_and_inputs()
      lowerCAmelCase_      :				List[str]      =       True
      lowerCAmelCase_      :				List[str]      =       True

      lowerCAmelCase_      :				Dict      =       model_class(lowerCamelCase		)
      model.to(lowerCamelCase		)
      model.train()

      lowerCAmelCase_      :				Union[str, Any]      =       model(lowerCamelCase   ,						mask_labels=lowerCamelCase   ,						class_labels=lowerCamelCase		)

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

      lowerCAmelCase_      :				List[str]      =       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_      :				Optional[int]      =       outputs.transformer_decoder_hidden_states[0]
      transformer_decoder_hidden_states.retain_grad()

      lowerCAmelCase_      :				Tuple      =       outputs.attentions[0]
      attentions.retain_grad()

      outputs.loss.backward(retain_graph=lowerCamelCase		)

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







__A :  List[Any]    							=				1E-4







def     UpperCamelCase_      (   ):
  '''simple docstring'''





  lowerCAmelCase_      :				int      =       Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
  return image






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







    """simple docstring"""



    @cached_property
    def __lowercase       (       self   :  Union[str, Any]		)       ->  List[Any]:
      return (
          MaskFormerImageProcessor.from_pretrained("""facebook/maskformer-swin-small-coco"""		)
          if is_vision_available()
          else None
      )

    def __lowercase       (       self   :  List[Any]		)       ->  Union[str, Any]:
      lowerCAmelCase_      :				Optional[int]      =       MaskFormerModel.from_pretrained("""facebook/maskformer-swin-small-coco"""		).to(lowerCamelCase		)
      lowerCAmelCase_      :				Dict      =       self.default_image_processor
      lowerCAmelCase_      :				Optional[int]      =       prepare_img()
      lowerCAmelCase_      :				Dict      =       image_processor(lowerCamelCase   ,						return_tensors="""pt"""		).to(lowerCamelCase		)
      lowerCAmelCase_      :				Union[str, 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(lowerCamelCase   ,						(1, 3, 8_00, 10_88)		)

      with torch.no_grad():
        lowerCAmelCase_      :				List[str]      =       model(**lowerCamelCase		)

      lowerCAmelCase_      :				Any      =       torch.tensor(
          [[-0.0_482, 0.9_228, 0.4_951], [-0.2_547, 0.8_017, 0.8_527], [-0.0_069, 0.3_385, -0.0_089]]		).to(lowerCamelCase		)
      self.assertTrue(
          torch.allclose(
              outputs.encoder_last_hidden_state[0, 0, :3, :3]   ,						lowerCamelCase   ,						atol=lowerCamelCase		)		)

      lowerCAmelCase_      :				Union[str, Any]      =       torch.tensor(
          [[-0.8_422, -0.8_434, -0.9_718], [-1.0_144, -0.5_565, -0.4_195], [-1.0_038, -0.4_484, -0.1_961]]		).to(lowerCamelCase		)
      self.assertTrue(
          torch.allclose(
              outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]   ,						lowerCamelCase   ,						atol=lowerCamelCase		)		)

      lowerCAmelCase_      :				Optional[Any]      =       torch.tensor(
          [[0.2_852, -0.0_159, 0.9_735], [0.6_254, 0.1_858, 0.8_529], [-0.0_680, -0.4_116, 1.8_413]]		).to(lowerCamelCase		)
      self.assertTrue(
          torch.allclose(
              outputs.transformer_decoder_last_hidden_state[0, :3, :3]   ,						lowerCamelCase   ,						atol=lowerCamelCase		)		)

    def __lowercase       (       self   :  Optional[int]		)       ->  Optional[int]:
      lowerCAmelCase_      :				Union[str, Any]      =       (
          MaskFormerForInstanceSegmentation.from_pretrained("""facebook/maskformer-swin-small-coco"""		)
          .to(lowerCamelCase		)
          .eval()
      )
      lowerCAmelCase_      :				Union[str, Any]      =       self.default_image_processor
      lowerCAmelCase_      :				Optional[Any]      =       prepare_img()
      lowerCAmelCase_      :				Optional[int]      =       image_processor(lowerCamelCase   ,						return_tensors="""pt"""		).to(lowerCamelCase		)
      lowerCAmelCase_      :				Optional[int]      =       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(lowerCamelCase   ,						(1, 3, 8_00, 10_88)		)

      with torch.no_grad():
        lowerCAmelCase_      :				List[str]      =       model(**lowerCamelCase		)
      # masks_queries_logits
      lowerCAmelCase_      :				Dict      =       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_      :				Any      =       [
          [-1.3_737_124, -1.7_724_937, -1.9_364_233],
          [-1.5_977_281, -1.9_867_939, -2.1_523_695],
          [-1.5_795_398, -1.9_269_832, -2.093_942],
      ]
      lowerCAmelCase_      :				Optional[int]      =       torch.tensor(lowerCamelCase		).to(lowerCamelCase		)
      self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]   ,						lowerCamelCase   ,						atol=lowerCamelCase		)		)
      # class_queries_logits
      lowerCAmelCase_      :				Optional[Any]      =       outputs.class_queries_logits
      self.assertEqual(
          class_queries_logits.shape   ,						(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)		)
      lowerCAmelCase_      :				Tuple      =       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(lowerCamelCase		)
      self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]   ,						lowerCamelCase   ,						atol=lowerCamelCase		)		)

    def __lowercase       (       self   :  Optional[int]		)       ->  List[str]:
      lowerCAmelCase_      :				List[str]      =       (
          MaskFormerForInstanceSegmentation.from_pretrained("""facebook/maskformer-resnet101-coco-stuff"""		)
          .to(lowerCamelCase		)
          .eval()
      )
      lowerCAmelCase_      :				Tuple      =       self.default_image_processor
      lowerCAmelCase_      :				int      =       prepare_img()
      lowerCAmelCase_      :				Any      =       image_processor(lowerCamelCase   ,						return_tensors="""pt"""		).to(lowerCamelCase		)
      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(lowerCamelCase   ,						(1, 3, 8_00, 10_88)		)

      with torch.no_grad():
        lowerCAmelCase_      :				Optional[Any]      =       model(**lowerCamelCase		)
      # masks_queries_logits
      lowerCAmelCase_      :				List[Any]      =       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_      :				Optional[Any]      =       [[-0.9_046, -2.6_366, -4.6_062], [-3.4_179, -5.7_890, -8.8_057], [-4.9_179, -7.6_560, -10.7_711]]
      lowerCAmelCase_      :				Union[str, Any]      =       torch.tensor(lowerCamelCase		).to(lowerCamelCase		)
      self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]   ,						lowerCamelCase   ,						atol=lowerCamelCase		)		)
      # class_queries_logits
      lowerCAmelCase_      :				Dict      =       outputs.class_queries_logits
      self.assertEqual(
          class_queries_logits.shape   ,						(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)		)
      lowerCAmelCase_      :				int      =       torch.tensor(
          [[4.7_188, -3.2_585, -2.8_857], [6.6_871, -2.9_181, -1.2_487], [7.2_449, -2.2_764, -2.1_874]]		).to(lowerCamelCase		)
      self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]   ,						lowerCamelCase   ,						atol=lowerCamelCase		)		)





    def __lowercase       (       self   :  Union[str, Any]		)       ->  List[str]:
      lowerCAmelCase_      :				Dict      =       (
          MaskFormerForInstanceSegmentation.from_pretrained("""facebook/maskformer-swin-small-coco"""		)
          .to(lowerCamelCase		)
          .eval()
      )
      lowerCAmelCase_      :				List[str]      =       self.default_image_processor

      lowerCAmelCase_      :				int      =       image_processor(
          [np.zeros((3, 8_00, 13_33)		), np.zeros((3, 8_00, 13_33)		)]   ,						segmentation_maps=[np.zeros((3_84, 3_84)		).astype(np.floataa		), np.zeros((3_84, 3_84)		).astype(np.floataa		)]   ,						return_tensors="""pt"""   ,						)

      lowerCAmelCase_      :				List[str]      =       inputs["""pixel_values"""].to(lowerCamelCase		)
      lowerCAmelCase_      :				Tuple      =       [el.to(lowerCamelCase		) for el in inputs["""mask_labels"""]]
      lowerCAmelCase_      :				Union[str, Any]      =       [el.to(lowerCamelCase		) for el in inputs["""class_labels"""]]

      with torch.no_grad():
        lowerCAmelCase_      :				Any      =       model(**lowerCamelCase		)

      self.assertTrue(outputs.loss is not None		)



