MCPcopy
hub / github.com/PaddlePaddle/PaddleOCR / OCRDet

Class OCRDet

deploy/hubserving/ocr_det/module.py:46–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

module.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…