class_docstr: Implements the Mask2Former head.
  
  See `Masked-attention Mask Transformer for Universal Image
  Segmentation <https://arxiv.org/pdf/2112.01527>`_ for details.
  
  Args:
      in_channels (list[int]): Number of channels in the input feature map.
      feat_channels (int): Number of channels for features.
      out_channels (int): Number of channels for output.
      num_things_classes (int): Number of things.
      num_stuff_classes (int): Number of stuff.
      num_queries (int): Number of query in Transformer decoder.
      pixel_decoder (:obj:`mmcv.ConfigDict` | dict): Config for pixel
          decoder. Defaults to None.
      enforce_decoder_input_project (bool, optional): Whether to add
          a layer to change the embed_dim of tranformer encoder in
          pixel decoder to the embed_dim of transformer decoder.
          Defaults to False.
      transformer_decoder (:obj:`mmcv.ConfigDict` | dict): Config for
          transformer decoder. Defaults to None.
      positional_encoding (:obj:`mmcv.ConfigDict` | dict): Config for
          transformer decoder position encoding. Defaults to None.
      loss_cls (:obj:`mmcv.ConfigDict` | dict): Config of the classification
          loss. Defaults to None.
      loss_mask (:obj:`mmcv.ConfigDict` | dict): Config of the mask loss.
          Defaults to None.
      loss_dice (:obj:`mmcv.ConfigDict` | dict): Config of the dice loss.
          Defaults to None.
      train_cfg (:obj:`mmcv.ConfigDict` | dict): Training config of
          Mask2Former head.
      test_cfg (:obj:`mmcv.ConfigDict` | dict): Testing config of
          Mask2Former head.
      init_cfg (dict or list[dict], optional): Initialization config dict.
          Defaults to None.
