merge dygraph
This commit is contained in:
commit
915d06324d
|
@ -10,7 +10,7 @@ Global:
|
|||
cal_metric_during_train: True
|
||||
pretrained_model:
|
||||
checkpoints:
|
||||
save_inference_dir:
|
||||
save_inference_dir: ./
|
||||
use_visualdl: False
|
||||
infer_img: doc/imgs_words_en/word_10.png
|
||||
# for data or label process
|
||||
|
@ -60,8 +60,8 @@ Metric:
|
|||
Train:
|
||||
dataset:
|
||||
name: SimpleDataSet
|
||||
data_dir: ./train_data/
|
||||
label_file_list: ["./train_data/train_list.txt"]
|
||||
data_dir: ./train_data/ic15_data/
|
||||
label_file_list: ["./train_data/ic15_data/rec_gt_train.txt"]
|
||||
transforms:
|
||||
- DecodeImage: # load image
|
||||
img_mode: BGR
|
||||
|
@ -81,8 +81,8 @@ Train:
|
|||
Eval:
|
||||
dataset:
|
||||
name: SimpleDataSet
|
||||
data_dir: ./train_data/
|
||||
label_file_list: ["./train_data/val_list.txt"]
|
||||
data_dir: ./train_data/ic15_data
|
||||
label_file_list: ["./train_data/ic15_data/rec_gt_test.txt"]
|
||||
transforms:
|
||||
- DecodeImage: # load image
|
||||
img_mode: BGR
|
||||
|
|
|
@ -37,10 +37,8 @@ endif()
|
|||
|
||||
|
||||
if (WIN32)
|
||||
include_directories("${PADDLE_LIB}/paddle/fluid/inference")
|
||||
include_directories("${PADDLE_LIB}/paddle/include")
|
||||
link_directories("${PADDLE_LIB}/paddle/lib")
|
||||
link_directories("${PADDLE_LIB}/paddle/fluid/inference")
|
||||
find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/build/ NO_DEFAULT_PATH)
|
||||
|
||||
else ()
|
||||
|
|
|
@ -21,12 +21,18 @@ std::vector<std::string> OCRConfig::split(const std::string &str,
|
|||
std::vector<std::string> res;
|
||||
if ("" == str)
|
||||
return res;
|
||||
char strs[str.length() + 1];
|
||||
|
||||
int strlen = str.length() + 1;
|
||||
chars *strs = new char[strlen];
|
||||
std::strcpy(strs, str.c_str());
|
||||
|
||||
char d[delim.length() + 1];
|
||||
int delimlen = delim.length() + 1;
|
||||
char *d = new char[delimlen];
|
||||
std::strcpy(d, delim.c_str());
|
||||
|
||||
delete[] strs;
|
||||
delete[] d;
|
||||
|
||||
char *p = std::strtok(strs, d);
|
||||
while (p) {
|
||||
std::string s = p;
|
||||
|
|
BIN
doc/joinus.PNG
BIN
doc/joinus.PNG
Binary file not shown.
Before Width: | Height: | Size: 212 KiB After Width: | Height: | Size: 203 KiB |
|
@ -7,5 +7,5 @@ tqdm
|
|||
numpy
|
||||
visualdl
|
||||
python-Levenshtein
|
||||
opencv-contrib-python==4.2.0.32
|
||||
opencv-contrib-python==4.4.0.46
|
||||
cython
|
|
@ -1,35 +0,0 @@
|
|||
model_name:ocr_det
|
||||
python:python3.7
|
||||
gpu_list:0|0,1
|
||||
Global.auto_cast:null
|
||||
Global.epoch_num:10
|
||||
Global.save_model_dir:./output/
|
||||
Train.loader.batch_size_per_card:
|
||||
Global.use_gpu:
|
||||
Global.pretrained_model:null
|
||||
|
||||
trainer:norm|pact
|
||||
norm_train:tools/train.py -c configs/det/det_mv3_db.yml -o Global.pretrained_model=./pretrain_models/MobileNetV3_large_x0_5_pretrained
|
||||
quant_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
|
||||
|
||||
eval:tools/eval.py -c configs/det/det_mv3_db.yml -o
|
||||
|
||||
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
|
||||
|
||||
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:./test/output/
|
|
@ -1,35 +0,0 @@
|
|||
model_name:ocr_rec
|
||||
python:python
|
||||
gpu_list:0|0,1
|
||||
Global.auto_cast:null
|
||||
Global.epoch_num:10
|
||||
Global.save_model_dir:./output/
|
||||
Train.loader.batch_size_per_card:
|
||||
Global.use_gpu:
|
||||
Global.pretrained_model:null
|
||||
|
||||
trainer:norm|pact
|
||||
norm_train:tools/train.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml
|
||||
quant_train:deploy/slim/quantization/quant.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml
|
||||
fpgm_train:null
|
||||
distill_train:null
|
||||
|
||||
eval:tools/eval.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml -o
|
||||
|
||||
Global.save_inference_dir:./output/
|
||||
Global.pretrained_model:
|
||||
norm_export:tools/export_model.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml -o
|
||||
quant_export:deploy/slim/quantization/export_model.py -c configs/rec/rec_mv3_none_bilstm_ctc.yml -o
|
||||
fpgm_export:null
|
||||
distill_export:null
|
||||
|
||||
inference:tools/infer/predict_rec.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
|
||||
--rec_model_dir:./inference/ch_ppocr_mobile_v2.0_rec_infer/
|
||||
--image_dir:./inference/rec_inference
|
||||
--save_log_path:./test/output/
|
146
test/prepare.sh
146
test/prepare.sh
|
@ -1,146 +0,0 @@
|
|||
#!/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
|
||||
if [ ${train_model_list[*]} = "ocr_det" ]; then
|
||||
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 ../
|
||||
fi
|
||||
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
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar # todo change to bcebos
|
||||
|
||||
cd ./train_data/ && tar xf icdar2015_lite.tar && tar xf ic15_data.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
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar
|
||||
cd ./train_data/ && tar xf icdar2015.tar && tar xf ic15_data.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
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar
|
||||
cd ./train_data/ && tar xf icdar2015_infer.tar && tar xf ic15_data.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
|
||||
|
||||
|
||||
IFS='|'
|
||||
for train_model in ${train_model_list[*]}; do
|
||||
if [ ${train_model} = "ocr_det" ];then
|
||||
model_name="ocr_det"
|
||||
yml_file="configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml"
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar
|
||||
cd ./inference && tar xf ch_det_data_50.tar && cd ../
|
||||
img_dir="./inference/ch_det_data_50/all-sum-510"
|
||||
data_dir=./inference/ch_det_data_50/
|
||||
data_label_file=[./inference/ch_det_data_50/test_gt_50.txt]
|
||||
elif [ ${train_model} = "ocr_rec" ];then
|
||||
model_name="ocr_rec"
|
||||
yml_file="configs/rec/rec_mv3_none_bilstm_ctc.yml"
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/rec_inference.tar
|
||||
cd ./inference && tar xf rec_inference.tar && cd ../
|
||||
img_dir="./inference/rec_inference/"
|
||||
data_dir=./inference/rec_inference
|
||||
data_label_file=[./inference/rec_inference/rec_gt_test.txt]
|
||||
fi
|
||||
|
||||
# eval
|
||||
for slim_trainer in ${trainer_list[*]}; do
|
||||
if [ ${slim_trainer} = "norm" ]; then
|
||||
if [ ${model_name} = "det" ]; then
|
||||
eval_model_name="ch_ppocr_mobile_v2.0_det_train"
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_train.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
|
||||
elif [ ${slim_trainer} = "pact" ]; then
|
||||
if [ ${model_name} = "det" ]; then
|
||||
eval_model_name="ch_ppocr_mobile_v2.0_det_quant_train"
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_det_quant_train.tar
|
||||
cd ./inference && tar xf ${eval_model_name}.tar && cd ../
|
||||
else
|
||||
eval_model_name="ch_ppocr_mobile_v2.0_rec_quant_train"
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_rec_quant_train.tar
|
||||
cd ./inference && tar xf ${eval_model_name}.tar && cd ../
|
||||
fi
|
||||
elif [ ${slim_trainer} = "distill" ]; then
|
||||
if [ ${model_name} = "det" ]; then
|
||||
eval_model_name="ch_ppocr_mobile_v2.0_det_distill_train"
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_det_distill_train.tar
|
||||
cd ./inference && tar xf ${eval_model_name}.tar && cd ../
|
||||
else
|
||||
eval_model_name="ch_ppocr_mobile_v2.0_rec_distill_train"
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_rec_distill_train.tar
|
||||
cd ./inference && tar xf ${eval_model_name}.tar && cd ../
|
||||
fi
|
||||
elif [ ${slim_trainer} = "fpgm" ]; 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
|
||||
cd ./inference && tar xf ${eval_model_name}.tar && cd ../
|
||||
else
|
||||
eval_model_name="ch_ppocr_mobile_v2.0_rec_prune_train"
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/slim/ch_ppocr_mobile_v2.0_rec_prune_train.tar
|
||||
cd ./inference && tar xf ${eval_model_name}.tar && cd ../
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
237
test/test.sh
237
test/test.sh
|
@ -1,237 +0,0 @@
|
|||
#!/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 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[0]}")
|
||||
python=$(func_parser_value "${lines[1]}")
|
||||
gpu_list=$(func_parser_value "${lines[2]}")
|
||||
autocast_list=$(func_parser_value "${lines[3]}")
|
||||
autocast_key=$(func_parser_key "${lines[3]}")
|
||||
epoch_key=$(func_parser_key "${lines[4]}")
|
||||
epoch_num=$(func_parser_value "${lines[4]}")
|
||||
save_model_key=$(func_parser_key "${lines[5]}")
|
||||
train_batch_key=$(func_parser_key "${lines[6]}")
|
||||
train_use_gpu_key=$(func_parser_key "${lines[7]}")
|
||||
pretrain_model_key=$(func_parser_key "${lines[8]}")
|
||||
pretrain_model_value=$(func_parser_value "${lines[8]}")
|
||||
|
||||
trainer_list=$(func_parser_value "${lines[9]}")
|
||||
norm_trainer=$(func_parser_value "${lines[10]}")
|
||||
pact_trainer=$(func_parser_value "${lines[11]}")
|
||||
fpgm_trainer=$(func_parser_value "${lines[12]}")
|
||||
distill_trainer=$(func_parser_value "${lines[13]}")
|
||||
|
||||
eval_py=$(func_parser_value "${lines[14]}")
|
||||
|
||||
save_infer_key=$(func_parser_key "${lines[15]}")
|
||||
export_weight=$(func_parser_key "${lines[16]}")
|
||||
norm_export=$(func_parser_value "${lines[17]}")
|
||||
pact_export=$(func_parser_value "${lines[18]}")
|
||||
fpgm_export=$(func_parser_value "${lines[19]}")
|
||||
distill_export=$(func_parser_value "${lines[20]}")
|
||||
|
||||
inference_py=$(func_parser_value "${lines[21]}")
|
||||
use_gpu_key=$(func_parser_key "${lines[22]}")
|
||||
use_gpu_list=$(func_parser_value "${lines[22]}")
|
||||
use_mkldnn_key=$(func_parser_key "${lines[23]}")
|
||||
use_mkldnn_list=$(func_parser_value "${lines[23]}")
|
||||
cpu_threads_key=$(func_parser_key "${lines[24]}")
|
||||
cpu_threads_list=$(func_parser_value "${lines[24]}")
|
||||
batch_size_key=$(func_parser_key "${lines[25]}")
|
||||
batch_size_list=$(func_parser_value "${lines[25]}")
|
||||
use_trt_key=$(func_parser_key "${lines[26]}")
|
||||
use_trt_list=$(func_parser_value "${lines[26]}")
|
||||
precision_key=$(func_parser_key "${lines[27]}")
|
||||
precision_list=$(func_parser_value "${lines[27]}")
|
||||
infer_model_key=$(func_parser_key "${lines[28]}")
|
||||
infer_model=$(func_parser_value "${lines[28]}")
|
||||
image_dir_key=$(func_parser_key "${lines[29]}")
|
||||
infer_img_dir=$(func_parser_value "${lines[29]}")
|
||||
save_log_key=$(func_parser_key "${lines[30]}")
|
||||
|
||||
LOG_PATH="./test/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
|
||||
|
||||
# inference
|
||||
for use_gpu in ${use_gpu_list[*]}; do
|
||||
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"
|
||||
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} ${image_dir_key}=${_img_dir} ${save_log_key}=${_save_log_path} --benchmark=True"
|
||||
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
|
||||
for batch_size in ${batch_size_list[*]}; do
|
||||
_save_log_path="${_log_path}/infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log"
|
||||
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} ${image_dir_key}=${_img_dir} ${save_log_key}=${_save_log_path} --benchmark=True"
|
||||
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
|
||||
if [ ${trainer} = "pact" ]; then
|
||||
run_train=${pact_trainer}
|
||||
run_export=${pact_export}
|
||||
elif [ ${trainer} = "fpgm" ]; then
|
||||
run_train=${fpgm_trainer}
|
||||
run_export=${fpgm_export}
|
||||
elif [ ${trainer} = "distill" ]; then
|
||||
run_train=${distill_trainer}
|
||||
run_export=${distill_export}
|
||||
else
|
||||
run_train=${norm_trainer}
|
||||
run_export=${norm_export}
|
||||
fi
|
||||
|
||||
if [ ${run_train} = "null" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ ${run_export} = "null" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# not set autocast when autocast is null
|
||||
if [ ${autocast} = "null" ]; then
|
||||
set_autocast=" "
|
||||
else
|
||||
set_autocast="${autocast_key}=${autocast}"
|
||||
fi
|
||||
# not set epoch when whole_train_infer
|
||||
if [ ${MODE} != "whole_train_infer" ]; then
|
||||
set_epoch="${epoch_key}=${epoch_num}"
|
||||
else
|
||||
set_epoch=" "
|
||||
fi
|
||||
# set pretrain
|
||||
if [ ${pretrain_model_value} != "null" ]; then
|
||||
set_pretrain="${pretrain_model_key}=${pretrain_model_value}"
|
||||
else
|
||||
set_pretrain=" "
|
||||
fi
|
||||
|
||||
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}"
|
||||
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}"
|
||||
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}"
|
||||
fi
|
||||
# run train
|
||||
eval $cmd
|
||||
status_check $? "${cmd}" "${status_log}"
|
||||
|
||||
# run eval
|
||||
eval_cmd="${python} ${eval_py} ${save_model_key}=${save_log} ${pretrain_model_key}=${save_log}/latest"
|
||||
eval $eval_cmd
|
||||
status_check $? "${eval_cmd}" "${status_log}"
|
||||
|
||||
# run export model
|
||||
save_infer_path="${save_log}"
|
||||
export_cmd="${python} ${run_export} ${save_model_key}=${save_log} ${export_weight}=${save_log}/latest ${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}" "${infer_img_dir}"
|
||||
eval "unset CUDA_VISIBLE_DEVICES"
|
||||
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}"
|
||||
fi
|
|
@ -0,0 +1,52 @@
|
|||
===========================train_params===========================
|
||||
model_name:ocr_det
|
||||
python:python3.7
|
||||
gpu_list:0|0,1
|
||||
Global.use_gpu:True|True
|
||||
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
|
||||
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
|
||||
fpgm_train:null
|
||||
distill_train:null
|
||||
null:null
|
||||
null:null
|
||||
##
|
||||
===========================eval_params===========================
|
||||
eval:tools/eval.py -c configs/det/det_mv3_db.yml -o
|
||||
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
|
||||
export1:null
|
||||
export2:null
|
||||
##
|
||||
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
|
||||
--cpu_threads:1|6
|
||||
--rec_batch_num:1
|
||||
--use_tensorrt:False|True
|
||||
--precision:fp32|fp16|int8
|
||||
--det_model_dir:
|
||||
--image_dir:./inference/ch_det_data_50/all-sum-510/
|
||||
--save_log_path:null
|
||||
--benchmark:True
|
||||
null:null
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
===========================train_params===========================
|
||||
model_name:ocr_rec
|
||||
python:python3.7
|
||||
gpu_list:0|2,3
|
||||
Global.use_gpu:True|True
|
||||
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=128|whole_train_infer=128
|
||||
Global.pretrained_model:null
|
||||
train_model_name:latest
|
||||
train_infer_img_dir:./train_data/ic15_data/train
|
||||
null:null
|
||||
##
|
||||
trainer:norm_train|pact_train
|
||||
norm_train:tools/train.py -c configs/rec/rec_icdar15_train.yml -o
|
||||
pact_train:deploy/slim/quantization/quant.py -c configs/rec/rec_icdar15_train.yml -o
|
||||
fpgm_train:null
|
||||
distill_train:null
|
||||
null:null
|
||||
null:null
|
||||
##
|
||||
===========================eval_params===========================
|
||||
eval:tools/eval.py -c configs/rec/rec_icdar15_train.yml -o
|
||||
null:null
|
||||
##
|
||||
===========================infer_params===========================
|
||||
Global.save_inference_dir:./output/
|
||||
Global.pretrained_model:
|
||||
norm_export:tools/export_model.py -c configs/rec/rec_icdar15_train.yml -o
|
||||
quant_export:deploy/slim/quantization/export_model.py -c configs/rec/rec_icdar15_train.yml -o
|
||||
fpgm_export:null
|
||||
distill_export:null
|
||||
export1:null
|
||||
export2:null
|
||||
##
|
||||
infer_model:./inference/ch_ppocr_mobile_v2.0_rec_infer/
|
||||
infer_export:null
|
||||
infer_quant:False
|
||||
inference:tools/infer/predict_rec.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
|
||||
--rec_model_dir:
|
||||
--image_dir:./inference/rec_inference
|
||||
--save_log_path:./test/output/
|
||||
--benchmark:True
|
||||
null:null
|
|
@ -0,0 +1,76 @@
|
|||
#!/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[1]}")
|
||||
|
||||
trainer_list=$(func_parser_value "${lines[14]}")
|
||||
|
||||
# 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
|
||||
rm -rf ./train_data/ic15_data
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar # todo change to bcebos
|
||||
|
||||
cd ./train_data/ && tar xf icdar2015_lite.tar && tar xf ic15_data.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
|
||||
rm -rf ./train_data/ic15_data
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015.tar
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar
|
||||
cd ./train_data/ && tar xf icdar2015.tar && tar xf ic15_data.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
|
||||
rm -rf ./train_data/ic15_data
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_infer.tar
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar
|
||||
cd ./train_data/ && tar xf icdar2015_infer.tar && tar xf ic15_data.tar
|
||||
ln -s ./icdar2015_infer ./icdar2015
|
||||
cd ../
|
||||
else
|
||||
if [ ${model_name} = "ocr_det" ]; then
|
||||
eval_model_name="ch_ppocr_mobile_v2.0_det_infer"
|
||||
rm -rf ./train_data/icdar2015
|
||||
wget -nc -P ./train_data https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ch_det_data_50.tar
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/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
|
||||
rm -rf ./train_data/ic15_data
|
||||
eval_model_name="ch_ppocr_mobile_v2.0_rec_infer"
|
||||
wget -nc -P ./train_data/ https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/ic15_data.tar
|
||||
wget -nc -P ./inference https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar
|
||||
cd ./inference && tar xf ${eval_model_name}.tar && tar xf ic15_data.tar && cd ../
|
||||
fi
|
||||
fi
|
||||
|
|
@ -0,0 +1,365 @@
|
|||
#!/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 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 [[ ${_flag_quant} = "False" ]] && [[ ${precision} =~ "int8" ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ ${precision} =~ "fp16" || ${precision} =~ "int8" ]] && [ ${use_trt} = "False" ]; then
|
||||
continue
|
||||
fi
|
||||
if [[ ${use_trt} = "False" || ${precision} =~ "int8" ]] && [ ${_flag_quant} = "True" ]; then
|
||||
continue
|
||||
fi
|
||||
for batch_size in ${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}")
|
||||
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}"
|
||||
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
|
||||
save_infer_dir=$(dirname $infer_model)
|
||||
set_export_weight=$(func_set_params "${export_weight}" "${infer_model}")
|
||||
set_save_infer_key=$(func_set_params "${save_infer_key}" "${save_infer_dir}")
|
||||
export_cmd="${python} ${norm_export} ${set_export_weight} ${set_save_infer_key}"
|
||||
eval $export_cmd
|
||||
status_export=$?
|
||||
if [ ${status_export} = 0 ];then
|
||||
status_check $status_export "${export_cmd}" "${status_log}"
|
||||
fi
|
||||
else
|
||||
save_infer_dir=${infer_model}
|
||||
fi
|
||||
#run inference
|
||||
is_quant=${infer_quant_flag[Count]}
|
||||
func_inference "${python}" "${inference_py}" "${save_infer_dir}" "${LOG_PATH}" "${infer_img_dir}" ${is_quant}
|
||||
Count=$(($Count + 1))
|
||||
done
|
||||
|
||||
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}"
|
||||
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}"
|
||||
|
||||
#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
|
|
@ -114,7 +114,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,
|
||||
|
@ -122,7 +122,8 @@ class TextDetector(object):
|
|||
time_keys=[
|
||||
'preprocess_time', 'inference_time', 'postprocess_time'
|
||||
],
|
||||
warmup=10)
|
||||
warmup=2,
|
||||
logger=logger)
|
||||
|
||||
def order_points_clockwise(self, pts):
|
||||
"""
|
||||
|
@ -244,7 +245,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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -216,6 +216,27 @@ def create_predictor(args, mode, logger):
|
|||
"elementwise_add_7": [1, 56, 40, 40],
|
||||
"nearest_interp_v2_0.tmp_0": [1, 256, 40, 40]
|
||||
}
|
||||
min_pact_shape = {
|
||||
"nearest_interp_v2_26.tmp_0":[1,256,20,20],
|
||||
"nearest_interp_v2_27.tmp_0":[1,64,20,20],
|
||||
"nearest_interp_v2_28.tmp_0":[1,64,20,20],
|
||||
"nearest_interp_v2_29.tmp_0":[1,64,20,20]
|
||||
}
|
||||
max_pact_shape = {
|
||||
"nearest_interp_v2_26.tmp_0":[1,256,400,400],
|
||||
"nearest_interp_v2_27.tmp_0":[1,64,400,400],
|
||||
"nearest_interp_v2_28.tmp_0":[1,64,400,400],
|
||||
"nearest_interp_v2_29.tmp_0":[1,64,400,400]
|
||||
}
|
||||
opt_pact_shape = {
|
||||
"nearest_interp_v2_26.tmp_0":[1,256,160,160],
|
||||
"nearest_interp_v2_27.tmp_0":[1,64,160,160],
|
||||
"nearest_interp_v2_28.tmp_0":[1,64,160,160],
|
||||
"nearest_interp_v2_29.tmp_0":[1,64,160,160]
|
||||
}
|
||||
min_input_shape.update(min_pact_shape)
|
||||
max_input_shape.update(max_pact_shape)
|
||||
opt_input_shape.update(opt_pact_shape)
|
||||
elif mode == "rec":
|
||||
min_input_shape = {"x": [args.rec_batch_num, 3, 32, 10]}
|
||||
max_input_shape = {"x": [args.rec_batch_num, 3, 32, 2000]}
|
||||
|
|
Loading…
Reference in New Issue