diff --git a/ppstructure/table/predict_table.py b/ppstructure/table/predict_table.py index 402d6c24189d044e2ee6d359edef8624d4aae145..aa05459589208dde66a6710322593d091af41325 100644 --- a/ppstructure/table/predict_table.py +++ b/ppstructure/table/predict_table.py @@ -28,6 +28,7 @@ import numpy as np import time import tools.infer.predict_rec as predict_rec import tools.infer.predict_det as predict_det +import tools.infer.utility as utility from ppocr.utils.utility import get_image_file_list, check_and_read_gif from ppocr.utils.logging import get_logger from ppstructure.table.matcher import distance, compute_iou @@ -59,11 +60,37 @@ class TableSystem(object): self.text_recognizer = predict_rec.TextRecognizer( args) if text_recognizer is None else text_recognizer self.table_structurer = predict_strture.TableStructurer(args) + self.benchmark = args.benchmark + self.predictor, self.input_tensor, self.output_tensors, self.config = utility.create_predictor( + args, 'table', logger) + if args.benchmark: + import auto_log + pid = os.getpid() + gpu_id = utility.get_infer_gpuid() + self.autolog = auto_log.AutoLogger( + model_name="table", + model_precision=args.precision, + batch_size=1, + data_shape="dynamic", + save_path=None, #args.save_log_path, + inference_config=self.config, + pids=pid, + process_name=None, + gpu_ids=gpu_id if args.use_gpu else None, + time_keys=[ + 'preprocess_time', 'inference_time', 'postprocess_time' + ], + warmup=0, + logger=logger) def __call__(self, img, return_ocr_result_in_table=False): result = dict() ori_im = img.copy() + if self.benchmark: + self.autolog.times.start() structure_res, elapse = self.table_structurer(copy.deepcopy(img)) + if self.benchmark: + self.autolog.times.stamp() dt_boxes, elapse = self.text_detector(copy.deepcopy(img)) dt_boxes = sorted_boxes(dt_boxes) if return_ocr_result_in_table: @@ -77,13 +104,11 @@ class TableSystem(object): box = [x_min, y_min, x_max, y_max] r_boxes.append(box) dt_boxes = np.array(r_boxes) - logger.debug("dt_boxes num : {}, elapse : {}".format( len(dt_boxes), elapse)) if dt_boxes is None: return None, None img_crop_list = [] - for i in range(len(dt_boxes)): det_box = dt_boxes[i] x0, y0, x1, y1 = expand(2, det_box, ori_im.shape) @@ -92,10 +117,14 @@ class TableSystem(object): rec_res, elapse = self.text_recognizer(img_crop_list) logger.debug("rec_res num : {}, elapse : {}".format( len(rec_res), elapse)) + if self.benchmark: + self.autolog.times.stamp() if return_ocr_result_in_table: result['rec_res'] = rec_res pred_html, pred = self.rebuild_table(structure_res, dt_boxes, rec_res) result['html'] = pred_html + if self.benchmark: + self.autolog.times.end(stamp=True) return result def rebuild_table(self, structure_res, dt_boxes, rec_res): @@ -213,6 +242,8 @@ def main(args): logger.info('excel saved to {}'.format(excel_path)) elapse = time.time() - starttime logger.info("Predict time : {:.3f}s".format(elapse)) + if args.benchmark: + text_sys.autolog.report() if __name__ == "__main__": diff --git a/test_tipc/common_func.sh b/test_tipc/common_func.sh index 85dfe217253bb1d4c8b92f17d26f138121a2a198..f7d8a1e04adee9d32332eda8cb5913bbaf168481 100644 --- a/test_tipc/common_func.sh +++ b/test_tipc/common_func.sh @@ -57,10 +57,11 @@ function status_check(){ last_status=$1 # the exit code run_command=$2 run_log=$3 + model_name=$4 if [ $last_status -eq 0 ]; then - echo -e "\033[33m Run successfully with command - ${run_command}! \033[0m" | tee -a ${run_log} + echo -e "\033[33m Run successfully with command - ${model_name} - ${run_command}! \033[0m" | tee -a ${run_log} else - echo -e "\033[33m Run failed with command - ${run_command}! \033[0m" | tee -a ${run_log} + echo -e "\033[33m Run failed with command - ${model_name} - ${run_command}! \033[0m" | tee -a ${run_log} fi } diff --git a/test_tipc/configs/ch_PP-OCRv2_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt b/test_tipc/configs/ch_PP-OCRv2_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt index 1aad65b687992155133ed11533a14f642510361d..ccc9e5ced086c2c617359bafdc8772fe92eab8fa 100644 --- a/test_tipc/configs/ch_PP-OCRv2_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt +++ b/test_tipc/configs/ch_PP-OCRv2_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt @@ -1,5 +1,5 @@ ===========================kl_quant_params=========================== -model_name:PPOCRv2_ocr_det_kl +model_name:ch_PP-OCRv2_det_KL python:python3.7 Global.pretrained_model:null Global.save_inference_dir:null @@ -8,10 +8,10 @@ infer_export:deploy/slim/quantization/quant_kl.py -c configs/det/ch_PP-OCRv2/ch_ infer_quant:True inference:tools/infer/predict_det.py --use_gpu:False|True ---enable_mkldnn:True ---cpu_threads:1|6 +--enable_mkldnn:False +--cpu_threads:6 --rec_batch_num:1 ---use_tensorrt:False|True +--use_tensorrt:False --precision:int8 --det_model_dir: --image_dir:./inference/ch_det_data_50/all-sum-510/ diff --git a/test_tipc/configs/ch_PP-OCRv2_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt b/test_tipc/configs/ch_PP-OCRv2_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt index 083a3ae26e726e290ffde4095821cbf3c40f7178..c30e0858efda4df8f9912183c5c31b56413a5252 100644 --- a/test_tipc/configs/ch_PP-OCRv2_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt +++ b/test_tipc/configs/ch_PP-OCRv2_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt @@ -1,17 +1,17 @@ ===========================kl_quant_params=========================== -model_name:PPOCRv2_ocr_rec_kl +model_name:ch_PP-OCRv2_rec_KL python:python3.7 Global.pretrained_model:null Global.save_inference_dir:null infer_model:./inference/ch_PP-OCRv2_rec_infer/ infer_export:deploy/slim/quantization/quant_kl.py -c test_tipc/configs/ch_PP-OCRv2_rec/ch_PP-OCRv2_rec_distillation.yml -o infer_quant:True -inference:tools/infer/predict_rec.py +inference:tools/infer/predict_rec.py --rec_image_shape="3,32,320" --use_gpu:False|True ---enable_mkldnn:False|True ---cpu_threads:1|6 +--enable_mkldnn:False +--cpu_threads:6 --rec_batch_num:1|6 ---use_tensorrt:True +--use_tensorrt:False --precision:int8 --rec_model_dir: --image_dir:./inference/rec_inference diff --git a/test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_infer_python.txt b/test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_infer_python.txt index 416832681794d32347d7c3bb36807787a83ff1d2..0ac75eff07a5ed4c17d7fdbe554fd4b5c0f11aed 100644 --- a/test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_infer_python.txt +++ b/test_tipc/configs/ch_PP-OCRv2_rec_PACT/train_infer_python.txt @@ -4,7 +4,7 @@ python:python3.7 gpu_list:0|0,1 Global.use_gpu:True|True Global.auto_cast:fp32 -Global.epoch_num:lite_train_lite_infer=6|whole_train_whole_infer=50 +Global.epoch_num:lite_train_lite_infer=1|whole_train_whole_infer=50 Global.save_model_dir:./output/ Train.loader.batch_size_per_card:lite_train_lite_infer=16|whole_train_whole_infer=128 Global.pretrained_model:pretrain_models/ch_PP-OCRv2_rec_train/best_accuracy diff --git a/test_tipc/configs/ch_PP-OCRv3_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt b/test_tipc/configs/ch_PP-OCRv3_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt index e4a3aa6c61899adff18e69da2777f07ada8cbaaa..c27e08a64075e15e4fbd8d4ffab7001752365417 100644 --- a/test_tipc/configs/ch_PP-OCRv3_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt +++ b/test_tipc/configs/ch_PP-OCRv3_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt @@ -1,5 +1,5 @@ ===========================kl_quant_params=========================== -model_name:PPOCRv3_ocr_det_kl +model_name:ch_PP-OCRv3_det_KL python:python3.7 Global.pretrained_model:null Global.save_inference_dir:null @@ -8,10 +8,10 @@ infer_export:deploy/slim/quantization/quant_kl.py -c configs/det/ch_PP-OCRv3/ch_ infer_quant:True inference:tools/infer/predict_det.py --use_gpu:False|True ---enable_mkldnn:True ---cpu_threads:1|6 +--enable_mkldnn:False +--cpu_threads:6 --rec_batch_num:1 ---use_tensorrt:False|True +--use_tensorrt:False --precision:int8 --det_model_dir: --image_dir:./inference/ch_det_data_50/all-sum-510/ diff --git a/test_tipc/configs/ch_PP-OCRv3_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt b/test_tipc/configs/ch_PP-OCRv3_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt index 51ad29a4edf81163a027f93ef1cb7f7c3b4168fd..d1a8c7c00137661bb1b5cced46f7616877f0b0a2 100644 --- a/test_tipc/configs/ch_PP-OCRv3_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt +++ b/test_tipc/configs/ch_PP-OCRv3_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt @@ -1,17 +1,17 @@ ===========================kl_quant_params=========================== -model_name:PPOCRv3_ocr_rec_kl +model_name:ch_PP-OCRv3_rec_KL python:python3.7 -Global.pretrained_model:null +Global.pretrained_model: Global.save_inference_dir:null infer_model:./inference/ch_PP-OCRv3_rec_infer/ infer_export:deploy/slim/quantization/quant_kl.py -c test_tipc/configs/ch_PP-OCRv3_rec/ch_PP-OCRv3_rec_distillation.yml -o infer_quant:True inference:tools/infer/predict_rec.py --rec_image_shape="3,48,320" --use_gpu:False|True ---enable_mkldnn:False|True ---cpu_threads:1|6 +--enable_mkldnn:False +--cpu_threads:6 --rec_batch_num:1|6 ---use_tensorrt:True +--use_tensorrt:False --precision:int8 --rec_model_dir: --image_dir:./inference/rec_inference diff --git a/test_tipc/configs/ch_PP-OCRv3_rec_PACT/train_infer_python.txt b/test_tipc/configs/ch_PP-OCRv3_rec_PACT/train_infer_python.txt index f26b86290af5f57569156c9329bc63c1c0b3a675..24469a91cfa0fa7d26ff24dba13c9c7e78a5ca10 100644 --- a/test_tipc/configs/ch_PP-OCRv3_rec_PACT/train_infer_python.txt +++ b/test_tipc/configs/ch_PP-OCRv3_rec_PACT/train_infer_python.txt @@ -4,7 +4,7 @@ python:python3.7 gpu_list:0|0,1 Global.use_gpu:True|True Global.auto_cast:fp32 -Global.epoch_num:lite_train_lite_infer=6|whole_train_whole_infer=50 +Global.epoch_num:lite_train_lite_infer=1|whole_train_whole_infer=50 Global.save_model_dir:./output/ Train.loader.batch_size_per_card:lite_train_lite_infer=16|whole_train_whole_infer=128 Global.pretrained_model:pretrain_models/ch_PP-OCRv3_rec_train/best_accuracy diff --git a/test_tipc/configs/ch_ppocr_mobile_v2.0_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt b/test_tipc/configs/ch_ppocr_mobile_v2.0_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt index 1039dcad06d63bb1fc1a47b7cc4760cd8d75ed63..2bdec848833b6cf3799370b0337fa00f185a94d5 100644 --- a/test_tipc/configs/ch_ppocr_mobile_v2.0_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt +++ b/test_tipc/configs/ch_ppocr_mobile_v2.0_det_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt @@ -8,10 +8,10 @@ infer_export:deploy/slim/quantization/quant_kl.py -c configs/det/ch_ppocr_v2.0/c infer_quant:True inference:tools/infer/predict_det.py --use_gpu:False|True ---enable_mkldnn:True ---cpu_threads:1|6 +--enable_mkldnn:False +--cpu_threads:6 --rec_batch_num:1 ---use_tensorrt:False|True +--use_tensorrt:False --precision:int8 --det_model_dir: --image_dir:./inference/ch_det_data_50/all-sum-510/ diff --git a/test_tipc/configs/ch_ppocr_mobile_v2.0_det_PACT/train_infer_python.txt b/test_tipc/configs/ch_ppocr_mobile_v2.0_det_PACT/train_infer_python.txt index 522f30d14b952d3d2da5ee8232b4b175d909d9a4..04c8d0e194b687f58da1c449a6a0d8d9c1acd25e 100644 --- a/test_tipc/configs/ch_ppocr_mobile_v2.0_det_PACT/train_infer_python.txt +++ b/test_tipc/configs/ch_ppocr_mobile_v2.0_det_PACT/train_infer_python.txt @@ -4,7 +4,7 @@ python:python3.7 gpu_list:0|0,1 Global.use_gpu:True|True Global.auto_cast:null -Global.epoch_num:lite_train_lite_infer=20|whole_train_whole_infer=50 +Global.epoch_num:lite_train_lite_infer=2|whole_train_whole_infer=50 Global.save_model_dir:./output/ Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_whole_infer=4 Global.pretrained_model:null diff --git a/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt b/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt index 4b77994f3f68c196b4d6e7a16eb44ec5fdef0d9e..f63fe4c2bb6a17353ecb008d83e2bee9d38aec23 100644 --- a/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt +++ b/test_tipc/configs/ch_ppocr_mobile_v2.0_rec_KL/model_linux_gpu_normal_normal_infer_python_linux_gpu_cpu.txt @@ -6,12 +6,12 @@ Global.save_inference_dir:null infer_model:./inference/ch_ppocr_mobile_v2.0_rec_infer/ infer_export:deploy/slim/quantization/quant_kl.py -c test_tipc/configs/ch_ppocr_mobile_v2.0_rec_KL/rec_chinese_lite_train_v2.0.yml -o infer_quant:True -inference:tools/infer/predict_rec.py +inference:tools/infer/predict_rec.py --rec_image_shape="3,32,320" --use_gpu:False|True ---enable_mkldnn:True ---cpu_threads:1|6 +--enable_mkldnn:False +--cpu_threads:6 --rec_batch_num:1 ---use_tensorrt:False|True +--use_tensorrt:False --precision:int8 --rec_model_dir: --image_dir:./inference/rec_inference