docstr: Prepare for prediction.
  For the usage and docs of paddle inference, please refer to
  https://paddleinference.paddlepaddle.org.cn/product_introduction/summary.html
docstr_tok: ["Prepare","for","prediction",".","For","the","usage","and","docs","of","paddle","inference",",","please","refer","to","https",":","\/\/paddleinference.paddlepaddle.org.cn\/product_introduction\/summary.html"]
code: def __init__(self, args):
      """
      Prepare for prediction.
      For the usage and docs of paddle inference, please refer to
      https://paddleinference.paddlepaddle.org.cn/product_introduction/summary.html
      """
      self.args = args
      self.cfg = DeployConfig(args.cfg)
  
      self._init_base_config()
  
      if args.device == "cpu":
          self._init_cpu_config()
      elif args.device == "npu":
          self.pred_cfg.enable_custom_device("npu")
      elif args.device == "xpu":
          self.pred_cfg.enable_xpu()
      else:
          self._init_gpu_config()
  
      try:
          self.predictor = create_predictor(self.pred_cfg)
      except Exception as e:
          logger.error(str(e))
          logger.error(
              "If the above error is '(InvalidArgument) some trt inputs dynamic shape info not set, "
              "..., Expected all_dynamic_shape_set == true, ...', "
              "please set `--enable_auto_tune=True` to use the auto tuning function. \n"
          )
          exit(1)
  
      if hasattr(args, "benchmark") and args.benchmark:
          import auto_log
  
          pid = os.getpid()
          self.autolog = auto_log.AutoLogger(
              model_name=args.model_name,
              model_precision=args.precision,
              batch_size=args.batch_size,
              data_shape="dynamic",
              save_path=None,
              inference_config=self.pred_cfg,
              pids=pid,
              process_name=None,
              gpu_ids=0,
              time_keys=[
                  "preprocess_time",
                  "inference_time",
                  "postprocess_time",
              ],
              warmup=0,
              logger=logger,
          )
  
imports: import os
  import os.path
  import argparse
  from ast import literal_eval
  import numpy
  from PIL import Image
  from paddle.inference import create_predictor, PrecisionType
  from paddle.inference import Config
  from paddleseg.utils import logger, get_image_list
  from paddleseg.deploy.infer import DeployConfig
  from paddlepanseg.cvlibs.info_dicts import build_info_dict
  from paddlepanseg.transforms.functional import id2rgb
label_desc: Use image node_id 1 to create a new Predictor object  with example: obj = Predictor(args)