Skip to content

enhance auto_log #3182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions tools/infer/predict_det.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
from ppocr.data import create_operators, transform
from ppocr.postprocess import build_post_process

# import tools.infer.benchmark_utils as benchmark_utils

logger = get_logger()


Expand Down Expand Up @@ -100,6 +98,24 @@ def __init__(self, args):
self.predictor, self.input_tensor, self.output_tensors, self.config = utility.create_predictor(
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):
"""
reference from: https://github.com/jrosebr1/imutils/blob/master/imutils/perspective.py
Expand Down Expand Up @@ -158,6 +174,10 @@ def __call__(self, img):
data = {'image': img}

st = time.time()

if args.benchmark:
self.autolog.times.start()

data = transform(data, self.preprocess_op)
img, shape_list = data
if img is None:
Expand All @@ -166,12 +186,17 @@ def __call__(self, img):
shape_list = np.expand_dims(shape_list, axis=0)
img = img.copy()

if args.benchmark:
self.autolog.times.stamp()

self.input_tensor.copy_from_cpu(img)
self.predictor.run()
outputs = []
for output_tensor in self.output_tensors:
output = output_tensor.copy_to_cpu()
outputs.append(output)
if args.benchmark:
self.autolog.times.stamp()

preds = {}
if self.det_algorithm == "EAST":
Expand All @@ -195,6 +220,8 @@ def __call__(self, img):
else:
dt_boxes = self.filter_tag_det_res(dt_boxes, ori_im.shape)

if args.benchmark:
self.autolog.times.end(stamp=True)
et = time.time()
return dt_boxes, et - st

Expand All @@ -212,8 +239,6 @@ def __call__(self, img):
for i in range(10):
res = text_detector(img)

cpu_mem, gpu_mem, gpu_util = 0, 0, 0

if not os.path.exists(draw_img_save):
os.makedirs(draw_img_save)
for image_file in image_file_list:
Expand All @@ -237,4 +262,7 @@ def __call__(self, img):
"det_res_{}".format(img_name_pure))
cv2.imwrite(img_path, src_im)
logger.info("The visualized image saved in {}".format(img_path))

if args.benchmark:
text_detector.autolog.report()