MCPcopy Index your code
hub / github.com/PaddlePaddle/PaddleOCR / TableSystem

Class TableSystem

deploy/hubserving/structure_table/module.py:48–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 type="cv/structure_table",
47)
48class TableSystem(hub.Module):
49 def _initialize(self, use_gpu=False, enable_mkldnn=False):
50 """
51 initialize with the necessary elements
52 """
53 cfg = self.merge_configs()
54 cfg.use_gpu = use_gpu
55 if use_gpu:
56 try:
57 _places = os.environ["CUDA_VISIBLE_DEVICES"]
58 int(_places[0])
59 print("use gpu: ", use_gpu)
60 print("CUDA_VISIBLE_DEVICES: ", _places)
61 cfg.gpu_mem = 8000
62 except:
63 raise RuntimeError(
64 "Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id."
65 )
66 cfg.ir_optim = True
67 cfg.enable_mkldnn = enable_mkldnn
68
69 self.table_sys = _TableSystem(cfg)
70
71 def merge_configs(self):
72 # default cfg
73 backup_argv = copy.deepcopy(sys.argv)
74 sys.argv = sys.argv[:1]
75 cfg = parse_args()
76
77 update_cfg_map = vars(read_params())
78
79 for key in update_cfg_map:
80 cfg.__setattr__(key, update_cfg_map[key])
81
82 sys.argv = copy.deepcopy(backup_argv)
83 return cfg
84
85 def read_images(self, paths=[]):
86 images = []
87 for img_path in paths:
88 assert os.path.isfile(img_path), "The {} isn't a valid file.".format(
89 img_path
90 )
91 img = cv2.imread(img_path)
92 if img is None:
93 logger.info("error in loading image:{}".format(img_path))
94 continue
95 images.append(img)
96 return images
97
98 def predict(self, images=[], paths=[]):
99 """
100 Get the chinese texts in the predicted images.
101 Args:
102 images (list(numpy.ndarray)): images data, shape of each is [H, W, C]. If images not paths
103 paths (list[str]): The paths of images. If paths not images
104 Returns:
105 res (list): The result of chinese texts and save path of images.

Callers 1

module.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…