From 66c3294cd2a0ce708eab0a57066af46b6da57c61 Mon Sep 17 00:00:00 2001 From: littletomatodonkey Date: Tue, 17 Aug 2021 17:09:38 +0800 Subject: [PATCH 01/11] fix cls type --- ppocr/losses/cls_loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ppocr/losses/cls_loss.py b/ppocr/losses/cls_loss.py index ecca5d2e..abc5e5b7 100755 --- a/ppocr/losses/cls_loss.py +++ b/ppocr/losses/cls_loss.py @@ -25,6 +25,6 @@ class ClsLoss(nn.Layer): self.loss_func = nn.CrossEntropyLoss(reduction='mean') def forward(self, predicts, batch): - label = batch[1] + label = batch[1].astype("int64") loss = self.loss_func(input=predicts, label=label) return {'loss': loss} From 30b10d2933725df9783cfe6ba2d87d43b039e91e Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 18 Aug 2021 07:01:13 +0000 Subject: [PATCH 02/11] raise error when run on cpu but set use_gpu as True --- tools/infer/utility.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index 527a811d..707328f2 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -159,6 +159,11 @@ def create_predictor(args, mode, logger): precision = inference.PrecisionType.Float32 if args.use_gpu: + gpu_id = get_infer_gpuid() + if gpu_id is None: + raise ValueError( + "Not found GPU in current device. Please check your device or set args.use_gpu as False" + ) config.enable_use_gpu(args.gpu_mem, 0) if args.use_tensorrt: config.enable_tensorrt_engine( From 08166b8351da1b164a9e93fe140678b3e8bf4712 Mon Sep 17 00:00:00 2001 From: MissPenguin Date: Thu, 19 Aug 2021 07:27:55 +0000 Subject: [PATCH 03/11] add cpp_infer for cice --- deploy/cpp_infer/src/main.cpp | 29 ++++----- tests/ocr_det_params.txt | 14 +++++ tests/prepare.sh | 92 ++++++++++++++++++++++++++- tests/test.sh | 115 +++++++++++++++++++++++++++++++++- 4 files changed, 232 insertions(+), 18 deletions(-) diff --git a/deploy/cpp_infer/src/main.cpp b/deploy/cpp_infer/src/main.cpp index 5e5c8515..139493a2 100644 --- a/deploy/cpp_infer/src/main.cpp +++ b/deploy/cpp_infer/src/main.cpp @@ -39,8 +39,8 @@ DEFINE_bool(use_gpu, false, "Infering with GPU or CPU."); DEFINE_int32(gpu_id, 0, "Device id of GPU to execute."); DEFINE_int32(gpu_mem, 4000, "GPU id when infering with GPU."); -DEFINE_int32(cpu_math_library_num_threads, 10, "Num of threads with CPU."); -DEFINE_bool(use_mkldnn, false, "Whether use mkldnn with CPU."); +DEFINE_int32(cpu_threads, 10, "Num of threads with CPU."); +DEFINE_bool(enable_mkldnn, false, "Whether use mkldnn with CPU."); DEFINE_bool(use_tensorrt, false, "Whether use tensorrt."); DEFINE_string(precision, "fp32", "Precision be one of fp32/fp16/int8"); DEFINE_bool(benchmark, true, "Whether use benchmark."); @@ -60,6 +60,7 @@ DEFINE_string(cls_model_dir, "", "Path of cls inference model."); DEFINE_double(cls_thresh, 0.9, "Threshold of cls_thresh."); // recognition related DEFINE_string(rec_model_dir, "", "Path of rec inference model."); +DEFINE_int32(rec_batch_num, 1, "rec_batch_num."); DEFINE_string(char_list_file, "../../ppocr/utils/ppocr_keys_v1.txt", "Path of dictionary."); @@ -78,8 +79,8 @@ void PrintBenchmarkLog(std::string model_name, LOG(INFO) << "ir_optim: " << "True"; LOG(INFO) << "enable_memory_optim: " << "True"; LOG(INFO) << "enable_tensorrt: " << FLAGS_use_tensorrt; - LOG(INFO) << "enable_mkldnn: " << (FLAGS_use_mkldnn ? "True" : "False"); - LOG(INFO) << "cpu_math_library_num_threads: " << FLAGS_cpu_math_library_num_threads; + LOG(INFO) << "enable_mkldnn: " << (FLAGS_enable_mkldnn ? "True" : "False"); + LOG(INFO) << "cpu_math_library_num_threads: " << FLAGS_cpu_threads; LOG(INFO) << "----------------------- Data info -----------------------"; LOG(INFO) << "batch_size: " << batch_size; LOG(INFO) << "input_shape: " << input_shape; @@ -110,8 +111,8 @@ static bool PathExists(const std::string& path){ int main_det(std::vector cv_all_img_names) { std::vector time_info = {0, 0, 0}; DBDetector det(FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_math_library_num_threads, - FLAGS_use_mkldnn, FLAGS_max_side_len, FLAGS_det_db_thresh, + FLAGS_gpu_mem, FLAGS_cpu_threads, + FLAGS_enable_mkldnn, FLAGS_max_side_len, FLAGS_det_db_thresh, FLAGS_det_db_box_thresh, FLAGS_det_db_unclip_ratio, FLAGS_use_polygon_score, FLAGS_visualize, FLAGS_use_tensorrt, FLAGS_precision); @@ -144,8 +145,8 @@ int main_det(std::vector cv_all_img_names) { int main_rec(std::vector cv_all_img_names) { std::vector time_info = {0, 0, 0}; CRNNRecognizer rec(FLAGS_rec_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_math_library_num_threads, - FLAGS_use_mkldnn, FLAGS_char_list_file, + FLAGS_gpu_mem, FLAGS_cpu_threads, + FLAGS_enable_mkldnn, FLAGS_char_list_file, FLAGS_use_tensorrt, FLAGS_precision); for (int i = 0; i < cv_all_img_names.size(); ++i) { @@ -175,8 +176,8 @@ int main_rec(std::vector cv_all_img_names) { int main_system(std::vector cv_all_img_names) { DBDetector det(FLAGS_det_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_math_library_num_threads, - FLAGS_use_mkldnn, FLAGS_max_side_len, FLAGS_det_db_thresh, + FLAGS_gpu_mem, FLAGS_cpu_threads, + FLAGS_enable_mkldnn, FLAGS_max_side_len, FLAGS_det_db_thresh, FLAGS_det_db_box_thresh, FLAGS_det_db_unclip_ratio, FLAGS_use_polygon_score, FLAGS_visualize, FLAGS_use_tensorrt, FLAGS_precision); @@ -184,14 +185,14 @@ int main_system(std::vector cv_all_img_names) { Classifier *cls = nullptr; if (FLAGS_use_angle_cls) { cls = new Classifier(FLAGS_cls_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_math_library_num_threads, - FLAGS_use_mkldnn, FLAGS_cls_thresh, + FLAGS_gpu_mem, FLAGS_cpu_threads, + FLAGS_enable_mkldnn, FLAGS_cls_thresh, FLAGS_use_tensorrt, FLAGS_precision); } CRNNRecognizer rec(FLAGS_rec_model_dir, FLAGS_use_gpu, FLAGS_gpu_id, - FLAGS_gpu_mem, FLAGS_cpu_math_library_num_threads, - FLAGS_use_mkldnn, FLAGS_char_list_file, + FLAGS_gpu_mem, FLAGS_cpu_threads, + FLAGS_enable_mkldnn, FLAGS_char_list_file, FLAGS_use_tensorrt, FLAGS_precision); auto start = std::chrono::system_clock::now(); diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 6aff66c6..6230cfc9 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -49,4 +49,18 @@ inference:tools/infer/predict_det.py --save_log_path:null --benchmark:True null:null +===========================cpp_infer_params=========================== +infer_model:./inference/ch_ppocr_mobile_v2.0_det_infer/ +infer_quant:False +inference:./deploy/cpp_infer/build/ppocr det +--use_gpu:True|False +--enable_mkldnn:True|False +--cpu_threads:1|6 +--rec_batch_num:1 +--use_tensorrt:False|True +--precision:fp32|fp16 +--det_model_dir: +--image_dir:./inference/ch_det_data_50/all-sum-510/ +--save_log_path:null +--benchmark:True diff --git a/tests/prepare.sh b/tests/prepare.sh index d27a051c..6b54e5c1 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -1,6 +1,6 @@ #!/bin/bash FILENAME=$1 -# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer'] +# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer', 'cpp_infer'] MODE=$2 dataline=$(cat ${FILENAME}) @@ -58,11 +58,11 @@ elif [ ${MODE} = "whole_infer" ];then cd ./train_data/ && tar xf icdar2015_infer.tar && tar xf ic15_data.tar ln -s ./icdar2015_infer ./icdar2015 cd ../ -else +elif [ ${MODE} = "infer" ] || [ ${MODE} = "cpp_infer" ];then if [ ${model_name} = "ocr_det" ]; then eval_model_name="ch_ppocr_mobile_v2.0_det_infer" rm -rf ./train_data/icdar2015 - wget -nc -P ./train_data 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/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 ${eval_model_name}.tar && tar xf ch_det_data_50.tar && cd ../ else @@ -74,3 +74,89 @@ else fi fi +if [ ${MODE} = "cpp_infer" ];then + ################### build opencv ################### + cd deploy/cpp_infer + rm -rf 3.4.7.tar.gz opencv-3.4.7/ + wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz + tar -xf 3.4.7.tar.gz + + cd opencv-3.4.7/ + install_path=$(pwd)/opencv-3.4.7/opencv3 + + rm -rf build + mkdir build + cd build + + cmake .. \ + -DCMAKE_INSTALL_PREFIX=${install_path} \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DWITH_IPP=OFF \ + -DBUILD_IPP_IW=OFF \ + -DWITH_LAPACK=OFF \ + -DWITH_EIGEN=OFF \ + -DCMAKE_INSTALL_LIBDIR=lib64 \ + -DWITH_ZLIB=ON \ + -DBUILD_ZLIB=ON \ + -DWITH_JPEG=ON \ + -DBUILD_JPEG=ON \ + -DWITH_PNG=ON \ + -DBUILD_PNG=ON \ + -DWITH_TIFF=ON \ + -DBUILD_TIFF=ON + + make -j + make install + cd ../ + ################### build opencv finished ################### + + +# ################### build paddle inference ################### +# rm -rf Paddle +# git clone https://github.com/PaddlePaddle/Paddle.git + +# cd Paddle +# rm -rf build +# mkdir build +# cd build + +# cmake .. \ +# -DWITH_CONTRIB=OFF \ +# -DWITH_MKL=ON \ +# -DWITH_MKLDNN=ON \ +# -DWITH_TESTING=OFF \ +# -DCMAKE_BUILD_TYPE=Release \ +# -DWITH_INFERENCE_API_TEST=OFF \ +# -DON_INFER=ON \ +# -DWITH_PYTHON=ON +# make -j +# make inference_lib_dist +# cd ../ +# ################### build paddle inference finished ################### + + + ################### build PaddleOCR demo ################### + OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/ + LIB_DIR=$(pwd)/Paddle/build/paddle_inference_install_dir/ + CUDA_LIB_DIR=/usr/local/cuda/lib64/ + CUDNN_LIB_DIR=/usr/lib/x86_64-linux-gnu/ + + BUILD_DIR=build + rm -rf ${BUILD_DIR} + mkdir ${BUILD_DIR} + cd ${BUILD_DIR} + cmake .. \ + -DPADDLE_LIB=${LIB_DIR} \ + -DWITH_MKL=ON \ + -DWITH_GPU=OFF \ + -DWITH_STATIC_LIB=OFF \ + -DWITH_TENSORRT=OFF \ + -DOPENCV_DIR=${OPENCV_DIR} \ + -DCUDNN_LIB=${CUDNN_LIB_DIR} \ + -DCUDA_LIB=${CUDA_LIB_DIR} \ + -DTENSORRT_DIR=${TENSORRT_DIR} \ + + make -j + ################### build PaddleOCR demo finished ################### +fi \ No newline at end of file diff --git a/tests/test.sh b/tests/test.sh index 9888e0fa..659c0149 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,6 +1,6 @@ #!/bin/bash FILENAME=$1 -# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer'] +# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer', 'cpp_infer'] MODE=$2 dataline=$(cat ${FILENAME}) @@ -145,6 +145,35 @@ benchmark_value=$(func_parser_value "${lines[49]}") infer_key1=$(func_parser_key "${lines[50]}") infer_value1=$(func_parser_value "${lines[50]}") +# parser cpp inference model +cpp_infer_model_dir_list=$(func_parser_value "${lines[52]}") +cpp_infer_is_quant=$(func_parser_value "${lines[53]}") +# parser cpp inference +inference_cmd=$(func_parser_value "${lines[54]}") +cpp_use_gpu_key=$(func_parser_key "${lines[55]}") +cpp_use_gpu_list=$(func_parser_value "${lines[55]}") +cpp_use_mkldnn_key=$(func_parser_key "${lines[56]}") +cpp_use_mkldnn_list=$(func_parser_value "${lines[56]}") +cpp_cpu_threads_key=$(func_parser_key "${lines[57]}") +cpp_cpu_threads_list=$(func_parser_value "${lines[57]}") +cpp_batch_size_key=$(func_parser_key "${lines[58]}") +cpp_batch_size_list=$(func_parser_value "${lines[58]}") +cpp_use_trt_key=$(func_parser_key "${lines[59]}") +cpp_use_trt_list=$(func_parser_value "${lines[59]}") +cpp_precision_key=$(func_parser_key "${lines[60]}") +cpp_precision_list=$(func_parser_value "${lines[60]}") +cpp_infer_model_key=$(func_parser_key "${lines[61]}") +cpp_image_dir_key=$(func_parser_key "${lines[62]}") +cpp_infer_img_dir=$(func_parser_value "${lines[62]}") +cpp_save_log_key=$(func_parser_key "${lines[63]}") +cpp_benchmark_key=$(func_parser_key "${lines[64]}") +cpp_benchmark_value=$(func_parser_value "${lines[64]}") + +echo $inference_cmd +echo $cpp_cpu_threads_key $cpp_cpu_threads_list +echo $cpp_precision_key $cpp_precision_list +echo $cpp_benchmark_key $cpp_benchmark_value + LOG_PATH="./tests/output" mkdir -p ${LOG_PATH} status_log="${LOG_PATH}/results.log" @@ -218,6 +247,71 @@ function func_inference(){ done } +function func_cpp_inference(){ + IFS='|' + _script=$1 + _model_dir=$2 + _log_path=$3 + _img_dir=$4 + _flag_quant=$5 + # inference + for use_gpu in ${cpp_use_gpu_list[*]}; do + if [ ${use_gpu} = "False" ] || [ ${use_gpu} = "cpu" ]; then + for use_mkldnn in ${cpp_use_mkldnn_list[*]}; do + if [ ${use_mkldnn} = "False" ] && [ ${_flag_quant} = "True" ]; then + continue + fi + for threads in ${cpp_cpu_threads_list[*]}; do + for batch_size in ${cpp_batch_size_list[*]}; do + _save_log_path="${_log_path}/cpp_infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_batchsize_${batch_size}.log" + set_infer_data=$(func_set_params "${cpp_image_dir_key}" "${_img_dir}") + set_benchmark=$(func_set_params "${cpp_benchmark_key}" "${cpp_benchmark_value}") + set_batchsize=$(func_set_params "${cpp_batch_size_key}" "${batch_size}") + set_cpu_threads=$(func_set_params "${cpp_cpu_threads_key}" "${threads}") + set_model_dir=$(func_set_params "${cpp_infer_model_key}" "${_model_dir}") + command="${_script} ${cpp_use_gpu_key}=${use_gpu} ${cpp_use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + eval $command + last_status=${PIPESTATUS[0]} + eval "cat ${_save_log_path}" + status_check $last_status "${command}" "${status_log}" + done + done + done + elif [ ${use_gpu} = "True" ] || [ ${use_gpu} = "gpu" ]; then + for use_trt in ${cpp_use_trt_list[*]}; do + for precision in ${cpp_precision_list[*]}; do + if [[ ${_flag_quant} = "False" ]] && [[ ${precision} =~ "int8" ]]; then + continue + fi + if [[ ${precision} =~ "fp16" || ${precision} =~ "int8" ]] && [ ${use_trt} = "False" ]; then + continue + fi + if [[ ${use_trt} = "False" || ${precision} =~ "int8" ]] && [ ${_flag_quant} = "True" ]; then + continue + fi + for batch_size in ${cpp_batch_size_list[*]}; do + _save_log_path="${_log_path}/cpp_infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log" + set_infer_data=$(func_set_params "${cpp_image_dir_key}" "${_img_dir}") + set_benchmark=$(func_set_params "${cpp_benchmark_key}" "${cpp_benchmark_value}") + set_batchsize=$(func_set_params "${cpp_batch_size_key}" "${batch_size}") + set_tensorrt=$(func_set_params "${cpp_use_trt_key}" "${use_trt}") + set_precision=$(func_set_params "${cpp_precision_key}" "${precision}") + set_model_dir=$(func_set_params "${cpp_infer_model_key}" "${_model_dir}") + command="${_script} ${cpp_use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + eval $command + last_status=${PIPESTATUS[0]} + eval "cat ${_save_log_path}" + status_check $last_status "${command}" "${status_log}" + + done + done + done + else + echo "Does not support hardware other than CPU and GPU Currently!" + fi + done +} + if [ ${MODE} = "infer" ]; then GPUID=$3 if [ ${#GPUID} -le 0 ];then @@ -252,6 +346,25 @@ if [ ${MODE} = "infer" ]; then Count=$(($Count + 1)) done +elif [ ${MODE} = "cpp_infer" ]; then + GPUID=$3 + if [ ${#GPUID} -le 0 ];then + env=" " + else + env="export CUDA_VISIBLE_DEVICES=${GPUID}" + fi + # set CUDA_VISIBLE_DEVICES + eval $env + export Count=0 + IFS="|" + infer_quant_flag=(${cpp_infer_is_quant}) + for infer_model in ${cpp_infer_model_dir_list[*]}; do + #run inference + is_quant=${infer_quant_flag[Count]} + func_cpp_inference "${inference_cmd}" "${infer_model}" "${LOG_PATH}" "${cpp_infer_img_dir}" ${is_quant} + Count=$(($Count + 1)) + done + else IFS="|" export Count=0 From 3f7f8c37591a5371445f91ea4eae5c1aba2050af Mon Sep 17 00:00:00 2001 From: MissPenguin Date: Thu, 19 Aug 2021 08:48:12 +0000 Subject: [PATCH 04/11] refine --- tests/prepare.sh | 32 ++++------------------------- tests/test.sh | 52 +++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 55 deletions(-) diff --git a/tests/prepare.sh b/tests/prepare.sh index 6b54e5c1..2fb01447 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -75,7 +75,7 @@ elif [ ${MODE} = "infer" ] || [ ${MODE} = "cpp_infer" ];then fi if [ ${MODE} = "cpp_infer" ];then - ################### build opencv ################### + echo "################### build opencv ###################" cd deploy/cpp_infer rm -rf 3.4.7.tar.gz opencv-3.4.7/ wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz @@ -109,34 +109,10 @@ if [ ${MODE} = "cpp_infer" ];then make -j make install cd ../ - ################### build opencv finished ################### + echo "################### build opencv finished ###################" -# ################### build paddle inference ################### -# rm -rf Paddle -# git clone https://github.com/PaddlePaddle/Paddle.git - -# cd Paddle -# rm -rf build -# mkdir build -# cd build - -# cmake .. \ -# -DWITH_CONTRIB=OFF \ -# -DWITH_MKL=ON \ -# -DWITH_MKLDNN=ON \ -# -DWITH_TESTING=OFF \ -# -DCMAKE_BUILD_TYPE=Release \ -# -DWITH_INFERENCE_API_TEST=OFF \ -# -DON_INFER=ON \ -# -DWITH_PYTHON=ON -# make -j -# make inference_lib_dist -# cd ../ -# ################### build paddle inference finished ################### - - - ################### build PaddleOCR demo ################### + echo "################### build PaddleOCR demo ####################" OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/ LIB_DIR=$(pwd)/Paddle/build/paddle_inference_install_dir/ CUDA_LIB_DIR=/usr/local/cuda/lib64/ @@ -158,5 +134,5 @@ if [ ${MODE} = "cpp_infer" ];then -DTENSORRT_DIR=${TENSORRT_DIR} \ make -j - ################### build PaddleOCR demo finished ################### + echo "################### build PaddleOCR demo finished ###################" fi \ No newline at end of file diff --git a/tests/test.sh b/tests/test.sh index 659c0149..a7523450 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -145,34 +145,32 @@ benchmark_value=$(func_parser_value "${lines[49]}") infer_key1=$(func_parser_key "${lines[50]}") infer_value1=$(func_parser_value "${lines[50]}") -# parser cpp inference model -cpp_infer_model_dir_list=$(func_parser_value "${lines[52]}") -cpp_infer_is_quant=$(func_parser_value "${lines[53]}") -# parser cpp inference -inference_cmd=$(func_parser_value "${lines[54]}") -cpp_use_gpu_key=$(func_parser_key "${lines[55]}") -cpp_use_gpu_list=$(func_parser_value "${lines[55]}") -cpp_use_mkldnn_key=$(func_parser_key "${lines[56]}") -cpp_use_mkldnn_list=$(func_parser_value "${lines[56]}") -cpp_cpu_threads_key=$(func_parser_key "${lines[57]}") -cpp_cpu_threads_list=$(func_parser_value "${lines[57]}") -cpp_batch_size_key=$(func_parser_key "${lines[58]}") -cpp_batch_size_list=$(func_parser_value "${lines[58]}") -cpp_use_trt_key=$(func_parser_key "${lines[59]}") -cpp_use_trt_list=$(func_parser_value "${lines[59]}") -cpp_precision_key=$(func_parser_key "${lines[60]}") -cpp_precision_list=$(func_parser_value "${lines[60]}") -cpp_infer_model_key=$(func_parser_key "${lines[61]}") -cpp_image_dir_key=$(func_parser_key "${lines[62]}") -cpp_infer_img_dir=$(func_parser_value "${lines[62]}") -cpp_save_log_key=$(func_parser_key "${lines[63]}") -cpp_benchmark_key=$(func_parser_key "${lines[64]}") -cpp_benchmark_value=$(func_parser_value "${lines[64]}") +if [ ${MODE} = "cpp_infer" ]; then + # parser cpp inference model + cpp_infer_model_dir_list=$(func_parser_value "${lines[52]}") + cpp_infer_is_quant=$(func_parser_value "${lines[53]}") + # parser cpp inference + inference_cmd=$(func_parser_value "${lines[54]}") + cpp_use_gpu_key=$(func_parser_key "${lines[55]}") + cpp_use_gpu_list=$(func_parser_value "${lines[55]}") + cpp_use_mkldnn_key=$(func_parser_key "${lines[56]}") + cpp_use_mkldnn_list=$(func_parser_value "${lines[56]}") + cpp_cpu_threads_key=$(func_parser_key "${lines[57]}") + cpp_cpu_threads_list=$(func_parser_value "${lines[57]}") + cpp_batch_size_key=$(func_parser_key "${lines[58]}") + cpp_batch_size_list=$(func_parser_value "${lines[58]}") + cpp_use_trt_key=$(func_parser_key "${lines[59]}") + cpp_use_trt_list=$(func_parser_value "${lines[59]}") + cpp_precision_key=$(func_parser_key "${lines[60]}") + cpp_precision_list=$(func_parser_value "${lines[60]}") + cpp_infer_model_key=$(func_parser_key "${lines[61]}") + cpp_image_dir_key=$(func_parser_key "${lines[62]}") + cpp_infer_img_dir=$(func_parser_value "${lines[62]}") + cpp_save_log_key=$(func_parser_key "${lines[63]}") + cpp_benchmark_key=$(func_parser_key "${lines[64]}") + cpp_benchmark_value=$(func_parser_value "${lines[64]}") +fi -echo $inference_cmd -echo $cpp_cpu_threads_key $cpp_cpu_threads_list -echo $cpp_precision_key $cpp_precision_list -echo $cpp_benchmark_key $cpp_benchmark_value LOG_PATH="./tests/output" mkdir -p ${LOG_PATH} From efb1b4120fb38f7a0bf693d6b8f48cc3c9c2210f Mon Sep 17 00:00:00 2001 From: MissPenguin Date: Fri, 20 Aug 2021 12:36:40 +0000 Subject: [PATCH 05/11] mv log to .h file --- deploy/cpp_infer/include/autolog.h | 83 ++++++++++++++++++++++++++++++ deploy/cpp_infer/src/main.cpp | 45 +++++----------- 2 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 deploy/cpp_infer/include/autolog.h diff --git a/deploy/cpp_infer/include/autolog.h b/deploy/cpp_infer/include/autolog.h new file mode 100644 index 00000000..7deec0af --- /dev/null +++ b/deploy/cpp_infer/include/autolog.h @@ -0,0 +1,83 @@ +// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + + +class AutoLogger { +public: + AutoLogger(std::string model_name, + bool use_gpu, + bool enable_tensorrt, + bool enable_mkldnn, + int cpu_threads, + int batch_size, + std::string input_shape, + std::string model_precision, + std::vector time_info, + int img_num) { + this->model_name_ = model_name; + this->use_gpu_ = use_gpu; + this->enable_tensorrt_ = enable_tensorrt; + this->enable_mkldnn_ = enable_mkldnn; + this->cpu_threads_ = cpu_threads; + this->batch_size_ = batch_size; + this->input_shape_ = input_shape; + this->model_precision_ = model_precision; + this->time_info_ = time_info; + this->img_num_ = img_num; + } + void report() { + LOG(INFO) << "----------------------- Config info -----------------------"; + LOG(INFO) << "runtime_device: " << (this->use_gpu_ ? "gpu" : "cpu"); + LOG(INFO) << "ir_optim: " << "True"; + LOG(INFO) << "enable_memory_optim: " << "True"; + LOG(INFO) << "enable_tensorrt: " << this->enable_tensorrt_; + LOG(INFO) << "enable_mkldnn: " << (this->enable_mkldnn_ ? "True" : "False"); + LOG(INFO) << "cpu_math_library_num_threads: " << this->cpu_threads_; + LOG(INFO) << "----------------------- Data info -----------------------"; + LOG(INFO) << "batch_size: " << this->batch_size_; + LOG(INFO) << "input_shape: " << this->input_shape_; + LOG(INFO) << "data_num: " << this->img_num_; + LOG(INFO) << "----------------------- Model info -----------------------"; + LOG(INFO) << "model_name: " << this->model_name_; + LOG(INFO) << "precision: " << this->model_precision_; + LOG(INFO) << "----------------------- Perf info ------------------------"; + LOG(INFO) << "Total time spent(ms): " + << std::accumulate(this->time_info_.begin(), this->time_info_.end(), 0); + LOG(INFO) << "preprocess_time(ms): " << this->time_info_[0] / this->img_num_ + << ", inference_time(ms): " << this->time_info_[1] / this->img_num_ + << ", postprocess_time(ms): " << this->time_info_[2] / this->img_num_; + } + +private: + std::string model_name_; + bool use_gpu_ = false; + bool enable_tensorrt_ = false; + bool enable_mkldnn_ = true; + int cpu_threads_ = 10; + int batch_size_ = 1; + std::string input_shape_ = "dynamic"; + std::string model_precision_ = "fp32"; + std::vector time_info_; + int img_num_; +}; diff --git a/deploy/cpp_infer/src/main.cpp b/deploy/cpp_infer/src/main.cpp index 139493a2..6d2eec04 100644 --- a/deploy/cpp_infer/src/main.cpp +++ b/deploy/cpp_infer/src/main.cpp @@ -35,6 +35,7 @@ #include #include +#include DEFINE_bool(use_gpu, false, "Infering with GPU or CPU."); DEFINE_int32(gpu_id, 0, "Device id of GPU to execute."); @@ -69,34 +70,6 @@ using namespace cv; using namespace PaddleOCR; -void PrintBenchmarkLog(std::string model_name, - int batch_size, - std::string input_shape, - std::vector time_info, - int img_num){ - LOG(INFO) << "----------------------- Config info -----------------------"; - LOG(INFO) << "runtime_device: " << (FLAGS_use_gpu ? "gpu" : "cpu"); - LOG(INFO) << "ir_optim: " << "True"; - LOG(INFO) << "enable_memory_optim: " << "True"; - LOG(INFO) << "enable_tensorrt: " << FLAGS_use_tensorrt; - LOG(INFO) << "enable_mkldnn: " << (FLAGS_enable_mkldnn ? "True" : "False"); - LOG(INFO) << "cpu_math_library_num_threads: " << FLAGS_cpu_threads; - LOG(INFO) << "----------------------- Data info -----------------------"; - LOG(INFO) << "batch_size: " << batch_size; - LOG(INFO) << "input_shape: " << input_shape; - LOG(INFO) << "data_num: " << img_num; - LOG(INFO) << "----------------------- Model info -----------------------"; - LOG(INFO) << "model_name: " << model_name; - LOG(INFO) << "precision: " << FLAGS_precision; - LOG(INFO) << "----------------------- Perf info ------------------------"; - LOG(INFO) << "Total time spent(ms): " - << std::accumulate(time_info.begin(), time_info.end(), 0); - LOG(INFO) << "preprocess_time(ms): " << time_info[0] / img_num - << ", inference_time(ms): " << time_info[1] / img_num - << ", postprocess_time(ms): " << time_info[2] / img_num; -} - - static bool PathExists(const std::string& path){ #ifdef _WIN32 struct _stat buffer; @@ -136,7 +109,17 @@ int main_det(std::vector cv_all_img_names) { } if (FLAGS_benchmark) { - PrintBenchmarkLog("det", 1, "dynamic", time_info, cv_all_img_names.size()); + AutoLogger autolog("ocr_det", + 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; } @@ -166,10 +149,6 @@ int main_rec(std::vector cv_all_img_names) { time_info[2] += rec_times[2]; } - if (FLAGS_benchmark) { - PrintBenchmarkLog("rec", 1, "dynamic", time_info, cv_all_img_names.size()); - } - return 0; } From 52c920fc6de46f8c378afb971bc0a322ec64d699 Mon Sep 17 00:00:00 2001 From: lipeihan01 Date: Mon, 23 Aug 2021 16:25:22 +0800 Subject: [PATCH 06/11] support download auto_log.h from third-party url --- deploy/cpp_infer/CMakeLists.txt | 4 ++++ deploy/cpp_infer/external-cmake/auto-log.cmake | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 deploy/cpp_infer/external-cmake/auto-log.cmake diff --git a/deploy/cpp_infer/CMakeLists.txt b/deploy/cpp_infer/CMakeLists.txt index efb183c5..29a50684 100644 --- a/deploy/cpp_infer/CMakeLists.txt +++ b/deploy/cpp_infer/CMakeLists.txt @@ -206,6 +206,10 @@ endif() set(DEPS ${DEPS} ${OpenCV_LIBS}) +include(ExternalProject) +include(external-cmake/auto-log.cmake) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/autolog/src/extern_Autolog/auto_log) + AUX_SOURCE_DIRECTORY(./src SRCS) add_executable(${DEMO_NAME} ${SRCS}) diff --git a/deploy/cpp_infer/external-cmake/auto-log.cmake b/deploy/cpp_infer/external-cmake/auto-log.cmake new file mode 100644 index 00000000..5f5142de --- /dev/null +++ b/deploy/cpp_infer/external-cmake/auto-log.cmake @@ -0,0 +1,14 @@ +find_package(Git REQUIRED) +message("${CMAKE_BUILD_TYPE}") + +set(AUTOLOG_REPOSITORY https://github.com/LDOUBLEV/AutoLog.git) +SET(AUTOLOG_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/install/Autolog) + +ExternalProject_Add( + extern_Autolog + PREFIX autolog + GIT_REPOSITORY ${AUTOLOG_REPOSITORY} + GIT_TAG support_cpp_log + DOWNLOAD_NO_EXTRACT True + INSTALL_COMMAND cmake -E echo "Skipping install step." +) From abefdcb88e945f45466e9cc431884e83a45c983a Mon Sep 17 00:00:00 2001 From: Peihan Date: Mon, 23 Aug 2021 16:31:53 +0800 Subject: [PATCH 07/11] change auto_log download branch --- deploy/cpp_infer/external-cmake/auto-log.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/cpp_infer/external-cmake/auto-log.cmake b/deploy/cpp_infer/external-cmake/auto-log.cmake index 5f5142de..dfa56188 100644 --- a/deploy/cpp_infer/external-cmake/auto-log.cmake +++ b/deploy/cpp_infer/external-cmake/auto-log.cmake @@ -8,7 +8,7 @@ ExternalProject_Add( extern_Autolog PREFIX autolog GIT_REPOSITORY ${AUTOLOG_REPOSITORY} - GIT_TAG support_cpp_log + GIT_TAG main DOWNLOAD_NO_EXTRACT True INSTALL_COMMAND cmake -E echo "Skipping install step." ) From 5f7d4b9fe17515969b4088b0c554eb456e3a774d Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 23 Aug 2021 08:52:42 +0000 Subject: [PATCH 08/11] fix trt dynamic shape --- tools/infer/utility.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index 1c822800..93b54505 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -231,13 +231,13 @@ def create_predictor(args, mode, logger): max_input_shape.update(max_pact_shape) opt_input_shape.update(opt_pact_shape) elif mode == "rec": - min_input_shape = {"x": [args.rec_batch_num, 3, 32, 10]} + min_input_shape = {"x": [1, 3, 32, 10]} max_input_shape = {"x": [args.rec_batch_num, 3, 32, 2000]} - opt_input_shape = {"x": [args.rec_batch_num, 3, 32, 320]} + opt_input_shape = {"x": [512, 3, 32, 320]} elif mode == "cls": - min_input_shape = {"x": [args.rec_batch_num, 3, 48, 10]} + min_input_shape = {"x": [1, 3, 48, 10]} max_input_shape = {"x": [args.rec_batch_num, 3, 48, 2000]} - opt_input_shape = {"x": [args.rec_batch_num, 3, 48, 320]} + opt_input_shape = {"x": [512, 3, 48, 320]} else: min_input_shape = {"x": [1, 3, 10, 10]} max_input_shape = {"x": [1, 3, 1000, 1000]} From 1bf24676c25730fb620423e2c6c23f49c041a104 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 23 Aug 2021 09:13:22 +0000 Subject: [PATCH 09/11] fix rec trt --- tools/infer/predict_rec.py | 2 +- tools/infer/utility.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index bb4a3170..5a9d4fda 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -277,7 +277,7 @@ def main(args): if args.warmup: img = np.random.uniform(0, 255, [32, 320, 3]).astype(np.uint8) for i in range(2): - res = text_recognizer([img]) + res = text_recognizer([img] * int(args.rec_batch_num)) for image_file in image_file_list: img, flag = check_and_read_gif(image_file) diff --git a/tools/infer/utility.py b/tools/infer/utility.py index 93b54505..1c822800 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -231,13 +231,13 @@ def create_predictor(args, mode, logger): max_input_shape.update(max_pact_shape) opt_input_shape.update(opt_pact_shape) elif mode == "rec": - min_input_shape = {"x": [1, 3, 32, 10]} + min_input_shape = {"x": [args.rec_batch_num, 3, 32, 10]} max_input_shape = {"x": [args.rec_batch_num, 3, 32, 2000]} - opt_input_shape = {"x": [512, 3, 32, 320]} + opt_input_shape = {"x": [args.rec_batch_num, 3, 32, 320]} elif mode == "cls": - min_input_shape = {"x": [1, 3, 48, 10]} + min_input_shape = {"x": [args.rec_batch_num, 3, 48, 10]} max_input_shape = {"x": [args.rec_batch_num, 3, 48, 2000]} - opt_input_shape = {"x": [512, 3, 48, 320]} + opt_input_shape = {"x": [args.rec_batch_num, 3, 48, 320]} else: min_input_shape = {"x": [1, 3, 10, 10]} max_input_shape = {"x": [1, 3, 1000, 1000]} From 45d4afec4199a8f98b1e0e9a520911ff6b2e06cb Mon Sep 17 00:00:00 2001 From: MissPenguin Date: Tue, 24 Aug 2021 06:27:47 +0000 Subject: [PATCH 10/11] refine --- tests/ocr_det_params.txt | 1 + tests/prepare.sh | 75 ++++++++++++++++++++++------------------ tests/test.sh | 42 +++++++++++----------- 3 files changed, 63 insertions(+), 55 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 6230cfc9..805b6fe2 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -50,6 +50,7 @@ inference:tools/infer/predict_det.py --benchmark:True null:null ===========================cpp_infer_params=========================== +use_opencv:True infer_model:./inference/ch_ppocr_mobile_v2.0_det_infer/ infer_quant:False inference:./deploy/cpp_infer/build/ppocr det diff --git a/tests/prepare.sh b/tests/prepare.sh index 2fb01447..c3b60299 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -75,49 +75,56 @@ elif [ ${MODE} = "infer" ] || [ ${MODE} = "cpp_infer" ];then fi if [ ${MODE} = "cpp_infer" ];then - echo "################### build opencv ###################" cd deploy/cpp_infer - rm -rf 3.4.7.tar.gz opencv-3.4.7/ - wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz - tar -xf 3.4.7.tar.gz + use_opencv=$(func_parser_value "${lines[52]}") + if [ ${use_opencv} = "True" ]; then + echo "################### build opencv ###################" + rm -rf 3.4.7.tar.gz opencv-3.4.7/ + wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz + tar -xf 3.4.7.tar.gz - cd opencv-3.4.7/ - install_path=$(pwd)/opencv-3.4.7/opencv3 + cd opencv-3.4.7/ + install_path=$(pwd)/opencv-3.4.7/opencv3 - rm -rf build - mkdir build - cd build + rm -rf build + mkdir build + cd build - cmake .. \ - -DCMAKE_INSTALL_PREFIX=${install_path} \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=OFF \ - -DWITH_IPP=OFF \ - -DBUILD_IPP_IW=OFF \ - -DWITH_LAPACK=OFF \ - -DWITH_EIGEN=OFF \ - -DCMAKE_INSTALL_LIBDIR=lib64 \ - -DWITH_ZLIB=ON \ - -DBUILD_ZLIB=ON \ - -DWITH_JPEG=ON \ - -DBUILD_JPEG=ON \ - -DWITH_PNG=ON \ - -DBUILD_PNG=ON \ - -DWITH_TIFF=ON \ - -DBUILD_TIFF=ON + cmake .. \ + -DCMAKE_INSTALL_PREFIX=${install_path} \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DWITH_IPP=OFF \ + -DBUILD_IPP_IW=OFF \ + -DWITH_LAPACK=OFF \ + -DWITH_EIGEN=OFF \ + -DCMAKE_INSTALL_LIBDIR=lib64 \ + -DWITH_ZLIB=ON \ + -DBUILD_ZLIB=ON \ + -DWITH_JPEG=ON \ + -DBUILD_JPEG=ON \ + -DWITH_PNG=ON \ + -DBUILD_PNG=ON \ + -DWITH_TIFF=ON \ + -DBUILD_TIFF=ON - make -j - make install - cd ../ - echo "################### build opencv finished ###################" + make -j + make install + cd ../ + echo "################### build opencv finished ###################" + fi echo "################### build PaddleOCR demo ####################" - OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/ + if [ ${use_opencv} = "True" ]; then + OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/ + else + OPENCV_DIR='' + fi LIB_DIR=$(pwd)/Paddle/build/paddle_inference_install_dir/ - CUDA_LIB_DIR=/usr/local/cuda/lib64/ - CUDNN_LIB_DIR=/usr/lib/x86_64-linux-gnu/ - + CUDA_LIB_DIR=$(dirname `find /usr -name libcudart.so`) + CUDNN_LIB_DIR=$(dirname `find /usr -name libcudnn.so`) + BUILD_DIR=build rm -rf ${BUILD_DIR} mkdir ${BUILD_DIR} diff --git a/tests/test.sh b/tests/test.sh index a7523450..484d5573 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -147,28 +147,28 @@ infer_value1=$(func_parser_value "${lines[50]}") if [ ${MODE} = "cpp_infer" ]; then # parser cpp inference model - cpp_infer_model_dir_list=$(func_parser_value "${lines[52]}") - cpp_infer_is_quant=$(func_parser_value "${lines[53]}") + cpp_infer_model_dir_list=$(func_parser_value "${lines[53]}") + cpp_infer_is_quant=$(func_parser_value "${lines[54]}") # parser cpp inference - inference_cmd=$(func_parser_value "${lines[54]}") - cpp_use_gpu_key=$(func_parser_key "${lines[55]}") - cpp_use_gpu_list=$(func_parser_value "${lines[55]}") - cpp_use_mkldnn_key=$(func_parser_key "${lines[56]}") - cpp_use_mkldnn_list=$(func_parser_value "${lines[56]}") - cpp_cpu_threads_key=$(func_parser_key "${lines[57]}") - cpp_cpu_threads_list=$(func_parser_value "${lines[57]}") - cpp_batch_size_key=$(func_parser_key "${lines[58]}") - cpp_batch_size_list=$(func_parser_value "${lines[58]}") - cpp_use_trt_key=$(func_parser_key "${lines[59]}") - cpp_use_trt_list=$(func_parser_value "${lines[59]}") - cpp_precision_key=$(func_parser_key "${lines[60]}") - cpp_precision_list=$(func_parser_value "${lines[60]}") - cpp_infer_model_key=$(func_parser_key "${lines[61]}") - cpp_image_dir_key=$(func_parser_key "${lines[62]}") - cpp_infer_img_dir=$(func_parser_value "${lines[62]}") - cpp_save_log_key=$(func_parser_key "${lines[63]}") - cpp_benchmark_key=$(func_parser_key "${lines[64]}") - cpp_benchmark_value=$(func_parser_value "${lines[64]}") + inference_cmd=$(func_parser_value "${lines[55]}") + cpp_use_gpu_key=$(func_parser_key "${lines[56]}") + cpp_use_gpu_list=$(func_parser_value "${lines[56]}") + cpp_use_mkldnn_key=$(func_parser_key "${lines[57]}") + cpp_use_mkldnn_list=$(func_parser_value "${lines[57]}") + cpp_cpu_threads_key=$(func_parser_key "${lines[58]}") + cpp_cpu_threads_list=$(func_parser_value "${lines[58]}") + cpp_batch_size_key=$(func_parser_key "${lines[59]}") + cpp_batch_size_list=$(func_parser_value "${lines[59]}") + cpp_use_trt_key=$(func_parser_key "${lines[60]}") + cpp_use_trt_list=$(func_parser_value "${lines[60]}") + cpp_precision_key=$(func_parser_key "${lines[61]}") + cpp_precision_list=$(func_parser_value "${lines[61]}") + cpp_infer_model_key=$(func_parser_key "${lines[62]}") + cpp_image_dir_key=$(func_parser_key "${lines[63]}") + cpp_infer_img_dir=$(func_parser_value "${lines[63]}") + cpp_save_log_key=$(func_parser_key "${lines[64]}") + cpp_benchmark_key=$(func_parser_key "${lines[65]}") + cpp_benchmark_value=$(func_parser_value "${lines[65]}") fi From cc132dec144316781a0615ffd8d69e482340ca55 Mon Sep 17 00:00:00 2001 From: MissPenguin Date: Tue, 24 Aug 2021 06:30:39 +0000 Subject: [PATCH 11/11] rm autolog h file --- deploy/cpp_infer/include/autolog.h | 83 ------------------------------ deploy/cpp_infer/src/main.cpp | 1 - 2 files changed, 84 deletions(-) delete mode 100644 deploy/cpp_infer/include/autolog.h diff --git a/deploy/cpp_infer/include/autolog.h b/deploy/cpp_infer/include/autolog.h deleted file mode 100644 index 7deec0af..00000000 --- a/deploy/cpp_infer/include/autolog.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - - -class AutoLogger { -public: - AutoLogger(std::string model_name, - bool use_gpu, - bool enable_tensorrt, - bool enable_mkldnn, - int cpu_threads, - int batch_size, - std::string input_shape, - std::string model_precision, - std::vector time_info, - int img_num) { - this->model_name_ = model_name; - this->use_gpu_ = use_gpu; - this->enable_tensorrt_ = enable_tensorrt; - this->enable_mkldnn_ = enable_mkldnn; - this->cpu_threads_ = cpu_threads; - this->batch_size_ = batch_size; - this->input_shape_ = input_shape; - this->model_precision_ = model_precision; - this->time_info_ = time_info; - this->img_num_ = img_num; - } - void report() { - LOG(INFO) << "----------------------- Config info -----------------------"; - LOG(INFO) << "runtime_device: " << (this->use_gpu_ ? "gpu" : "cpu"); - LOG(INFO) << "ir_optim: " << "True"; - LOG(INFO) << "enable_memory_optim: " << "True"; - LOG(INFO) << "enable_tensorrt: " << this->enable_tensorrt_; - LOG(INFO) << "enable_mkldnn: " << (this->enable_mkldnn_ ? "True" : "False"); - LOG(INFO) << "cpu_math_library_num_threads: " << this->cpu_threads_; - LOG(INFO) << "----------------------- Data info -----------------------"; - LOG(INFO) << "batch_size: " << this->batch_size_; - LOG(INFO) << "input_shape: " << this->input_shape_; - LOG(INFO) << "data_num: " << this->img_num_; - LOG(INFO) << "----------------------- Model info -----------------------"; - LOG(INFO) << "model_name: " << this->model_name_; - LOG(INFO) << "precision: " << this->model_precision_; - LOG(INFO) << "----------------------- Perf info ------------------------"; - LOG(INFO) << "Total time spent(ms): " - << std::accumulate(this->time_info_.begin(), this->time_info_.end(), 0); - LOG(INFO) << "preprocess_time(ms): " << this->time_info_[0] / this->img_num_ - << ", inference_time(ms): " << this->time_info_[1] / this->img_num_ - << ", postprocess_time(ms): " << this->time_info_[2] / this->img_num_; - } - -private: - std::string model_name_; - bool use_gpu_ = false; - bool enable_tensorrt_ = false; - bool enable_mkldnn_ = true; - int cpu_threads_ = 10; - int batch_size_ = 1; - std::string input_shape_ = "dynamic"; - std::string model_precision_ = "fp32"; - std::vector time_info_; - int img_num_; -}; diff --git a/deploy/cpp_infer/src/main.cpp b/deploy/cpp_infer/src/main.cpp index 6d2eec04..382be797 100644 --- a/deploy/cpp_infer/src/main.cpp +++ b/deploy/cpp_infer/src/main.cpp @@ -35,7 +35,6 @@ #include #include -#include DEFINE_bool(use_gpu, false, "Infering with GPU or CPU."); DEFINE_int32(gpu_id, 0, "Device id of GPU to execute.");