code: def create_and_check_maskformer_instance_segmentation_head_model(
      self, config, pixel_values, pixel_mask, mask_labels, class_labels
  ):
      model = MaskFormerForInstanceSegmentation(config=config)
      model.to(torch_device)
      model.eval()
  
      def comm_check_on_output(result):
          # 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():
          result = model(
              pixel_values=pixel_values, pixel_mask=pixel_mask
          )
          result = model(pixel_values)
  
          comm_check_on_output(result)
  
          result = model(
              pixel_values=pixel_values,
              pixel_mask=pixel_mask,
              mask_labels=mask_labels,
              class_labels=class_labels,
          )
  
      comm_check_on_output(result)
  
      self.parent.assertTrue(result.loss is not None)
      self.parent.assertEqual(result.loss.shape, torch.Size([]))
  
imports: import copy
  import unittest
  import numpy
  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_accelerator, require_torch_fp16, 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
label_desc: Use image node_id 7 for calling the MaskFormerModelTester obj's underlying member method code with example usage: obj.create_and_check_maskformer_instance_segmentation_head_model(config, pixel_values, pixel_mask, mask_labels, class_labels) without return types