code: def write_results(
      preds,
      scales,
      centers,
      datadir,
      dataset,
      result_dir,
      input_size=[473, 473],
  ):
      palette = get_palette(20)
      if not os.path.exists(result_dir):
          os.makedirs(result_dir)
  
      json_file = os.path.join(
          datadir, "annotations", dataset + ".json"
      )
      with open(json_file) as data_file:
          data_list = json.load(data_file)
          data_list = data_list["root"]
      for item, pred_out, s, c in zip(
          data_list, preds, scales, centers
      ):
          im_name = item["im_name"]
          w = item["img_width"]
          h = item["img_height"]
          pred = transform_parsing(pred_out, c, s, w, h, input_size)
  
          save_path = os.path.join(result_dir, im_name[:-4] + ".png")
          output_im = PILImage.fromarray(
              np.asarray(pred, dtype=np.uint8)
          )
          output_im.putpalette(palette)
          output_im.save(save_path)
  
file_path: insightface/parsing/dml_csr/utils/miou.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import argparse
  import cv2
  import json
  import numpy
  import os
  from collections import OrderedDict
  from PIL import Image
  from utils.transforms import transform_parsing
label_desc: Use image node_id 7 for calling a global function with example usage: write_results(preds, scales, centers, datadir, dataset, result_dir, input_size) without return types