Skip to content

Commit

Permalink
Save detection inference logs to file (PaddlePaddle#12042)
Browse files Browse the repository at this point in the history
* Save detection inference logs to file

* Minor fix on save_log_path

* Formatted with black

* If logger is None: get_logger()
  • Loading branch information
AlexPasqua authored and luzhongqiu committed Jun 3, 2024
1 parent 3adbe29 commit c1e7ecb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tools/infer/predict_det.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
from ppocr.postprocess import build_post_process
import json

logger = get_logger()


class TextDetector(object):
def __init__(self, args):
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
Expand Down Expand Up @@ -158,7 +158,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,
Expand Down Expand Up @@ -398,11 +398,21 @@ 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) 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)

# create text detector
text_detector = TextDetector(args, logger)

if args.warmup:
img = np.random.uniform(0, 255, [640, 640, 3]).astype(np.uint8)
for i in range(2):
Expand Down

0 comments on commit c1e7ecb

Please sign in to comment.