From 9d5d552b7971198b03f0ff5e948dc0097fca0648 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 14 Jul 2021 06:18:29 +0000 Subject: [PATCH 01/29] delete save_log_path and set logger --- tools/infer/predict_det.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index 6a45f81e48..568381b1f7 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -106,7 +106,7 @@ class TextDetector(object): model_precision=args.precision, batch_size=1, data_shape="dynamic", - save_path=args.save_log_path, + save_path=None, inference_config=self.config, pids=pid, process_name=None, @@ -114,7 +114,8 @@ class TextDetector(object): time_keys=[ 'preprocess_time', 'inference_time', 'postprocess_time' ], - warmup=10) + warmup=10, + logger=logger) def order_points_clockwise(self, pts): """ From f6167acc1fa4ce9cfc867f689d9260ae1243a30a Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 14 Jul 2021 06:19:08 +0000 Subject: [PATCH 02/29] add test_v7 --- tests/params.txt | 48 ++++++++ tests/prepare.sh | 77 +++++++++++++ tests/test.sh | 282 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 407 insertions(+) create mode 100644 tests/params.txt create mode 100644 tests/prepare.sh create mode 100644 tests/test.sh diff --git a/tests/params.txt b/tests/params.txt new file mode 100644 index 0000000000..4fc6626cef --- /dev/null +++ b/tests/params.txt @@ -0,0 +1,48 @@ +===========================train_params=========================== +model_name:ocr_det +python:python3.7 +gpu_list:0|0,1 +Global.auto_cast:null +Global.epoch_num:2 +Global.save_model_dir:./output/ +Train.loader.batch_size_per_card:2 +Global.use_gpu: +Global.pretrained_model:null +train_model_name:latest +train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/ +null:null +## +trainer:norm_train|pact_train +norm_train:tools/train.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/MobileNetV3_large_x0_5_pretrained +pact_train:deploy/slim/quantization/quant.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/det_mv3_db_v2.0_train/best_accuracy +fpgm_train:null +distill_train:null +null:null +null:null +## +===========================eval_params=========================== +eval:null +null:null +## +===========================infer_params=========================== +Global.save_inference_dir:./output/ +Global.pretrained_model: +norm_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o +quant_export:deploy/slim/quantization/export_model.py -c configs/det/det_mv3_db.yml -o +fpgm_export:deploy/slim/prune/export_prune_model.py +distill_export:null +null:null +null:null +## +inference:tools/infer/predict_det.py +--use_gpu:True|False +--enable_mkldnn:True|False +--cpu_threads:1|6 +--rec_batch_num:1 +--use_tensorrt:True|False +--precision:fp32|fp16|int8 +--det_model_dir:./inference/ch_ppocr_mobile_v2.0_det_infer/ +--image_dir:./inference/ch_det_data_50/all-sum-510/ +--save_log_path:null +--benchmark:True +null:null diff --git a/tests/prepare.sh b/tests/prepare.sh new file mode 100644 index 0000000000..2811cb3fc0 --- /dev/null +++ b/tests/prepare.sh @@ -0,0 +1,77 @@ +#!/bin/bash +FILENAME=$1 +# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer'] +MODE=$2 + +dataline=$(cat ${FILENAME}) + +# parser params +IFS=$'\n' +lines=(${dataline}) +function func_parser_key(){ + strs=$1 + IFS=":" + array=(${strs}) + tmp=${array[0]} + echo ${tmp} +} +function func_parser_value(){ + strs=$1 + IFS=":" + array=(${strs}) + tmp=${array[1]} + echo ${tmp} +} +IFS=$'\n' +# The training params +model_name=$(func_parser_value "${lines[0]}") +train_model_list=$(func_parser_value "${lines[0]}") + +trainer_list=$(func_parser_value "${lines[10]}") + + +# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer'] +MODE=$2 +# prepare pretrained weights and dataset +wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams +wget -nc -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar +cd pretrain_models && tar xf det_mv3_db_v2.0_train.tar && cd ../ + +if [ ${MODE} = "lite_train_infer" ];then + # pretrain lite train data + rm -rf ./train_data/icdar2015 + wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar + cd ./train_data/ && tar xf icdar2015_lite.tar + ln -s ./icdar2015_lite ./icdar2015 + cd ../ + epoch=10 + eval_batch_step=10 +elif [ ${MODE} = "whole_train_infer" ];then + rm -rf ./train_data/icdar2015 + wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015.tar + cd ./train_data/ && tar xf icdar2015.tar && cd ../ + epoch=500 + eval_batch_step=200 +elif [ ${MODE} = "whole_infer" ];then + rm -rf ./train_data/icdar2015 + wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_infer.tar + cd ./train_data/ && tar xf icdar2015_infer.tar + ln -s ./icdar2015_infer ./icdar2015 + cd ../ + epoch=10 + eval_batch_step=10 +else + rm -rf ./train_data/icdar2015 + wget -nc -P ./train_data https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar + if [ ${model_name} = "ocr_det" ]; then + eval_model_name="ch_ppocr_mobile_v2.0_det_infer" + 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 && cd ../ + else + eval_model_name="ch_ppocr_mobile_v2.0_rec_train" + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_train.tar + cd ./inference && tar xf ${eval_model_name}.tar && cd ../ + fi +fi + + diff --git a/tests/test.sh b/tests/test.sh new file mode 100644 index 0000000000..fde636fc1c --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,282 @@ +#!/bin/bash +FILENAME=$1 +# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer', 'infer'] +MODE=$2 + +dataline=$(cat ${FILENAME}) + +# parser params +IFS=$'\n' +lines=(${dataline}) + +function func_parser_key(){ + strs=$1 + IFS=":" + array=(${strs}) + tmp=${array[0]} + echo ${tmp} +} +function func_parser_value(){ + strs=$1 + IFS=":" + array=(${strs}) + tmp=${array[1]} + echo ${tmp} +} +function func_set_params(){ + key=$1 + value=$2 + if [ ${key} = "null" ];then + echo " " + elif [[ ${value} = "null" ]] || [[ ${value} = " " ]] || [ ${#value} -le 0 ];then + echo " " + else + echo "${key}=${value}" + fi +} +function status_check(){ + last_status=$1 # the exit code + run_command=$2 + run_log=$3 + if [ $last_status -eq 0 ]; then + echo -e "\033[33m Run successfully with command - ${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} + fi +} + +IFS=$'\n' +# The training params +model_name=$(func_parser_value "${lines[1]}") +python=$(func_parser_value "${lines[2]}") +gpu_list=$(func_parser_value "${lines[3]}") +autocast_list=$(func_parser_value "${lines[4]}") +autocast_key=$(func_parser_key "${lines[4]}") +epoch_key=$(func_parser_key "${lines[5]}") +epoch_num=$(func_parser_value "${lines[5]}") +save_model_key=$(func_parser_key "${lines[6]}") +train_batch_key=$(func_parser_key "${lines[7]}") +train_batch_value=$(func_parser_value "${lines[7]}") +train_use_gpu_key=$(func_parser_key "${lines[8]}") +pretrain_model_key=$(func_parser_key "${lines[9]}") +pretrain_model_value=$(func_parser_value "${lines[9]}") +train_model_name=$(func_parser_value "${lines[10]}") +train_infer_img_dir=$(func_parser_value "${lines[11]}") +train_param_key1=$(func_parser_key "${lines[12]}") +train_param_value1=$(func_parser_value "${lines[12]}") + +trainer_list=$(func_parser_value "${lines[14]}") +trainer_norm=$(func_parser_key "${lines[15]}") +norm_trainer=$(func_parser_value "${lines[15]}") +pact_key=$(func_parser_key "${lines[16]}") +pact_trainer=$(func_parser_value "${lines[16]}") +fpgm_key=$(func_parser_key "${lines[17]}") +fpgm_trainer=$(func_parser_value "${lines[17]}") +distill_key=$(func_parser_key "${lines[18]}") +distill_trainer=$(func_parser_value "${lines[18]}") +trainer_key1=$(func_parser_key "${lines[19]}") +trainer_value1=$(func_parser_value "${lines[19]}") +trainer_key1=$(func_parser_key "${lines[20]}") +trainer_value2=$(func_parser_value "${lines[20]}") + +eval_py=$(func_parser_value "${lines[23]}") +eval_key1=$(func_parser_key "${lines[24]}") +eval_value1=$(func_parser_value "${lines[24]}") + +save_infer_key=$(func_parser_key "${lines[27]}") +export_weight=$(func_parser_key "${lines[28]}") +norm_export=$(func_parser_value "${lines[29]}") +pact_export=$(func_parser_value "${lines[30]}") +fpgm_export=$(func_parser_value "${lines[31]}") +distill_export=$(func_parser_value "${lines[32]}") +export_key1=$(func_parser_key "${lines[33]}") +export_value1=$(func_parser_value "${lines[33]}") +export_key2=$(func_parser_key "${lines[34]}") +export_value2=$(func_parser_value "${lines[34]}") + +inference_py=$(func_parser_value "${lines[36]}") +use_gpu_key=$(func_parser_key "${lines[37]}") +use_gpu_list=$(func_parser_value "${lines[37]}") +use_mkldnn_key=$(func_parser_key "${lines[38]}") +use_mkldnn_list=$(func_parser_value "${lines[38]}") +cpu_threads_key=$(func_parser_key "${lines[39]}") +cpu_threads_list=$(func_parser_value "${lines[39]}") +batch_size_key=$(func_parser_key "${lines[40]}") +batch_size_list=$(func_parser_value "${lines[40]}") +use_trt_key=$(func_parser_key "${lines[41]}") +use_trt_list=$(func_parser_value "${lines[41]}") +precision_key=$(func_parser_key "${lines[42]}") +precision_list=$(func_parser_value "${lines[42]}") +infer_model_key=$(func_parser_key "${lines[43]}") +infer_model=$(func_parser_value "${lines[43]}") +image_dir_key=$(func_parser_key "${lines[44]}") +infer_img_dir=$(func_parser_value "${lines[44]}") +save_log_key=$(func_parser_key "${lines[45]}") +benchmark_key=$(func_parser_key "${lines[46]}") +benchmark_value=$(func_parser_value "${lines[46]}") +infer_key2=$(func_parser_key "${lines[47]}") +infer_value2=$(func_parser_value "${lines[47]}") + +LOG_PATH="./tests/output" +mkdir -p ${LOG_PATH} +status_log="${LOG_PATH}/results.log" + + +function func_inference(){ + IFS='|' + _python=$1 + _script=$2 + _model_dir=$3 + _log_path=$4 + _img_dir=$5 + _flag_quant=$6 + # inference + for use_gpu in ${use_gpu_list[*]}; do + if [ ${use_gpu} = "False" ] && [ ${_flag_quant} = "True" ]; then + continue + fi + if [ ${use_gpu} = "False" ]; then + for use_mkldnn in ${use_mkldnn_list[*]}; do + for threads in ${cpu_threads_list[*]}; do + for batch_size in ${batch_size_list[*]}; do + _save_log_path="${_log_path}/infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_batchsize_${batch_size}.log" + #${image_dir_key}=${_img_dir} ${save_log_key}=${_save_log_path} --benchmark=True + set_infer_data=$(func_set_params "${image_dir_key}" "${_img_dir}") + set_benchmark=$(func_set_params "${benchmark_key}" "${benchmark_value}") + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${cpu_threads_key}=${threads} ${infer_model_key}=${_model_dir} ${batch_size_key}=${batch_size} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + eval $command + status_check $? "${command}" "${status_log}" + done + done + done + else + for use_trt in ${use_trt_list[*]}; do + for precision in ${precision_list[*]}; do + if [ ${use_trt} = "False" ] && [ ${precision} != "fp32" ]; then + continue + fi + if [ ${use_trt} = "False" ] && [ ${_flag_quant} = "True" ]; then + continue + fi + if [ ${precision} != "int8" ] && [ ${_flag_quant} = "True" ]; then + continue + fi + for batch_size in ${batch_size_list[*]}; do + _save_log_path="${_log_path}/infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log" + set_infer_data=$(func_set_params "${image_dir_key}" "${_img_dir}") + set_benchmark=$(func_set_params "${benchmark_key}" "${benchmark_value}") + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_trt_key}=${use_trt} ${precision_key}=${precision} ${infer_model_key}=${_model_dir} ${batch_size_key}=${batch_size} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + eval $command + status_check $? "${command}" "${status_log}" + done + done + done + fi + done +} + +if [ ${MODE} != "infer" ]; then + +IFS="|" +for gpu in ${gpu_list[*]}; do + use_gpu=True + if [ ${gpu} = "-1" ];then + use_gpu=False + env="" + elif [ ${#gpu} -le 1 ];then + env="export CUDA_VISIBLE_DEVICES=${gpu}" + eval ${env} + elif [ ${#gpu} -le 15 ];then + IFS="," + array=(${gpu}) + env="export CUDA_VISIBLE_DEVICES=${array[0]}" + IFS="|" + else + IFS=";" + array=(${gpu}) + ips=${array[0]} + gpu=${array[1]} + IFS="|" + env=" " + fi + for autocast in ${autocast_list[*]}; do + for trainer in ${trainer_list[*]}; do + flag_quant=False + if [ ${trainer} = ${pact_key} ]; then + run_train=${pact_trainer} + run_export=${pact_export} + flag_quant=True + elif [ ${trainer} = "${fpgm_key}" ]; then + run_train=${fpgm_trainer} + run_export=${fpgm_export} + elif [ ${trainer} = "${distill_key}" ]; then + run_train=${distill_trainer} + run_export=${distill_export} + elif [ ${trainer} = ${trainer_key1} ]; then + run_train=${trainer_value1} + run_export=${export_value1} + elif [[ ${trainer} = ${trainer_key2} ]]; then + run_train=${trainer_value2} + run_export=${export_value2} + else + run_train=${norm_trainer} + run_export=${norm_export} + fi + + if [ ${run_train} = "null" ]; then + continue + fi + + set_autocast=$(func_set_params "${autocast_key}" "${autocast}") + set_autocast=$(func_set_params "${epoch_key}" "${epoch_num}") + set_pretrain=$(func_set_params "${pretrain_model_key}" "${pretrain_model_value}") + set_batchsize=$(func_set_params "${train_batch_key}" "${train_batch_value}") + set_train_params1=$(func_set_params "${train_param_key1}" "${train_param_value1}") + + save_log="${LOG_PATH}/${trainer}_gpus_${gpu}_autocast_${autocast}" + if [ ${#gpu} -le 2 ];then # train with cpu or single gpu + cmd="${python} ${run_train} ${train_use_gpu_key}=${use_gpu} ${save_model_key}=${save_log} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " + elif [ ${#gpu} -le 15 ];then # train with multi-gpu + cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${save_model_key}=${save_log} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1}" + else # train with multi-machine + cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${save_model_key}=${save_log} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_train_params1}" + fi + # run train + eval $cmd + status_check $? "${cmd}" "${status_log}" + + # run eval + if [ ${eval_py} != "null" ]; then + eval_cmd="${python} ${eval_py} ${save_model_key}=${save_log} ${pretrain_model_key}=${save_log}/${train_model_name}" + eval $eval_cmd + status_check $? "${eval_cmd}" "${status_log}" + fi + + if [ ${run_export} != "null" ]; then + # run export model + save_infer_path="${save_log}" + export_cmd="${python} ${run_export} ${save_model_key}=${save_log} ${export_weight}=${save_log}/${train_model_name} ${save_infer_key}=${save_infer_path}" + eval $export_cmd + status_check $? "${export_cmd}" "${status_log}" + + #run inference + eval $env + save_infer_path="${save_log}" + func_inference "${python}" "${inference_py}" "${save_infer_path}" "${LOG_PATH}" "${train_infer_img_dir}" "${flag_quant}" + eval "unset CUDA_VISIBLE_DEVICES" + fi + done + done +done + +else + GPUID=$3 + if [ ${#GPUID} -le 0 ];then + env=" " + else + env="export CUDA_VISIBLE_DEVICES=${GPUID}" + fi + echo $env + #run inference + func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" "False" +fi From be8b7fdec9b418bd48ef3787d99abf3357a2920d Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 14 Jul 2021 06:20:52 +0000 Subject: [PATCH 03/29] rename params --- tests/ocr_det_params.txt | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/ocr_det_params.txt diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt new file mode 100644 index 0000000000..4fc6626cef --- /dev/null +++ b/tests/ocr_det_params.txt @@ -0,0 +1,48 @@ +===========================train_params=========================== +model_name:ocr_det +python:python3.7 +gpu_list:0|0,1 +Global.auto_cast:null +Global.epoch_num:2 +Global.save_model_dir:./output/ +Train.loader.batch_size_per_card:2 +Global.use_gpu: +Global.pretrained_model:null +train_model_name:latest +train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/ +null:null +## +trainer:norm_train|pact_train +norm_train:tools/train.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/MobileNetV3_large_x0_5_pretrained +pact_train:deploy/slim/quantization/quant.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/det_mv3_db_v2.0_train/best_accuracy +fpgm_train:null +distill_train:null +null:null +null:null +## +===========================eval_params=========================== +eval:null +null:null +## +===========================infer_params=========================== +Global.save_inference_dir:./output/ +Global.pretrained_model: +norm_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o +quant_export:deploy/slim/quantization/export_model.py -c configs/det/det_mv3_db.yml -o +fpgm_export:deploy/slim/prune/export_prune_model.py +distill_export:null +null:null +null:null +## +inference:tools/infer/predict_det.py +--use_gpu:True|False +--enable_mkldnn:True|False +--cpu_threads:1|6 +--rec_batch_num:1 +--use_tensorrt:True|False +--precision:fp32|fp16|int8 +--det_model_dir:./inference/ch_ppocr_mobile_v2.0_det_infer/ +--image_dir:./inference/ch_det_data_50/all-sum-510/ +--save_log_path:null +--benchmark:True +null:null From 2be96bfc9a91e02bd6f3001847df44aab99e8112 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 14 Jul 2021 06:41:38 +0000 Subject: [PATCH 04/29] support cpu+mkldnn+quant_model infer --- tests/params.txt | 48 ------------------------------------------------ tests/test.sh | 6 +++--- 2 files changed, 3 insertions(+), 51 deletions(-) delete mode 100644 tests/params.txt diff --git a/tests/params.txt b/tests/params.txt deleted file mode 100644 index 4fc6626cef..0000000000 --- a/tests/params.txt +++ /dev/null @@ -1,48 +0,0 @@ -===========================train_params=========================== -model_name:ocr_det -python:python3.7 -gpu_list:0|0,1 -Global.auto_cast:null -Global.epoch_num:2 -Global.save_model_dir:./output/ -Train.loader.batch_size_per_card:2 -Global.use_gpu: -Global.pretrained_model:null -train_model_name:latest -train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/ -null:null -## -trainer:norm_train|pact_train -norm_train:tools/train.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/MobileNetV3_large_x0_5_pretrained -pact_train:deploy/slim/quantization/quant.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/det_mv3_db_v2.0_train/best_accuracy -fpgm_train:null -distill_train:null -null:null -null:null -## -===========================eval_params=========================== -eval:null -null:null -## -===========================infer_params=========================== -Global.save_inference_dir:./output/ -Global.pretrained_model: -norm_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o -quant_export:deploy/slim/quantization/export_model.py -c configs/det/det_mv3_db.yml -o -fpgm_export:deploy/slim/prune/export_prune_model.py -distill_export:null -null:null -null:null -## -inference:tools/infer/predict_det.py ---use_gpu:True|False ---enable_mkldnn:True|False ---cpu_threads:1|6 ---rec_batch_num:1 ---use_tensorrt:True|False ---precision:fp32|fp16|int8 ---det_model_dir:./inference/ch_ppocr_mobile_v2.0_det_infer/ ---image_dir:./inference/ch_det_data_50/all-sum-510/ ---save_log_path:null ---benchmark:True -null:null diff --git a/tests/test.sh b/tests/test.sh index fde636fc1c..10c26d2c0b 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -132,11 +132,11 @@ function func_inference(){ _flag_quant=$6 # inference for use_gpu in ${use_gpu_list[*]}; do - if [ ${use_gpu} = "False" ] && [ ${_flag_quant} = "True" ]; then - continue - fi if [ ${use_gpu} = "False" ]; then for use_mkldnn in ${use_mkldnn_list[*]}; do + if [ ${use_mkldnn} = "False" ] && [ ${_flag_quant} = "True" ]; then + continue + fi for threads in ${cpu_threads_list[*]}; do for batch_size in ${batch_size_list[*]}; do _save_log_path="${_log_path}/infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_batchsize_${batch_size}.log" From 425e343b0525996cbd48991c62605df908f33e3a Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 14 Jul 2021 13:54:42 +0000 Subject: [PATCH 05/29] support use_gpu as device --- tests/ocr_det_params.txt | 2 +- tests/test.sh | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 4fc6626cef..31928cef2c 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -2,11 +2,11 @@ model_name:ocr_det python:python3.7 gpu_list:0|0,1 +Global.use_gpu:True|False Global.auto_cast:null Global.epoch_num:2 Global.save_model_dir:./output/ Train.loader.batch_size_per_card:2 -Global.use_gpu: Global.pretrained_model:null train_model_name:latest train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/ diff --git a/tests/test.sh b/tests/test.sh index 10c26d2c0b..60b0233c01 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -50,14 +50,15 @@ IFS=$'\n' model_name=$(func_parser_value "${lines[1]}") python=$(func_parser_value "${lines[2]}") gpu_list=$(func_parser_value "${lines[3]}") -autocast_list=$(func_parser_value "${lines[4]}") -autocast_key=$(func_parser_key "${lines[4]}") -epoch_key=$(func_parser_key "${lines[5]}") -epoch_num=$(func_parser_value "${lines[5]}") -save_model_key=$(func_parser_key "${lines[6]}") -train_batch_key=$(func_parser_key "${lines[7]}") -train_batch_value=$(func_parser_value "${lines[7]}") -train_use_gpu_key=$(func_parser_key "${lines[8]}") +train_use_gpu_key=$(func_parser_key "${lines[4]}") +train_use_gpu_value=$(func_parser_value "${lines[4]}") +autocast_list=$(func_parser_value "${lines[5]}") +autocast_key=$(func_parser_key "${lines[5]}") +epoch_key=$(func_parser_key "${lines[6]}") +epoch_num=$(func_parser_value "${lines[6]}") +save_model_key=$(func_parser_key "${lines[7]}") +train_batch_key=$(func_parser_key "${lines[8]}") +train_batch_value=$(func_parser_value "${lines[8]}") pretrain_model_key=$(func_parser_key "${lines[9]}") pretrain_model_value=$(func_parser_value "${lines[9]}") train_model_name=$(func_parser_value "${lines[10]}") @@ -132,7 +133,7 @@ function func_inference(){ _flag_quant=$6 # inference for use_gpu in ${use_gpu_list[*]}; do - if [ ${use_gpu} = "False" ]; then + if [ ${use_gpu} = "False" ] || [ ${use_gpu} = "cpu" ]; then for use_mkldnn in ${use_mkldnn_list[*]}; do if [ ${use_mkldnn} = "False" ] && [ ${_flag_quant} = "True" ]; then continue @@ -149,7 +150,7 @@ function func_inference(){ done done done - else + elif [ ${use_gpu} = "True" ] || [ ${use_gpu} = "gpu" ]; then for use_trt in ${use_trt_list[*]}; do for precision in ${precision_list[*]}; do if [ ${use_trt} = "False" ] && [ ${precision} != "fp32" ]; then @@ -171,6 +172,8 @@ function func_inference(){ done done done + else + echo "Currently does not support hardware other than CPU and GPU" fi done } @@ -178,10 +181,12 @@ function func_inference(){ if [ ${MODE} != "infer" ]; then IFS="|" +export Count=0 +USE_GPU_KEY=(${train_use_gpu_value}) for gpu in ${gpu_list[*]}; do - use_gpu=True + use_gpu=${USE_GPU_KEY[Count]} + Count=$(($Count + 1)) if [ ${gpu} = "-1" ];then - use_gpu=False env="" elif [ ${#gpu} -le 1 ];then env="export CUDA_VISIBLE_DEVICES=${gpu}" @@ -232,10 +237,11 @@ for gpu in ${gpu_list[*]}; do set_pretrain=$(func_set_params "${pretrain_model_key}" "${pretrain_model_value}") set_batchsize=$(func_set_params "${train_batch_key}" "${train_batch_value}") set_train_params1=$(func_set_params "${train_param_key1}" "${train_param_value1}") + set_use_gpu=$(func_set_params "${train_use_gpu_key}" "${use_gpu}") save_log="${LOG_PATH}/${trainer}_gpus_${gpu}_autocast_${autocast}" if [ ${#gpu} -le 2 ];then # train with cpu or single gpu - cmd="${python} ${run_train} ${train_use_gpu_key}=${use_gpu} ${save_model_key}=${save_log} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " + cmd="${python} ${run_train} ${set_use_gpu} ${save_model_key}=${save_log} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " elif [ ${#gpu} -le 15 ];then # train with multi-gpu cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${save_model_key}=${save_log} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1}" else # train with multi-machine @@ -247,7 +253,7 @@ for gpu in ${gpu_list[*]}; do # run eval if [ ${eval_py} != "null" ]; then - eval_cmd="${python} ${eval_py} ${save_model_key}=${save_log} ${pretrain_model_key}=${save_log}/${train_model_name}" + eval_cmd="${python} ${eval_py} ${save_model_key}=${save_log} ${pretrain_model_key}=${save_log}/${train_model_name} ${set_use_gpu}" eval $eval_cmd status_check $? "${eval_cmd}" "${status_log}" fi From 98d743482bd32ffae5077fdfb6f3f1a8b286f1ef Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Thu, 15 Jul 2021 02:12:16 +0000 Subject: [PATCH 06/29] fix params.txt --- tests/ocr_det_params.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 31928cef2c..b8900bae46 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -2,7 +2,7 @@ model_name:ocr_det python:python3.7 gpu_list:0|0,1 -Global.use_gpu:True|False +Global.use_gpu:True|True Global.auto_cast:null Global.epoch_num:2 Global.save_model_dir:./output/ From fb42b2fe780e16687f887486954776b8165d91e8 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Thu, 15 Jul 2021 03:01:17 +0000 Subject: [PATCH 07/29] unset CUDA_VISIBLE_DEVICES before train --- tests/test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test.sh b/tests/test.sh index 60b0233c01..8e8d012a13 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -248,6 +248,7 @@ for gpu in ${gpu_list[*]}; do cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${save_model_key}=${save_log} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_train_params1}" fi # run train + eval "unset CUDA_VISIBLE_DEVICES" eval $cmd status_check $? "${cmd}" "${status_log}" From 859d403833cd2d0d0546701812869fa08bf78f36 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 19 Jul 2021 06:24:35 +0000 Subject: [PATCH 08/29] fix bugs --- tests/ocr_det_params.txt | 2 +- tests/test.sh | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index b8900bae46..9383250e6d 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -3,7 +3,7 @@ model_name:ocr_det python:python3.7 gpu_list:0|0,1 Global.use_gpu:True|True -Global.auto_cast:null +Global.auto_cast:False Global.epoch_num:2 Global.save_model_dir:./output/ Train.loader.batch_size_per_card:2 diff --git a/tests/test.sh b/tests/test.sh index 8e8d012a13..a976ba4b6a 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -141,10 +141,12 @@ function func_inference(){ for threads in ${cpu_threads_list[*]}; do for batch_size in ${batch_size_list[*]}; do _save_log_path="${_log_path}/infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_batchsize_${batch_size}.log" - #${image_dir_key}=${_img_dir} ${save_log_key}=${_save_log_path} --benchmark=True set_infer_data=$(func_set_params "${image_dir_key}" "${_img_dir}") set_benchmark=$(func_set_params "${benchmark_key}" "${benchmark_value}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${cpu_threads_key}=${threads} ${infer_model_key}=${_model_dir} ${batch_size_key}=${batch_size} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + set_batchsize=$(func_set_params "${batch_size_key}" "${batch_size}") + set_cpu_threads=$(func_set_params "${cpu_threads_key}" "${threads}") + set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${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 status_check $? "${command}" "${status_log}" done @@ -166,7 +168,11 @@ function func_inference(){ _save_log_path="${_log_path}/infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log" set_infer_data=$(func_set_params "${image_dir_key}" "${_img_dir}") set_benchmark=$(func_set_params "${benchmark_key}" "${benchmark_value}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_trt_key}=${use_trt} ${precision_key}=${precision} ${infer_model_key}=${_model_dir} ${batch_size_key}=${batch_size} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + set_batchsize=$(func_set_params "${batch_size_key}" "${batch_size}") + set_tensorrt=$(func_set_params "${use_trt_key}" "${use_trt}") + set_precision=$(func_set_params "${precision_key}" "${precision}") + set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") + command="${_python} ${_script} ${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 status_check $? "${command}" "${status_log}" done @@ -233,28 +239,30 @@ for gpu in ${gpu_list[*]}; do fi set_autocast=$(func_set_params "${autocast_key}" "${autocast}") - set_autocast=$(func_set_params "${epoch_key}" "${epoch_num}") + set_epoch=$(func_set_params "${epoch_key}" "${epoch_num}") set_pretrain=$(func_set_params "${pretrain_model_key}" "${pretrain_model_value}") set_batchsize=$(func_set_params "${train_batch_key}" "${train_batch_value}") set_train_params1=$(func_set_params "${train_param_key1}" "${train_param_value1}") set_use_gpu=$(func_set_params "${train_use_gpu_key}" "${use_gpu}") - save_log="${LOG_PATH}/${trainer}_gpus_${gpu}_autocast_${autocast}" + + set_save_model=$(func_set_params "${save_model_key}" "${save_log}") if [ ${#gpu} -le 2 ];then # train with cpu or single gpu - cmd="${python} ${run_train} ${set_use_gpu} ${save_model_key}=${save_log} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " + cmd="${python} ${run_train} ${set_use_gpu} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " elif [ ${#gpu} -le 15 ];then # train with multi-gpu - cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${save_model_key}=${save_log} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1}" + cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1}" else # train with multi-machine - cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${save_model_key}=${save_log} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_train_params1}" + cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${set_save_model} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_train_params1}" fi # run train eval "unset CUDA_VISIBLE_DEVICES" eval $cmd status_check $? "${cmd}" "${status_log}" + set_eval_pretrain=$(func_set_params "${pretrain_model_key}" "${save_log}/${train_model_name}") # run eval if [ ${eval_py} != "null" ]; then - eval_cmd="${python} ${eval_py} ${save_model_key}=${save_log} ${pretrain_model_key}=${save_log}/${train_model_name} ${set_use_gpu}" + eval_cmd="${python} ${eval_py} ${set_eval_pretrain} ${set_use_gpu}" eval $eval_cmd status_check $? "${eval_cmd}" "${status_log}" fi @@ -262,7 +270,7 @@ for gpu in ${gpu_list[*]}; do if [ ${run_export} != "null" ]; then # run export model save_infer_path="${save_log}" - export_cmd="${python} ${run_export} ${save_model_key}=${save_log} ${export_weight}=${save_log}/${train_model_name} ${save_infer_key}=${save_infer_path}" + export_cmd="${python} ${run_export} ${export_weight}=${save_log}/${train_model_name} ${save_infer_key}=${save_infer_path}" eval $export_cmd status_check $? "${export_cmd}" "${status_log}" From a2df17dc0e83d755bafc7c8874d9a9bc775adf82 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 19 Jul 2021 07:09:35 +0000 Subject: [PATCH 09/29] fix set epoch and batchsize --- tests/ocr_det_params.txt | 4 ++-- tests/test.sh | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 9383250e6d..3efe804e1b 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -4,9 +4,9 @@ python:python3.7 gpu_list:0|0,1 Global.use_gpu:True|True Global.auto_cast:False -Global.epoch_num:2 +Global.epoch_num:lite_train_infer=2|whole_train_infer=300 Global.save_model_dir:./output/ -Train.loader.batch_size_per_card:2 +Train.loader.batch_size_per_card:lite_train_infer=2|whole_train_infer=4 Global.pretrained_model:null train_model_name:latest train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/ diff --git a/tests/test.sh b/tests/test.sh index a976ba4b6a..2c1591f615 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -34,6 +34,28 @@ function func_set_params(){ echo "${key}=${value}" fi } +function func_parser_params(){ + strs=$1 + IFS=":" + array=(${strs}) + key=${array[0]} + tmp=${array[1]} + IFS="|" + res="" + for _params in ${tmp[*]}; do + IFS="=" + array=(${_params}) + mode=${array[0]} + value=${array[1]} + if [[ ${mode} = ${MODE} ]]; then + IFS="|" + echo $(func_set_params "${mode}" "${value}") + break + fi + IFS="|" + done + echo ${res} +} function status_check(){ last_status=$1 # the exit code run_command=$2 @@ -55,10 +77,10 @@ train_use_gpu_value=$(func_parser_value "${lines[4]}") autocast_list=$(func_parser_value "${lines[5]}") autocast_key=$(func_parser_key "${lines[5]}") epoch_key=$(func_parser_key "${lines[6]}") -epoch_num=$(func_parser_value "${lines[6]}") +epoch_num=$(func_parser_params "${lines[6]}") save_model_key=$(func_parser_key "${lines[7]}") train_batch_key=$(func_parser_key "${lines[8]}") -train_batch_value=$(func_parser_value "${lines[8]}") +train_batch_value=$(func_parser_params "${lines[8]}") pretrain_model_key=$(func_parser_key "${lines[9]}") pretrain_model_value=$(func_parser_value "${lines[9]}") train_model_name=$(func_parser_value "${lines[10]}") From ef0803b0418ed15e50a8d4f46ebaeb9547f3c96f Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 19 Jul 2021 07:27:38 +0000 Subject: [PATCH 10/29] fix bugs --- tests/ocr_det_params.txt | 2 +- tests/prepare.sh | 12 ++++++------ tests/test.sh | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 3efe804e1b..141e886849 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -1,4 +1,4 @@ -===========================train_params=========================== +===========================train_params=========================== model_name:ocr_det python:python3.7 gpu_list:0|0,1 diff --git a/tests/prepare.sh b/tests/prepare.sh index 2811cb3fc0..c584ada544 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -24,10 +24,10 @@ function func_parser_value(){ } IFS=$'\n' # The training params -model_name=$(func_parser_value "${lines[0]}") -train_model_list=$(func_parser_value "${lines[0]}") +model_name=$(func_parser_value "${lines[1]}") +train_model_list=$(func_parser_value "${lines[1]}") -trainer_list=$(func_parser_value "${lines[10]}") +trainer_list=$(func_parser_value "${lines[14]}") # MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer'] @@ -62,11 +62,11 @@ elif [ ${MODE} = "whole_infer" ];then eval_batch_step=10 else rm -rf ./train_data/icdar2015 - wget -nc -P ./train_data https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar - if [ ${model_name} = "ocr_det" ]; 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 eval_model_name="ch_ppocr_mobile_v2.0_det_infer" 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 && cd ../ + cd ./inference && tar xf ${eval_model_name}.tar && tar xf ch_det_data_50.tar && cd ../ else eval_model_name="ch_ppocr_mobile_v2.0_rec_train" wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_train.tar diff --git a/tests/test.sh b/tests/test.sh index 2c1591f615..39db2b4b74 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -99,7 +99,7 @@ distill_key=$(func_parser_key "${lines[18]}") distill_trainer=$(func_parser_value "${lines[18]}") trainer_key1=$(func_parser_key "${lines[19]}") trainer_value1=$(func_parser_value "${lines[19]}") -trainer_key1=$(func_parser_key "${lines[20]}") +trainer_key2=$(func_parser_key "${lines[20]}") trainer_value2=$(func_parser_value "${lines[20]}") eval_py=$(func_parser_value "${lines[23]}") From 69663192cbf9822c04035b6fe930bcaf8b2503c9 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 19 Jul 2021 09:11:23 +0000 Subject: [PATCH 11/29] set eval --- tests/ocr_det_params.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 141e886849..2bafbe9c16 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -21,7 +21,7 @@ null:null null:null ## ===========================eval_params=========================== -eval:null +eval:tools/eval.py -c configs/det/det_mv3_db.yml -o null:null ## ===========================infer_params=========================== From acd638418783c37d6360a371f65f58baf37d74c7 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 19 Jul 2021 11:35:27 +0000 Subject: [PATCH 12/29] fix bugs 2 --- tests/test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test.sh b/tests/test.sh index 39db2b4b74..2182c289d6 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -49,7 +49,8 @@ function func_parser_params(){ value=${array[1]} if [[ ${mode} = ${MODE} ]]; then IFS="|" - echo $(func_set_params "${mode}" "${value}") + #echo $(func_set_params "${mode}" "${value}") + echo value break fi IFS="|" From e450e32d1a8c2eeae004c2d3f3e25d11e88c0909 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Mon, 19 Jul 2021 11:38:30 +0000 Subject: [PATCH 13/29] fix bugs --- tests/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.sh b/tests/test.sh index 2182c289d6..36cf2b6f78 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -50,7 +50,7 @@ function func_parser_params(){ if [[ ${mode} = ${MODE} ]]; then IFS="|" #echo $(func_set_params "${mode}" "${value}") - echo value + echo $value break fi IFS="|" From 09e721108275a58cba9c1f925a036a7442528cb9 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 20 Jul 2021 06:47:18 +0000 Subject: [PATCH 14/29] fix bugs and adjust warmup times from 10 to 2 to speed up --- tests/test.sh | 11 +++++++---- tools/infer/predict_det.py | 4 ++-- tools/infer/predict_rec.py | 9 +++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index 36cf2b6f78..9caab02aee 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -138,8 +138,8 @@ infer_img_dir=$(func_parser_value "${lines[44]}") save_log_key=$(func_parser_key "${lines[45]}") benchmark_key=$(func_parser_key "${lines[46]}") benchmark_value=$(func_parser_value "${lines[46]}") -infer_key2=$(func_parser_key "${lines[47]}") -infer_value2=$(func_parser_value "${lines[47]}") +infer_key1=$(func_parser_key "${lines[47]}") +infer_value1=$(func_parser_value "${lines[47]}") LOG_PATH="./tests/output" mkdir -p ${LOG_PATH} @@ -169,7 +169,8 @@ function func_inference(){ set_batchsize=$(func_set_params "${batch_size_key}" "${batch_size}") set_cpu_threads=$(func_set_params "${cpu_threads_key}" "${threads}") set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + set_infer_params1=$(func_set_params "${infer_key1}" "${infer_value1}") + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_save_log_path} 2>&1 " eval $command status_check $? "${command}" "${status_log}" done @@ -285,7 +286,8 @@ for gpu in ${gpu_list[*]}; do set_eval_pretrain=$(func_set_params "${pretrain_model_key}" "${save_log}/${train_model_name}") # run eval if [ ${eval_py} != "null" ]; then - eval_cmd="${python} ${eval_py} ${set_eval_pretrain} ${set_use_gpu}" + set_eval_params1=$(func_set_params "${eval_key1}" "${eval_value1}") + eval_cmd="${python} ${eval_py} ${set_eval_pretrain} ${set_use_gpu} ${set_eval_params1}" eval $eval_cmd status_check $? "${eval_cmd}" "${status_log}" fi @@ -318,3 +320,4 @@ else #run inference func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" "False" fi + diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index 568381b1f7..3de00d83a8 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -114,7 +114,7 @@ class TextDetector(object): time_keys=[ 'preprocess_time', 'inference_time', 'postprocess_time' ], - warmup=10, + warmup=2, logger=logger) def order_points_clockwise(self, pts): @@ -237,7 +237,7 @@ if __name__ == "__main__": if args.warmup: img = np.random.uniform(0, 255, [640, 640, 3]).astype(np.uint8) - for i in range(10): + for i in range(2): res = text_detector(img) if not os.path.exists(draw_img_save): diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index bc9f713aea..bb4a317064 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -73,7 +73,7 @@ class TextRecognizer(object): model_precision=args.precision, batch_size=args.rec_batch_num, data_shape="dynamic", - save_path=args.save_log_path, + save_path=None, #args.save_log_path, inference_config=self.config, pids=pid, process_name=None, @@ -81,7 +81,8 @@ class TextRecognizer(object): time_keys=[ 'preprocess_time', 'inference_time', 'postprocess_time' ], - warmup=10) + warmup=2, + logger=logger) def resize_norm_img(self, img, max_wh_ratio): imgC, imgH, imgW = self.rec_image_shape @@ -272,10 +273,10 @@ def main(args): valid_image_file_list = [] img_list = [] - # warmup 10 times + # warmup 2 times if args.warmup: img = np.random.uniform(0, 255, [32, 320, 3]).astype(np.uint8) - for i in range(10): + for i in range(2): res = text_recognizer([img]) for image_file in image_file_list: From b4d7be33f0a37bf729316491cc75e927895d5bff Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 20 Jul 2021 12:22:57 +0000 Subject: [PATCH 15/29] fix comments --- tests/ocr_det_params.txt | 2 +- tests/prepare.sh | 13 +-- tests/test.sh | 219 ++++++++++++++++++++------------------- 3 files changed, 116 insertions(+), 118 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 2bafbe9c16..f74fc3f5f8 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -14,7 +14,7 @@ null:null ## trainer:norm_train|pact_train norm_train:tools/train.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/MobileNetV3_large_x0_5_pretrained -pact_train:deploy/slim/quantization/quant.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/det_mv3_db_v2.0_train/best_accuracy +pact_train:deploy/slim/quantization/quant.py -c configs/det/det_mv3_db.yml -o fpgm_train:null distill_train:null null:null diff --git a/tests/prepare.sh b/tests/prepare.sh index c584ada544..3c6206ae94 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -25,34 +25,27 @@ function func_parser_value(){ IFS=$'\n' # The training params model_name=$(func_parser_value "${lines[1]}") -train_model_list=$(func_parser_value "${lines[1]}") trainer_list=$(func_parser_value "${lines[14]}") - # MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer'] MODE=$2 -# prepare pretrained weights and dataset -wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams -wget -nc -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_mv3_db_v2.0_train.tar -cd pretrain_models && tar xf det_mv3_db_v2.0_train.tar && cd ../ if [ ${MODE} = "lite_train_infer" ];then # pretrain lite train data + wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams rm -rf ./train_data/icdar2015 wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar cd ./train_data/ && tar xf icdar2015_lite.tar ln -s ./icdar2015_lite ./icdar2015 cd ../ - epoch=10 - eval_batch_step=10 elif [ ${MODE} = "whole_train_infer" ];then + wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams rm -rf ./train_data/icdar2015 wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015.tar cd ./train_data/ && tar xf icdar2015.tar && cd ../ - epoch=500 - eval_batch_step=200 elif [ ${MODE} = "whole_infer" ];then + wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams rm -rf ./train_data/icdar2015 wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_infer.tar cd ./train_data/ && tar xf icdar2015_infer.tar diff --git a/tests/test.sh b/tests/test.sh index 9caab02aee..7398ff6a6d 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -182,10 +182,7 @@ function func_inference(){ if [ ${use_trt} = "False" ] && [ ${precision} != "fp32" ]; then continue fi - if [ ${use_trt} = "False" ] && [ ${_flag_quant} = "True" ]; then - continue - fi - if [ ${precision} != "int8" ] && [ ${_flag_quant} = "True" ]; then + if [ ${use_trt} = "False" || ${precision} != "int8"] && [ ${_flag_quant} = "True" ]; then continue fi for batch_size in ${batch_size_list[*]}; do @@ -208,108 +205,7 @@ function func_inference(){ done } -if [ ${MODE} != "infer" ]; then - -IFS="|" -export Count=0 -USE_GPU_KEY=(${train_use_gpu_value}) -for gpu in ${gpu_list[*]}; do - use_gpu=${USE_GPU_KEY[Count]} - Count=$(($Count + 1)) - if [ ${gpu} = "-1" ];then - env="" - elif [ ${#gpu} -le 1 ];then - env="export CUDA_VISIBLE_DEVICES=${gpu}" - eval ${env} - elif [ ${#gpu} -le 15 ];then - IFS="," - array=(${gpu}) - env="export CUDA_VISIBLE_DEVICES=${array[0]}" - IFS="|" - else - IFS=";" - array=(${gpu}) - ips=${array[0]} - gpu=${array[1]} - IFS="|" - env=" " - fi - for autocast in ${autocast_list[*]}; do - for trainer in ${trainer_list[*]}; do - flag_quant=False - if [ ${trainer} = ${pact_key} ]; then - run_train=${pact_trainer} - run_export=${pact_export} - flag_quant=True - elif [ ${trainer} = "${fpgm_key}" ]; then - run_train=${fpgm_trainer} - run_export=${fpgm_export} - elif [ ${trainer} = "${distill_key}" ]; then - run_train=${distill_trainer} - run_export=${distill_export} - elif [ ${trainer} = ${trainer_key1} ]; then - run_train=${trainer_value1} - run_export=${export_value1} - elif [[ ${trainer} = ${trainer_key2} ]]; then - run_train=${trainer_value2} - run_export=${export_value2} - else - run_train=${norm_trainer} - run_export=${norm_export} - fi - - if [ ${run_train} = "null" ]; then - continue - fi - - set_autocast=$(func_set_params "${autocast_key}" "${autocast}") - set_epoch=$(func_set_params "${epoch_key}" "${epoch_num}") - set_pretrain=$(func_set_params "${pretrain_model_key}" "${pretrain_model_value}") - set_batchsize=$(func_set_params "${train_batch_key}" "${train_batch_value}") - set_train_params1=$(func_set_params "${train_param_key1}" "${train_param_value1}") - set_use_gpu=$(func_set_params "${train_use_gpu_key}" "${use_gpu}") - save_log="${LOG_PATH}/${trainer}_gpus_${gpu}_autocast_${autocast}" - - set_save_model=$(func_set_params "${save_model_key}" "${save_log}") - if [ ${#gpu} -le 2 ];then # train with cpu or single gpu - cmd="${python} ${run_train} ${set_use_gpu} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " - elif [ ${#gpu} -le 15 ];then # train with multi-gpu - cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1}" - else # train with multi-machine - cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${set_save_model} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_train_params1}" - fi - # run train - eval "unset CUDA_VISIBLE_DEVICES" - eval $cmd - status_check $? "${cmd}" "${status_log}" - - set_eval_pretrain=$(func_set_params "${pretrain_model_key}" "${save_log}/${train_model_name}") - # run eval - if [ ${eval_py} != "null" ]; then - set_eval_params1=$(func_set_params "${eval_key1}" "${eval_value1}") - eval_cmd="${python} ${eval_py} ${set_eval_pretrain} ${set_use_gpu} ${set_eval_params1}" - eval $eval_cmd - status_check $? "${eval_cmd}" "${status_log}" - fi - - if [ ${run_export} != "null" ]; then - # run export model - save_infer_path="${save_log}" - export_cmd="${python} ${run_export} ${export_weight}=${save_log}/${train_model_name} ${save_infer_key}=${save_infer_path}" - eval $export_cmd - status_check $? "${export_cmd}" "${status_log}" - - #run inference - eval $env - save_infer_path="${save_log}" - func_inference "${python}" "${inference_py}" "${save_infer_path}" "${LOG_PATH}" "${train_infer_img_dir}" "${flag_quant}" - eval "unset CUDA_VISIBLE_DEVICES" - fi - done - done -done - -else +if [ ${MODE} = "infer" ]; then GPUID=$3 if [ ${#GPUID} -le 0 ];then env=" " @@ -319,5 +215,114 @@ else echo $env #run inference func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" "False" -fi + +else + IFS="|" + export Count=0 + USE_GPU_KEY=(${train_use_gpu_value}) + for gpu in ${gpu_list[*]}; do + use_gpu=${USE_GPU_KEY[Count]} + Count=$(($Count + 1)) + if [ ${gpu} = "-1" ];then + env="" + elif [ ${#gpu} -le 1 ];then + env="export CUDA_VISIBLE_DEVICES=${gpu}" + eval ${env} + elif [ ${#gpu} -le 15 ];then + IFS="," + array=(${gpu}) + env="export CUDA_VISIBLE_DEVICES=${array[0]}" + IFS="|" + else + IFS=";" + array=(${gpu}) + ips=${array[0]} + gpu=${array[1]} + IFS="|" + env=" " + fi + for autocast in ${autocast_list[*]}; do + for trainer in ${trainer_list[*]}; do + flag_quant=False + if [ ${trainer} = ${pact_key} ]; then + run_train=${pact_trainer} + run_export=${pact_export} + flag_quant=True + elif [ ${trainer} = "${fpgm_key}" ]; then + run_train=${fpgm_trainer} + run_export=${fpgm_export} + elif [ ${trainer} = "${distill_key}" ]; then + run_train=${distill_trainer} + run_export=${distill_export} + elif [ ${trainer} = ${trainer_key1} ]; then + run_train=${trainer_value1} + run_export=${export_value1} + elif [[ ${trainer} = ${trainer_key2} ]]; then + run_train=${trainer_value2} + run_export=${export_value2} + else + run_train=${norm_trainer} + run_export=${norm_export} + fi + + if [ ${run_train} = "null" ]; then + continue + fi + + set_autocast=$(func_set_params "${autocast_key}" "${autocast}") + set_epoch=$(func_set_params "${epoch_key}" "${epoch_num}") + set_pretrain=$(func_set_params "${pretrain_model_key}" "${pretrain_model_value}") + set_batchsize=$(func_set_params "${train_batch_key}" "${train_batch_value}") + set_train_params1=$(func_set_params "${train_param_key1}" "${train_param_value1}") + set_use_gpu=$(func_set_params "${train_use_gpu_key}" "${use_gpu}") + save_log="${LOG_PATH}/${trainer}_gpus_${gpu}_autocast_${autocast}" + + # load pretrain from norm training if current trainer is pact or fpgm trainer + if [ ${trainer} = ${pact_key} ] || [ ${trainer} = ${fpgm_key} ]; then + set_pretrain="${load_norm_train_model}" + fi + + set_save_model=$(func_set_params "${save_model_key}" "${save_log}") + if [ ${#gpu} -le 2 ];then # train with cpu or single gpu + cmd="${python} ${run_train} ${set_use_gpu} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " + elif [ ${#gpu} -le 15 ];then # train with multi-gpu + cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1}" + else # train with multi-machine + cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${set_save_model} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_train_params1}" + fi + # run train + eval "unset CUDA_VISIBLE_DEVICES" + eval $cmd + status_check $? "${cmd}" "${status_log}" + + set_eval_pretrain=$(func_set_params "${pretrain_model_key}" "${save_log}/${train_model_name}") + # save norm trained models to set pretrain for pact training and fpgm training + if [ ${trainer} = ${trainer_norm} ]; then + load_norm_train_model=${set_eval_pretrain} + fi + # run eval + if [ ${eval_py} != "null" ]; then + set_eval_params1=$(func_set_params "${eval_key1}" "${eval_value1}") + eval_cmd="${python} ${eval_py} ${set_eval_pretrain} ${set_use_gpu} ${set_eval_params1}" + eval $eval_cmd + status_check $? "${eval_cmd}" "${status_log}" + fi + # run export model + if [ ${run_export} != "null" ]; then + # run export model + save_infer_path="${save_log}" + export_cmd="${python} ${run_export} ${export_weight}=${save_log}/${train_model_name} ${save_infer_key}=${save_infer_path}" + eval $export_cmd + status_check $? "${export_cmd}" "${status_log}" + + #run inference + eval $env + save_infer_path="${save_log}" + func_inference "${python}" "${inference_py}" "${save_infer_path}" "${LOG_PATH}" "${train_infer_img_dir}" "${flag_quant}" + eval "unset CUDA_VISIBLE_DEVICES" + fi + done # done with: for trainer in ${trainer_list[*]}; do + done # done with: for autocast in ${autocast_list[*]}; do + done # done with: for gpu in ${gpu_list[*]}; do +fi # end if [ ${MODE} = "infer" ]; then From a03814573468635aa2804b2a5cc96e9133b86325 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 21 Jul 2021 11:42:47 +0000 Subject: [PATCH 16/29] fix bug in line185 --- tests/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.sh b/tests/test.sh index 7398ff6a6d..3a40182e4d 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -182,7 +182,7 @@ function func_inference(){ if [ ${use_trt} = "False" ] && [ ${precision} != "fp32" ]; then continue fi - if [ ${use_trt} = "False" || ${precision} != "int8"] && [ ${_flag_quant} = "True" ]; then + if [[ ${use_trt} = "False" || ${precision} != "int8" ]] && [ ${_flag_quant} = "True" ]; then continue fi for batch_size in ${batch_size_list[*]}; do From 52f2152aad7eafbcd3a7f58e8c38a61fdd50225a Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 21 Jul 2021 12:25:56 +0000 Subject: [PATCH 17/29] add tee --- tests/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index 3a40182e4d..af21005063 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -170,7 +170,7 @@ function func_inference(){ set_cpu_threads=$(func_set_params "${cpu_threads_key}" "${threads}") set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") set_infer_params1=$(func_set_params "${infer_key1}" "${infer_value1}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_save_log_path} 2>&1 " + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} 2>&1 | tee ${_save_log_path} " eval $command status_check $? "${command}" "${status_log}" done @@ -193,7 +193,7 @@ function func_inference(){ set_tensorrt=$(func_set_params "${use_trt_key}" "${use_trt}") set_precision=$(func_set_params "${precision_key}" "${precision}") set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} 2>&1 | tee ${_save_log_path}" eval $command status_check $? "${command}" "${status_log}" done From 41816deeeed71f28057de79dc9c8f89e27b5dd68 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Fri, 23 Jul 2021 07:50:00 +0000 Subject: [PATCH 18/29] support multi inference model inference --- tests/ocr_det_params.txt | 15 +++++--- tests/test.sh | 79 ++++++++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index f74fc3f5f8..bb32990e4f 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -31,17 +31,20 @@ norm_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o quant_export:deploy/slim/quantization/export_model.py -c configs/det/det_mv3_db.yml -o fpgm_export:deploy/slim/prune/export_prune_model.py distill_export:null -null:null -null:null +export1:null +export2:null ## +infer_model:./inference/ch_ppocr_mobile_v2.0_det_train/best_accuracy|./inference/ch_mobile_det_quant_dev_lr/ +infer_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o |null +infer_quant:False|True inference:tools/infer/predict_det.py ---use_gpu:True|False +--use_gpu:True --enable_mkldnn:True|False --cpu_threads:1|6 --rec_batch_num:1 ---use_tensorrt:True|False ---precision:fp32|fp16|int8 ---det_model_dir:./inference/ch_ppocr_mobile_v2.0_det_infer/ +--use_tensorrt:False|True +--precision:fp32|int8 +--det_model_dir: --image_dir:./inference/ch_det_data_50/all-sum-510/ --save_log_path:null --benchmark:True diff --git a/tests/test.sh b/tests/test.sh index af21005063..79a490f068 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -118,28 +118,32 @@ export_value1=$(func_parser_value "${lines[33]}") export_key2=$(func_parser_key "${lines[34]}") export_value2=$(func_parser_value "${lines[34]}") -inference_py=$(func_parser_value "${lines[36]}") -use_gpu_key=$(func_parser_key "${lines[37]}") -use_gpu_list=$(func_parser_value "${lines[37]}") -use_mkldnn_key=$(func_parser_key "${lines[38]}") -use_mkldnn_list=$(func_parser_value "${lines[38]}") -cpu_threads_key=$(func_parser_key "${lines[39]}") -cpu_threads_list=$(func_parser_value "${lines[39]}") -batch_size_key=$(func_parser_key "${lines[40]}") -batch_size_list=$(func_parser_value "${lines[40]}") -use_trt_key=$(func_parser_key "${lines[41]}") -use_trt_list=$(func_parser_value "${lines[41]}") -precision_key=$(func_parser_key "${lines[42]}") -precision_list=$(func_parser_value "${lines[42]}") -infer_model_key=$(func_parser_key "${lines[43]}") -infer_model=$(func_parser_value "${lines[43]}") -image_dir_key=$(func_parser_key "${lines[44]}") -infer_img_dir=$(func_parser_value "${lines[44]}") -save_log_key=$(func_parser_key "${lines[45]}") -benchmark_key=$(func_parser_key "${lines[46]}") -benchmark_value=$(func_parser_value "${lines[46]}") -infer_key1=$(func_parser_key "${lines[47]}") -infer_value1=$(func_parser_value "${lines[47]}") +# parser inference model +infer_model_dir_list=$(func_parser_value "${lines[36]}") +infer_export_list=$(func_parser_value "${lines[37]}") +infer_is_quant=$(func_parser_value "${lines[38]}") +# parser inference +inference_py=$(func_parser_value "${lines[39]}") +use_gpu_key=$(func_parser_key "${lines[40]}") +use_gpu_list=$(func_parser_value "${lines[40]}") +use_mkldnn_key=$(func_parser_key "${lines[41]}") +use_mkldnn_list=$(func_parser_value "${lines[41]}") +cpu_threads_key=$(func_parser_key "${lines[42]}") +cpu_threads_list=$(func_parser_value "${lines[42]}") +batch_size_key=$(func_parser_key "${lines[43]}") +batch_size_list=$(func_parser_value "${lines[43]}") +use_trt_key=$(func_parser_key "${lines[44]}") +use_trt_list=$(func_parser_value "${lines[44]}") +precision_key=$(func_parser_key "${lines[45]}") +precision_list=$(func_parser_value "${lines[45]}") +infer_model_key=$(func_parser_key "${lines[46]}") +image_dir_key=$(func_parser_key "${lines[47]}") +infer_img_dir=$(func_parser_value "${lines[47]}") +save_log_key=$(func_parser_key "${lines[48]}") +benchmark_key=$(func_parser_key "${lines[49]}") +benchmark_value=$(func_parser_value "${lines[49]}") +infer_key1=$(func_parser_key "${lines[50]}") +infer_value1=$(func_parser_value "${lines[50]}") LOG_PATH="./tests/output" mkdir -p ${LOG_PATH} @@ -179,10 +183,10 @@ function func_inference(){ elif [ ${use_gpu} = "True" ] || [ ${use_gpu} = "gpu" ]; then for use_trt in ${use_trt_list[*]}; do for precision in ${precision_list[*]}; do - if [ ${use_trt} = "False" ] && [ ${precision} != "fp32" ]; then + if [[ ${precision} =~ "fp16" || ${precision} =~ "int8" ]] && [ ${use_trt} = "False" ]; then continue fi - if [[ ${use_trt} = "False" || ${precision} != "int8" ]] && [ ${_flag_quant} = "True" ]; then + if [[ ${use_trt} = "False" || ${precision} =~ "int8" ]] && [ ${_flag_quant} = "True" ]; then continue fi for batch_size in ${batch_size_list[*]}; do @@ -200,7 +204,7 @@ function func_inference(){ done done else - echo "Currently does not support hardware other than CPU and GPU" + echo "Does not support hardware other than CPU and GPU Currently!" fi done } @@ -212,9 +216,28 @@ if [ ${MODE} = "infer" ]; then else env="export CUDA_VISIBLE_DEVICES=${GPUID}" fi - echo $env - #run inference - func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" "False" + # set CUDA_VISIBLE_DEVICES + eval $env + export Count=0 + IFS="|" + infer_run_exports=(${infer_export_list}) + infer_quant_flag=(${infer_is_quant}) + for infer_model in ${infer_model_dir_list[*]}; do + # run export + if [ ${infer_run_exports[Count]} != "null" ];then + export_cmd="${python} ${norm_export} ${export_weight}=${infer_model} ${save_infer_key}=${infer_model}" + eval $export_cmd + status_export=$? + if [ ${status_export} = 0 ];then + status_check $status_export "${export_cmd}" "${status_log}" + fi + fi + #run inference + is_quant=${infer_quant_flag[Count]} + echo "is_quant: ${is_quant}" + func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" ${is_quant} + Count=$(($Count + 1)) + done else IFS="|" From e97ac92528d6afc6c85fe0b21e487ed02d1aead7 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 28 Jul 2021 07:21:16 +0000 Subject: [PATCH 19/29] fix bugs --- tests/ocr_det_params.txt | 4 ++-- tests/test.sh | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index bb32990e4f..99b53254e4 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -3,7 +3,7 @@ model_name:ocr_det python:python3.7 gpu_list:0|0,1 Global.use_gpu:True|True -Global.auto_cast:False +Global.auto_cast:null Global.epoch_num:lite_train_infer=2|whole_train_infer=300 Global.save_model_dir:./output/ Train.loader.batch_size_per_card:lite_train_infer=2|whole_train_infer=4 @@ -34,7 +34,7 @@ distill_export:null export1:null export2:null ## -infer_model:./inference/ch_ppocr_mobile_v2.0_det_train/best_accuracy|./inference/ch_mobile_det_quant_dev_lr/ +infer_model:./inference/ch_ppocr_mobile_v2.0_det_train/best_accuracy|./inference/ch_mobile_det_quant_dev_lr/inference/ infer_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o |null infer_quant:False|True inference:tools/infer/predict_det.py diff --git a/tests/test.sh b/tests/test.sh index 79a490f068..7d1e6d74df 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -174,9 +174,11 @@ function func_inference(){ set_cpu_threads=$(func_set_params "${cpu_threads_key}" "${threads}") set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") set_infer_params1=$(func_set_params "${infer_key1}" "${infer_value1}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} 2>&1 | tee ${_save_log_path} " + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_save_log_path} 2>&1 " eval $command - status_check $? "${command}" "${status_log}" + last_status=${PIPESTATUS[0]} + eval "cat ${_save_log_path}" + status_check $last_status "${command}" "${status_log}" done done done @@ -197,9 +199,12 @@ function func_inference(){ set_tensorrt=$(func_set_params "${use_trt_key}" "${use_trt}") set_precision=$(func_set_params "${precision_key}" "${precision}") set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} 2>&1 | tee ${_save_log_path}" + command="${_python} ${_script} ${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 - status_check $? "${command}" "${status_log}" + last_status=${PIPESTATUS[0]} + eval "cat ${_save_log_path}" + status_check $last_status "${command}" "${status_log}" + done done done From c40de77ca5f43e1f03aeb01547938ab57f0ab631 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 28 Jul 2021 07:26:24 +0000 Subject: [PATCH 20/29] fix inference --- tests/ocr_det_params.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index 99b53254e4..e167e619eb 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -38,12 +38,12 @@ infer_model:./inference/ch_ppocr_mobile_v2.0_det_train/best_accuracy|./inference infer_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o |null infer_quant:False|True inference:tools/infer/predict_det.py ---use_gpu:True +--use_gpu:True|False --enable_mkldnn:True|False --cpu_threads:1|6 --rec_batch_num:1 --use_tensorrt:False|True ---precision:fp32|int8 +--precision:fp32|fp16|int8 --det_model_dir: --image_dir:./inference/ch_det_data_50/all-sum-510/ --save_log_path:null From 66af12438b6f89945a747edbf8b406aee7da53c8 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 28 Jul 2021 07:34:46 +0000 Subject: [PATCH 21/29] fix infer --- tests/ocr_det_params.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index e167e619eb..6ef5230f6b 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -34,9 +34,9 @@ distill_export:null export1:null export2:null ## -infer_model:./inference/ch_ppocr_mobile_v2.0_det_train/best_accuracy|./inference/ch_mobile_det_quant_dev_lr/inference/ -infer_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o |null -infer_quant:False|True +infer_model:./inference/ch_ppocr_mobile_v2.0_det_infer/ +infer_export:null +infer_quant:False inference:tools/infer/predict_det.py --use_gpu:True|False --enable_mkldnn:True|False From 000f8c4b34c08f34b222761cbf88bf49c4f65b3b Mon Sep 17 00:00:00 2001 From: Double_V Date: Wed, 28 Jul 2021 15:47:17 +0800 Subject: [PATCH 22/29] fix infer --- tests/ocr_det_params.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ocr_det_params.txt b/tests/ocr_det_params.txt index bb32990e4f..6ef5230f6b 100644 --- a/tests/ocr_det_params.txt +++ b/tests/ocr_det_params.txt @@ -3,7 +3,7 @@ model_name:ocr_det python:python3.7 gpu_list:0|0,1 Global.use_gpu:True|True -Global.auto_cast:False +Global.auto_cast:null Global.epoch_num:lite_train_infer=2|whole_train_infer=300 Global.save_model_dir:./output/ Train.loader.batch_size_per_card:lite_train_infer=2|whole_train_infer=4 @@ -34,16 +34,16 @@ distill_export:null export1:null export2:null ## -infer_model:./inference/ch_ppocr_mobile_v2.0_det_train/best_accuracy|./inference/ch_mobile_det_quant_dev_lr/ -infer_export:tools/export_model.py -c configs/det/det_mv3_db.yml -o |null -infer_quant:False|True +infer_model:./inference/ch_ppocr_mobile_v2.0_det_infer/ +infer_export:null +infer_quant:False inference:tools/infer/predict_det.py ---use_gpu:True +--use_gpu:True|False --enable_mkldnn:True|False --cpu_threads:1|6 --rec_batch_num:1 --use_tensorrt:False|True ---precision:fp32|int8 +--precision:fp32|fp16|int8 --det_model_dir: --image_dir:./inference/ch_det_data_50/all-sum-510/ --save_log_path:null From 6ea53b072d11b6aa524faa7cb905cc1b3d26fa66 Mon Sep 17 00:00:00 2001 From: Double_V Date: Wed, 28 Jul 2021 15:47:53 +0800 Subject: [PATCH 23/29] fix infer --- tests/prepare.sh | 357 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 321 insertions(+), 36 deletions(-) diff --git a/tests/prepare.sh b/tests/prepare.sh index 3c6206ae94..5a2c548305 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -8,6 +8,7 @@ dataline=$(cat ${FILENAME}) # parser params IFS=$'\n' lines=(${dataline}) + function func_parser_key(){ strs=$1 IFS=":" @@ -22,49 +23,333 @@ function func_parser_value(){ tmp=${array[1]} echo ${tmp} } +function func_set_params(){ + key=$1 + value=$2 + if [ ${key} = "null" ];then + echo " " + elif [[ ${value} = "null" ]] || [[ ${value} = " " ]] || [ ${#value} -le 0 ];then + echo " " + else + echo "${key}=${value}" + fi +} +function func_parser_params(){ + strs=$1 + IFS=":" + array=(${strs}) + key=${array[0]} + tmp=${array[1]} + IFS="|" + res="" + for _params in ${tmp[*]}; do + IFS="=" + array=(${_params}) + mode=${array[0]} + value=${array[1]} + if [[ ${mode} = ${MODE} ]]; then + IFS="|" + #echo $(func_set_params "${mode}" "${value}") + echo $value + break + fi + IFS="|" + done + echo ${res} +} +function status_check(){ + last_status=$1 # the exit code + run_command=$2 + run_log=$3 + if [ $last_status -eq 0 ]; then + echo -e "\033[33m Run successfully with command - ${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} + fi +} + IFS=$'\n' # The training params model_name=$(func_parser_value "${lines[1]}") +python=$(func_parser_value "${lines[2]}") +gpu_list=$(func_parser_value "${lines[3]}") +train_use_gpu_key=$(func_parser_key "${lines[4]}") +train_use_gpu_value=$(func_parser_value "${lines[4]}") +autocast_list=$(func_parser_value "${lines[5]}") +autocast_key=$(func_parser_key "${lines[5]}") +epoch_key=$(func_parser_key "${lines[6]}") +epoch_num=$(func_parser_params "${lines[6]}") +save_model_key=$(func_parser_key "${lines[7]}") +train_batch_key=$(func_parser_key "${lines[8]}") +train_batch_value=$(func_parser_params "${lines[8]}") +pretrain_model_key=$(func_parser_key "${lines[9]}") +pretrain_model_value=$(func_parser_value "${lines[9]}") +train_model_name=$(func_parser_value "${lines[10]}") +train_infer_img_dir=$(func_parser_value "${lines[11]}") +train_param_key1=$(func_parser_key "${lines[12]}") +train_param_value1=$(func_parser_value "${lines[12]}") trainer_list=$(func_parser_value "${lines[14]}") +trainer_norm=$(func_parser_key "${lines[15]}") +norm_trainer=$(func_parser_value "${lines[15]}") +pact_key=$(func_parser_key "${lines[16]}") +pact_trainer=$(func_parser_value "${lines[16]}") +fpgm_key=$(func_parser_key "${lines[17]}") +fpgm_trainer=$(func_parser_value "${lines[17]}") +distill_key=$(func_parser_key "${lines[18]}") +distill_trainer=$(func_parser_value "${lines[18]}") +trainer_key1=$(func_parser_key "${lines[19]}") +trainer_value1=$(func_parser_value "${lines[19]}") +trainer_key2=$(func_parser_key "${lines[20]}") +trainer_value2=$(func_parser_value "${lines[20]}") -# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer'] -MODE=$2 +eval_py=$(func_parser_value "${lines[23]}") +eval_key1=$(func_parser_key "${lines[24]}") +eval_value1=$(func_parser_value "${lines[24]}") + +save_infer_key=$(func_parser_key "${lines[27]}") +export_weight=$(func_parser_key "${lines[28]}") +norm_export=$(func_parser_value "${lines[29]}") +pact_export=$(func_parser_value "${lines[30]}") +fpgm_export=$(func_parser_value "${lines[31]}") +distill_export=$(func_parser_value "${lines[32]}") +export_key1=$(func_parser_key "${lines[33]}") +export_value1=$(func_parser_value "${lines[33]}") +export_key2=$(func_parser_key "${lines[34]}") +export_value2=$(func_parser_value "${lines[34]}") + +# parser inference model +infer_model_dir_list=$(func_parser_value "${lines[36]}") +infer_export_list=$(func_parser_value "${lines[37]}") +infer_is_quant=$(func_parser_value "${lines[38]}") +# parser inference +inference_py=$(func_parser_value "${lines[39]}") +use_gpu_key=$(func_parser_key "${lines[40]}") +use_gpu_list=$(func_parser_value "${lines[40]}") +use_mkldnn_key=$(func_parser_key "${lines[41]}") +use_mkldnn_list=$(func_parser_value "${lines[41]}") +cpu_threads_key=$(func_parser_key "${lines[42]}") +cpu_threads_list=$(func_parser_value "${lines[42]}") +batch_size_key=$(func_parser_key "${lines[43]}") +batch_size_list=$(func_parser_value "${lines[43]}") +use_trt_key=$(func_parser_key "${lines[44]}") +use_trt_list=$(func_parser_value "${lines[44]}") +precision_key=$(func_parser_key "${lines[45]}") +precision_list=$(func_parser_value "${lines[45]}") +infer_model_key=$(func_parser_key "${lines[46]}") +image_dir_key=$(func_parser_key "${lines[47]}") +infer_img_dir=$(func_parser_value "${lines[47]}") +save_log_key=$(func_parser_key "${lines[48]}") +benchmark_key=$(func_parser_key "${lines[49]}") +benchmark_value=$(func_parser_value "${lines[49]}") +infer_key1=$(func_parser_key "${lines[50]}") +infer_value1=$(func_parser_value "${lines[50]}") + +LOG_PATH="./tests/output" +mkdir -p ${LOG_PATH} +status_log="${LOG_PATH}/results.log" + + +function func_inference(){ + IFS='|' + _python=$1 + _script=$2 + _model_dir=$3 + _log_path=$4 + _img_dir=$5 + _flag_quant=$6 + # inference + for use_gpu in ${use_gpu_list[*]}; do + if [ ${use_gpu} = "False" ] || [ ${use_gpu} = "cpu" ]; then + for use_mkldnn in ${use_mkldnn_list[*]}; do + if [ ${use_mkldnn} = "False" ] && [ ${_flag_quant} = "True" ]; then + continue + fi + for threads in ${cpu_threads_list[*]}; do + for batch_size in ${batch_size_list[*]}; do + _save_log_path="${_log_path}/infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_batchsize_${batch_size}.log" + set_infer_data=$(func_set_params "${image_dir_key}" "${_img_dir}") + set_benchmark=$(func_set_params "${benchmark_key}" "${benchmark_value}") + set_batchsize=$(func_set_params "${batch_size_key}" "${batch_size}") + set_cpu_threads=$(func_set_params "${cpu_threads_key}" "${threads}") + set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") + set_infer_params1=$(func_set_params "${infer_key1}" "${infer_value1}") + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_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 ${use_trt_list[*]}; do + for precision in ${precision_list[*]}; do + 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 ${batch_size_list[*]}; do + _save_log_path="${_log_path}/infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log" + set_infer_data=$(func_set_params "${image_dir_key}" "${_img_dir}") + set_benchmark=$(func_set_params "${benchmark_key}" "${benchmark_value}") + set_batchsize=$(func_set_params "${batch_size_key}" "${batch_size}") + set_tensorrt=$(func_set_params "${use_trt_key}" "${use_trt}") + set_precision=$(func_set_params "${precision_key}" "${precision}") + set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") + command="${_python} ${_script} ${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 + env=" " + else + env="export CUDA_VISIBLE_DEVICES=${GPUID}" + fi + # set CUDA_VISIBLE_DEVICES + eval $env + export Count=0 + IFS="|" + infer_run_exports=(${infer_export_list}) + infer_quant_flag=(${infer_is_quant}) + for infer_model in ${infer_model_dir_list[*]}; do + # run export + if [ ${infer_run_exports[Count]} != "null" ];then + export_cmd="${python} ${norm_export} ${export_weight}=${infer_model} ${save_infer_key}=${infer_model}" + eval $export_cmd + status_export=$? + if [ ${status_export} = 0 ];then + status_check $status_export "${export_cmd}" "${status_log}" + fi + fi + #run inference + is_quant=${infer_quant_flag[Count]} + echo "is_quant: ${is_quant}" + func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" ${is_quant} + Count=$(($Count + 1)) + done -if [ ${MODE} = "lite_train_infer" ];then - # pretrain lite train data - wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams - rm -rf ./train_data/icdar2015 - wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar - cd ./train_data/ && tar xf icdar2015_lite.tar - ln -s ./icdar2015_lite ./icdar2015 - cd ../ -elif [ ${MODE} = "whole_train_infer" ];then - wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams - rm -rf ./train_data/icdar2015 - wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015.tar - cd ./train_data/ && tar xf icdar2015.tar && cd ../ -elif [ ${MODE} = "whole_infer" ];then - wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams - rm -rf ./train_data/icdar2015 - wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_infer.tar - cd ./train_data/ && tar xf icdar2015_infer.tar - ln -s ./icdar2015_infer ./icdar2015 - cd ../ - epoch=10 - eval_batch_step=10 else - rm -rf ./train_data/icdar2015 - if [[ ${model_name} = "ocr_det" ]]; then - wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar - eval_model_name="ch_ppocr_mobile_v2.0_det_infer" - 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 - eval_model_name="ch_ppocr_mobile_v2.0_rec_train" - wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_train.tar - cd ./inference && tar xf ${eval_model_name}.tar && cd ../ - fi -fi + IFS="|" + export Count=0 + USE_GPU_KEY=(${train_use_gpu_value}) + for gpu in ${gpu_list[*]}; do + use_gpu=${USE_GPU_KEY[Count]} + Count=$(($Count + 1)) + if [ ${gpu} = "-1" ];then + env="" + elif [ ${#gpu} -le 1 ];then + env="export CUDA_VISIBLE_DEVICES=${gpu}" + eval ${env} + elif [ ${#gpu} -le 15 ];then + IFS="," + array=(${gpu}) + env="export CUDA_VISIBLE_DEVICES=${array[0]}" + IFS="|" + else + IFS=";" + array=(${gpu}) + ips=${array[0]} + gpu=${array[1]} + IFS="|" + env=" " + fi + for autocast in ${autocast_list[*]}; do + for trainer in ${trainer_list[*]}; do + flag_quant=False + if [ ${trainer} = ${pact_key} ]; then + run_train=${pact_trainer} + run_export=${pact_export} + flag_quant=True + elif [ ${trainer} = "${fpgm_key}" ]; then + run_train=${fpgm_trainer} + run_export=${fpgm_export} + elif [ ${trainer} = "${distill_key}" ]; then + run_train=${distill_trainer} + run_export=${distill_export} + elif [ ${trainer} = ${trainer_key1} ]; then + run_train=${trainer_value1} + run_export=${export_value1} + elif [[ ${trainer} = ${trainer_key2} ]]; then + run_train=${trainer_value2} + run_export=${export_value2} + else + run_train=${norm_trainer} + run_export=${norm_export} + fi + if [ ${run_train} = "null" ]; then + continue + fi + + set_autocast=$(func_set_params "${autocast_key}" "${autocast}") + set_epoch=$(func_set_params "${epoch_key}" "${epoch_num}") + set_pretrain=$(func_set_params "${pretrain_model_key}" "${pretrain_model_value}") + set_batchsize=$(func_set_params "${train_batch_key}" "${train_batch_value}") + set_train_params1=$(func_set_params "${train_param_key1}" "${train_param_value1}") + set_use_gpu=$(func_set_params "${train_use_gpu_key}" "${use_gpu}") + save_log="${LOG_PATH}/${trainer}_gpus_${gpu}_autocast_${autocast}" + + # load pretrain from norm training if current trainer is pact or fpgm trainer + if [ ${trainer} = ${pact_key} ] || [ ${trainer} = ${fpgm_key} ]; then + set_pretrain="${load_norm_train_model}" + fi + set_save_model=$(func_set_params "${save_model_key}" "${save_log}") + if [ ${#gpu} -le 2 ];then # train with cpu or single gpu + cmd="${python} ${run_train} ${set_use_gpu} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " + elif [ ${#gpu} -le 15 ];then # train with multi-gpu + cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1}" + else # train with multi-machine + cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${set_save_model} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_train_params1}" + fi + # run train + eval "unset CUDA_VISIBLE_DEVICES" + eval $cmd + status_check $? "${cmd}" "${status_log}" + + set_eval_pretrain=$(func_set_params "${pretrain_model_key}" "${save_log}/${train_model_name}") + # save norm trained models to set pretrain for pact training and fpgm training + if [ ${trainer} = ${trainer_norm} ]; then + load_norm_train_model=${set_eval_pretrain} + fi + # run eval + if [ ${eval_py} != "null" ]; then + set_eval_params1=$(func_set_params "${eval_key1}" "${eval_value1}") + eval_cmd="${python} ${eval_py} ${set_eval_pretrain} ${set_use_gpu} ${set_eval_params1}" + eval $eval_cmd + status_check $? "${eval_cmd}" "${status_log}" + fi + # run export model + if [ ${run_export} != "null" ]; then + # run export model + save_infer_path="${save_log}" + export_cmd="${python} ${run_export} ${export_weight}=${save_log}/${train_model_name} ${save_infer_key}=${save_infer_path}" + eval $export_cmd + status_check $? "${export_cmd}" "${status_log}" + + #run inference + eval $env + save_infer_path="${save_log}" + func_inference "${python}" "${inference_py}" "${save_infer_path}" "${LOG_PATH}" "${train_infer_img_dir}" "${flag_quant}" + eval "unset CUDA_VISIBLE_DEVICES" + fi + done # done with: for trainer in ${trainer_list[*]}; do + done # done with: for autocast in ${autocast_list[*]}; do + done # done with: for gpu in ${gpu_list[*]}; do +fi # end if [ ${MODE} = "infer" ]; then From 3ecc2a22df87fef11f8ae3485436d6a06eca9e6f Mon Sep 17 00:00:00 2001 From: Double_V Date: Wed, 28 Jul 2021 15:48:49 +0800 Subject: [PATCH 24/29] fix test.sh --- tests/test.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index 79a490f068..5a2c548305 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -174,9 +174,11 @@ function func_inference(){ set_cpu_threads=$(func_set_params "${cpu_threads_key}" "${threads}") set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") set_infer_params1=$(func_set_params "${infer_key1}" "${infer_value1}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} 2>&1 | tee ${_save_log_path} " + command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_save_log_path} 2>&1 " eval $command - status_check $? "${command}" "${status_log}" + last_status=${PIPESTATUS[0]} + eval "cat ${_save_log_path}" + status_check $last_status "${command}" "${status_log}" done done done @@ -197,9 +199,12 @@ function func_inference(){ set_tensorrt=$(func_set_params "${use_trt_key}" "${use_trt}") set_precision=$(func_set_params "${precision_key}" "${precision}") set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} 2>&1 | tee ${_save_log_path}" + command="${_python} ${_script} ${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 - status_check $? "${command}" "${status_log}" + last_status=${PIPESTATUS[0]} + eval "cat ${_save_log_path}" + status_check $last_status "${command}" "${status_log}" + done done done @@ -348,4 +353,3 @@ else done # done with: for autocast in ${autocast_list[*]}; do done # done with: for gpu in ${gpu_list[*]}; do fi # end if [ ${MODE} = "infer" ]; then - From fc16c1fca3ecafd098a937f2569ca52beb8edf01 Mon Sep 17 00:00:00 2001 From: Double_V Date: Wed, 28 Jul 2021 15:49:25 +0800 Subject: [PATCH 25/29] fix prepare.sh --- tests/prepare.sh | 359 +++++------------------------------------------ 1 file changed, 36 insertions(+), 323 deletions(-) diff --git a/tests/prepare.sh b/tests/prepare.sh index 5a2c548305..5886b2e69c 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -8,7 +8,6 @@ dataline=$(cat ${FILENAME}) # parser params IFS=$'\n' lines=(${dataline}) - function func_parser_key(){ strs=$1 IFS=":" @@ -23,333 +22,47 @@ function func_parser_value(){ tmp=${array[1]} echo ${tmp} } -function func_set_params(){ - key=$1 - value=$2 - if [ ${key} = "null" ];then - echo " " - elif [[ ${value} = "null" ]] || [[ ${value} = " " ]] || [ ${#value} -le 0 ];then - echo " " - else - echo "${key}=${value}" - fi -} -function func_parser_params(){ - strs=$1 - IFS=":" - array=(${strs}) - key=${array[0]} - tmp=${array[1]} - IFS="|" - res="" - for _params in ${tmp[*]}; do - IFS="=" - array=(${_params}) - mode=${array[0]} - value=${array[1]} - if [[ ${mode} = ${MODE} ]]; then - IFS="|" - #echo $(func_set_params "${mode}" "${value}") - echo $value - break - fi - IFS="|" - done - echo ${res} -} -function status_check(){ - last_status=$1 # the exit code - run_command=$2 - run_log=$3 - if [ $last_status -eq 0 ]; then - echo -e "\033[33m Run successfully with command - ${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} - fi -} - IFS=$'\n' # The training params model_name=$(func_parser_value "${lines[1]}") -python=$(func_parser_value "${lines[2]}") -gpu_list=$(func_parser_value "${lines[3]}") -train_use_gpu_key=$(func_parser_key "${lines[4]}") -train_use_gpu_value=$(func_parser_value "${lines[4]}") -autocast_list=$(func_parser_value "${lines[5]}") -autocast_key=$(func_parser_key "${lines[5]}") -epoch_key=$(func_parser_key "${lines[6]}") -epoch_num=$(func_parser_params "${lines[6]}") -save_model_key=$(func_parser_key "${lines[7]}") -train_batch_key=$(func_parser_key "${lines[8]}") -train_batch_value=$(func_parser_params "${lines[8]}") -pretrain_model_key=$(func_parser_key "${lines[9]}") -pretrain_model_value=$(func_parser_value "${lines[9]}") -train_model_name=$(func_parser_value "${lines[10]}") -train_infer_img_dir=$(func_parser_value "${lines[11]}") -train_param_key1=$(func_parser_key "${lines[12]}") -train_param_value1=$(func_parser_value "${lines[12]}") trainer_list=$(func_parser_value "${lines[14]}") -trainer_norm=$(func_parser_key "${lines[15]}") -norm_trainer=$(func_parser_value "${lines[15]}") -pact_key=$(func_parser_key "${lines[16]}") -pact_trainer=$(func_parser_value "${lines[16]}") -fpgm_key=$(func_parser_key "${lines[17]}") -fpgm_trainer=$(func_parser_value "${lines[17]}") -distill_key=$(func_parser_key "${lines[18]}") -distill_trainer=$(func_parser_value "${lines[18]}") -trainer_key1=$(func_parser_key "${lines[19]}") -trainer_value1=$(func_parser_value "${lines[19]}") -trainer_key2=$(func_parser_key "${lines[20]}") -trainer_value2=$(func_parser_value "${lines[20]}") -eval_py=$(func_parser_value "${lines[23]}") -eval_key1=$(func_parser_key "${lines[24]}") -eval_value1=$(func_parser_value "${lines[24]}") - -save_infer_key=$(func_parser_key "${lines[27]}") -export_weight=$(func_parser_key "${lines[28]}") -norm_export=$(func_parser_value "${lines[29]}") -pact_export=$(func_parser_value "${lines[30]}") -fpgm_export=$(func_parser_value "${lines[31]}") -distill_export=$(func_parser_value "${lines[32]}") -export_key1=$(func_parser_key "${lines[33]}") -export_value1=$(func_parser_value "${lines[33]}") -export_key2=$(func_parser_key "${lines[34]}") -export_value2=$(func_parser_value "${lines[34]}") - -# parser inference model -infer_model_dir_list=$(func_parser_value "${lines[36]}") -infer_export_list=$(func_parser_value "${lines[37]}") -infer_is_quant=$(func_parser_value "${lines[38]}") -# parser inference -inference_py=$(func_parser_value "${lines[39]}") -use_gpu_key=$(func_parser_key "${lines[40]}") -use_gpu_list=$(func_parser_value "${lines[40]}") -use_mkldnn_key=$(func_parser_key "${lines[41]}") -use_mkldnn_list=$(func_parser_value "${lines[41]}") -cpu_threads_key=$(func_parser_key "${lines[42]}") -cpu_threads_list=$(func_parser_value "${lines[42]}") -batch_size_key=$(func_parser_key "${lines[43]}") -batch_size_list=$(func_parser_value "${lines[43]}") -use_trt_key=$(func_parser_key "${lines[44]}") -use_trt_list=$(func_parser_value "${lines[44]}") -precision_key=$(func_parser_key "${lines[45]}") -precision_list=$(func_parser_value "${lines[45]}") -infer_model_key=$(func_parser_key "${lines[46]}") -image_dir_key=$(func_parser_key "${lines[47]}") -infer_img_dir=$(func_parser_value "${lines[47]}") -save_log_key=$(func_parser_key "${lines[48]}") -benchmark_key=$(func_parser_key "${lines[49]}") -benchmark_value=$(func_parser_value "${lines[49]}") -infer_key1=$(func_parser_key "${lines[50]}") -infer_value1=$(func_parser_value "${lines[50]}") - -LOG_PATH="./tests/output" -mkdir -p ${LOG_PATH} -status_log="${LOG_PATH}/results.log" - - -function func_inference(){ - IFS='|' - _python=$1 - _script=$2 - _model_dir=$3 - _log_path=$4 - _img_dir=$5 - _flag_quant=$6 - # inference - for use_gpu in ${use_gpu_list[*]}; do - if [ ${use_gpu} = "False" ] || [ ${use_gpu} = "cpu" ]; then - for use_mkldnn in ${use_mkldnn_list[*]}; do - if [ ${use_mkldnn} = "False" ] && [ ${_flag_quant} = "True" ]; then - continue - fi - for threads in ${cpu_threads_list[*]}; do - for batch_size in ${batch_size_list[*]}; do - _save_log_path="${_log_path}/infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_batchsize_${batch_size}.log" - set_infer_data=$(func_set_params "${image_dir_key}" "${_img_dir}") - set_benchmark=$(func_set_params "${benchmark_key}" "${benchmark_value}") - set_batchsize=$(func_set_params "${batch_size_key}" "${batch_size}") - set_cpu_threads=$(func_set_params "${cpu_threads_key}" "${threads}") - set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") - set_infer_params1=$(func_set_params "${infer_key1}" "${infer_value1}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} ${set_infer_params1} > ${_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 ${use_trt_list[*]}; do - for precision in ${precision_list[*]}; do - 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 ${batch_size_list[*]}; do - _save_log_path="${_log_path}/infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log" - set_infer_data=$(func_set_params "${image_dir_key}" "${_img_dir}") - set_benchmark=$(func_set_params "${benchmark_key}" "${benchmark_value}") - set_batchsize=$(func_set_params "${batch_size_key}" "${batch_size}") - set_tensorrt=$(func_set_params "${use_trt_key}" "${use_trt}") - set_precision=$(func_set_params "${precision_key}" "${precision}") - set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") - command="${_python} ${_script} ${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 - env=" " - else - env="export CUDA_VISIBLE_DEVICES=${GPUID}" - fi - # set CUDA_VISIBLE_DEVICES - eval $env - export Count=0 - IFS="|" - infer_run_exports=(${infer_export_list}) - infer_quant_flag=(${infer_is_quant}) - for infer_model in ${infer_model_dir_list[*]}; do - # run export - if [ ${infer_run_exports[Count]} != "null" ];then - export_cmd="${python} ${norm_export} ${export_weight}=${infer_model} ${save_infer_key}=${infer_model}" - eval $export_cmd - status_export=$? - if [ ${status_export} = 0 ];then - status_check $status_export "${export_cmd}" "${status_log}" - fi - fi - #run inference - is_quant=${infer_quant_flag[Count]} - echo "is_quant: ${is_quant}" - func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" ${is_quant} - Count=$(($Count + 1)) - done +# MODE be one of ['lite_train_infer' 'whole_infer' 'whole_train_infer'] +MODE=$2 +if [ ${MODE} = "lite_train_infer" ];then + # pretrain lite train data + wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams + rm -rf ./train_data/icdar2015 + wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar + cd ./train_data/ && tar xf icdar2015_lite.tar + ln -s ./icdar2015_lite ./icdar2015 + cd ../ +elif [ ${MODE} = "whole_train_infer" ];then + wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams + rm -rf ./train_data/icdar2015 + wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015.tar + cd ./train_data/ && tar xf icdar2015.tar && cd ../ +elif [ ${MODE} = "whole_infer" ];then + wget -nc -P ./pretrain_models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams + rm -rf ./train_data/icdar2015 + wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_infer.tar + cd ./train_data/ && tar xf icdar2015_infer.tar + ln -s ./icdar2015_infer ./icdar2015 + cd ../ + epoch=10 + eval_batch_step=10 else - IFS="|" - export Count=0 - USE_GPU_KEY=(${train_use_gpu_value}) - for gpu in ${gpu_list[*]}; do - use_gpu=${USE_GPU_KEY[Count]} - Count=$(($Count + 1)) - if [ ${gpu} = "-1" ];then - env="" - elif [ ${#gpu} -le 1 ];then - env="export CUDA_VISIBLE_DEVICES=${gpu}" - eval ${env} - elif [ ${#gpu} -le 15 ];then - IFS="," - array=(${gpu}) - env="export CUDA_VISIBLE_DEVICES=${array[0]}" - IFS="|" - else - IFS=";" - array=(${gpu}) - ips=${array[0]} - gpu=${array[1]} - IFS="|" - env=" " - fi - for autocast in ${autocast_list[*]}; do - for trainer in ${trainer_list[*]}; do - flag_quant=False - if [ ${trainer} = ${pact_key} ]; then - run_train=${pact_trainer} - run_export=${pact_export} - flag_quant=True - elif [ ${trainer} = "${fpgm_key}" ]; then - run_train=${fpgm_trainer} - run_export=${fpgm_export} - elif [ ${trainer} = "${distill_key}" ]; then - run_train=${distill_trainer} - run_export=${distill_export} - elif [ ${trainer} = ${trainer_key1} ]; then - run_train=${trainer_value1} - run_export=${export_value1} - elif [[ ${trainer} = ${trainer_key2} ]]; then - run_train=${trainer_value2} - run_export=${export_value2} - else - run_train=${norm_trainer} - run_export=${norm_export} - fi - - if [ ${run_train} = "null" ]; then - continue - fi - - set_autocast=$(func_set_params "${autocast_key}" "${autocast}") - set_epoch=$(func_set_params "${epoch_key}" "${epoch_num}") - set_pretrain=$(func_set_params "${pretrain_model_key}" "${pretrain_model_value}") - set_batchsize=$(func_set_params "${train_batch_key}" "${train_batch_value}") - set_train_params1=$(func_set_params "${train_param_key1}" "${train_param_value1}") - set_use_gpu=$(func_set_params "${train_use_gpu_key}" "${use_gpu}") - save_log="${LOG_PATH}/${trainer}_gpus_${gpu}_autocast_${autocast}" - - # load pretrain from norm training if current trainer is pact or fpgm trainer - if [ ${trainer} = ${pact_key} ] || [ ${trainer} = ${fpgm_key} ]; then - set_pretrain="${load_norm_train_model}" - fi - - set_save_model=$(func_set_params "${save_model_key}" "${save_log}") - if [ ${#gpu} -le 2 ];then # train with cpu or single gpu - cmd="${python} ${run_train} ${set_use_gpu} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1} " - elif [ ${#gpu} -le 15 ];then # train with multi-gpu - cmd="${python} -m paddle.distributed.launch --gpus=${gpu} ${run_train} ${set_save_model} ${set_epoch} ${set_pretrain} ${set_autocast} ${set_batchsize} ${set_train_params1}" - else # train with multi-machine - cmd="${python} -m paddle.distributed.launch --ips=${ips} --gpus=${gpu} ${run_train} ${set_save_model} ${set_pretrain} ${set_epoch} ${set_autocast} ${set_batchsize} ${set_train_params1}" - fi - # run train - eval "unset CUDA_VISIBLE_DEVICES" - eval $cmd - status_check $? "${cmd}" "${status_log}" - - set_eval_pretrain=$(func_set_params "${pretrain_model_key}" "${save_log}/${train_model_name}") - # save norm trained models to set pretrain for pact training and fpgm training - if [ ${trainer} = ${trainer_norm} ]; then - load_norm_train_model=${set_eval_pretrain} - fi - # run eval - if [ ${eval_py} != "null" ]; then - set_eval_params1=$(func_set_params "${eval_key1}" "${eval_value1}") - eval_cmd="${python} ${eval_py} ${set_eval_pretrain} ${set_use_gpu} ${set_eval_params1}" - eval $eval_cmd - status_check $? "${eval_cmd}" "${status_log}" - fi - # run export model - if [ ${run_export} != "null" ]; then - # run export model - save_infer_path="${save_log}" - export_cmd="${python} ${run_export} ${export_weight}=${save_log}/${train_model_name} ${save_infer_key}=${save_infer_path}" - eval $export_cmd - status_check $? "${export_cmd}" "${status_log}" - - #run inference - eval $env - save_infer_path="${save_log}" - func_inference "${python}" "${inference_py}" "${save_infer_path}" "${LOG_PATH}" "${train_infer_img_dir}" "${flag_quant}" - eval "unset CUDA_VISIBLE_DEVICES" - fi - done # done with: for trainer in ${trainer_list[*]}; do - done # done with: for autocast in ${autocast_list[*]}; do - done # done with: for gpu in ${gpu_list[*]}; do -fi # end if [ ${MODE} = "infer" ]; then + rm -rf ./train_data/icdar2015 + if [[ ${model_name} = "ocr_det" ]]; then + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar + eval_model_name="ch_ppocr_mobile_v2.0_det_infer" + 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 + eval_model_name="ch_ppocr_mobile_v2.0_rec_train" + wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_train.tar + cd ./inference && tar xf ${eval_model_name}.tar && cd ../ + fi +fi From edca15c2f628fb99de6e012939ad1bcdcb4941b8 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 28 Jul 2021 20:18:16 +0800 Subject: [PATCH 26/29] delete test and fix export --- tests/test.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index 5a2c548305..c6c0c9b3d3 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -230,7 +230,9 @@ if [ ${MODE} = "infer" ]; then for infer_model in ${infer_model_dir_list[*]}; do # run export if [ ${infer_run_exports[Count]} != "null" ];then - export_cmd="${python} ${norm_export} ${export_weight}=${infer_model} ${save_infer_key}=${infer_model}" + set_export_weight=$(func_set_params "${export_weight}" "${infer_model}") + set_save_infer_key=$(func_set_params "${save_infer_key}" "${infer_model}") + export_cmd="${python} ${norm_export} ${set_export_weight} ${set_save_infer_key}" eval $export_cmd status_export=$? if [ ${status_export} = 0 ];then @@ -339,7 +341,9 @@ else if [ ${run_export} != "null" ]; then # run export model save_infer_path="${save_log}" - export_cmd="${python} ${run_export} ${export_weight}=${save_log}/${train_model_name} ${save_infer_key}=${save_infer_path}" + set_export_weight=$(func_set_params "${export_weight}" "${save_log}/${train_model_name}") + set_save_infer_key=$(func_set_params "${save_infer_key}" "${save_infer_path}") + export_cmd="${python} ${run_export} ${set_export_weight} ${set_save_infer_key}" eval $export_cmd status_check $? "${export_cmd}" "${status_log}" From 1cff9db1116f8292ddfe389fc91962ed3f5c26f2 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 3 Aug 2021 08:50:04 +0000 Subject: [PATCH 27/29] fix prepare.sh --- tests/prepare.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/prepare.sh b/tests/prepare.sh index 5886b2e69c..c105d8f432 100644 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -51,8 +51,6 @@ elif [ ${MODE} = "whole_infer" ];then cd ./train_data/ && tar xf icdar2015_infer.tar ln -s ./icdar2015_infer ./icdar2015 cd ../ - epoch=10 - eval_batch_step=10 else rm -rf ./train_data/icdar2015 if [[ ${model_name} = "ocr_det" ]]; then From 5801311cb2e3f30a8d1a4ef2dee07dcb8e31d183 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 4 Aug 2021 02:54:23 +0000 Subject: [PATCH 28/29] not infer for int8 + normal trained model --- tests/test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test.sh b/tests/test.sh index c6c0c9b3d3..7bc7c0fa37 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -185,6 +185,9 @@ function func_inference(){ elif [ ${use_gpu} = "True" ] || [ ${use_gpu} = "gpu" ]; then for use_trt in ${use_trt_list[*]}; do for precision in ${precision_list[*]}; do + if [[ ${_flag_quant} = "False" ]] && [[ ${precision} =~ "int8" ]]; then + continue + fi if [[ ${precision} =~ "fp16" || ${precision} =~ "int8" ]] && [ ${use_trt} = "False" ]; then continue fi @@ -241,7 +244,6 @@ if [ ${MODE} = "infer" ]; then fi #run inference is_quant=${infer_quant_flag[Count]} - echo "is_quant: ${is_quant}" func_inference "${python}" "${inference_py}" "${infer_model}" "${LOG_PATH}" "${infer_img_dir}" ${is_quant} Count=$(($Count + 1)) done From 61bd5296e0dec1a6486d46461c5dba85f40f15ac Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Wed, 4 Aug 2021 03:24:30 +0000 Subject: [PATCH 29/29] add infer_params1 --- tests/test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test.sh b/tests/test.sh index 7bc7c0fa37..c57532fd37 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -202,7 +202,8 @@ function func_inference(){ set_tensorrt=$(func_set_params "${use_trt_key}" "${use_trt}") set_precision=$(func_set_params "${precision_key}" "${precision}") set_model_dir=$(func_set_params "${infer_model_key}" "${_model_dir}") - command="${_python} ${_script} ${use_gpu_key}=${use_gpu} ${set_tensorrt} ${set_precision} ${set_model_dir} ${set_batchsize} ${set_infer_data} ${set_benchmark} > ${_save_log_path} 2>&1 " + set_infer_params1=$(func_set_params "${infer_key1}" "${infer_value1}") + command="${_python} ${_script} ${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 " eval $command last_status=${PIPESTATUS[0]} eval "cat ${_save_log_path}"