code: def _semantic_inference(self, mask_cls, mask_pred, text_prompts):
      mask_cls = F.softmax(mask_cls, dim=-1)[..., :-1]
      mask_pred = mask_pred.sigmoid()
      sem_seg = torch.einsum("qc,qhw->chw", mask_cls, mask_pred)
  
      if sem_seg.shape[0] == 1:
          # 0 is foreground, ignore_index is background
          sem_seg = (sem_seg.squeeze(0) <= self.test_cfg.mask_thr).int()
          sem_seg[sem_seg == 1] = self.test_cfg.get("ignore_index", 255)
      else:
          # 0 is foreground, ignore_index is background
          if self.test_cfg.use_thr_for_mc:
              foreground_flag = sem_seg > self.test_cfg.mask_thr
              sem_seg = sem_seg.max(0)[1]
              sem_seg[foreground_flag.sum(0) == 0] = self.test_cfg.get(
                  "ignore_index", 255
              )
          else:
              sem_seg = sem_seg.max(0)[1]
      pred_sem_seg = PixelData(
          sem_seg=sem_seg[None],
          metainfo={
              "label_names": text_prompts,
              "ignore_index": self.test_cfg.get("ignore_index", 255),
          },
      )
      return pred_sem_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 6 for calling the XDecoderUnifiedhead obj's underlying member method code with example usage: obj._semantic_inference(mask_cls, mask_pred, text_prompts) and returns: pred_sem_seg