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: Perform forward propagation and loss calculation of the panoptic
  head on the features of the upstream network.
  
  Args:
      x (tuple[Tensor]): Multi-level features from the upstream
          network, each is a 4D-tensor.
      batch_data_samples (List[:obj:`DetDataSample`]): The Data
          Samples. It usually includes information such as
          `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
  
  Returns:
      dict[str, Tensor]: a dictionary of loss components
docstr_tok: ["Perform","forward","propagation","and","loss","calculation","of","the","panoptic","head","on","the","features","of","the","upstream","network",".","Args",":","x","(","tuple","[","Tensor","]",")",":","Multi-level","features","from","the","upstream","network",",","each","is","a","4D-tensor",".","batch_data_samples","(","List","[",":","obj",":","`","DetDataSample","`","]",")",":","The","Data","Samples",".","It","usually","includes","information","such","as","`","gt_instance","`",",","`","gt_panoptic_seg","`","and","`","gt_sem_seg","`",".","Returns",":","dict","[","str",",","Tensor","]",":","a","dictionary","of","loss","components"]
code: def loss(
      self,
      x: Tuple[Tensor],
      batch_data_samples: SampleList,
  ) -> Dict[str, Tensor]:
      """Perform forward propagation and loss calculation of the panoptic
      head on the features of the upstream network.
  
      Args:
          x (tuple[Tensor]): Multi-level features from the upstream
              network, each is a 4D-tensor.
          batch_data_samples (List[:obj:`DetDataSample`]): The Data
              Samples. It usually includes information such as
              `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
  
      Returns:
          dict[str, Tensor]: a dictionary of loss components
      """
      batch_img_metas = []
      batch_gt_instances = []
      batch_gt_semantic_segs = []
      for data_sample in batch_data_samples:
          batch_img_metas.append(data_sample.metainfo)
          batch_gt_instances.append(data_sample.gt_instances)
          if "gt_sem_seg" in data_sample:
              batch_gt_semantic_segs.append(data_sample.gt_sem_seg)
          else:
              batch_gt_semantic_segs.append(None)
  
      # forward
      all_cls_scores, all_mask_preds = self(x, batch_data_samples)
  
      # preprocess ground truth
      batch_gt_instances = self.preprocess_gt(
          batch_gt_instances, batch_gt_semantic_segs
      )
  
      # loss
      losses = self.loss_by_feat(
          all_cls_scores,
          all_mask_preds,
          batch_gt_instances,
          batch_img_metas,
      )
  
      return losses
  
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 9 for calling the MaskFormerHead obj's underlying member method code with example usage: obj.loss(x, batch_data_samples) and returns: losses