docstr: Call the inferencer.
  
  Args:
      inputs (InputsType): Inputs for the inferencer.
      batch_size (int): Inference batch size. Defaults to 1.
      show (bool): Whether to display the visualization results in a
          popup window. Defaults to False.
      wait_time (float): The interval of show (s). Defaults to 0.
      no_save_vis (bool): Whether to force not to save prediction
          vis results. Defaults to False.
      draw_pred (bool): Whether to draw predicted bounding boxes.
          Defaults to True.
      pred_score_thr (float): Minimum score of bboxes to draw.
          Defaults to 0.3.
      return_datasamples (bool): Whether to return results as
          :obj:`DetDataSample`. Defaults to False.
      print_result (bool): Whether to print the inference result w/o
          visualization to the console. Defaults to False.
      no_save_pred (bool): Whether to force not to save prediction
          results. Defaults to True.
      out_file: Dir to save the inference results or
          visualization. If left as empty, no file will be saved.
          Defaults to ''.
  
      **kwargs: Other keyword arguments passed to :meth:`preprocess`,
          :meth:`forward`, :meth:`visualize` and :meth:`postprocess`.
          Each key in kwargs should be in the corresponding set of
          ``preprocess_kwargs``, ``forward_kwargs``, ``visualize_kwargs``
          and ``postprocess_kwargs``.
  
  Returns:
      dict: Inference and visualization results.
