class_docstr: Object Detection Inferencer.
  
  Args:
      model (str, optional): Path to the config file or the model name
          defined in metafile. For example, it could be
          "rtmdet-s" or 'rtmdet_s_8xb32-300e_coco' or
          "configs/rtmdet/rtmdet_s_8xb32-300e_coco.py".
          If model is not specified, user must provide the
          `weights` saved by MMEngine which contains the config string.
          Defaults to None.
      weights (str, optional): Path to the checkpoint. If it is not specified
          and model is a model name of metafile, the weights will be loaded
          from metafile. Defaults to None.
      device (str, optional): Device to run inference. If None, the available
          device will be automatically used. Defaults to None.
      scope (str, optional): The scope of the model. Defaults to mmdet.
      palette (str): Color palette used for visualization. The order of
          priority is palette -> config -> checkpoint. Defaults to 'none'.
      show_progress (bool): Control whether to display the progress
          bar during the inference process. Defaults to True.
docstr: Process the predictions and visualization results from ``forward``
  and ``visualize``.
  
  This method should be responsible for the following tasks:
  
  1. Convert datasamples into a json-serializable dict if needed.
  2. Pack the predictions and visualization results and return them.
  3. Dump or log the predictions.
  
  Args:
      preds (List[:obj:`DetDataSample`]): Predictions of the model.
      visualization (Optional[np.ndarray]): Visualized predictions.
      return_datasamples (bool): Whether to use Datasample to store
          inference results. If False, dict will be used.
      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 False.
      pred_out_dir: Dir to save the inference results w/o
          visualization. If left as empty, no file will be saved.
          Defaults to ''.
  
  Returns:
      dict: Inference and visualization results with key ``predictions``
      and ``visualization``.
  
      - ``visualization`` (Any): Returned by :meth:`visualize`.
      - ``predictions`` (dict or DataSample): Returned by
          :meth:`forward` and processed in :meth:`postprocess`.
          If ``return_datasamples=False``, it usually should be a
          json-serializable dict containing only basic data elements such
          as strings and numbers.
docstr_tok: ["Process","the","predictions","and","visualization","results","from","``","forward","``","and","``","visualize","``",".","This","method","should","be","responsible","for","the","following","tasks",":","1",".","Convert","datasamples","into","a","json-serializable","dict","if","needed",".","2",".","Pack","the","predictions","and","visualization","results","and","return","them",".","3",".","Dump","or","log","the","predictions",".","Args",":","preds","(","List","[",":","obj",":","`","DetDataSample","`","]",")",":","Predictions","of","the","model",".","visualization","(","Optional","[","np.ndarray","]",")",":","Visualized","predictions",".","return_datasamples","(","bool",")",":","Whether","to","use","Datasample","to","store","inference","results",".","If","False",",","dict","will","be","used",".","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","False",".","pred_out_dir",":","Dir","to","save","the","inference","results","w\/o","visualization",".","If","left","as","empty",",","no","file","will","be","saved",".","Defaults","to","``",".","Returns",":","dict",":","Inference","and","visualization","results","with","key","``","predictions","``","and","``","visualization","``",".","-","``","visualization","``","(","Any",")",":","Returned","by",":","meth",":","`","visualize","`",".","-","``","predictions","``","(","dict","or","DataSample",")",":","Returned","by",":","meth",":","`","forward","`","and","processed","in",":","meth",":","`","postprocess","`",".","If","``","return_datasamples=False","``",",","it","usually","should","be","a","json-serializable","dict","containing","only","basic","data","elements","such","as","strings","and","numbers","."]
code: def postprocess(
      self,
      preds: PredType,
      visualization: Optional[List[np.ndarray]] = None,
      return_datasamples: bool = False,
      print_result: bool = False,
      no_save_pred: bool = False,
      pred_out_dir: str = "",
      **kwargs,
  ) -> Dict:
      """Process the predictions and visualization results from ``forward``
      and ``visualize``.
  
      This method should be responsible for the following tasks:
  
      1. Convert datasamples into a json-serializable dict if needed.
      2. Pack the predictions and visualization results and return them.
      3. Dump or log the predictions.
  
      Args:
          preds (List[:obj:`DetDataSample`]): Predictions of the model.
          visualization (Optional[np.ndarray]): Visualized predictions.
          return_datasamples (bool): Whether to use Datasample to store
              inference results. If False, dict will be used.
          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 False.
          pred_out_dir: Dir to save the inference results w/o
              visualization. If left as empty, no file will be saved.
              Defaults to ''.
  
      Returns:
          dict: Inference and visualization results with key ``predictions``
          and ``visualization``.
  
          - ``visualization`` (Any): Returned by :meth:`visualize`.
          - ``predictions`` (dict or DataSample): Returned by
              :meth:`forward` and processed in :meth:`postprocess`.
              If ``return_datasamples=False``, it usually should be a
              json-serializable dict containing only basic data elements such
              as strings and numbers.
      """
      if no_save_pred is True:
          pred_out_dir = ""
  
      result_dict = {}
      results = preds
      if not return_datasamples:
          results = []
          for pred in preds:
              result = self.pred2dict(pred, pred_out_dir)
              results.append(result)
      elif pred_out_dir != "":
          warnings.warn(
              "Currently does not support saving datasample "
              "when return_datasamples is set to True. "
              "Prediction results are not saved!"
          )
      # Add img to the results after printing and dumping
      result_dict["predictions"] = results
      if print_result:
          print(result_dict)
      result_dict["visualization"] = visualization
      return result_dict
  
imports: import copy
  import os.path
  import warnings
  from typing import Dict, Iterable, List, Optional, Sequence, Tuple, Union
  import mmcv
  import mmengine
  import numpy
  import torch.nn
  from mmcv.transforms import LoadImageFromFile
  from mmengine.dataset import Compose
  from mmengine.fileio import get_file_backend, isdir, join_path, list_dir_or_file
  from mmengine.infer.infer import BaseInferencer, ModelType
  from mmengine.model.utils import revert_sync_batchnorm
  from mmengine.registry import init_default_scope
  from mmengine.runner.checkpoint import _load_checkpoint_to_model
  from mmengine.visualization import Visualizer
  from rich.progress import track
  from mmdet.evaluation import INSTANCE_OFFSET
  from mmdet.registry import DATASETS
  from mmdet.structures import DetDataSample
  from mmdet.structures.mask import encode_mask_results, mask2bbox
  from mmdet.utils import ConfigType
  from ..evaluation import get_classes
label_desc: Use image node_id 11 for calling the DetInferencer obj's underlying member method code with example usage: obj.postprocess(preds, visualization, return_datasamples, print_result, no_save_pred, pred_out_dir) and returns: result_dict