code: def __init__(self, device: torch.device):
      if cv2 is None:
          raise ValueError("`cv2` is needed for `PiDiAPI`")
      model_path = os.path.join(
          OPT.external_dir, "annotators", "table5_pidinet.pth"
      )
      if not os.path.isfile(model_path):
          raise ValueError(
              f"cannot find `table5_pidinet.pth` at {model_path}"
          )
      self.model = pidinet()
      d = torch.load(model_path, map_location="cpu")["state_dict"]
      self.model.load_state_dict(
          {k.replace("module.", ""): v for k, v in d.items()}
      )
      self.device = device
  
imports: import os
  import math
  import torch
  import numpy
  import torch.nn
  import torch.nn.functional
  from typing import Optional
  from cftool.cv import to_uint8
  from ....parameters import OPT
label_desc: Use image node_id 1 to create a new PiDiAPI object  with example: obj = PiDiAPI(device)