code: def load_predictor(
      model_dir,
      run_mode="paddle",
      batch_size=1,
      use_gpu=False,
      min_subgraph_size=3,
  ):
      """set AnalysisConfig, generate AnalysisPredictor
      Args:
          model_dir (str): root path of __model__ and __params__
          use_gpu (bool): whether use gpu
      Returns:
          predictor (PaddlePredictor): AnalysisPredictor
      Raises:
          ValueError: predict by TensorRT need use_gpu == True.
      """
      if not use_gpu and not run_mode == "paddle":
          raise ValueError(
              "Predict by TensorRT mode: {}, expect use_gpu==True, but use_gpu == {}".format(
                  run_mode, use_gpu
              )
          )
      if run_mode == "trt_int8":
          raise ValueError(
              "TensorRT int8 mode is not supported now, "
              "please use trt_fp32 or trt_fp16 instead."
          )
      precision_map = {
          "trt_int8": PrecisionType.Int8,
          "trt_fp32": PrecisionType.Float32,
          "trt_fp16": PrecisionType.Half,
      }
      config = Config(model_dir + ".pdmodel", model_dir + ".pdiparams")
      if use_gpu:
          # initial GPU memory(M), device ID
          config.enable_use_gpu(100, 0)
          # optimize graph and fuse op
          config.switch_ir_optim(True)
      else:
          config.disable_gpu()
  
      if run_mode in precision_map.keys():
          config.enable_tensorrt_engine(
              workspace_size=1 << 10,
              max_batch_size=batch_size,
              min_subgraph_size=min_subgraph_size,
              precision_mode=precision_map[run_mode],
              use_static=False,
              use_calib_mode=False,
          )
  
      # 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
  
file_path: PaddleHub/modules/image/instance_segmentation/solov2/data_feed.py
imports: import base64
  import cv2
  import numpy
  from paddle.inference import Config
  from paddle.inference import create_predictor
  from paddle.inference import PrecisionType
  from PIL import Image
  from PIL import ImageDraw
label_desc: Use image node_id 8 for calling a global function with example usage: load_predictor(model_dir, run_mode, batch_size, use_gpu, min_subgraph_size) and returns: predictor