code: def save_result(result, result_dir, filename, remove_duplicate=""):
      """Saving predictions as json file for evaluation."""
      # combine results from all processes
      if remove_duplicate:
          result_new = []
          id_list = []
          for res in track_iter_progress(result):
              if res[remove_duplicate] not in id_list:
                  id_list.append(res[remove_duplicate])
                  result_new.append(res)
          result = result_new
  
      final_result_file_url = os.path.join(
          result_dir, "%s.json" % filename
      )
      print(f"result file saved to {final_result_file_url}")
      json.dump(result, open(final_result_file_url, "w"))
  
      return final_result_file_url
  
file_path: mmdetection/mmdet/evaluation/metrics/coco_caption_metric.py
imports: import json
  import os
  import tempfile
  from typing import List, Optional
  from mmengine.evaluator import BaseMetric
  from mmengine.utils import track_iter_progress
  from pycocotools.coco import COCO
  from mmdet.registry import METRICS
label_desc: Use image node_id 1 for calling a global function with example usage: save_result(result, result_dir, filename, remove_duplicate) and returns: final_result_file_url