code: def _panoptic_inference(
      self, mask_cls, mask_pred, all_text_prompts, num_thing_class
  ):
      scores, labels = F.softmax(mask_cls, dim=-1).max(-1)
      mask_pred = mask_pred.sigmoid()
  
      keep = labels.ne(len(all_text_prompts)) & (
          scores > self.test_cfg.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.test_cfg.get("ignore_index", 255),
          dtype=torch.int32,
          device=cur_masks.device,
      )
      instance_id = 1
  
      if cur_masks.shape[0] > 0:
          cur_mask_ids = cur_prob_masks.argmax(0)
          for k in range(cur_classes.shape[0]):
              pred_class = cur_classes[k].item()
              isthing = int(pred_class) < num_thing_class
              mask_area = (cur_mask_ids == k).sum().item()
              original_area = (cur_masks[k] >= 0.5).sum().item()
              mask = (cur_mask_ids == k) & (cur_masks[k] >= 0.5)
  
              if (
                  mask_area > 0
                  and original_area > 0
                  and mask.sum().item() > 0
              ):
                  if (
                      mask_area / original_area
                      < self.test_cfg.overlap_thr
                  ):
                      continue
                  # merge stuff regions
                  if not isthing:
                      panoptic_seg[mask] = int(pred_class)
                  else:
                      panoptic_seg[mask] = (
                          int(pred_class)
                          + instance_id * INSTANCE_OFFSET
                      )
                      instance_id += 1
  
      panoptic_seg = PixelData(
          sem_seg=panoptic_seg[None],
          metainfo={
              "label_names": all_text_prompts,
              "ignore_index": self.test_cfg.get("ignore_index", 255),
          },
      )
      return panoptic_seg
  
file_path: mmdetection/projects/XDecoder/xdecoder/unified_head.py
imports: import copy
  from typing import Sequence
  import torch
  from mmengine.structures import InstanceData, PixelData
  from torch import nn
  from torch.nn import functional
  from mmdet.evaluation.functional import INSTANCE_OFFSET
  from mmdet.registry import MODELS
  from .utils import is_lower_torch_version, retry_if_cuda_oom, sem_seg_postprocess
label_desc: Use image node_id 7 for calling the XDecoderUnifiedhead obj's underlying member method code with example usage: obj._panoptic_inference(mask_cls, mask_pred, all_text_prompts, num_thing_class) and returns: panoptic_seg