class_docstr: MaskFormer fusion head which postprocesses results for panoptic
  segmentation, instance segmentation and semantic segmentation.
class_docstr_tok: ["MaskFormer","fusion","head","which","postprocesses","results","for","panoptic","segmentation",",","instance","segmentation","and","semantic","segmentation","."]
docstr: Panoptic segmengation inference.
  
  Args:
      mask_cls (Tensor): Classfication outputs of shape
          (num_queries, cls_out_channels) for a image.
          Note `cls_out_channels` should includes
          background.
      mask_pred (Tensor): Mask outputs of shape
          (num_queries, h, w) for a image.
  
  Returns:
      :obj:`PixelData`: Panoptic segment result of shape                 (h, w), each element in Tensor means:                 ``segment_id = _cls + instance_id * INSTANCE_OFFSET``.
docstr_tok: ["Panoptic","segmengation","inference",".","Args",":","mask_cls","(","Tensor",")",":","Classfication","outputs","of","shape","(","num_queries",",","cls_out_channels",")","for","a","image",".","Note","`","cls_out_channels","`","should","includes","background",".","mask_pred","(","Tensor",")",":","Mask","outputs","of","shape","(","num_queries",",","h",",","w",")","for","a","image",".","Returns",":",":","obj",":","`","PixelData","`",":","Panoptic","segment","result","of","shape","(","h",",","w",")",",","each","element","in","Tensor","means",":","``","segment_id","=","_cls","+","instance_id","*","INSTANCE_OFFSET","``","."]
code: def panoptic_postprocess(
      self, mask_cls: Tensor, mask_pred: Tensor
  ) -> PixelData:
      """Panoptic segmengation inference.
  
          Args:
              mask_cls (Tensor): Classfication outputs of shape
                  (num_queries, cls_out_channels) for a image.
                  Note `cls_out_channels` should includes
                  background.
              mask_pred (Tensor): Mask outputs of shape
                  (num_queries, h, w) for a image.
  
          Returns:
              :obj:`PixelData`: Panoptic segment result of shape \
                  (h, w), each element in Tensor means: \
                  ``segment_id = _cls + instance_id * INSTANCE_OFFSET``.
          """
      object_mask_thr = self.test_cfg.get("object_mask_thr", 0.8)
      iou_thr = self.test_cfg.get("iou_thr", 0.8)
      filter_low_score = self.test_cfg.get("filter_low_score", False)
  
      scores, labels = F.softmax(mask_cls, dim=-1).max(-1)
      mask_pred = mask_pred.sigmoid()
  
      keep = labels.ne(self.num_classes) & (scores > object_mask_thr)
      cur_scores = scores[keep]
      cur_classes = labels[keep]
      cur_masks = mask_pred[keep]
  
      cur_prob_masks = cur_scores.view(-1, 1, 1) * cur_masks
  
      h, w = cur_masks.shape[-2:]
      panoptic_seg = torch.full(
          (h, w),
          self.num_classes,
          dtype=torch.int32,
          device=cur_masks.device,
      )
      if cur_masks.shape[0] == 0:
          # We didn't detect any mask :(
          pass
      else:
          cur_mask_ids = cur_prob_masks.argmax(0)
          instance_id = 1
          for k in range(cur_classes.shape[0]):
              pred_class = int(cur_classes[k].item())
              isthing = pred_class < self.num_things_classes
              mask = cur_mask_ids == k
              mask_area = mask.sum().item()
              original_area = (cur_masks[k] >= 0.5).sum().item()
  
              if filter_low_score:
                  mask = mask & (cur_masks[k] >= 0.5)
  
              if mask_area > 0 and original_area > 0:
                  if mask_area / original_area < iou_thr:
                      continue
  
                  if not isthing:
                      # different stuff regions of same class will be
                      # merged here, and stuff share the instance_id 0.
                      panoptic_seg[mask] = pred_class
                  else:
                      panoptic_seg[mask] = (
                          pred_class + instance_id * INSTANCE_OFFSET
                      )
                      instance_id += 1
  
      return PixelData(sem_seg=panoptic_seg[None])
  
file_path: mmdetection/mmdet/models/seg_heads/panoptic_fusion_heads/maskformer_fusion_head.py
imports: from typing import List
  import torch
  import torch.nn.functional
  from mmengine.structures import InstanceData, PixelData
  from torch import Tensor
  from mmdet.evaluation.functional import INSTANCE_OFFSET
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.mask import mask2bbox
  from mmdet.utils import OptConfigType, OptMultiConfig
  from .base_panoptic_fusion_head import BasePanopticFusionHead
label_desc: Use image node_id 3 for calling the MaskFormerFusionHead obj's underlying member method code with example usage: obj.panoptic_postprocess(mask_cls, mask_pred) and returns: PixelData