From 202fa428544b1bfef7d11a5486a3f3aed713f95d Mon Sep 17 00:00:00 2001 From: WenmuZhou <572459439@qq.com> Date: Mon, 11 Apr 2022 07:24:17 +0000 Subject: [PATCH] adatator tipc --- deploy/cpp_infer/src/main.cpp | 35 ++++++++++++------- deploy/cpp_infer/src/paddleocr.cpp | 4 ++- ..._normal_normal_infer_cpp_linux_gpu_cpu.txt | 10 ++++-- test_tipc/test_inference_cpp.sh | 22 ++++++++++-- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/deploy/cpp_infer/src/main.cpp b/deploy/cpp_infer/src/main.cpp index 84bf1698..66ac795f 100644 --- a/deploy/cpp_infer/src/main.cpp +++ b/deploy/cpp_infer/src/main.cpp @@ -75,20 +75,31 @@ int main(int argc, char **argv) { ocr.ocr(cv_all_img_names, FLAGS_det, FLAGS_rec, FLAGS_cls); for (int i = 0; i < cv_all_img_names.size(); ++i) { - cout << cv_all_img_names[i] << "\n"; - Utility::print_result(ocr_results[i]); - if (FLAGS_visualize && FLAGS_det) { - cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); - if (!srcimg.data) { - std::cerr << "[ERROR] image read failed! image path: " - << cv_all_img_names[i] << endl; - exit(1); + if (FLAGS_benchmark) { + cout << cv_all_img_names[i] << '\t'; + for (int n = 0; n < ocr_results[i].size(); n++) { + for (int m = 0; m < ocr_results[i][n].box.size(); m++) { + cout << ocr_results[i][n].box[m][0] << ' ' + << ocr_results[i][n].box[m][1] << ' '; + } } - std::string file_name = Utility::basename(cv_all_img_names[i]); + cout << endl; + } else { + cout << cv_all_img_names[i] << "\n"; + Utility::print_result(ocr_results[i]); + if (FLAGS_visualize && FLAGS_det) { + cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); + if (!srcimg.data) { + std::cerr << "[ERROR] image read failed! image path: " + << cv_all_img_names[i] << endl; + exit(1); + } + std::string file_name = Utility::basename(cv_all_img_names[i]); - Utility::VisualizeBboxes(srcimg, ocr_results[i], - FLAGS_output + "/" + file_name); + Utility::VisualizeBboxes(srcimg, ocr_results[i], + FLAGS_output + "/" + file_name); + } + cout << "***************************" << endl; } - cout << "***************************" << endl; } } diff --git a/deploy/cpp_infer/src/paddleocr.cpp b/deploy/cpp_infer/src/paddleocr.cpp index 3ea6e78d..861461a0 100644 --- a/deploy/cpp_infer/src/paddleocr.cpp +++ b/deploy/cpp_infer/src/paddleocr.cpp @@ -144,7 +144,9 @@ PaddleOCR::ocr(std::vector cv_all_img_names, bool det, bool rec, for (int i = 0; i < cv_all_img_names.size(); ++i) { std::vector ocr_result; - cout << "predict img: " << cv_all_img_names[i] << endl; + if (!FLAGS_benchmark) { + cout << "predict img: " << cv_all_img_names[i] << endl; + } cv::Mat srcimg = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR); if (!srcimg.data) { diff --git a/test_tipc/configs/ch_ppocr_mobile_v2.0_det/model_linux_gpu_normal_normal_infer_cpp_linux_gpu_cpu.txt b/test_tipc/configs/ch_ppocr_mobile_v2.0_det/model_linux_gpu_normal_normal_infer_cpp_linux_gpu_cpu.txt index 0b413987..62993c6a 100644 --- a/test_tipc/configs/ch_ppocr_mobile_v2.0_det/model_linux_gpu_normal_normal_infer_cpp_linux_gpu_cpu.txt +++ b/test_tipc/configs/ch_ppocr_mobile_v2.0_det/model_linux_gpu_normal_normal_infer_cpp_linux_gpu_cpu.txt @@ -3,8 +3,8 @@ model_name:ocr_det use_opencv:True infer_model:./inference/ch_ppocr_mobile_v2.0_det_infer/ infer_quant:False -inference:./deploy/cpp_infer/build/ppocr det ---use_gpu:True|False +inference:./deploy/cpp_infer/build/ppocr +--use_gpu:False --enable_mkldnn:True|False --cpu_threads:1|6 --rec_batch_num:1 @@ -13,4 +13,8 @@ inference:./deploy/cpp_infer/build/ppocr det --det_model_dir: --image_dir:./inference/ch_det_data_50/all-sum-510/ null:null ---benchmark:True \ No newline at end of file +--benchmark:True +--det:True +--rec:False +--cls:False +--use_angle_cls:False \ No newline at end of file diff --git a/test_tipc/test_inference_cpp.sh b/test_tipc/test_inference_cpp.sh index 257200fb..9885e393 100644 --- a/test_tipc/test_inference_cpp.sh +++ b/test_tipc/test_inference_cpp.sh @@ -2,7 +2,7 @@ source test_tipc/common_func.sh FILENAME=$1 -dataline=$(awk 'NR==1, NR==16{print}' $FILENAME) +dataline=$(awk 'NR==1, NR==20{print}' $FILENAME) # parser params IFS=$'\n' @@ -34,6 +34,14 @@ cpp_infer_key1=$(func_parser_key "${lines[14]}") cpp_infer_value1=$(func_parser_value "${lines[14]}") cpp_benchmark_key=$(func_parser_key "${lines[15]}") cpp_benchmark_value=$(func_parser_value "${lines[15]}") +cpp_det_key=$(func_parser_key "${lines[16]}") +cpp_det_value=$(func_parser_value "${lines[16]}") +cpp_rec_key=$(func_parser_key "${lines[17]}") +cpp_rec_value=$(func_parser_value "${lines[17]}") +cpp_cls_key=$(func_parser_key "${lines[18]}") +cpp_cls_value=$(func_parser_value "${lines[18]}") +cpp_use_angle_cls_key=$(func_parser_key "${lines[19]}") +cpp_use_angle_cls_value=$(func_parser_value "${lines[19]}") LOG_PATH="./test_tipc/output" mkdir -p ${LOG_PATH} @@ -68,7 +76,11 @@ function func_cpp_inference(){ set_cpu_threads=$(func_set_params "${cpp_cpu_threads_key}" "${threads}") set_model_dir=$(func_set_params "${cpp_infer_model_key}" "${_model_dir}") set_infer_params1=$(func_set_params "${cpp_infer_key1}" "${cpp_infer_value1}") - command="${_script} ${cpp_use_gpu_key}=${use_gpu} ${set_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_save_log_path} 2>&1 " + set_det=$(func_set_params "${cpp_det_key}" "${cpp_det_value}") + set_rec=$(func_set_params "${cpp_rec_key}" "${cpp_rec_value}") + set_cls=$(func_set_params "${cpp_cls_key}" "${cpp_cls_value}") + set_use_angle_cls=$(func_set_params "${cpp_use_angle_cls_key}" "${cpp_use_angle_cls_value}") + command="${_script} ${cpp_use_gpu_key}=${use_gpu} ${set_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_det} ${set_rec} ${set_cls} ${set_use_angle_cls} ${set_infer_params1} > ${_save_log_path} 2>&1 " eval $command last_status=${PIPESTATUS[0]} eval "cat ${_save_log_path}" @@ -97,7 +109,11 @@ function func_cpp_inference(){ set_precision=$(func_set_params "${cpp_precision_key}" "${precision}") set_model_dir=$(func_set_params "${cpp_infer_model_key}" "${_model_dir}") set_infer_params1=$(func_set_params "${cpp_infer_key1}" "${cpp_infer_value1}") - command="${_script} ${cpp_use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_save_log_path} 2>&1 " + set_det=$(func_set_params "${cpp_det_key}" "${cpp_det_value}") + set_rec=$(func_set_params "${cpp_rec_key}" "${cpp_rec_value}") + set_cls=$(func_set_params "${cpp_cls_key}" "${cpp_cls_value}") + set_use_angle_cls=$(func_set_params "${cpp_use_angle_cls_key}" "${cpp_use_angle_cls_value}") + command="${_script} ${cpp_use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_det} ${set_rec} ${set_cls} ${set_use_angle_cls} ${set_infer_params1} > ${_save_log_path} 2>&1 " eval $command last_status=${PIPESTATUS[0]} eval "cat ${_save_log_path}" -- GitLab