code: def save_result(save_path, results, catid2name, threshold):
      """
      save result as txt
      """
      img_id = int(results["im_id"])
      with open(save_path, "w") as f:
          if "bbox_res" in results:
              for dt in results["bbox_res"]:
                  catid, bbox, score = (
                      dt["category_id"],
                      dt["bbox"],
                      dt["score"],
                  )
                  if score < threshold:
                      continue
                  # each bbox result as a line
                  # for rbox: classname score x1 y1 x2 y2 x3 y3 x4 y4
                  # for bbox: classname score x1 y1 w h
                  bbox_pred = "{} {} ".format(
                      catid2name[catid], score
                  ) + " ".join([str(e) for e in bbox])
                  f.write(bbox_pred + "\n")
          elif "keypoint_res" in results:
              for dt in results["keypoint_res"]:
                  kpts = dt["keypoints"]
                  scores = dt["score"]
                  keypoint_pred = [img_id, scores, kpts]
                  print(keypoint_pred, file=f)
          else:
              print("No valid results found, skip txt save")
  
file_path: PaddleDetection/ppdet/utils/visualizer.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import os
  import numpy
  from PIL import Image, ImageDraw, ImageFont
  import cv2
  import math
  from .colormap import colormap
  from ppdet.utils.logger import setup_logger
  from ppdet.utils.compact import imagedraw_textsize_c
  from ppdet.utils.download import get_path
label_desc: Use image node_id 4 for calling a global function with example usage: save_result(save_path, results, catid2name, threshold) without return types