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_classes (int): Number of VIS classes.
      num_queries (int): Number of query in Transformer decoder.
          Defaults to 100.
      num_transformer_feat_level (int): Number of feats levels.
          Defaults to 3.
      pixel_decoder (:obj:`ConfigDict` or dict): Config for pixel
          decoder.
      enforce_decoder_input_project (bool, optional): 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.
          Defaults to `SinePositionalEncoding3D`.
      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 'CrossEntropyLoss'.
      loss_dice (:obj:`ConfigDict` or dict): Config of the dice loss.
          Defaults to 'DiceLoss'.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config of
          Mask2Former head. Defaults to None.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config of
          Mask2Former head. Defaults to None.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or             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_classes","(","int",")",":","Number","of","VIS","classes",".","num_queries","(","int",")",":","Number","of","query","in","Transformer","decoder",".","Defaults","to","100.","num_transformer_feat_level","(","int",")",":","Number","of","feats","levels",".","Defaults","to","3.","pixel_decoder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","for","pixel","decoder",".","enforce_decoder_input_project","(","bool",",","optional",")",":","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",".","Defaults","to","`","SinePositionalEncoding3D","`",".","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","'CrossEntropyLoss","'",".","loss_dice","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","the","dice","loss",".","Defaults","to","'DiceLoss","'",".","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Training","config","of","Mask2Former","head",".","Defaults","to","None",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Testing","config","of","Mask2Former","head",".","Defaults","to","None",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[",":","obj",":","`","ConfigDict","`","or","dict","]",",","optional",")",":","Initialization","config","dict",".","Defaults","to","None","."]
docstr: Test without augmentation.
  
  Args:
      x (tuple[Tensor]): Multi-level features from the
          upstream network, each is a 4D-tensor.
      data_samples (List[:obj:`TrackDataSample`]): The Data
          Samples. It usually includes information such as `gt_instance`.
      rescale (bool, Optional): If False, then returned bboxes and masks
          will fit the scale of img, otherwise, returned bboxes and masks
          will fit the scale of original image shape. Defaults to True.
  
  Returns:
      list[obj:`InstanceData`]: each contains the following keys
          - labels (Tensor): Prediction class indices                    for an image, with shape (n, ), n is the sum of                    number of stuff type and number of instance in an image.
          - masks (Tensor): Prediction mask for a                    image, with shape (n, t, h, w).
docstr_tok: ["Test","without","augmentation",".","Args",":","x","(","tuple","[","Tensor","]",")",":","Multi-level","features","from","the","upstream","network",",","each","is","a","4D-tensor",".","data_samples","(","List","[",":","obj",":","`","TrackDataSample","`","]",")",":","The","Data","Samples",".","It","usually","includes","information","such","as","`","gt_instance","`",".","rescale","(","bool",",","Optional",")",":","If","False",",","then","returned","bboxes","and","masks","will","fit","the","scale","of","img",",","otherwise",",","returned","bboxes","and","masks","will","fit","the","scale","of","original","image","shape",".","Defaults","to","True",".","Returns",":","list","[","obj",":","`","InstanceData","`","]",":","each","contains","the","following","keys","-","labels","(","Tensor",")",":","Prediction","class","indices","for","an","image",",","with","shape","(","n",",",")",",","n","is","the","sum","of","number","of","stuff","type","and","number","of","instance","in","an","image",".","-","masks","(","Tensor",")",":","Prediction","mask","for","a","image",",","with","shape","(","n",",","t",",","h",",","w",")","."]
code: def predict(
      self,
      x: Tuple[Tensor],
      data_samples: TrackDataSample,
      rescale: bool = True,
  ) -> InstanceList:
      """Test without augmentation.
  
          Args:
              x (tuple[Tensor]): Multi-level features from the
                  upstream network, each is a 4D-tensor.
              data_samples (List[:obj:`TrackDataSample`]): The Data
                  Samples. It usually includes information such as `gt_instance`.
              rescale (bool, Optional): If False, then returned bboxes and masks
                  will fit the scale of img, otherwise, returned bboxes and masks
                  will fit the scale of original image shape. Defaults to True.
  
          Returns:
              list[obj:`InstanceData`]: each contains the following keys
                  - labels (Tensor): Prediction class indices\
                      for an image, with shape (n, ), n is the sum of\
                      number of stuff type and number of instance in an image.
                  - masks (Tensor): Prediction mask for a\
                      image, with shape (n, t, h, w).
          """
  
      batch_img_metas = [
          data_samples[img_idx].metainfo
          for img_idx in range(len(data_samples))
      ]
      all_cls_scores, all_mask_preds = self(x, data_samples)
      mask_cls_results = all_cls_scores[-1]
      mask_pred_results = all_mask_preds[-1]
  
      mask_cls_results = mask_cls_results[0]
      # upsample masks
      img_shape = batch_img_metas[0]["batch_input_shape"]
      mask_pred_results = F.interpolate(
          mask_pred_results[0],
          size=(img_shape[0], img_shape[1]),
          mode="bilinear",
          align_corners=False,
      )
  
      results = self.predict_by_feat(
          mask_cls_results, mask_pred_results, batch_img_metas
      )
      return results
  
imports: import copy
  from collections import defaultdict
  from typing import Dict, List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Conv2d
  from mmcv.ops import point_sample
  from mmengine.model import ModuleList
  from mmengine.model.weight_init import caffe2_xavier_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.dense_heads import AnchorFreeHead, MaskFormerHead
  from mmdet.models.utils import get_uncertain_point_coords_with_randomness
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import TrackDataSample, TrackSampleList
  from mmdet.structures.mask import mask2bbox
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptMultiConfig, reduce_mean
  from ..layers import Mask2FormerTransformerDecoder
label_desc: Use image node_id 9 for calling the Mask2FormerTrackHead obj's underlying member method code with example usage: obj.predict(x, data_samples, rescale) and returns: results