code: def create_predictor(args, cfg, mode):
      if mode == "det":
          model_dir = cfg["det_model_dir"]
      else:
          model_dir = cfg["rec_model_dir"]
  
      if model_dir is None:
          print(
              "not find {} model file path {}".format(mode, model_dir)
          )
          sys.exit(0)
  
      model_file_path = model_dir + "/inference.pdmodel"
      params_file_path = model_dir + "/inference.pdiparams"
      if not os.path.exists(model_file_path):
          raise ValueError(
              "not find model file path {}".format(model_file_path)
          )
      if not os.path.exists(params_file_path):
          raise ValueError(
              "not find params file path {}".format(params_file_path)
          )
  
      config = inference.Config(model_file_path, params_file_path)
  
      batch_size = 1
  
      if args.device == "GPU":
          gpu_id = get_infer_gpuid()
          if gpu_id is None:
              print(
                  "GPU is not found in current device by nvidia-smi. Please check your device or ignore it if run on jetson."
              )
          config.enable_use_gpu(500, 0)
  
          precision_map = {
              "trt_int8": inference.PrecisionType.Int8,
              "trt_fp32": inference.PrecisionType.Float32,
              "trt_fp16": inference.PrecisionType.Half,
          }
          min_subgraph_size = 15
          if args.run_mode in precision_map.keys():
              config.enable_tensorrt_engine(
                  workspace_size=(1 << 25) * batch_size,
                  max_batch_size=batch_size,
                  min_subgraph_size=min_subgraph_size,
                  precision_mode=precision_map[args.run_mode],
              )
              use_dynamic_shape = True
  
              if mode == "det":
                  min_input_shape = {
                      "x": [1, 3, 50, 50],
                      "conv2d_92.tmp_0": [1, 120, 20, 20],
                      "conv2d_91.tmp_0": [1, 24, 10, 10],
                      "conv2d_59.tmp_0": [1, 96, 20, 20],
                      "nearest_interp_v2_1.tmp_0": [1, 256, 10, 10],
                      "nearest_interp_v2_2.tmp_0": [1, 256, 20, 20],
                      "conv2d_124.tmp_0": [1, 256, 20, 20],
                      "nearest_interp_v2_3.tmp_0": [1, 64, 20, 20],
                      "nearest_interp_v2_4.tmp_0": [1, 64, 20, 20],
                      "nearest_interp_v2_5.tmp_0": [1, 64, 20, 20],
                      "elementwise_add_7": [1, 56, 2, 2],
                      "nearest_interp_v2_0.tmp_0": [1, 256, 2, 2],
                  }
                  max_input_shape = {
                      "x": [1, 3, 1536, 1536],
                      "conv2d_92.tmp_0": [1, 120, 400, 400],
                      "conv2d_91.tmp_0": [1, 24, 200, 200],
                      "conv2d_59.tmp_0": [1, 96, 400, 400],
                      "nearest_interp_v2_1.tmp_0": [1, 256, 200, 200],
                      "conv2d_124.tmp_0": [1, 256, 400, 400],
                      "nearest_interp_v2_2.tmp_0": [1, 256, 400, 400],
                      "nearest_interp_v2_3.tmp_0": [1, 64, 400, 400],
                      "nearest_interp_v2_4.tmp_0": [1, 64, 400, 400],
                      "nearest_interp_v2_5.tmp_0": [1, 64, 400, 400],
                      "elementwise_add_7": [1, 56, 400, 400],
                      "nearest_interp_v2_0.tmp_0": [1, 256, 400, 400],
                  }
                  opt_input_shape = {
                      "x": [1, 3, 640, 640],
                      "conv2d_92.tmp_0": [1, 120, 160, 160],
                      "conv2d_91.tmp_0": [1, 24, 80, 80],
                      "conv2d_59.tmp_0": [1, 96, 160, 160],
                      "nearest_interp_v2_1.tmp_0": [1, 256, 80, 80],
                      "nearest_interp_v2_2.tmp_0": [1, 256, 160, 160],
                      "conv2d_124.tmp_0": [1, 256, 160, 160],
                      "nearest_interp_v2_3.tmp_0": [1, 64, 160, 160],
                      "nearest_interp_v2_4.tmp_0": [1, 64, 160, 160],
                      "nearest_interp_v2_5.tmp_0": [1, 64, 160, 160],
                      "elementwise_add_7": [1, 56, 40, 40],
                      "nearest_interp_v2_0.tmp_0": [1, 256, 40, 40],
                  }
                  min_pact_shape = {
                      "nearest_interp_v2_26.tmp_0": [1, 256, 20, 20],
                      "nearest_interp_v2_27.tmp_0": [1, 64, 20, 20],
                      "nearest_interp_v2_28.tmp_0": [1, 64, 20, 20],
                      "nearest_interp_v2_29.tmp_0": [1, 64, 20, 20],
                  }
                  max_pact_shape = {
                      "nearest_interp_v2_26.tmp_0": [1, 256, 400, 400],
                      "nearest_interp_v2_27.tmp_0": [1, 64, 400, 400],
                      "nearest_interp_v2_28.tmp_0": [1, 64, 400, 400],
                      "nearest_interp_v2_29.tmp_0": [1, 64, 400, 400],
                  }
                  opt_pact_shape = {
                      "nearest_interp_v2_26.tmp_0": [1, 256, 160, 160],
                      "nearest_interp_v2_27.tmp_0": [1, 64, 160, 160],
                      "nearest_interp_v2_28.tmp_0": [1, 64, 160, 160],
                      "nearest_interp_v2_29.tmp_0": [1, 64, 160, 160],
                  }
                  min_input_shape.update(min_pact_shape)
                  max_input_shape.update(max_pact_shape)
                  opt_input_shape.update(opt_pact_shape)
              elif mode == "rec":
                  imgH = int(cfg["rec_image_shape"][-2])
                  min_input_shape = {"x": [1, 3, imgH, 10]}
                  max_input_shape = {"x": [batch_size, 3, imgH, 2304]}
                  opt_input_shape = {"x": [batch_size, 3, imgH, 320]}
                  config.exp_disable_tensorrt_ops(["transpose2"])
              elif mode == "cls":
                  min_input_shape = {"x": [1, 3, 48, 10]}
                  max_input_shape = {"x": [batch_size, 3, 48, 1024]}
                  opt_input_shape = {"x": [batch_size, 3, 48, 320]}
              else:
                  use_dynamic_shape = False
              if use_dynamic_shape:
                  config.set_trt_dynamic_shape_info(
                      min_input_shape, max_input_shape, opt_input_shape
                  )
  
      else:
          config.disable_gpu()
          if hasattr(args, "cpu_threads"):
              config.set_cpu_math_library_num_threads(args.cpu_threads)
          else:
              # default cpu threads as 10
              config.set_cpu_math_library_num_threads(10)
          if args.enable_mkldnn:
              # cache 10 different shapes for mkldnn to avoid memory leak
              config.set_mkldnn_cache_capacity(10)
              config.enable_mkldnn()
              if args.run_mode == "fp16":
                  config.enable_mkldnn_bfloat16()
      # enable memory optim
      config.enable_memory_optim()
      config.disable_glog_info()
      config.delete_pass("conv_transpose_eltwiseadd_bn_fuse_pass")
      config.delete_pass("matmul_transpose_reshape_fuse_pass")
      if mode == "table":
          config.delete_pass("fc_fuse_pass")  # not supported for table
      config.switch_use_feed_fetch_ops(False)
      config.switch_ir_optim(True)
  
      # create predictor
      predictor = inference.create_predictor(config)
      input_names = predictor.get_input_names()
      for name in input_names:
          input_tensor = predictor.get_input_handle(name)
      output_tensors = get_output_tensors(cfg, mode, predictor)
      return predictor, input_tensor, output_tensors, config
  
imports: import argparse
  import os
  import sys
  import platform
  import cv2
  import numpy
  import paddle
  from PIL import Image, ImageDraw, ImageFont
  import math
  from paddle import inference
  import time
  import ast
label_desc: Use image node_id 1 for calling a global function with example usage: create_predictor(args, cfg, mode) and returns: predictor,  input_tensor,  output_tensors,  config