docstr_tok: ["Call","the","inferencer",".","Args",":","inputs","(","InputsType",")",":","Inputs","for","the","inferencer",".","batch_size","(","int",")",":","Inference","batch","size",".","Defaults","to","1.","show","(","bool",")",":","Whether","to","display","the","visualization","results","in","a","popup","window",".","Defaults","to","False",".","wait_time","(","float",")",":","The","interval","of","show","(","s",")",".","Defaults","to","0.","no_save_vis","(","bool",")",":","Whether","to","force","not","to","save","prediction","vis","results",".","Defaults","to","False",".","draw_pred","(","bool",")",":","Whether","to","draw","predicted","bounding","boxes",".","Defaults","to","True",".","pred_score_thr","(","float",")",":","Minimum","score","of","bboxes","to","draw",".","Defaults","to","0.3.","return_datasamples","(","bool",")",":","Whether","to","return","results","as",":","obj",":","`","DetDataSample","`",".","Defaults","to","False",".","print_result","(","bool",")",":","Whether","to","print","the","inference","result","w\/o","visualization","to","the","console",".","Defaults","to","False",".","no_save_pred","(","bool",")",":","Whether","to","force","not","to","save","prediction","results",".","Defaults","to","True",".","out_file",":","Dir","to","save","the","inference","results","or","visualization",".","If","left","as","empty",",","no","file","will","be","saved",".","Defaults","to","``",".","*","*","kwargs",":","Other","keyword","arguments","passed","to",":","meth",":","`","preprocess","`",",",":","meth",":","`","forward","`",",",":","meth",":","`","visualize","`","and",":","meth",":","`","postprocess","`",".","Each","key","in","kwargs","should","be","in","the","corresponding","set","of","``","preprocess_kwargs","``",",","``","forward_kwargs","``",",","``","visualize_kwargs","``","and","``","postprocess_kwargs","``",".","Returns",":","dict",":","Inference","and","visualization","results","."]
code: def __call__(
      self,
      inputs: InputsType,
      batch_size: int = 1,
      return_vis: bool = False,
      show: bool = False,
      wait_time: int = 0,
      no_save_vis: bool = False,
      draw_pred: bool = True,
      pred_score_thr: float = 0.3,
      return_datasamples: bool = False,
      print_result: bool = False,
      no_save_pred: bool = True,
      out_dir: str = "",
      texts: Optional[Union[str, list]] = None,
      # by open panoptic task
      stuff_texts: Optional[Union[str, list]] = None,
      custom_entities: bool = False,  # by GLIP
      **kwargs,
  ) -> dict:
      """Call the inferencer.
  
      Args:
          inputs (InputsType): Inputs for the inferencer.
          batch_size (int): Inference batch size. Defaults to 1.
          show (bool): Whether to display the visualization results in a
              popup window. Defaults to False.
          wait_time (float): The interval of show (s). Defaults to 0.
          no_save_vis (bool): Whether to force not to save prediction
              vis results. Defaults to False.
          draw_pred (bool): Whether to draw predicted bounding boxes.
              Defaults to True.
          pred_score_thr (float): Minimum score of bboxes to draw.
              Defaults to 0.3.
          return_datasamples (bool): Whether to return results as
              :obj:`DetDataSample`. Defaults to False.
          print_result (bool): Whether to print the inference result w/o
              visualization to the console. Defaults to False.
          no_save_pred (bool): Whether to force not to save prediction
              results. Defaults to True.
          out_file: Dir to save the inference results or
              visualization. If left as empty, no file will be saved.
              Defaults to ''.
  
          **kwargs: Other keyword arguments passed to :meth:`preprocess`,
              :meth:`forward`, :meth:`visualize` and :meth:`postprocess`.
              Each key in kwargs should be in the corresponding set of
              ``preprocess_kwargs``, ``forward_kwargs``, ``visualize_kwargs``
              and ``postprocess_kwargs``.
  
      Returns:
          dict: Inference and visualization results.
      """
      assert batch_size == 1
      (
          preprocess_kwargs,
          forward_kwargs,
          visualize_kwargs,
          postprocess_kwargs,
      ) = self._dispatch_kwargs(**kwargs)
  
      ori_inputs = self._inputs_to_list(inputs)
  
      if isinstance(texts, str):
          texts = [texts] * len(ori_inputs)
  
      for i in range(len(texts)):
          if isinstance(ori_inputs[i], str):
              ori_inputs[i] = {
                  "text": texts[i],
                  "img_path": ori_inputs[i],
                  "custom_entities": custom_entities,
              }
          else:
              ori_inputs[i] = {
                  "text": texts[i],
                  "img": ori_inputs[i],
                  "custom_entities": custom_entities,
              }
      inputs = self.preprocess(
          ori_inputs, batch_size=batch_size, **preprocess_kwargs
      )
  
      results_dict = {"predictions": [], "visualization": []}
      for ori_inputs, grounding_data, caption_data in track(
          inputs, description="Inference"
      ):
          self.model.sem_seg_head.task = "ref-seg"
          self.model.sem_seg_head.predictor.task = "ref-seg"
          preds = self.forward(grounding_data, **forward_kwargs)
  
          for data_sample, pred_datasmaple in zip(
              caption_data["data_samples"], preds
          ):
              data_sample.pred_instances = (
                  pred_datasmaple.pred_instances
              )
              data_sample.set_metainfo(
                  {
                      "grounding_img_shape": pred_datasmaple.metainfo[
                          "img_shape"
                      ]
                  }
              )
  
          self.model.sem_seg_head.task = "caption"
          self.model.sem_seg_head.predictor.task = "caption"
  
          preds = self.forward(caption_data, **forward_kwargs)
  
          if isinstance(ori_inputs, dict):
              ori_inputs = ori_inputs["img_path"]
  
          visualization = self.visualize(
              ori_inputs,
              preds,
              return_vis=return_vis,
              show=show,
              wait_time=wait_time,
              draw_pred=draw_pred,
              pred_score_thr=pred_score_thr,
              no_save_vis=no_save_vis,
              img_out_dir=out_dir,
              **visualize_kwargs,
          )
          results = self.postprocess(
              preds,
              visualization,
              return_datasamples=return_datasamples,
              print_result=print_result,
              no_save_pred=no_save_pred,
              pred_out_dir=out_dir,
              **postprocess_kwargs,
          )
          results_dict["predictions"].extend(results["predictions"])
          if results["visualization"] is not None:
              results_dict["visualization"].extend(
                  results["visualization"]
              )
      return results_dict
  
file_path: mmdetection/projects/XDecoder/xdecoder/inference/image_caption.py
imports: import copy
  import os.path
  from typing import Iterable, List, Optional, Tuple, Union
  import mmcv
  import mmengine
  import numpy
  import torch
  from mmengine.dataset import Compose
  from rich.progress import track
  from mmdet.apis.det_inferencer import DetInferencer, InputsType, PredType
  from mmdet.utils import ConfigType
label_desc: Use image node_id 3 for calling the RefImageCaptionInferencer obj's underlying member method code with example usage: obj.__call__(inputs, batch_size, return_vis, show, wait_time, no_save_vis, draw_pred, pred_score_thr, return_datasamples, print_result, no_save_pred, out_dir, texts, stuff_texts, custom_entities) and returns: results_dict