code: def load_predictor(
      model_dir,
      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,
  ):
      """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/NPU, 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
      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()
              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,
              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 use_dynamic_shape:
              min_input_shape = {
                  "image": [batch_size, 3, trt_min_shape, trt_min_shape]
              }
              max_input_shape = {
                  "image": [batch_size, 3, trt_max_shape, trt_max_shape]
              }
              opt_input_shape = {
                  "image": [batch_size, 3, trt_opt_shape, trt_opt_shape]
              }
              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)
      predictor = create_predictor(config)
      return predictor, config
  
imports: import os
  import yaml
  import glob
  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, Pad, decode_image
  from mot.visualize import visualize_box_mask
  from mot_utils import argsparser, Timer, get_current_memory_mb
label_desc: Use image node_id 3 for calling a global function with example usage: load_predictor(model_dir, 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) and returns: predictor,  config