code: def post_process(
      self,
      predictions,
      batch_data_samples,
      all_text_prompts,
      num_thing_class,
  ):
      batch_img_metas = [
          data_samples.metainfo for data_samples in batch_data_samples
      ]
      batch_input_shape = batch_data_samples[0].metainfo[
          "batch_input_shape"
      ]
  
      if self.task == "caption":
          for text, data_samples in zip(
              predictions["pred_caption"], batch_data_samples
          ):
              data_samples.pred_caption = text
  
          if "pred_instances" in batch_data_samples[0]:
              for img_metas, data_samples in zip(
                  batch_img_metas, batch_data_samples
              ):
                  original_caption = data_samples.text.split(".")
                  text_prompts = list(
                      filter(lambda x: len(x) > 0, original_caption)
                  )
  
                  height = img_metas["ori_shape"][0]
                  width = img_metas["ori_shape"][1]
                  image_size = img_metas["grounding_img_shape"][:2]
  
                  mask_pred_result = (
                      data_samples.pred_instances.masks.float()
                  )
                  mask_cls_result = (
                      data_samples.pred_instances.scores.float()
                  )
  
                  mask_pred_result = retry_if_cuda_oom(
                      sem_seg_postprocess
                  )(mask_pred_result, image_size, height, width)
  
                  pred_instances = retry_if_cuda_oom(
                      self._instance_inference
                  )(mask_cls_result, mask_pred_result, text_prompts)
                  data_samples.pred_instances = pred_instances
  
      elif self.task in ["semseg", "instance", "panoptic"]:
          mask_pred_results = predictions["pred_masks"]
          mask_cls_results = predictions["pred_logits"]
          if is_lower_torch_version():
              mask_pred_results = F.interpolate(
                  mask_pred_results,
                  size=(batch_input_shape[-2], batch_input_shape[-1]),
                  mode="bicubic",
                  align_corners=False,
              )
          else:
              mask_pred_results = F.interpolate(
                  mask_pred_results,
                  size=(batch_input_shape[-2], batch_input_shape[-1]),
                  mode="bicubic",
                  align_corners=False,
                  antialias=True,
              )
  
          # for batch
          for (
              mask_cls_result,
              mask_pred_result,
              img_metas,
              data_samples,
          ) in zip(
              mask_cls_results,
              mask_pred_results,
              batch_img_metas,
              batch_data_samples,
          ):
              height = img_metas["ori_shape"][0]
              width = img_metas["ori_shape"][1]
              image_size = img_metas["img_shape"][:2]
              mask_pred_result = retry_if_cuda_oom(sem_seg_postprocess)(
                  mask_pred_result, image_size, height, width
              )
              mask_cls_result = mask_cls_result.to(mask_pred_result)
  
              if self.task == "semseg":
                  pred_sem_seg = retry_if_cuda_oom(
                      self._semantic_inference
                  )(mask_cls_result, mask_pred_result, all_text_prompts)
                  data_samples.pred_sem_seg = pred_sem_seg
              elif self.task == "instance":
                  pred_instances = retry_if_cuda_oom(
                      self._instance_inference
                  )(mask_cls_result, mask_pred_result, all_text_prompts)
                  data_samples.pred_instances = pred_instances
              elif self.task == "panoptic":
                  pred_panoptic_seg = retry_if_cuda_oom(
                      self._panoptic_inference
                  )(
                      mask_cls_result,
                      mask_pred_result,
                      all_text_prompts,
                      num_thing_class,
                  )
                  data_samples.pred_panoptic_seg = pred_panoptic_seg
      elif self.task == "ref-seg":
          mask_pred_results = predictions["pred_masks"]
          mask_cls_results = predictions["pred_logits"]
          results_ = zip(
              mask_pred_results,
              mask_cls_results,
              batch_img_metas,
              batch_data_samples,
          )
          for (
              mask_pred_result,
              mask_cls_result,
              img_metas,
              data_samples,
          ) in results_:
              if is_lower_torch_version():
                  mask_pred_result = F.interpolate(
                      mask_pred_result[None],
                      size=(
                          batch_input_shape[-2],
                          batch_input_shape[-1],
                      ),
                      mode="bicubic",
                      align_corners=False,
                  )[0]
              else:
                  mask_pred_result = F.interpolate(
                      mask_pred_result[None],
                      size=(
                          batch_input_shape[-2],
                          batch_input_shape[-1],
                      ),
                      mode="bicubic",
                      align_corners=False,
                      antialias=True,
                  )[0]
  
              if self.return_inter_mask:
                  mask = mask_pred_result > 0
                  pred_instances = InstanceData()
                  pred_instances.masks = mask
                  pred_instances.scores = mask_cls_result
                  data_samples.pred_instances = pred_instances
                  continue
  
              height = img_metas["ori_shape"][0]
              width = img_metas["ori_shape"][1]
              image_size = img_metas["img_shape"][:2]
              mask_pred_result = retry_if_cuda_oom(sem_seg_postprocess)(
                  mask_pred_result, image_size, height, width
              )
  
              pred_instances = retry_if_cuda_oom(
                  self._instance_inference
              )(mask_cls_result, mask_pred_result, all_text_prompts)
              data_samples.pred_instances = pred_instances
      elif self.task == "retrieval":
          batch_data_samples[0].pred_score = predictions["pred_logits"]
      return batch_data_samples
  
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 4 for calling the XDecoderUnifiedhead obj's underlying member method code with example usage: obj.post_process(predictions, batch_data_samples, all_text_prompts, num_thing_class) and returns: batch_data_samples