code: def main():
      args = parse_args()
  
      results = []
      cfg_visualizer = None
      dataset_meta = None
  
      inputs = []
      filename_list = []
      if isdir(args.inputs):
          dir = list_dir_or_file(
              args.inputs, list_dir=False, suffix=IMG_EXTENSIONS
          )
          for filename in dir:
              img = mmcv.imread(join_path(args.inputs, filename))
              inputs.append(img)
              filename_list.append(filename)
      else:
          img = mmcv.imread(args.inputs)
          inputs.append(img)
          img_name = osp.basename(args.inputs)
          filename_list.append(img_name)
  
      for i, (config, checkpoint) in enumerate(
          zip(args.config, args.checkpoints)
      ):
          inferencer = DetInferencer(
              config,
              checkpoint,
              device=args.device,
              palette=args.palette,
          )
  
          result_raw = inferencer(
              inputs=inputs,
              batch_size=args.batch_size,
              no_save_vis=True,
              pred_score_thr=args.pred_score_thr,
          )
  
          if i == 0:
              cfg_visualizer = inferencer.cfg.visualizer
              dataset_meta = inferencer.model.dataset_meta
              results = [
                  {
                      "bboxes_list": [],
                      "scores_list": [],
                      "labels_list": [],
                  }
                  for _ in range(len(result_raw["predictions"]))
              ]
  
          for res, raw in zip(results, result_raw["predictions"]):
              res["bboxes_list"].append(raw["bboxes"])
              res["scores_list"].append(raw["scores"])
              res["labels_list"].append(raw["labels"])
  
      visualizer = VISUALIZERS.build(cfg_visualizer)
      visualizer.dataset_meta = dataset_meta
  
      for i in range(len(results)):
          bboxes, scores, labels = weighted_boxes_fusion(
              results[i]["bboxes_list"],
              results[i]["scores_list"],
              results[i]["labels_list"],
              weights=args.weights,
              iou_thr=args.fusion_iou_thr,
              skip_box_thr=args.skip_box_thr,
              conf_type=args.conf_type,
          )
  
          pred_instances = InstanceData()
          pred_instances.bboxes = bboxes
          pred_instances.scores = scores
          pred_instances.labels = labels
  
          fusion_result = DetDataSample(pred_instances=pred_instances)
  
          img_name = filename_list[i]
  
          if not args.no_save_pred:
              out_json_path = (
                  args.out_dir
                  + "/preds/"
                  + img_name.split(".")[0]
                  + ".json"
              )
              mmengine.dump(
                  {
                      "labels": labels.tolist(),
                      "scores": scores.tolist(),
                      "bboxes": bboxes.tolist(),
                  },
                  out_json_path,
              )
  
          out_file = (
              osp.join(args.out_dir, "vis", img_name)
              if not args.no_save_vis
              else None
          )
  
          visualizer.add_datasample(
              img_name,
              inputs[i][..., ::-1],
              data_sample=fusion_result,
              show=args.show,
              draw_gt=False,
              wait_time=0,
              pred_score_thr=args.pred_score_thr,
              out_file=out_file,
          )
  
      if not args.no_save_vis:
          print_log(f"results have been saved at {args.out_dir}")
  
file_path: mmdetection/demo/demo_multi_model.py
imports: import argparse
  import os.path
  import mmcv
  import mmengine
  from mmengine.fileio import isdir, join_path, list_dir_or_file
  from mmengine.logging import print_log
  from mmengine.structures import InstanceData
  from mmdet.apis import DetInferencer
  from mmdet.models.utils import weighted_boxes_fusion
  from mmdet.registry import VISUALIZERS
  from mmdet.structures import DetDataSample
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types