docstr: Predict results from a batch of inputs and data samples with post-
  processing.
  
  Args:
      batch_inputs (Tensor): Inputs with shape (N, C, H, W).
      batch_data_samples (List[:obj:`DetDataSample`]): The Data
          Samples. It usually includes information such as
          `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
      rescale (bool): Whether to rescale the results.
          Defaults to True.
  
  Returns:
      list[:obj:`DetDataSample`]: Return the detection results of the
      input images. The returns value is DetDataSample,
      which usually contain 'pred_instances'. And the
      ``pred_instances`` usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
              (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
              (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
              the last dimension 4 arrange as (x1, y1, x2, y2).
          - masks (Tensor): Has a shape (num_instances, H, W).
docstr_tok: ["Predict","results","from","a","batch","of","inputs","and","data","samples","with","post-","processing",".","Args",":","batch_inputs","(","Tensor",")",":","Inputs","with","shape","(","N",",","C",",","H",",","W",")",".","batch_data_samples","(","List","[",":","obj",":","`","DetDataSample","`","]",")",":","The","Data","Samples",".","It","usually","includes","information","such","as","`","gt_instance","`",",","`","gt_panoptic_seg","`","and","`","gt_sem_seg","`",".","rescale","(","bool",")",":","Whether","to","rescale","the","results",".","Defaults","to","True",".","Returns",":","list","[",":","obj",":","`","DetDataSample","`","]",":","Return","the","detection","results","of","the","input","images",".","The","returns","value","is","DetDataSample",",","which","usually","contain","'pred_instances","'",".","And","the","``","pred_instances","``","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")",".","-","masks","(","Tensor",")",":","Has","a","shape","(","num_instances",",","H",",","W",")","."]
code: def predict(
      self,
      batch_inputs: Tensor,
      batch_data_samples: SampleList,
      rescale: bool = True,
  ) -> SampleList:
      """Predict results from a batch of inputs and data samples with post-
      processing.
  
      Args:
          batch_inputs (Tensor): Inputs with shape (N, C, H, W).
          batch_data_samples (List[:obj:`DetDataSample`]): The Data
              Samples. It usually includes information such as
              `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
          rescale (bool): Whether to rescale the results.
              Defaults to True.
  
      Returns:
          list[:obj:`DetDataSample`]: Return the detection results of the
          input images. The returns value is DetDataSample,
          which usually contain 'pred_instances'. And the
          ``pred_instances`` usually contains following keys.
  
              - scores (Tensor): Classification scores, has a shape
                  (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                  (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                  the last dimension 4 arrange as (x1, y1, x2, y2).
              - masks (Tensor): Has a shape (num_instances, H, W).
      """
      # For single image inference
      if "custom_entities" in batch_data_samples[0]:
          text_prompts = batch_data_samples[0].text
          if text_prompts != self._text_prompts:
              self._text_prompts = text_prompts
              class_names, zs_weight = get_class_weight(text_prompts)
              self._entities = class_names
              reset_cls_layer_weight(self.roi_head, zs_weight)
  
      assert self.with_bbox, "Bbox head must be implemented."
  
      x = self.extract_feat(batch_inputs)
  
      # If there are no pre-defined proposals, use RPN to get proposals
      if batch_data_samples[0].get("proposals", None) is None:
          rpn_results_list = self.rpn_head.predict(
              x, batch_data_samples, rescale=False
          )
      else:
          rpn_results_list = [
              data_sample.proposals
              for data_sample in batch_data_samples
          ]
  
      results_list = self.roi_head.predict(
          x, rpn_results_list, batch_data_samples, rescale=rescale
      )
  
      for data_sample, pred_instances in zip(
          batch_data_samples, results_list
      ):
          if len(pred_instances) > 0:
              label_names = []
              for labels in pred_instances.labels:
                  label_names.append(self._entities[labels])
              # for visualization
              pred_instances.label_names = label_names
          data_sample.pred_instances = pred_instances
  
      return batch_data_samples
  
imports: import copy
  from typing import List, Union
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmengine.logging import print_log
  from torch import Tensor
  from mmdet.datasets import LVISV1Dataset
  from mmdet.models.detectors.cascade_rcnn import CascadeRCNN
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
label_desc: Use image node_id 3 for calling the Detic obj's underlying member method code with example usage: obj.predict(batch_inputs, batch_data_samples, rescale) and returns: batch_data_samples