From b9c73d9a72b05ab7afd1fab0f3f46c7f8eed61ce Mon Sep 17 00:00:00 2001 From: MissPenguin Date: Tue, 7 Sep 2021 13:16:35 +0000 Subject: [PATCH] support rec for cpp cice --- deploy/cpp_infer/src/main.cpp | 63 +++++++++++++++++++++++++++-------- tests/ocr_rec_params.txt | 15 +++++++++ tests/prepare.sh | 17 +++++++++- 3 files changed, 80 insertions(+), 15 deletions(-) diff --git a/deploy/cpp_infer/src/main.cpp b/deploy/cpp_infer/src/main.cpp index 6e8ded7f..3165b72d 100644 --- a/deploy/cpp_infer/src/main.cpp +++ b/deploy/cpp_infer/src/main.cpp @@ -148,12 +148,28 @@ int main_rec(std::vector cv_all_img_names) { time_info[1] += rec_times[1]; time_info[2] += rec_times[2]; } - + + if (FLAGS_benchmark) { + AutoLogger autolog("ocr_rec", + FLAGS_use_gpu, + FLAGS_use_tensorrt, + FLAGS_enable_mkldnn, + FLAGS_cpu_threads, + 1, + "dynamic", + FLAGS_precision, + time_info, + cv_all_img_names.size()); + autolog.report(); + } return 0; } int main_system(std::vector cv_all_img_names) { + std::vector time_info_det = {0, 0, 0}; + std::vector time_info_rec = {0, 0, 0}; + DBDetector det(FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, FLAGS_gpu_mem, FLAGS_cpu_threads, FLAGS_enable_mkldnn, FLAGS_max_side_len, FLAGS_det_db_thresh, @@ -174,8 +190,6 @@ int main_system(std::vector cv_all_img_names) { FLAGS_enable_mkldnn, FLAGS_char_list_file, FLAGS_use_tensorrt, FLAGS_precision); - auto start = std::chrono::system_clock::now(); - for (int i = 0; i < cv_all_img_names.size(); ++i) { LOG(INFO) << "The predict img: " << cv_all_img_names[i]; @@ -189,7 +203,10 @@ int main_system(std::vector cv_all_img_names) { std::vector rec_times; det.Run(srcimg, boxes, &det_times); - + time_info_det[0] += det_times[0]; + time_info_det[1] += det_times[1]; + time_info_det[2] += det_times[2]; + cv::Mat crop_img; for (int j = 0; j < boxes.size(); j++) { crop_img = Utility::GetRotateCropImage(srcimg, boxes[j]); @@ -198,18 +215,36 @@ int main_system(std::vector cv_all_img_names) { crop_img = cls->Run(crop_img); } rec.Run(crop_img, &rec_times); + time_info_rec[0] += rec_times[0]; + time_info_rec[1] += rec_times[1]; + time_info_rec[2] += rec_times[2]; } - - auto end = std::chrono::system_clock::now(); - auto duration = - std::chrono::duration_cast(end - start); - std::cout << "Cost " - << double(duration.count()) * - std::chrono::microseconds::period::num / - std::chrono::microseconds::period::den - << "s" << std::endl; } - + if (FLAGS_benchmark) { + AutoLogger autolog_det("ocr_det", + FLAGS_use_gpu, + FLAGS_use_tensorrt, + FLAGS_enable_mkldnn, + FLAGS_cpu_threads, + 1, + "dynamic", + FLAGS_precision, + time_info_det, + cv_all_img_names.size()); + AutoLogger autolog_rec("ocr_rec", + FLAGS_use_gpu, + FLAGS_use_tensorrt, + FLAGS_enable_mkldnn, + FLAGS_cpu_threads, + 1, + "dynamic", + FLAGS_precision, + time_info_rec, + cv_all_img_names.size()); + autolog_det.report(); + std::cout << endl; + autolog_rec.report(); + } return 0; } diff --git a/tests/ocr_rec_params.txt b/tests/ocr_rec_params.txt index 2d27a9ee..a801c0af 100644 --- a/tests/ocr_rec_params.txt +++ b/tests/ocr_rec_params.txt @@ -49,3 +49,18 @@ inference:tools/infer/predict_rec.py --save_log_path:./test/output/ --benchmark:True null:null +===========================cpp_infer_params=========================== +use_opencv:True +infer_model:./inference/ch_ppocr_mobile_v2.0_rec_infer/ +infer_quant:False +inference:./deploy/cpp_infer/build/ppocr rec +--use_gpu:True|False +--enable_mkldnn:True|False +--cpu_threads:1|6 +--rec_batch_num:1 +--use_tensorrt:False|True +--precision:fp32|fp16 +--rec_model_dir: +--image_dir:./inference/rec_inference/ +--save_log_path:null +--benchmark:True \ No newline at end of file diff --git a/tests/prepare.sh b/tests/prepare.sh index aa642005..77fc46e0 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -64,7 +64,7 @@ elif [ ${MODE} = "whole_infer" ];then cd ./train_data/ && tar xf icdar2015_infer.tar && tar xf ic15_data.tar ln -s ./icdar2015_infer ./icdar2015 cd ../ -elif [ ${MODE} = "infer" ] || [ ${MODE} = "cpp_infer" ];then +elif [ ${MODE} = "infer" ];then if [ ${model_name} = "ocr_det" ]; then eval_model_name="ch_ppocr_mobile_v2.0_det_train" rm -rf ./train_data/icdar2015 @@ -87,6 +87,21 @@ elif [ ${MODE} = "infer" ] || [ ${MODE} = "cpp_infer" ];then wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar cd ./inference && tar xf ${eval_model_name}.tar && tar xf rec_inference.tar && cd ../ fi +elif [ ${MODE} = "cpp_infer" ];then + if [ ${model_name} = "ocr_det" ]; then + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar + cd ./inference && tar xf ch_ppocr_mobile_v2.0_det_infer.tar && tar xf ch_det_data_50.tar && cd ../ + elif [ ${model_name} = "ocr_rec" ]; then + wget -nc -P ./inference/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/rec_inference.tar + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar + cd ./inference && tar xf ch_ppocr_mobile_v2.0_rec_infer.tar && tar xf rec_inference.tar && cd ../ + elif [ ${model_name} = "ocr_system" ]; then + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar + cd ./inference && tar xf ch_ppocr_mobile_v2.0_det_infer.tar && tar xf ch_ppocr_mobile_v2.0_rec_infer.tar && tar xf ch_det_data_50.tar && cd ../ + fi fi if [ ${MODE} = "serving_infer" ];then -- GitLab