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: Compute classification and mask targets for all images for a decoder
  layer.
  
  Args:
      cls_scores_list (list[Tensor]): Mask score logits from a single
          decoder layer for all images. Each with shape [num_queries,
          cls_out_channels].
      mask_preds_list (list[Tensor]): Mask logits from a single decoder
          layer for all images. Each with shape [num_queries, h, w].
      gt_labels_list (list[Tensor]): Ground truth class indices for all
          images. Each 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,
          each with shape (n, h, w).
      img_metas (list[dict]): List of image meta information.
  
  Returns:
      tuple[list[Tensor]]: a tuple containing the following targets.
  
          - labels_list (list[Tensor]): Labels of all images.
              Each with shape [num_queries, ].
          - label_weights_list (list[Tensor]): Label weights of all
              images.Each with shape [num_queries, ].
          - mask_targets_list (list[Tensor]): Mask targets of all images.
              Each with shape [num_queries, h, w].
          - mask_weights_list (list[Tensor]): Mask weights of all images.
              Each with shape [num_queries, ].
          - num_total_pos (int): Number of positive samples in all
              images.
          - num_total_neg (int): Number of negative samples in all
              images.
docstr_tok: ["Compute","classification","and","mask","targets","for","all","images","for","a","decoder","layer",".","Args",":","cls_scores_list","(","list","[","Tensor","]",")",":","Mask","score","logits","from","a","single","decoder","layer","for","all","images",".","Each","with","shape","[","num_queries",",","cls_out_channels","]",".","mask_preds_list","(","list","[","Tensor","]",")",":","Mask","logits","from","a","single","decoder","layer","for","all","images",".","Each","with","shape","[","num_queries",",","h",",","w","]",".","gt_labels_list","(","list","[","Tensor","]",")",":","Ground","truth","class","indices","for","all","images",".","Each","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",",","each","with","shape","(","n",",","h",",","w",")",".","img_metas","(","list","[","dict","]",")",":","List","of","image","meta","information",".","Returns",":","tuple","[","list","[","Tensor","]","]",":","a","tuple","containing","the","following","targets",".","-","labels_list","(","list","[","Tensor","]",")",":","Labels","of","all","images",".","Each","with","shape","[","num_queries",",","]",".","-","label_weights_list","(","list","[","Tensor","]",")",":","Label","weights","of","all","images.Each","with","shape","[","num_queries",",","]",".","-","mask_targets_list","(","list","[","Tensor","]",")",":","Mask","targets","of","all","images",".","Each","with","shape","[","num_queries",",","h",",","w","]",".","-","mask_weights_list","(","list","[","Tensor","]",")",":","Mask","weights","of","all","images",".","Each","with","shape","[","num_queries",",","]",".","-","num_total_pos","(","int",")",":","Number","of","positive","samples","in","all","images",".","-","num_total_neg","(","int",")",":","Number","of","negative","samples","in","all","images","."]
code: def get_targets(
      self,
      cls_scores_list,
      mask_preds_list,
      gt_labels_list,
      gt_masks_list,
      img_metas,
  ):
      """Compute classification and mask targets for all images for a decoder
      layer.
  
      Args:
          cls_scores_list (list[Tensor]): Mask score logits from a single
              decoder layer for all images. Each with shape [num_queries,
              cls_out_channels].
          mask_preds_list (list[Tensor]): Mask logits from a single decoder
              layer for all images. Each with shape [num_queries, h, w].
          gt_labels_list (list[Tensor]): Ground truth class indices for all
              images. Each 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,
              each with shape (n, h, w).
          img_metas (list[dict]): List of image meta information.
  
      Returns:
          tuple[list[Tensor]]: a tuple containing the following targets.
  
              - labels_list (list[Tensor]): Labels of all images.
                  Each with shape [num_queries, ].
              - label_weights_list (list[Tensor]): Label weights of all
                  images.Each with shape [num_queries, ].
              - mask_targets_list (list[Tensor]): Mask targets of all images.
                  Each with shape [num_queries, h, w].
              - mask_weights_list (list[Tensor]): Mask weights of all images.
                  Each with shape [num_queries, ].
              - num_total_pos (int): Number of positive samples in all
                  images.
              - num_total_neg (int): Number of negative samples in all
                  images.
      """
      (
          labels_list,
          label_weights_list,
          mask_targets_list,
          mask_weights_list,
          pos_inds_list,
          neg_inds_list,
      ) = multi_apply(
          self._get_target_single,
          cls_scores_list,
          mask_preds_list,
          gt_labels_list,
          gt_masks_list,
          img_metas,
      )
  
      num_total_pos = sum((inds.numel() for inds in pos_inds_list))
      num_total_neg = sum((inds.numel() for inds in neg_inds_list))
      return (
          labels_list,
          label_weights_list,
          mask_targets_list,
          mask_weights_list,
          num_total_pos,
          num_total_neg,
      )
  
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 3 for calling the Mask2FormerHead obj's underlying member method code with example usage: obj.get_targets(cls_scores_list, mask_preds_list, gt_labels_list, gt_masks_list, img_metas) and returns: labels_list,  label_weights_list,  mask_targets_list,  mask_weights_list,  num_total_pos,  num_total_neg