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","."]
code: def __init__(
      self,
      in_channels: List[int],
      feat_channels: int,
      out_channels: int,
      num_things_classes: int = 80,
      num_stuff_classes: int = 53,
      num_queries: int = 100,
      pixel_decoder: ConfigType = ...,
      enforce_decoder_input_project: bool = False,
      transformer_decoder: ConfigType = ...,
      positional_encoding: ConfigType = dict(
          num_feats=128, normalize=True
      ),
      loss_cls: ConfigType = dict(
          type="CrossEntropyLoss",
          use_sigmoid=False,
          loss_weight=1.0,
          class_weight=[1.0] * 133 + [0.1],
      ),
      loss_mask: ConfigType = dict(
          type="FocalLoss",
          use_sigmoid=True,
          gamma=2.0,
          alpha=0.25,
          loss_weight=20.0,
      ),
      loss_dice: ConfigType = dict(
          type="DiceLoss",
          use_sigmoid=True,
          activate=True,
          naive_dice=True,
          loss_weight=1.0,
      ),
      train_cfg: OptConfigType = None,
      test_cfg: OptConfigType = None,
      init_cfg: OptMultiConfig = None,
      **kwargs,
  ) -> None:
      super(AnchorFreeHead, self).__init__(init_cfg=init_cfg)
      self.num_things_classes = num_things_classes
      self.num_stuff_classes = num_stuff_classes
      self.num_classes = (
          self.num_things_classes + self.num_stuff_classes
      )
      self.num_queries = num_queries
  
      pixel_decoder.update(
          in_channels=in_channels,
          feat_channels=feat_channels,
          out_channels=out_channels,
      )
      self.pixel_decoder = MODELS.build(pixel_decoder)
      self.transformer_decoder = DetrTransformerDecoder(
          **transformer_decoder
      )
      self.decoder_embed_dims = self.transformer_decoder.embed_dims
      if type(self.pixel_decoder) == PixelDecoder and (
          self.decoder_embed_dims != in_channels[-1]
          or enforce_decoder_input_project
      ):
          self.decoder_input_proj = Conv2d(
              in_channels[-1], self.decoder_embed_dims, kernel_size=1
          )
      else:
          self.decoder_input_proj = nn.Identity()
      self.decoder_pe = SinePositionalEncoding(**positional_encoding)
      self.query_embed = nn.Embedding(self.num_queries, out_channels)
  
      self.cls_embed = nn.Linear(feat_channels, self.num_classes + 1)
      self.mask_embed = nn.Sequential(
          nn.Linear(feat_channels, feat_channels),
          nn.ReLU(inplace=True),
          nn.Linear(feat_channels, feat_channels),
          nn.ReLU(inplace=True),
          nn.Linear(feat_channels, out_channels),
      )
  
      self.test_cfg = test_cfg
      self.train_cfg = train_cfg
      if train_cfg:
          self.assigner = TASK_UTILS.build(train_cfg["assigner"])
          self.sampler = TASK_UTILS.build(
              train_cfg["sampler"], default_args=dict(context=self)
          )
  
      self.class_weight = loss_cls.class_weight
      self.loss_cls = MODELS.build(loss_cls)
      self.loss_mask = MODELS.build(loss_mask)
      self.loss_dice = MODELS.build(loss_dice)
  
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 1 to create a new MaskFormerHead object from inherited base classes: AnchorFreeHead with example: obj = MaskFormerHead(in_channels, feat_channels, out_channels, num_things_classes, num_stuff_classes, num_queries, pixel_decoder, enforce_decoder_input_project, transformer_decoder, positional_encoding, loss_cls, loss_mask, loss_dice, train_cfg, test_cfg, init_cfg)