From 58437e644821d420871fae89334a848749181c34 Mon Sep 17 00:00:00 2001 From: LDOUBLEV Date: Tue, 8 Jun 2021 21:22:54 +0800 Subject: [PATCH] refine status check --- test/infer.sh | 43 +++++++++++++++++++++++++++++++++---------- test/test.sh | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 59 insertions(+), 33 deletions(-) diff --git a/test/infer.sh b/test/infer.sh index 35c4db2d..61d10b4d 100644 --- a/test/infer.sh +++ b/test/infer.sh @@ -28,6 +28,19 @@ gpu_trt_list=$(func_parser "${lines[10]}") gpu_precision_list=$(func_parser "${lines[11]}") +function status_check(){ + last_status=$1 # 上个阶段的退出码 + run_model=$2 + run_command=$3 + save_log=$4 + echo ${case3} + if [ $last_status -eq 0 ]; then + echo -e "\033[33m $run_model successfully with command - ${run_command}! \033[0m" | tee -a ${save_log} + else + echo -e "\033[33m $case failed with command - ${run_command}! \033[0m" | tee -a ${save_log} + fi +} + for train_model in ${train_model_list[*]}; do if [ ${train_model} = "det" ];then model_name="det" @@ -42,7 +55,7 @@ for train_model in ${train_model_list[*]}; do # eval for slim_trainer in ${slim_trainer_list[*]}; do if [ ${slim_trainer} = "norm" ]; then - if [ ${model_name} = "model_name" ]; then + if [ ${model_name} = "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_train.tar else @@ -50,7 +63,7 @@ for train_model in ${train_model_list[*]}; do wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_train.tar fi elif [ ${slim_trainer} = "quant" ]; then - if [ ${model_name} = "model_name" ]; then + if [ ${model_name} = "det" ]; then eval_model_name="ch_ppocr_mobile_v2.0_det_quant_infer" wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_det_quant_train.tar else @@ -58,7 +71,7 @@ for train_model in ${train_model_list[*]}; do wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_rec_quant_train.tar fi elif [ ${slim_trainer} = "distill" ]; then - if [ ${model_name} = "model_name" ]; then + if [ ${model_name} = "det" ]; then eval_model_name="ch_ppocr_mobile_v2.0_det_distill_infer" wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_det_distill_train.tar else @@ -66,7 +79,7 @@ for train_model in ${train_model_list[*]}; do wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_rec_distill_train.tar fi elif [ ${slim_trainer} = "prune" ]; then - if [ ${model_name} = "model_name" ]; then + if [ ${model_name} = "det" ]; then eval_model_name="ch_ppocr_mobile_v2.0_det_prune_train" wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_det_prune_train.tar else @@ -74,9 +87,15 @@ for train_model in ${train_model_list[*]}; do wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_rec_prune_train.tar fi fi + save_log_path="${log_path}/${eval_model_name}" + command="${python} tools/eval.py -c ${yml_file} -o Global.pretrained_model=${eval_model_name} Global.save_model_dir=${save_log_path}" + ${python} tools/eval.py -c ${yml_file} -o Global.pretrained_model=${eval_model_name} Global.save_model_dir=${save_log_path} + status_check $? "${trainer}" "${command}" "${save_log_path}/train.log" + + command="${python} tools/export_model.py -c ${yml_file} -o Global.pretrained_model=${eval_model_name} Global.save_inference_dir=${log_path}/${eval_model_name}_infer Global.save_model_dir=${save_log_path}" + ${python} tools/export_model.py -c ${yml_file} -o Global.pretrained_model=${eval_model_name} Global.save_inference_dir=${log_path}/${eval_model_name}_infer Global.save_model_dir=${save_log_path} + status_check $? "${trainer}" "${command}" "${save_log_path}/train.log" - echo ${python} tools/eval.py -c ${yml_file} -o Global.pretrained_model=${eval_model_name} Global.save_model_dir=${log_path}/${model_name} - echo ${python} tools/export_model.py -c ${yml_file} -o Global.pretrained_model=${eval_model_name} Global.save_inference_dir=${log_path}/${eval_model_name}_infer if [ $? -eq 0 ]; then echo -e "\033[33m training of $model_name successfully!\033[0m" | tee -a ${save_log}/train.log else @@ -99,8 +118,10 @@ for train_model in ${train_model_list[*]}; do for use_mkldnn in ${use_mkldnn_list[*]}; do for threads in ${cpu_threads_list[*]}; do for rec_batch_size in ${rec_batch_size_list[*]}; do - echo ${python} ${inference} --enable_mkldnn=${use_mkldnn} --use_gpu=False --cpu_threads=${threads} --benchmark=True --det_model_dir=${det_model_dir} --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${log_path}/${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log - # ${python} ${inference} --enable_mkldnn=${use_mkldnn} --use_gpu=False --cpu_threads=${threads} --benchmark=True --det_model_dir=${save_log}/export_inference/ --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} 2>&1 | tee ${log_path}/${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log + save_log_path="${log_path}/${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log" + command="${python} ${inference} --enable_mkldnn=${use_mkldnn} --use_gpu=False --cpu_threads=${threads} --benchmark=True --det_model_dir=${det_model_dir} --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${save_log_path}" + ${python} ${inference} --enable_mkldnn=${use_mkldnn} --use_gpu=False --cpu_threads=${threads} --benchmark=True --det_model_dir=${det_model_dir} --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${save_log_path} + status_check $? "${trainer}" "${command}" "${save_log_path}" done done done @@ -111,8 +132,10 @@ for train_model in ${train_model_list[*]}; do continue fi for rec_batch_size in ${rec_batch_size_list[*]}; do - # echo "${model_name} ${det_model_dir} ${rec_model_dir}, use_trt: ${use_trt} use_fp16: ${use_fp16}" - echo ${python} ${inference} --use_gpu=True --use_tensorrt=${use_trt} --precision=${precision} --benchmark=True --det_model_dir=${log_path}/${eval_model_name}_infer --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${log_path}/${model_name}_${slim_trainer}_gpu_usetensorrt_${use_trt}_usefp16_${precision}_recbatchnum_${rec_batch_size}_infer.log + save_log_path="${log_path}/${model_name}_${slim_trainer}_gpu_usetensorrt_${use_trt}_usefp16_${precision}_recbatchnum_${rec_batch_size}_infer.log" + command="${python} ${inference} --use_gpu=True --use_tensorrt=${use_trt} --precision=${precision} --benchmark=True --det_model_dir=${log_path}/${eval_model_name}_infer --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${save_log_path}" + ${python} ${inference} --use_gpu=True --use_tensorrt=${use_trt} --precision=${precision} --benchmark=True --det_model_dir=${log_path}/${eval_model_name}_infer --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${save_log_path} + status_check $? "${trainer}" "${command}" "${save_log_path}" done done done diff --git a/test/test.sh b/test/test.sh index b43b1a61..cb894f26 100644 --- a/test/test.sh +++ b/test/test.sh @@ -21,7 +21,7 @@ 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=300 + epoch=500 eval_batch_step=200 else echo "Do Nothing" @@ -55,9 +55,19 @@ rec_batch_size_list=$(func_parser "${lines[9]}") gpu_trt_list=$(func_parser "${lines[10]}") gpu_precision_list=$(func_parser "${lines[11]}") img_dir="./train_data/icdar2015/text_localization/ch4_test_images/" -# train superparameters -#epoch=$(func_parser "${lines[12]}") -#checkpoints=$(func_parser "${lines[13]}") + +function status_check(){ + last_status=$1 # 上个阶段的退出码 + run_model=$2 + run_command=$3 + save_log=$4 + echo ${case3} + if [ $last_status -eq 0 ]; then + echo -e "\033[33m $run_model successfully with command - ${run_command}! \033[0m" | tee -a ${save_log} + else + echo -e "\033[33m $case failed with command - ${run_command}! \033[0m" | tee -a ${save_log} + fi +} for train_model in ${train_model_list[*]}; do @@ -101,17 +111,14 @@ for train_model in ${train_model_list[*]}; do trainer="tools/train.py" export_model="tools/export_model.py" fi - # dataset="Train.dataset.data_dir=${train_dir} Train.dataset.label_file_list=${train_label_file} Eval.dataset.data_dir=${eval_dir} Eval.dataset.label_file_list=${eval_label_file}" save_log=${log_path}/${model_name}_${slim_trainer}_autocast_${auto_cast}_gpuid_${gpu} - + command="${python} ${launch} ${trainer} -c ${yml_file} -o Global.epoch_num=${epoch} Global.eval_batch_step=${eval_batch_step} Global.auto_cast=${auto_cast} Global.save_model_dir=${save_log} Global.use_gpu=${use_gpu}" ${python} ${launch} ${trainer} -c ${yml_file} -o Global.epoch_num=${epoch} Global.eval_batch_step=${eval_batch_step} Global.auto_cast=${auto_cast} Global.save_model_dir=${save_log} Global.use_gpu=${use_gpu} + status_check $? "${trainer}" "${command}" "${save_log}/train.log" + + command="${python} ${export_model} -c ${yml_file} -o Global.pretrained_model=${save_log}/best_accuracy Global.save_inference_dir=${save_log}/export_inference/ Global.save_model_dir=${save_log}" ${python} ${export_model} -c ${yml_file} -o Global.pretrained_model=${save_log}/best_accuracy Global.save_inference_dir=${save_log}/export_inference/ Global.save_model_dir=${save_log} - if [ $? -eq 0 ]; then - echo -e "\033[33m training of $model_name successfully!\033[0m" | tee -a ${save_log}/train.log - else - cat ${save_log}/train.log - echo -e "\033[33m training of $model_name failed!\033[0m" | tee -a ${save_log}/train.log - fi + status_check $? "${trainer}" "${command}" "${save_log}/train.log" if [ "${model_name}" = "det" ]; then export rec_batch_size_list=( "1" ) @@ -129,15 +136,10 @@ for train_model in ${train_model_list[*]}; do for use_mkldnn in ${use_mkldnn_list[*]}; do for threads in ${cpu_threads_list[*]}; do for rec_batch_size in ${rec_batch_size_list[*]}; do - echo ${python} ${inference} --enable_mkldnn=${use_mkldnn} --use_gpu=False --cpu_threads=${threads} --benchmark=True --det_model_dir=${save_log}/export_inference/ --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${log_path}/${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log - ${python} ${inference} --enable_mkldnn=${use_mkldnn} --use_gpu=False --cpu_threads=${threads} --benchmark=True --det_model_dir=${save_log}/export_inference/ --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${log_path}/${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log - if [ $? -eq 0 ]; then - echo -e "\033[33m training of $model_name successfully!\033[0m" | tee -a ${log_path}${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log - else - cat ${log_path}${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log - echo -e "\033[33m training of $model_name failed!\033[0m" | tee -a ${log_path}${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log - fi - + save_log_path="${log_path}/${model_name}_${slim_trainer}_cpu_usemkldnn_${use_mkldnn}_cputhreads_${threads}_recbatchnum_${rec_batch_size}_infer.log" + command="${python} ${inference} --enable_mkldnn=${use_mkldnn} --use_gpu=False --cpu_threads=${threads} --benchmark=True --det_model_dir=${save_log}/export_inference/ --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${save_log_path}" + ${python} ${inference} --enable_mkldnn=${use_mkldnn} --use_gpu=False --cpu_threads=${threads} --benchmark=True --det_model_dir=${save_log}/export_inference/ --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${save_log_path} + status_check $? "${inference}" "${command}" "${save_log}" done done done @@ -148,8 +150,9 @@ for train_model in ${train_model_list[*]}; do continue fi for rec_batch_size in ${rec_batch_size_list[*]}; do - # echo "${model_name} ${det_model_dir} ${rec_model_dir}, use_trt: ${use_trt} use_fp16: ${use_fp16}" - ${python} ${inference} --use_gpu=True --use_tensorrt=${use_trt} --precision=${precision} --benchmark=True --det_model_dir=${save_log}/export_inference/ --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${log_path}/${model_name}_${slim_trainer}_gpu_usetensorrt_${use_trt}_usefp16_${precision}_recbatchnum_${rec_batch_size}_infer.log + save_log_path="${log_path}/${model_name}_${slim_trainer}_gpu_usetensorrt_${use_trt}_usefp16_${precision}_recbatchnum_${rec_batch_size}_infer.log" + ${python} ${inference} --use_gpu=True --use_tensorrt=${use_trt} --precision=${precision} --benchmark=True --det_model_dir=${save_log}/export_inference/ --rec_batch_num=${rec_batch_size} --rec_model_dir=${rec_model_dir} --image_dir=${img_dir} --save_log_path=${save_log_path} + status_check $? "${inference}" "${command}" "${save_log}" done done done -- GitLab