class_docstr: Implements the MaskFormer head.
  
  See `Per-Pixel Classification is Not All You Need for Semantic
  Segmentation <https://arxiv.org/pdf/2107.06278>`_ for details.
  
  Args:
      in_channels (list[int]): Number of channels in the input feature map.
      feat_channels (int): Number of channels for feature.
      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.
      pixel_decoder (:obj:`ConfigDict` or dict): Config for pixel
          decoder.
      enforce_decoder_input_project (bool): Whether to add a layer
          to change the embed_dim of transformer encoder in pixel decoder to
          the embed_dim of transformer decoder. Defaults to False.
      transformer_decoder (:obj:`ConfigDict` or dict): Config for
          transformer decoder.
      positional_encoding (:obj:`ConfigDict` or dict): Config for
          transformer decoder position encoding.
      loss_cls (:obj:`ConfigDict` or dict): Config of the classification
          loss. Defaults to `CrossEntropyLoss`.
      loss_mask (:obj:`ConfigDict` or dict): Config of the mask loss.
          Defaults to `FocalLoss`.
      loss_dice (:obj:`ConfigDict` or dict): Config of the dice loss.
          Defaults to `DiceLoss`.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config of
          MaskFormer head.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config of
          MaskFormer head.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or             dict], optional): Initialization config dict. Defaults to None.
class_docstr_tok: ["Implements","the","MaskFormer","head",".","See","`","Per-Pixel","Classification","is","Not","All","You","Need","for","Semantic","Segmentation","<","https",":","\/\/arxiv.org\/pdf\/2107.06278",">","`","_","for","details",".","Args",":","in_channels","(","list","[","int","]",")",":","Number","of","channels","in","the","input","feature","map",".","feat_channels","(","int",")",":","Number","of","channels","for","feature",".","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",".","pixel_decoder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","for","pixel","decoder",".","enforce_decoder_input_project","(","bool",")",":","Whether","to","add","a","layer","to","change","the","embed_dim","of","transformer","encoder","in","pixel","decoder","to","the","embed_dim","of","transformer","decoder",".","Defaults","to","False",".","transformer_decoder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","for","transformer","decoder",".","positional_encoding","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","for","transformer","decoder","position","encoding",".","loss_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","the","classification","loss",".","Defaults","to","`","CrossEntropyLoss","`",".","loss_mask","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","the","mask","loss",".","Defaults","to","`","FocalLoss","`",".","loss_dice","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","the","dice","loss",".","Defaults","to","`","DiceLoss","`",".","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Training","config","of","MaskFormer","head",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Testing","config","of","MaskFormer","head",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[",":","obj",":","`","ConfigDict","`","or","dict","]",",","optional",")",":","Initialization","config","dict",".","Defaults","to","None","."]
docstr: Preprocess the ground truth for all images.
  
  Args:
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance. It usually includes ``labels``, each is
          ground truth labels of each bbox, with shape (num_gts, )
          and ``masks``, each is ground truth masks of each instances
          of a image, shape (num_gts, h, w).
      gt_semantic_seg (list[Optional[PixelData]]): Ground truth of
          semantic segmentation, each with the shape (1, h, w).
          [0, num_thing_class - 1] means things,
          [num_thing_class, num_class-1] means stuff,
          255 means VOID. It's None when training instance segmentation.
  
  Returns:
      list[obj:`InstanceData`]: each contains the following keys
  
          - labels (Tensor): Ground truth class indices                    for a image, with shape (n, ), n is the sum of                    number of stuff type and number of instance in a image.
          - masks (Tensor): Ground truth mask for a                    image, with shape (n, h, w).
docstr_tok: ["Preprocess","the","ground","truth","for","all","images",".","Args",":","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","labels","``",",","each","is","ground","truth","labels","of","each","bbox",",","with","shape","(","num_gts",",",")","and","``","masks","``",",","each","is","ground","truth","masks","of","each","instances","of","a","image",",","shape","(","num_gts",",","h",",","w",")",".","gt_semantic_seg","(","list","[","Optional","[","PixelData","]","]",")",":","Ground","truth","of","semantic","segmentation",",","each","with","the","shape","(","1",",","h",",","w",")",".","[","0",",","num_thing_class","-","1","]","means","things",",","[","num_thing_class",",","num_class-1","]","means","stuff",",","255","means","VOID",".","It","'s","None","when","training","instance","segmentation",".","Returns",":","list","[","obj",":","`","InstanceData","`","]",":","each","contains","the","following","keys","-","labels","(","Tensor",")",":","Ground","truth","class","indices","for","a","image",",","with","shape","(","n",",",")",",","n","is","the","sum","of","number","of","stuff","type","and","number","of","instance","in","a","image",".","-","masks","(","Tensor",")",":","Ground","truth","mask","for","a","image",",","with","shape","(","n",",","h",",","w",")","."]
code: def preprocess_gt(
      self,
      batch_gt_instances: InstanceList,
      batch_gt_semantic_segs: List[Optional[PixelData]],
  ) -> InstanceList:
      """Preprocess the ground truth for all images.
  
          Args:
              batch_gt_instances (list[:obj:`InstanceData`]): Batch of
                  gt_instance. It usually includes ``labels``, each is
                  ground truth labels of each bbox, with shape (num_gts, )
                  and ``masks``, each is ground truth masks of each instances
                  of a image, shape (num_gts, h, w).
              gt_semantic_seg (list[Optional[PixelData]]): Ground truth of
                  semantic segmentation, each with the shape (1, h, w).
                  [0, num_thing_class - 1] means things,
                  [num_thing_class, num_class-1] means stuff,
                  255 means VOID. It's None when training instance segmentation.
  
          Returns:
              list[obj:`InstanceData`]: each contains the following keys
  
                  - labels (Tensor): Ground truth class indices\
                      for a image, with shape (n, ), n is the sum of\
                      number of stuff type and number of instance in a image.
                  - masks (Tensor): Ground truth mask for a\
                      image, with shape (n, h, w).
          """
      num_things_list = [self.num_things_classes] * len(
          batch_gt_instances
      )
      num_stuff_list = [self.num_stuff_classes] * len(
          batch_gt_instances
      )
      gt_labels_list = [
          gt_instances["labels"] for gt_instances in batch_gt_instances
      ]
      gt_masks_list = [
          gt_instances["masks"] for gt_instances in batch_gt_instances
      ]
      gt_semantic_segs = [
          None if gt_semantic_seg is None else gt_semantic_seg.sem_seg
          for gt_semantic_seg in batch_gt_semantic_segs
      ]
      targets = multi_apply(
          preprocess_panoptic_gt,
          gt_labels_list,
          gt_masks_list,
          gt_semantic_segs,
          num_things_list,
          num_stuff_list,
      )
      labels, masks = targets
      batch_gt_instances = [
          InstanceData(labels=label, masks=mask)
          for label, mask in zip(labels, masks)
      ]
      return batch_gt_instances
  
imports: from typing import Dict, List, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Conv2d
  from mmengine.model import caffe2_xavier_init
  from mmengine.structures import InstanceData, PixelData
  from torch import Tensor
  from mmdet.models.layers.pixel_decoder import PixelDecoder
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import SampleList
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptMultiConfig, reduce_mean
  from ..layers import DetrTransformerDecoder, SinePositionalEncoding
  from ..utils import multi_apply, preprocess_panoptic_gt
  from .anchor_free_head import AnchorFreeHead
label_desc: Use image node_id 3 for calling the MaskFormerHead obj's underlying member method code with example usage: obj.preprocess_gt(batch_gt_instances, batch_gt_semantic_segs) and returns: batch_gt_instances