code: def main(args):
      image_file_list = get_image_file_list(args.image_dir)
      ser_predictor = SerPredictor(args)
      count = 0
      total_time = 0
  
      os.makedirs(args.output, exist_ok=True)
      with open(
          os.path.join(args.output, "infer.txt"),
          mode="w",
          encoding="utf-8",
      ) as f_w:
          for image_file in image_file_list:
              img, flag, _ = check_and_read(image_file)
              if not flag:
                  img = cv2.imread(image_file)
                  img = img[:, :, ::-1]
              if img is None:
                  logger.info(
                      "error in loading image:{}".format(image_file)
                  )
                  continue
              ser_res, _, elapse = ser_predictor(img)
              ser_res = ser_res[0]
  
              res_str = "{}\t{}\n".format(
                  image_file,
                  json.dumps(
                      {
                          "ocr_info": ser_res,
                      },
                      ensure_ascii=False,
                  ),
              )
              f_w.write(res_str)
  
              img_res = draw_ser_results(
                  image_file,
                  ser_res,
                  font_path=args.vis_font_path,
              )
  
              img_save_path = os.path.join(
                  args.output, os.path.basename(image_file)
              )
              cv2.imwrite(img_save_path, img_res)
              logger.info("save vis result to {}".format(img_save_path))
              if count > 0:
                  total_time += elapse
              count += 1
              logger.info(
                  "Predict time of {}: {}".format(image_file, elapse)
              )
  
file_path: PaddleOCR/ppstructure/kie/predict_kie_token_ser.py
imports: import os
  import sys
  import cv2
  import json
  import numpy
  import time
  import tools.infer.utility
  from ppocr.data import create_operators, transform
  from ppocr.postprocess import build_post_process
  from ppocr.utils.logging import get_logger
  from ppocr.utils.visual import draw_ser_results
  from ppocr.utils.utility import get_image_file_list, check_and_read
  from ppstructure.utility import parse_args
  from paddleocr import PaddleOCR
label_desc: Use image node_id 1 for calling a global function with example usage: main(args) without return types