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: Forward for head part which is called after every decoder layer.
  
  Args:
      decoder_out (Tensor): in shape (num_queries, batch_size, c).
      mask_feature (Tensor): in shape (batch_size, c, h, w).
      attn_mask_target_size (tuple[int, int]): target attention
          mask size.
  
  Returns:
      tuple: A tuple contain three elements.
  
      - cls_pred (Tensor): Classification scores in shape                 (batch_size, num_queries, cls_out_channels).                 Note `cls_out_channels` should includes background.
      - mask_pred (Tensor): Mask scores in shape                 (batch_size, num_queries,h, w).
      - attn_mask (Tensor): Attention mask in shape                 (batch_size * num_heads, num_queries, h, w).
docstr_tok: ["Forward","for","head","part","which","is","called","after","every","decoder","layer",".","Args",":","decoder_out","(","Tensor",")",":","in","shape","(","num_queries",",","batch_size",",","c",")",".","mask_feature","(","Tensor",")",":","in","shape","(","batch_size",",","c",",","h",",","w",")",".","attn_mask_target_size","(","tuple","[","int",",","int","]",")",":","target","attention","mask","size",".","Returns",":","tuple",":","A","tuple","contain","three","elements",".","-","cls_pred","(","Tensor",")",":","Classification","scores","in","shape","(","batch_size",",","num_queries",",","cls_out_channels",")",".","Note","`","cls_out_channels","`","should","includes","background",".","-","mask_pred","(","Tensor",")",":","Mask","scores","in","shape","(","batch_size",",","num_queries",",","h",",","w",")",".","-","attn_mask","(","Tensor",")",":","Attention","mask","in","shape","(","batch_size","*","num_heads",",","num_queries",",","h",",","w",")","."]
code: def forward_head(
      self, decoder_out, mask_feature, attn_mask_target_size
  ):
      """Forward for head part which is called after every decoder layer.
  
          Args:
              decoder_out (Tensor): in shape (num_queries, batch_size, c).
              mask_feature (Tensor): in shape (batch_size, c, h, w).
              attn_mask_target_size (tuple[int, int]): target attention
                  mask size.
  
          Returns:
              tuple: A tuple contain three elements.
  
              - cls_pred (Tensor): Classification scores in shape \
                  (batch_size, num_queries, cls_out_channels). \
                  Note `cls_out_channels` should includes background.
              - mask_pred (Tensor): Mask scores in shape \
                  (batch_size, num_queries,h, w).
              - attn_mask (Tensor): Attention mask in shape \
                  (batch_size * num_heads, num_queries, h, w).
          """
      decoder_out = self.transformer_decoder.post_norm(decoder_out)
      decoder_out = decoder_out.transpose(0, 1)
      # shape (num_queries, batch_size, c)
      cls_pred = self.cls_embed(decoder_out)
      # shape (num_queries, batch_size, c)
      mask_embed = self.mask_embed(decoder_out)
      # shape (num_queries, batch_size, h, w)
      mask_pred = torch.einsum(
          "bqc,bchw->bqhw", mask_embed, mask_feature
      )
      attn_mask = F.interpolate(
          mask_pred,
          attn_mask_target_size,
          mode="bilinear",
          align_corners=False,
      )
      # shape (num_queries, batch_size, h, w) ->
      #   (batch_size * num_head, num_queries, h, w)
      attn_mask = (
          attn_mask.flatten(2)
          .unsqueeze(1)
          .repeat((1, self.num_heads, 1, 1))
          .flatten(0, 1)
      )
      attn_mask = attn_mask.sigmoid() < 0.5
      attn_mask = attn_mask.detach()
  
      return cls_pred, mask_pred, attn_mask
  
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 7 for calling the Mask2FormerHead obj's underlying member method code with example usage: obj.forward_head(decoder_out, mask_feature, attn_mask_target_size) and returns: cls_pred,  mask_pred,  attn_mask