未验证 提交 5661c686 编写于 作者: D Double_V 提交者: GitHub

Merge pull request #3182 from LDOUBLEV/autolog

enhance auto_log
...@@ -98,6 +98,24 @@ class TextDetector(object): ...@@ -98,6 +98,24 @@ 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)
if args.benchmark:
import auto_log
pid = os.getpid()
self.autolog = auto_log.AutoLogger(
model_name="det",
model_precision=args.precision,
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
...@@ -156,6 +174,10 @@ class TextDetector(object): ...@@ -156,6 +174,10 @@ class TextDetector(object):
data = {'image': img} data = {'image': img}
st = time.time() st = time.time()
if args.benchmark:
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:
...@@ -164,12 +186,17 @@ class TextDetector(object): ...@@ -164,12 +186,17 @@ 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()
if args.benchmark:
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 = []
for output_tensor in self.output_tensors: for output_tensor in self.output_tensors:
output = output_tensor.copy_to_cpu() output = output_tensor.copy_to_cpu()
outputs.append(output) outputs.append(output)
if args.benchmark:
self.autolog.times.stamp()
preds = {} preds = {}
if self.det_algorithm == "EAST": if self.det_algorithm == "EAST":
...@@ -193,6 +220,8 @@ class TextDetector(object): ...@@ -193,6 +220,8 @@ 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)
if args.benchmark:
self.autolog.times.end(stamp=True)
et = time.time() et = time.time()
return dt_boxes, et - st return dt_boxes, et - st
...@@ -210,8 +239,6 @@ if __name__ == "__main__": ...@@ -210,8 +239,6 @@ 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
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)
for image_file in image_file_list: for image_file in image_file_list:
...@@ -236,3 +263,6 @@ if __name__ == "__main__": ...@@ -236,3 +263,6 @@ if __name__ == "__main__":
cv2.imwrite(img_path, src_im) cv2.imwrite(img_path, src_im)
logger.info("The visualized image saved in {}".format(img_path)) logger.info("The visualized image saved in {}".format(img_path))
if args.benchmark:
text_detector.autolog.report()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册