code: def load_predictor(
      model_dir,
      arch,
      run_mode="paddle",
      batch_size=1,
      device="CPU",
      min_subgraph_size=3,
      use_dynamic_shape=False,
      trt_min_shape=1,
      trt_max_shape=1280,
      trt_opt_shape=640,
      trt_calib_mode=False,
      cpu_threads=1,
      enable_mkldnn=False,
      enable_mkldnn_bfloat16=False,
      delete_shuffle_pass=False,
  ):
      """set AnalysisConfig, generate AnalysisPredictor
      Args:
          model_dir (str): root path of __model__ and __params__
          device (str): Choose the device you want to run, it can be: CPU/GPU/XPU, default is CPU
          run_mode (str): mode of running(paddle/trt_fp32/trt_fp16/trt_int8)
          use_dynamic_shape (bool): use dynamic shape or not
          trt_min_shape (int): min shape for dynamic shape in trt
          trt_max_shape (int): max shape for dynamic shape in trt
          trt_opt_shape (int): opt shape for dynamic shape in trt
          trt_calib_mode (bool): If the model is produced by TRT offline quantitative
              calibration, trt_calib_mode need to set True
          delete_shuffle_pass (bool): whether to remove shuffle_channel_detect_pass in TensorRT.
                                      Used by action model.
      Returns:
          predictor (PaddlePredictor): AnalysisPredictor
      Raises:
          ValueError: predict by TensorRT need device == 'GPU'.
      """
      if device != "GPU" and run_mode != "paddle":
          raise ValueError(
              "Predict by TensorRT mode: {}, expect device=='GPU', but device == {}".format(
                  run_mode, device
              )
          )
      infer_model = os.path.join(model_dir, "model.pdmodel")
      infer_params = os.path.join(model_dir, "model.pdiparams")
      if not os.path.exists(infer_model):
          infer_model = os.path.join(model_dir, "inference.pdmodel")
          infer_params = os.path.join(model_dir, "inference.pdiparams")
          if not os.path.exists(infer_model):
              raise ValueError(
                  "Cannot find any inference model in dir: {},".format(
                      model_dir
                  )
              )
      config = Config(infer_model, infer_params)
      if device == "GPU":
          # initial GPU memory(M), device ID
          config.enable_use_gpu(200, 0)
          # optimize graph and fuse op
          config.switch_ir_optim(True)
      elif device == "XPU":
          if config.lite_engine_enabled():
              config.enable_lite_engine()
          config.enable_xpu(10 * 1024 * 1024)
      elif device == "NPU":
          if config.lite_engine_enabled():
              config.enable_lite_engine()
          config.enable_custom_device("npu")
      else:
          config.disable_gpu()
          config.set_cpu_math_library_num_threads(cpu_threads)
          if enable_mkldnn:
              try:
                  # cache 10 different shapes for mkldnn to avoid memory leak
                  config.set_mkldnn_cache_capacity(10)
                  config.enable_mkldnn()
                  if enable_mkldnn_bfloat16:
                      config.enable_mkldnn_bfloat16()
              except Exception as e:
                  print(
                      "The current environment does not support `mkldnn`, so disable mkldnn."
                  )
                  pass
  
      precision_map = {
          "trt_int8": Config.Precision.Int8,
          "trt_fp32": Config.Precision.Float32,
          "trt_fp16": Config.Precision.Half,
      }
      if 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[run_mode],
              use_static=False,
              use_calib_mode=trt_calib_mode,
          )
          if FLAGS.collect_trt_shape_info:
              config.collect_shape_range_info(
                  FLAGS.tuned_trt_shape_file
              )
          elif os.path.exists(FLAGS.tuned_trt_shape_file):
              print(
                  f"Use dynamic shape file: "
                  f"{FLAGS.tuned_trt_shape_file} for TRT..."
              )
              config.enable_tuned_tensorrt_dynamic_shape(
                  FLAGS.tuned_trt_shape_file, True
              )
  
          if use_dynamic_shape:
              min_input_shape = {
                  "image": [
                      batch_size,
                      3,
                      trt_min_shape,
                      trt_min_shape,
                  ],
                  "scale_factor": [batch_size, 2],
              }
              max_input_shape = {
                  "image": [
                      batch_size,
                      3,
                      trt_max_shape,
                      trt_max_shape,
                  ],
                  "scale_factor": [batch_size, 2],
              }
              opt_input_shape = {
                  "image": [
                      batch_size,
                      3,
                      trt_opt_shape,
                      trt_opt_shape,
                  ],
                  "scale_factor": [batch_size, 2],
              }
              config.set_trt_dynamic_shape_info(
                  min_input_shape, max_input_shape, opt_input_shape
              )
              print("trt set dynamic shape done!")
  
      # disable print log when predict
      config.disable_glog_info()
      # enable shared memory
      config.enable_memory_optim()
      # disable feed, fetch OP, needed by zero_copy_run
      config.switch_use_feed_fetch_ops(False)
      if delete_shuffle_pass:
          config.delete_pass("shuffle_channel_detect_pass")
      predictor = create_predictor(config)
      return predictor, config
  
imports: import os
  import yaml
  import glob
  import json
  from pathlib import Path
  from functools import reduce
  import cv2
  import numpy
  import math
  import paddle
  from paddle.inference import Config
  from paddle.inference import create_predictor
  import sys
  from benchmark_utils import PaddleInferBenchmark
  from picodet_postprocess import PicoDetPostProcess
  from preprocess import preprocess, Resize, NormalizeImage, Permute, PadStride, LetterBoxResize, WarpAffine, Pad, decode_image, CULaneResize
  from keypoint_preprocess import EvalAffine, TopDownEvalAffine, expand_crop
  from clrnet_postprocess import CLRNetPostProcess
  from visualize import visualize_box_mask, imshow_lanes
  from utils import argsparser, Timer, get_current_memory_mb, multiclass_nms, coco_clsid2catid
label_desc: Use image node_id 3 for calling a global function with example usage: load_predictor(model_dir, arch, run_mode, batch_size, device, min_subgraph_size, use_dynamic_shape, trt_min_shape, trt_max_shape, trt_opt_shape, trt_calib_mode, cpu_threads, enable_mkldnn, enable_mkldnn_bfloat16, delete_shuffle_pass) and returns: predictor,  config