code: def save_results(self, results, output_dir, imid2path):
      if imid2path:
          data_dicts = defaultdict(list)
          for result in results:
              image_id = result["image_id"]
              data_dicts[image_id].append(result)
  
          for image_id, image_path in imid2path.items():
              basename = os.path.splitext(
                  os.path.split(image_path)[-1]
              )[0]
              output = os.path.join(
                  output_dir, "{}.txt".format(basename)
              )
              dets = data_dicts.get(image_id, [])
              with open(output, "w") as f:
                  for det in dets:
                      catid, bbox, score = (
                          det["category_id"],
                          det["bbox"],
                          det["score"],
                      )
                      bbox_pred = "{} {} ".format(
                          self.catid2name[catid], score
                      ) + " ".join([str(e) for e in bbox])
                      f.write(bbox_pred + "\n")
  
          logger.info(
              "The bbox result is saved to {}.".format(output_dir)
          )
      else:
          output = os.path.join(output_dir, "bbox.json")
          with open(output, "w") as f:
              json.dump(results, f)
  
          logger.info("The bbox result is saved to {}.".format(output))
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import sys
  import json
  import paddle
  import numpy
  import typing
  from collections import defaultdict
  from pathlib import Path
  from .map_utils import prune_zero_padding, DetectionMAP
  from .coco_utils import get_infer_results, cocoapi_eval
  from .widerface_utils import face_eval_run
  from ppdet.data.source.category import get_categories
  from ppdet.modeling.rbox_utils import poly2rbox_np
  from ppdet.utils.logger import setup_logger
label_desc: Use image node_id 4 for calling the RBoxMetric obj's underlying member method code with example usage: obj.save_results(results, output_dir, imid2path) without return types