|
37 | 37 |
|
38 | 38 |
|
39 | 39 | class TextRecognizer(object):
|
40 |
| - def __init__(self, args): |
| 40 | + def __init__(self, args, logger=None): |
| 41 | + if logger is None: |
| 42 | + logger = get_logger() |
41 | 43 | self.rec_image_shape = [int(v) for v in args.rec_image_shape.split(",")]
|
42 | 44 | self.rec_batch_num = args.rec_batch_num
|
43 | 45 | self.rec_algorithm = args.rec_algorithm
|
@@ -157,7 +159,7 @@ def __init__(self, args):
|
157 | 159 | model_precision=args.precision,
|
158 | 160 | batch_size=args.rec_batch_num,
|
159 | 161 | data_shape="dynamic",
|
160 |
| - save_path=None, # args.save_log_path, |
| 162 | + save_path=None, # not used if logger is not None |
161 | 163 | inference_config=self.config,
|
162 | 164 | pids=pid,
|
163 | 165 | process_name=None,
|
@@ -701,14 +703,25 @@ def __call__(self, img_list):
|
701 | 703 |
|
702 | 704 | def main(args):
|
703 | 705 | image_file_list = get_image_file_list(args.image_dir)
|
704 |
| - text_recognizer = TextRecognizer(args) |
705 | 706 | valid_image_file_list = []
|
706 | 707 | img_list = []
|
707 | 708 |
|
| 709 | + # logger |
| 710 | + log_file = args.save_log_path |
| 711 | + if os.path.is_dir(args.save_log_path) or ( |
| 712 | + not os.path.exists(args.save_log_path) and args.save_log_path.endswith("/") |
| 713 | + ): |
| 714 | + log_file = os.path.join(log_file, "benchmark_recognition.log") |
| 715 | + logger = get_logger(log_file=log_file) |
| 716 | + |
| 717 | + # create text recognizer |
| 718 | + text_recognizer = TextRecognizer(args) |
| 719 | + |
708 | 720 | logger.info(
|
709 | 721 | "In PP-OCRv3, rec_image_shape parameter defaults to '3, 48, 320', "
|
710 | 722 | "if you are using recognition model with PP-OCRv2 or an older version, please set --rec_image_shape='3,32,320"
|
711 | 723 | )
|
| 724 | + |
712 | 725 | # warmup 2 times
|
713 | 726 | if args.warmup:
|
714 | 727 | img = np.random.uniform(0, 255, [48, 320, 3]).astype(np.uint8)
|
|
0 commit comments