From eb77554616d3c9aed636f9542040f9f838aed278 Mon Sep 17 00:00:00 2001 From: AlexPasqua Date: Thu, 2 May 2024 13:13:47 +0200 Subject: [PATCH 1/4] Save detection inference logs to file --- tools/infer/predict_det.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index 148010acc1..b83ab6a00f 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -32,11 +32,9 @@ from ppocr.postprocess import build_post_process import json -logger = get_logger() - class TextDetector(object): - def __init__(self, args): + def __init__(self, args, logger): self.args = args self.det_algorithm = args.det_algorithm self.use_onnx = args.use_onnx @@ -158,7 +156,7 @@ def __init__(self, args): model_precision=args.precision, batch_size=1, data_shape="dynamic", - save_path=None, + save_path=None, # not used if logger is not None inference_config=self.config, pids=pid, process_name=None, @@ -383,10 +381,18 @@ def __call__(self, img): if __name__ == "__main__": args = utility.parse_args() image_file_list = get_image_file_list(args.image_dir) - text_detector = TextDetector(args) total_time = 0 draw_img_save_dir = args.draw_img_save_dir os.makedirs(draw_img_save_dir, exist_ok=True) + + # logger + log_file = args.save_log_path + if os.path.isdir(args.save_log_path): + log_file = os.path.join(log_file, "benchmark_detection.log") + logger = get_logger(log_file=log_file) + + # create text detector + text_detector = TextDetector(args, logger) if args.warmup: img = np.random.uniform(0, 255, [640, 640, 3]).astype(np.uint8) From 85f9344c9700a579f8900548fd6724878f5c00ef Mon Sep 17 00:00:00 2001 From: AlexPasqua Date: Sat, 4 May 2024 12:22:54 +0200 Subject: [PATCH 2/4] Minor fix on save_log_path --- tools/infer/predict_det.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index b83ab6a00f..e08be29ab8 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -387,7 +387,7 @@ def __call__(self, img): # logger log_file = args.save_log_path - if os.path.isdir(args.save_log_path): + if os.path.isdir(args.save_log_path) or (not os.path.exists(args.save_log_path) and args.save_log_path.endswith("/")): log_file = os.path.join(log_file, "benchmark_detection.log") logger = get_logger(log_file=log_file) From 1569cfb430dee06b23413b7b0a6d99dc8c84ab70 Mon Sep 17 00:00:00 2001 From: AlexPasqua Date: Mon, 20 May 2024 12:32:12 +0200 Subject: [PATCH 3/4] Formatted with black --- tools/infer/predict_det.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index e08be29ab8..ca1af5a561 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -156,7 +156,7 @@ def __init__(self, args, logger): model_precision=args.precision, batch_size=1, data_shape="dynamic", - save_path=None, # not used if logger is not None + save_path=None, # not used if logger is not None inference_config=self.config, pids=pid, process_name=None, @@ -384,10 +384,12 @@ def __call__(self, img): total_time = 0 draw_img_save_dir = args.draw_img_save_dir os.makedirs(draw_img_save_dir, exist_ok=True) - + # logger log_file = args.save_log_path - if os.path.isdir(args.save_log_path) or (not os.path.exists(args.save_log_path) and args.save_log_path.endswith("/")): + if os.path.isdir(args.save_log_path) or ( + not os.path.exists(args.save_log_path) and args.save_log_path.endswith("/") + ): log_file = os.path.join(log_file, "benchmark_detection.log") logger = get_logger(log_file=log_file) From 30e94ccec8326030061b9a4a1375f3af8b4c3f0e Mon Sep 17 00:00:00 2001 From: AlexPasqua Date: Fri, 24 May 2024 19:08:13 +0200 Subject: [PATCH 4/4] If logger is None: get_logger() --- tools/infer/predict_det.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index ca1af5a561..387da009a8 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -34,7 +34,9 @@ class TextDetector(object): - def __init__(self, args, logger): + def __init__(self, args, logger=None): + if logger is None: + logger = get_logger() self.args = args self.det_algorithm = args.det_algorithm self.use_onnx = args.use_onnx