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 one image.
  
  Args:
      cls_score (Tensor): Mask score logits from a single decoder layer
          for one image. Shape (num_queries, cls_out_channels).
      mask_pred (Tensor): Mask logits for a single decoder layer for one
          image. Shape (num_queries, h, w).
      gt_labels (Tensor): Ground truth class indices for one image with
          shape (num_gts, ).
      gt_masks (Tensor): Ground truth mask for each image, each with
          shape (num_gts, h, w).
      img_metas (dict): Image informtation.
  
  Returns:
      tuple[Tensor]: A tuple containing the following for one image.
  
          - labels (Tensor): Labels of each image.                     shape (num_queries, ).
          - label_weights (Tensor): Label weights of each image.                     shape (num_queries, ).
          - mask_targets (Tensor): Mask targets of each image.                     shape (num_queries, h, w).
          - mask_weights (Tensor): Mask weights of each image.                     shape (num_queries, ).
          - pos_inds (Tensor): Sampled positive indices for each                     image.
          - neg_inds (Tensor): Sampled negative indices for each                     image.
docstr_tok: ["Compute","classification","and","mask","targets","for","one","image",".","Args",":","cls_score","(","Tensor",")",":","Mask","score","logits","from","a","single","decoder","layer","for","one","image",".","Shape","(","num_queries",",","cls_out_channels",")",".","mask_pred","(","Tensor",")",":","Mask","logits","for","a","single","decoder","layer","for","one","image",".","Shape","(","num_queries",",","h",",","w",")",".","gt_labels","(","Tensor",")",":","Ground","truth","class","indices","for","one","image","with","shape","(","num_gts",",",")",".","gt_masks","(","Tensor",")",":","Ground","truth","mask","for","each","image",",","each","with","shape","(","num_gts",",","h",",","w",")",".","img_metas","(","dict",")",":","Image","informtation",".","Returns",":","tuple","[","Tensor","]",":","A","tuple","containing","the","following","for","one","image",".","-","labels","(","Tensor",")",":","Labels","of","each","image",".","shape","(","num_queries",",",")",".","-","label_weights","(","Tensor",")",":","Label","weights","of","each","image",".","shape","(","num_queries",",",")",".","-","mask_targets","(","Tensor",")",":","Mask","targets","of","each","image",".","shape","(","num_queries",",","h",",","w",")",".","-","mask_weights","(","Tensor",")",":","Mask","weights","of","each","image",".","shape","(","num_queries",",",")",".","-","pos_inds","(","Tensor",")",":","Sampled","positive","indices","for","each","image",".","-","neg_inds","(","Tensor",")",":","Sampled","negative","indices","for","each","image","."]
code: def _get_target_single(
      self, cls_score, mask_pred, gt_labels, gt_masks, img_metas
  ):
      """Compute classification and mask targets for one image.
  
          Args:
              cls_score (Tensor): Mask score logits from a single decoder layer
                  for one image. Shape (num_queries, cls_out_channels).
              mask_pred (Tensor): Mask logits for a single decoder layer for one
                  image. Shape (num_queries, h, w).
              gt_labels (Tensor): Ground truth class indices for one image with
                  shape (num_gts, ).
              gt_masks (Tensor): Ground truth mask for each image, each with
                  shape (num_gts, h, w).
              img_metas (dict): Image informtation.
  
          Returns:
              tuple[Tensor]: A tuple containing the following for one image.
  
                  - labels (Tensor): Labels of each image. \
                      shape (num_queries, ).
                  - label_weights (Tensor): Label weights of each image. \
                      shape (num_queries, ).
                  - mask_targets (Tensor): Mask targets of each image. \
                      shape (num_queries, h, w).
                  - mask_weights (Tensor): Mask weights of each image. \
                      shape (num_queries, ).
                  - pos_inds (Tensor): Sampled positive indices for each \
                      image.
                  - neg_inds (Tensor): Sampled negative indices for each \
                      image.
          """
      # sample points
      num_queries = cls_score.shape[0]
      num_gts = gt_labels.shape[0]
  
      point_coords = torch.rand(
          (1, self.num_points, 2), device=cls_score.device
      )
      # shape (num_queries, num_points)
      mask_points_pred = point_sample(
          mask_pred.unsqueeze(1), point_coords.repeat(num_queries, 1, 1)
      ).squeeze(1)
      # shape (num_gts, num_points)
      gt_points_masks = point_sample(
          gt_masks.unsqueeze(1).float(),
          point_coords.repeat(num_gts, 1, 1),
      ).squeeze(1)
  
      # assign and sample
      assign_result = self.assigner.assign(
          cls_score,
          mask_points_pred,
          gt_labels,
          gt_points_masks,
          img_metas,
      )
      sampling_result = self.sampler.sample(
          assign_result, mask_pred, gt_masks
      )
      pos_inds = sampling_result.pos_inds
      neg_inds = sampling_result.neg_inds
  
      # label target
      labels = gt_labels.new_full(
          (self.num_queries,), self.num_classes, dtype=torch.long
      )
      labels[pos_inds] = gt_labels[sampling_result.pos_assigned_gt_inds]
      label_weights = gt_labels.new_ones((self.num_queries,))
  
      # mask target
      mask_targets = gt_masks[sampling_result.pos_assigned_gt_inds]
      mask_weights = mask_pred.new_zeros((self.num_queries,))
      mask_weights[pos_inds] = 1.0
  
      return (
          labels,
          label_weights,
          mask_targets,
          mask_weights,
          pos_inds,
          neg_inds,
      )
  
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 4 for calling the Mask2FormerHead obj's underlying member method code with example usage: obj._get_target_single(cls_score, mask_pred, gt_labels, gt_masks, img_metas) and returns: labels,  label_weights,  mask_targets,  mask_weights,  pos_inds,  neg_inds