code: def write_kie_result(fout, node, data):
      """
      Write infer result to output file, sorted by the predict label of each line.
      The format keeps the same as the input with additional score attribute.
      """
      import json
  
      label = data["label"]
      annotations = json.loads(label)
      max_value, max_idx = paddle.max(node, -1), paddle.argmax(node, -1)
      node_pred_label = max_idx.numpy().tolist()
      node_pred_score = max_value.numpy().tolist()
      res = []
      for i, label in enumerate(node_pred_label):
          pred_score = "{:.2f}".format(node_pred_score[i])
          pred_res = {
              "label": label,
              "transcription": annotations[i]["transcription"],
              "score": pred_score,
              "points": annotations[i]["points"],
          }
          res.append(pred_res)
      res.sort(key=lambda x: x["label"])
      fout.writelines([json.dumps(res, ensure_ascii=False) + "\n"])
  
file_path: PaddleOCR/tools/infer_kie.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import paddle.nn.functional
  import os
  import sys
  import cv2
  import paddle
  from ppocr.data import create_operators, transform
  from ppocr.modeling.architectures import build_model
  from ppocr.utils.save_load import load_model
  import tools.program
  import time
label_desc: Use image node_id 3 for calling a global function with example usage: write_kie_result(fout, node, data) without return types