class_docstr_tok: ["Implements","the","Mask2Former","head",".","See","`","Masked-attention","Mask","Transformer","for","Universal","Image","Segmentation","<","https",":","\/\/arxiv.org\/pdf\/2112.01527",">","`","_","for","details",".","Args",":","in_channels","(","list","[","int","]",")",":","Number","of","channels","in","the","input","feature","map",".","feat_channels","(","int",")",":","Number","of","channels","for","features",".","out_channels","(","int",")",":","Number","of","channels","for","output",".","num_things_classes","(","int",")",":","Number","of","things",".","num_stuff_classes","(","int",")",":","Number","of","stuff",".","num_queries","(","int",")",":","Number","of","query","in","Transformer","decoder",".","pixel_decoder","(",":","obj",":","`","mmcv.ConfigDict","`","|","dict",")",":","Config","for","pixel","decoder",".","Defaults","to","None",".","enforce_decoder_input_project","(","bool",",","optional",")",":","Whether","to","add","a","layer","to","change","the","embed_dim","of","tranformer","encoder","in","pixel","decoder","to","the","embed_dim","of","transformer","decoder",".","Defaults","to","False",".","transformer_decoder","(",":","obj",":","`","mmcv.ConfigDict","`","|","dict",")",":","Config","for","transformer","decoder",".","Defaults","to","None",".","positional_encoding","(",":","obj",":","`","mmcv.ConfigDict","`","|","dict",")",":","Config","for","transformer","decoder","position","encoding",".","Defaults","to","None",".","loss_cls","(",":","obj",":","`","mmcv.ConfigDict","`","|","dict",")",":","Config","of","the","classification","loss",".","Defaults","to","None",".","loss_mask","(",":","obj",":","`","mmcv.ConfigDict","`","|","dict",")",":","Config","of","the","mask","loss",".","Defaults","to","None",".","loss_dice","(",":","obj",":","`","mmcv.ConfigDict","`","|","dict",")",":","Config","of","the","dice","loss",".","Defaults","to","None",".","train_cfg","(",":","obj",":","`","mmcv.ConfigDict","`","|","dict",")",":","Training","config","of","Mask2Former","head",".","test_cfg","(",":","obj",":","`","mmcv.ConfigDict","`","|","dict",")",":","Testing","config","of","Mask2Former","head",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Defaults","to","None","."]
docstr: Loss function.
  
  Args:
      all_cls_scores (Tensor): Classification scores for all decoder
          layers with shape [num_decoder, batch_size, num_queries,
          cls_out_channels].
      all_mask_preds (Tensor): Mask scores for all decoder layers with
          shape [num_decoder, batch_size, num_queries, h, w].
      gt_labels_list (list[Tensor]): Ground truth class indices for each
          image with shape (n, ). n is the sum of number of stuff type
          and number of instance in a image.
      gt_masks_list (list[Tensor]): Ground truth mask for each image with
          shape (n, h, w).
      img_metas (list[dict]): List of image meta information.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Loss","function",".","Args",":","all_cls_scores","(","Tensor",")",":","Classification","scores","for","all","decoder","layers","with","shape","[","num_decoder",",","batch_size",",","num_queries",",","cls_out_channels","]",".","all_mask_preds","(","Tensor",")",":","Mask","scores","for","all","decoder","layers","with","shape","[","num_decoder",",","batch_size",",","num_queries",",","h",",","w","]",".","gt_labels_list","(","list","[","Tensor","]",")",":","Ground","truth","class","indices","for","each","image","with","shape","(","n",",",")",".","n","is","the","sum","of","number","of","stuff","type","and","number","of","instance","in","a","image",".","gt_masks_list","(","list","[","Tensor","]",")",":","Ground","truth","mask","for","each","image","with","shape","(","n",",","h",",","w",")",".","img_metas","(","list","[","dict","]",")",":","List","of","image","meta","information",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def loss(
      self,
      all_cls_scores,
      all_mask_preds,
      gt_labels_list,
      gt_masks_list,
      img_metas,
  ):
      """Loss function.
  
      Args:
          all_cls_scores (Tensor): Classification scores for all decoder
              layers with shape [num_decoder, batch_size, num_queries,
              cls_out_channels].
          all_mask_preds (Tensor): Mask scores for all decoder layers with
              shape [num_decoder, batch_size, num_queries, h, w].
          gt_labels_list (list[Tensor]): Ground truth class indices for each
              image with shape (n, ). n is the sum of number of stuff type
              and number of instance in a image.
          gt_masks_list (list[Tensor]): Ground truth mask for each image with
              shape (n, h, w).
          img_metas (list[dict]): List of image meta information.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      num_dec_layers = len(all_cls_scores)
      all_gt_labels_list = [
          gt_labels_list for _ in range(num_dec_layers)
      ]
      all_gt_masks_list = [gt_masks_list for _ in range(num_dec_layers)]
      img_metas_list = [img_metas for _ in range(num_dec_layers)]
      losses_cls, losses_mask, losses_dice = multi_apply(
          self.loss_single,
          all_cls_scores,
          all_mask_preds,
          all_gt_labels_list,
          all_gt_masks_list,
          img_metas_list,
      )
  
      loss_dict = dict()
      # loss from the last decoder layer
      loss_dict["loss_cls"] = losses_cls[-1]
      loss_dict["loss_mask"] = losses_mask[-1]
      loss_dict["loss_dice"] = losses_dice[-1]
      # loss from other decoder layers
      num_dec_layer = 0
      for loss_cls_i, loss_mask_i, loss_dice_i in zip(
          losses_cls[:-1], losses_mask[:-1], losses_dice[:-1]
      ):
          loss_dict[f"d{num_dec_layer}.loss_cls"] = loss_cls_i
          loss_dict[f"d{num_dec_layer}.loss_mask"] = loss_mask_i
          loss_dict[f"d{num_dec_layer}.loss_dice"] = loss_dice_i
          num_dec_layer += 1
      return loss_dict
  
imports: import copy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Conv2d, build_plugin_layer, caffe2_xavier_init
  from mmcv.cnn.bricks.transformer import build_positional_encoding, build_transformer_layer_sequence
  from mmcv.ops import point_sample
  from mmcv.runner import ModuleList, force_fp32
  from mmseg.models.builder import HEADS, build_loss
  from mmseg.models.decode_heads.decode_head import BaseDecodeHead
  from ...core import build_sampler, multi_apply, reduce_mean
  from ..builder import build_assigner
  from ..utils import get_uncertain_point_coords_with_randomness
label_desc: Use image node_id 6 for calling the Mask2FormerHead obj's underlying member method code with example usage: obj.loss(all_cls_scores, all_mask_preds, gt_labels_list, gt_masks_list, img_metas) and returns: loss_dict