From f6097cbd368a63e3b903be5d919d0e0cb8be7d5f Mon Sep 17 00:00:00 2001 From: cuicheng01 Date: Thu, 18 Nov 2021 02:34:56 +0000 Subject: [PATCH 1/5] add tipc lite multi-predictor & arm_gpu_opencl chains --- deploy/lite/ocr_db_crnn.cc | 78 +++++++-- ...nux_gpu_normal_normal_lite_cpp_arm_cpu.txt | 5 +- ..._normal_normal_lite_cpp_arm_gpu_opencl.txt | 13 ++ ...nux_gpu_normal_normal_lite_cpp_arm_cpu.txt | 13 ++ ..._normal_normal_lite_cpp_arm_gpu_opencl.txt | 13 ++ ...te_arm_cpu_cpp.md => test_lite_arm_cpp.md} | 38 +++- test_tipc/prepare_lite.sh | 55 ------ test_tipc/prepare_lite_cpp.sh | 95 ++++++++++ test_tipc/readme.md | 5 +- test_tipc/test_lite_arm_cpp.sh | 162 ++++++++++++++++++ test_tipc/test_lite_arm_cpu_cpp.sh | 60 ------- 11 files changed, 398 insertions(+), 139 deletions(-) create mode 100644 test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_gpu_opencl.txt create mode 100644 test_tipc/configs/ppocr_system_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_cpu.txt create mode 100644 test_tipc/configs/ppocr_system_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_gpu_opencl.txt rename test_tipc/docs/{test_lite_arm_cpu_cpp.md => test_lite_arm_cpp.md} (51%) delete mode 100644 test_tipc/prepare_lite.sh create mode 100644 test_tipc/prepare_lite_cpp.sh create mode 100644 test_tipc/test_lite_arm_cpp.sh delete mode 100644 test_tipc/test_lite_arm_cpu_cpp.sh diff --git a/deploy/lite/ocr_db_crnn.cc b/deploy/lite/ocr_db_crnn.cc index 011d4adbeb..0de953a4d9 100644 --- a/deploy/lite/ocr_db_crnn.cc +++ b/deploy/lite/ocr_db_crnn.cc @@ -172,7 +172,10 @@ void RunRecModel(std::vector>> boxes, cv::Mat img, cv::Mat resize_img; int index = 0; + + std::vector time_info = {0, 0, 0}; for (int i = boxes.size() - 1; i >= 0; i--) { + auto preprocess_start = std::chrono::steady_clock::now(); crop_img = GetRotateCropImage(srcimg, boxes[i]); if (use_direction_classify >= 1) { crop_img = RunClsModel(crop_img, predictor_cls); @@ -191,7 +194,9 @@ void RunRecModel(std::vector>> boxes, cv::Mat img, auto *data0 = input_tensor0->mutable_data(); NeonMeanScale(dimg, data0, resize_img.rows * resize_img.cols, mean, scale); + auto preprocess_end = std::chrono::steady_clock::now(); //// Run CRNN predictor + auto inference_start = std::chrono::steady_clock::now(); predictor_crnn->Run(); // Get output and run postprocess @@ -199,8 +204,10 @@ void RunRecModel(std::vector>> boxes, cv::Mat img, std::move(predictor_crnn->GetOutput(0))); auto *predict_batch = output_tensor0->data(); auto predict_shape = output_tensor0->shape(); + auto inference_end = std::chrono::steady_clock::now(); // ctc decode + auto postprocess_start = std::chrono::steady_clock::now(); std::string str_res; int argmax_idx; int last_index = 0; @@ -224,7 +231,20 @@ void RunRecModel(std::vector>> boxes, cv::Mat img, score /= count; rec_text.push_back(str_res); rec_text_score.push_back(score); + auto postprocess_end = std::chrono::steady_clock::now(); + + std::chrono::duration preprocess_diff = preprocess_end - preprocess_start; + time_info[0] += double(preprocess_diff.count() * 1000); + std::chrono::duration inference_diff = inference_end - inference_start; + time_info[1] += double(inference_diff.count() * 1000); + std::chrono::duration postprocess_diff = postprocess_end - postprocess_start; + time_info[2] += double(postprocess_diff.count() * 1000); + } + +times->push_back(time_info[0]); +times->push_back(time_info[1]); +times->push_back(time_info[2]); } std::vector>> @@ -312,7 +332,7 @@ std::shared_ptr loadModel(std::string model_file, int num_threa config.set_model_from_file(model_file); config.set_threads(num_threads); - + std::cout< predictor = CreatePaddlePredictor(config); return predictor; @@ -434,6 +454,9 @@ void system(char **argv){ auto rec_predictor = loadModel(rec_model_file, std::stoi(num_threads)); auto cls_predictor = loadModel(cls_model_file, std::stoi(num_threads)); + std::vector det_time_info = {0, 0, 0}; + std::vector rec_time_info = {0, 0, 0}; + for (int i = 0; i < cv_all_img_names.size(); ++i) { std::cout << "The predict img: " << cv_all_img_names[i] << std::endl; cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); @@ -459,8 +482,38 @@ void system(char **argv){ //// print recognized text for (int i = 0; i < rec_text.size(); i++) { std::cout << i << "\t" << rec_text[i] << "\t" << rec_text_score[i] - << std::endl; + << std::endl; + } + + det_time_info[0] += det_times[0]; + det_time_info[1] += det_times[1]; + det_time_info[2] += det_times[2]; + rec_time_info[0] += rec_times[0]; + rec_time_info[1] += rec_times[1]; + rec_time_info[2] += rec_times[2]; + } + if (strcmp(argv[12], "True") == 0) { + AutoLogger autolog_det(det_model_file, + runtime_device, + std::stoi(num_threads), + std::stoi(batchsize), + "dynamic", + precision, + det_time_info, + cv_all_img_names.size()); + AutoLogger autolog_rec(rec_model_file, + runtime_device, + std::stoi(num_threads), + std::stoi(batchsize), + "dynamic", + precision, + rec_time_info, + cv_all_img_names.size()); + + autolog_det.report(); + std::cout << std::endl; + autolog_rec.report(); } } @@ -503,15 +556,15 @@ void det(int argc, char **argv) { auto img_vis = Visualization(srcimg, boxes); std::cout << boxes.size() << " bboxes have detected:" << std::endl; - // for (int i=0; i Date: Thu, 18 Nov 2021 02:43:05 +0000 Subject: [PATCH 2/5] update test_lite_arm_cpp.md --- test_tipc/docs/test_lite_arm_cpp.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test_tipc/docs/test_lite_arm_cpp.md b/test_tipc/docs/test_lite_arm_cpp.md index 2125e17cc6..f785a53c12 100644 --- a/test_tipc/docs/test_lite_arm_cpp.md +++ b/test_tipc/docs/test_lite_arm_cpp.md @@ -10,13 +10,13 @@ Lite\_arm\_cpp预测功能测试的主程序为`test_lite_arm_cpp.sh`,可以 - 模型类型:包括正常模型(FP32)和量化模型(INT8) - batch-size:包括1和4 - threads:包括1和4 -- predictor数量:包括多predictor预测和单predictor预测 +- predictor数量:包括单predictor预测和多predictor预测 - 预测库来源:包括下载方式和编译方式 - 测试硬件:ARM\_CPU/ARM\_GPU_OPENCL | 模型类型 | batch-size | threads | predictor数量 | 预测库来源 | 测试硬件 | | :----: | :----: | :----: | :----: | :----: | :----: | -| 正常模型/量化模型 | 1 | 1/4 | 1/2 | 下载方式 | ARM\_CPU/ARM\_GPU_OPENCL | +| 正常模型/量化模型 | 1 | 1/4 | 单/多 | 下载方式 | ARM\_CPU/ARM\_GPU_OPENCL | ## 2. 测试流程 @@ -26,7 +26,7 @@ Lite\_arm\_cpp预测功能测试的主程序为`test_lite_arm_cpp.sh`,可以 先运行`prepare_lite_cpp.sh`,运行后会在当前路径下生成`test_lite.tar`,其中包含了测试数据、测试模型和用于预测的可执行文件。将`test_lite.tar`上传到被测试的手机上,在手机的终端解压该文件,进入`test_lite`目录中,然后运行`test_lite_arm_cpp.sh`进行测试,最终在`test_lite/output`目录下生成`lite_*.log`后缀的日志文件。 -#### 2.1.1 测试ARM\_CPU +#### 2.1.1 基于ARM\_CPU测试 ```shell @@ -38,7 +38,7 @@ bash test_lite_arm_cpp.sh model_linux_gpu_normal_normal_lite_cpp_arm_cpu.txt ``` -#### 2.1.2 ARM\_GPU\_OPENCL +#### 2.1.2 基于ARM\_GPU\_OPENCL测试 ```shell @@ -55,9 +55,9 @@ bash test_lite_arm_cpp.sh model_linux_gpu_normal_normal_lite_cpp_arm_gpu_opencl. 1.由于运行该项目需要bash等命令,传统的adb方式不能很好的安装。所以此处推荐通在手机上开启虚拟终端的方式连接电脑,连接方式可以参考[安卓手机termux连接电脑](./termux_for_android.md)。 -2.如果测试文本检测和识别完整的pipeline,在执行`prepare_lite_cpp.sh`时,配置文件需替换为`test_tipc/configs/ppocr_system_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_cpu.tx`。在手机端测试阶段,配置文件同样修改为该文件。 +2.如果测试文本检测和识别完整的pipeline,在执行`prepare_lite_cpp.sh`时,配置文件需替换为`test_tipc/configs/ppocr_system_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_cpu.txt`。在手机端测试阶段,配置文件同样修改为该文件。 -#### 运行结果 +### 2.2 运行结果 各测试的运行情况会打印在 `./output/` 中: 运行成功时会输出: From 0efe2fe64deee9bc5653493d54fc85238f810557 Mon Sep 17 00:00:00 2001 From: cuicheng01 Date: Thu, 18 Nov 2021 02:48:59 +0000 Subject: [PATCH 3/5] update prepare_lite_cpp.sh --- test_tipc/prepare_lite_cpp.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test_tipc/prepare_lite_cpp.sh b/test_tipc/prepare_lite_cpp.sh index eba794eefc..b129322ddd 100644 --- a/test_tipc/prepare_lite_cpp.sh +++ b/test_tipc/prepare_lite_cpp.sh @@ -72,8 +72,6 @@ cd ./inference_models && tar -xf ${inference_model} && cd ../ cd ./test_data && tar -xf ${data_file} && rm ${data_file} && cd ../ # prepare lite env -export http_proxy=http://172.19.57.45:3128 -export https_proxy=http://172.19.57.45:3128 paddlelite_zipfile=$(echo $paddlelite_url | awk -F "/" '{print $NF}') paddlelite_file=${paddlelite_zipfile:0:${end_index}} wget ${paddlelite_url} && tar -xf ${paddlelite_zipfile} @@ -85,8 +83,8 @@ cp ${paddlelite_file}/cxx/lib/libpaddle_light_api_shared.so ${paddlelite_file}/d cp ${FILENAME} test_tipc/test_lite_arm_cpp.sh test_tipc/common_func.sh ${paddlelite_file}/demo/cxx/ocr/test_lite cd ${paddlelite_file}/demo/cxx/ocr/ git clone https://github.com/cuicheng01/AutoLog.git -unset http_proxy -unset https_proxy + +# make make -j sleep 1 make -j From ec90d769499be1444f97d4da043caf11eb27a56a Mon Sep 17 00:00:00 2001 From: cuicheng01 Date: Thu, 18 Nov 2021 04:22:10 +0000 Subject: [PATCH 4/5] update tipc lite --- .../model_linux_gpu_normal_normal_lite_cpp_arm_cpu.txt | 8 ++++---- ...el_linux_gpu_normal_normal_lite_cpp_arm_gpu_opencl.txt | 8 ++++---- test_tipc/docs/test_lite_arm_cpp.md | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_cpu.txt b/test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_cpu.txt index 51a9c1b1ce..003d776352 100644 --- a/test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_cpu.txt +++ b/test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_cpu.txt @@ -2,12 +2,12 @@ inference:./ocr_db_crnn det runtime_device:ARM_CPU det_infer_model:ch_PP-OCRv2_det_infer|ch_PP-OCRv2_det_slim_quant_infer -rec_infer_model:ch_PP-OCRv2_rec_infer|ch_PP-OCRv2_rec_slim_quant_infer -cls_infer_model:ch_ppocr_mobile_v2.0_cls_infer|ch_ppocr_mobile_v2.0_cls_slim_infer +null:null +null:null --cpu_threads:1|4 --det_batch_size:1 ---rec_batch_size:1 +null:null --image_dir:./test_data/icdar2015_lite/text_localization/ch4_test_images/ --config_dir:./config.txt ---rec_dict_dir:./ppocr_keys_v1.txt +null:null --benchmark:True diff --git a/test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_gpu_opencl.txt b/test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_gpu_opencl.txt index 3ee00bc729..a0b5569a63 100644 --- a/test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_gpu_opencl.txt +++ b/test_tipc/configs/ppocr_det_mobile/model_linux_gpu_normal_normal_lite_cpp_arm_gpu_opencl.txt @@ -2,12 +2,12 @@ inference:./ocr_db_crnn det runtime_device:ARM_GPU_OPENCL det_infer_model:ch_PP-OCRv2_det_infer|ch_PP-OCRv2_det_slim_quant_infer -rec_infer_model:ch_PP-OCRv2_rec_infer|ch_PP-OCRv2_rec_slim_quant_infer -cls_infer_model:ch_ppocr_mobile_v2.0_cls_infer|ch_ppocr_mobile_v2.0_cls_slim_infer +null:null +null:null --cpu_threads:1|4 --det_batch_size:1 ---rec_batch_size:1 +null:null --image_dir:./test_data/icdar2015_lite/text_localization/ch4_test_images/ --config_dir:./config.txt ---rec_dict_dir:./ppocr_keys_v1.txt +null:null --benchmark:True diff --git a/test_tipc/docs/test_lite_arm_cpp.md b/test_tipc/docs/test_lite_arm_cpp.md index f785a53c12..b3f24f4701 100644 --- a/test_tipc/docs/test_lite_arm_cpp.md +++ b/test_tipc/docs/test_lite_arm_cpp.md @@ -1,6 +1,6 @@ # Lite\_arm\_cpp预测功能测试 -Lite\_arm\_cpp预测功能测试的主程序为`test_lite_arm_cpp.sh`,可以在ARM CPU上基于Lite预测库测试模型的C++推理功能。 +Lite\_arm\_cpp预测功能测试的主程序为`test_lite_arm_cpp.sh`,可以在ARM上基于Lite预测库测试模型的C++推理功能。 ## 1. 测试结论汇总 From dbdb6afb7a511bfed2fcdda6a2404f433e82feee Mon Sep 17 00:00:00 2001 From: cuicheng01 Date: Thu, 18 Nov 2021 04:37:42 +0000 Subject: [PATCH 5/5] update tipc lite --- deploy/lite/ocr_db_crnn.cc | 1 - test_tipc/test_lite_arm_cpp.sh | 3 --- 2 files changed, 4 deletions(-) diff --git a/deploy/lite/ocr_db_crnn.cc b/deploy/lite/ocr_db_crnn.cc index 0de953a4d9..1ffbbacb74 100644 --- a/deploy/lite/ocr_db_crnn.cc +++ b/deploy/lite/ocr_db_crnn.cc @@ -332,7 +332,6 @@ std::shared_ptr loadModel(std::string model_file, int num_threa config.set_model_from_file(model_file); config.set_threads(num_threads); - std::cout< predictor = CreatePaddlePredictor(config); return predictor; diff --git a/test_tipc/test_lite_arm_cpp.sh b/test_tipc/test_lite_arm_cpp.sh index f119c1643a..c071a236bb 100644 --- a/test_tipc/test_lite_arm_cpp.sh +++ b/test_tipc/test_lite_arm_cpp.sh @@ -56,7 +56,6 @@ function func_test_det(){ for det_batchsize in ${det_batch_size_list[*]}; do _save_log_path="${_log_path}/lite_${_det_model}_runtime_device_${runtime_device}_precision_${precision}_det_batchsize_${det_batchsize}_threads_${num_threads}.log" command="${_script} ${_det_model} ${runtime_device} ${precision} ${num_threads} ${det_batchsize} ${_img_dir} ${_config} ${benchmark_value} > ${_save_log_path} 2>&1" - echo ${command} eval ${command} status_check $? "${command}" "${status_log}" done @@ -84,7 +83,6 @@ function func_test_rec(){ for rec_batchsize in ${rec_batch_size_list[*]}; do _save_log_path="${_log_path}/lite_${_rec_model}_${cls_model}_runtime_device_${runtime_device}_precision_${_precision}_rec_batchsize_${rec_batchsize}_threads_${num_threads}.log" command="${_script} ${_rec_model} ${_cls_model} ${runtime_device} ${_precision} ${num_threads} ${rec_batchsize} ${_img_dir} ${_config} ${_rec_dict_dir} ${benchmark_value} > ${_save_log_path} 2>&1" - echo ${command} eval ${command} status_check $? "${command}" "${status_log}" done @@ -113,7 +111,6 @@ function func_test_system(){ for rec_batchsize in ${rec_batch_size_list[*]}; do _save_log_path="${_log_path}/lite_${_det_model}_${_rec_model}_${_cls_model}_runtime_device_${runtime_device}_precision_${_precision}_det_batchsize_${det_batchsize}_rec_batchsize_${rec_batchsize}_threads_${num_threads}.log" command="${_script} ${_det_model} ${_rec_model} ${_cls_model} ${runtime_device} ${_precision} ${num_threads} ${det_batchsize} ${_img_dir} ${_config} ${_rec_dict_dir} ${benchmark_value} > ${_save_log_path} 2>&1" - echo ${command} eval ${command} status_check $? "${command}" "${status_log}" done