enhance auto_log
This commit is contained in:
parent
01c4ee5de0
commit
ea60a03487
|
@ -34,6 +34,7 @@ from ppocr.postprocess import build_post_process
|
||||||
# import tools.infer.benchmark_utils as benchmark_utils
|
# import tools.infer.benchmark_utils as benchmark_utils
|
||||||
|
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
import auto_log
|
||||||
|
|
||||||
|
|
||||||
class TextDetector(object):
|
class TextDetector(object):
|
||||||
|
@ -100,6 +101,22 @@ class TextDetector(object):
|
||||||
self.predictor, self.input_tensor, self.output_tensors, self.config = utility.create_predictor(
|
self.predictor, self.input_tensor, self.output_tensors, self.config = utility.create_predictor(
|
||||||
args, 'det', logger)
|
args, 'det', logger)
|
||||||
|
|
||||||
|
pid = os.getpid()
|
||||||
|
self.autolog = auto_log.AutoLogger(
|
||||||
|
model_name="det",
|
||||||
|
model_precision="fp32",
|
||||||
|
batch_size=1,
|
||||||
|
data_shape="dynamic",
|
||||||
|
save_path="./output/auto_log.lpg",
|
||||||
|
inference_config=self.config,
|
||||||
|
pids=pid,
|
||||||
|
process_name=None,
|
||||||
|
gpu_ids=0,
|
||||||
|
time_keys=[
|
||||||
|
'preprocess_time', 'inference_time', 'postprocess_time'
|
||||||
|
],
|
||||||
|
warmup=10)
|
||||||
|
|
||||||
def order_points_clockwise(self, pts):
|
def order_points_clockwise(self, pts):
|
||||||
"""
|
"""
|
||||||
reference from: https://github.com/jrosebr1/imutils/blob/master/imutils/perspective.py
|
reference from: https://github.com/jrosebr1/imutils/blob/master/imutils/perspective.py
|
||||||
|
@ -158,6 +175,9 @@ class TextDetector(object):
|
||||||
data = {'image': img}
|
data = {'image': img}
|
||||||
|
|
||||||
st = time.time()
|
st = time.time()
|
||||||
|
|
||||||
|
self.autolog.times.start()
|
||||||
|
|
||||||
data = transform(data, self.preprocess_op)
|
data = transform(data, self.preprocess_op)
|
||||||
img, shape_list = data
|
img, shape_list = data
|
||||||
if img is None:
|
if img is None:
|
||||||
|
@ -166,6 +186,8 @@ class TextDetector(object):
|
||||||
shape_list = np.expand_dims(shape_list, axis=0)
|
shape_list = np.expand_dims(shape_list, axis=0)
|
||||||
img = img.copy()
|
img = img.copy()
|
||||||
|
|
||||||
|
self.autolog.times.stamp()
|
||||||
|
|
||||||
self.input_tensor.copy_from_cpu(img)
|
self.input_tensor.copy_from_cpu(img)
|
||||||
self.predictor.run()
|
self.predictor.run()
|
||||||
outputs = []
|
outputs = []
|
||||||
|
@ -173,6 +195,8 @@ class TextDetector(object):
|
||||||
output = output_tensor.copy_to_cpu()
|
output = output_tensor.copy_to_cpu()
|
||||||
outputs.append(output)
|
outputs.append(output)
|
||||||
|
|
||||||
|
self.autolog.times.stamp()
|
||||||
|
|
||||||
preds = {}
|
preds = {}
|
||||||
if self.det_algorithm == "EAST":
|
if self.det_algorithm == "EAST":
|
||||||
preds['f_geo'] = outputs[0]
|
preds['f_geo'] = outputs[0]
|
||||||
|
@ -195,7 +219,9 @@ class TextDetector(object):
|
||||||
else:
|
else:
|
||||||
dt_boxes = self.filter_tag_det_res(dt_boxes, ori_im.shape)
|
dt_boxes = self.filter_tag_det_res(dt_boxes, ori_im.shape)
|
||||||
|
|
||||||
|
self.autolog.times.end(stamp=True)
|
||||||
et = time.time()
|
et = time.time()
|
||||||
|
self.autolog.get_avg_mem_mb()
|
||||||
return dt_boxes, et - st
|
return dt_boxes, et - st
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,7 +238,7 @@ if __name__ == "__main__":
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
res = text_detector(img)
|
res = text_detector(img)
|
||||||
|
|
||||||
cpu_mem, gpu_mem, gpu_util = 0, 0, 0
|
text_detector.autolog.mem_info._start_subprocess()
|
||||||
|
|
||||||
if not os.path.exists(draw_img_save):
|
if not os.path.exists(draw_img_save):
|
||||||
os.makedirs(draw_img_save)
|
os.makedirs(draw_img_save)
|
||||||
|
@ -237,3 +263,5 @@ if __name__ == "__main__":
|
||||||
"det_res_{}".format(img_name_pure))
|
"det_res_{}".format(img_name_pure))
|
||||||
|
|
||||||
logger.info("The visualized image saved in {}".format(img_path))
|
logger.info("The visualized image saved in {}".format(img_path))
|
||||||
|
|
||||||
|
text_detector.autolog.report()
|
||||||
|
|
Loading…
Reference in New Issue