提交 dd6bd28d 编写于 作者: D dongshuilong

fix bug for c++(cls, shitu) chain for tipc

上级 de726400
...@@ -15,3 +15,5 @@ use_tensorrt:False|True ...@@ -15,3 +15,5 @@ use_tensorrt:False|True
precision:fp32|fp16 precision:fp32|fp16
data_dir:./dataset/drink_dataset_v1.0 data_dir:./dataset/drink_dataset_v1.0
benchmark:True benchmark:True
generate_yaml_cmd:python3 test_tipc/generate_cpp_yaml.py
transform_index_cmd:python3 deploy/cpp_shitu/tools/transform_id_map.py -c inference_drink.yaml
...@@ -15,3 +15,4 @@ use_tensorrt:False|True ...@@ -15,3 +15,4 @@ use_tensorrt:False|True
precision:fp32|fp16 precision:fp32|fp16
image_dir:./dataset/ILSVRC2012/val image_dir:./dataset/ILSVRC2012/val
benchmark:True benchmark:True
generate_yaml_cmd:python3 test_tipc/generate_cpp_yaml.py
...@@ -20,6 +20,7 @@ def parse_args(): ...@@ -20,6 +20,7 @@ def parse_args():
parser.add_argument('--tensorrt', type=str2bool, default=False) parser.add_argument('--tensorrt', type=str2bool, default=False)
parser.add_argument('--precision', type=str, choices=["fp32", "fp16"]) parser.add_argument('--precision', type=str, choices=["fp32", "fp16"])
parser.add_argument('--benchmark', type=str2bool, default=True) parser.add_argument('--benchmark', type=str2bool, default=True)
parser.add_argument('--gpu_id', type=int, default=0)
parser.add_argument( parser.add_argument(
'--cls_yaml_path', '--cls_yaml_path',
type=str, type=str,
...@@ -55,6 +56,7 @@ def main(): ...@@ -55,6 +56,7 @@ def main():
config["Global"]["benchmark"] = args.benchmark config["Global"]["benchmark"] = args.benchmark
config["Global"]["use_tensorrt"] = args.tensorrt config["Global"]["use_tensorrt"] = args.tensorrt
config["Global"]["use_fp16"] = True if args.precision == "fp16" else False config["Global"]["use_fp16"] = True if args.precision == "fp16" else False
config["Global"]["gpu_id"] = args.gpu_id
if args.type == "cls": if args.type == "cls":
config["Global"]["infer_imgs"] = args.data_dir config["Global"]["infer_imgs"] = args.data_dir
assert args.cls_model_dir assert args.cls_model_dir
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
source test_tipc/common_func.sh source test_tipc/common_func.sh
FILENAME=$1 FILENAME=$1
GPUID=$2
if [[ ! $GPUID ]];then
GPUID=0
fi
dataline=$(awk 'NR==1, NR==16{print}' $FILENAME) dataline=$(awk 'NR==1, NR==16{print}' $FILENAME)
# parser params # parser params
...@@ -24,11 +28,13 @@ cpp_use_trt_list=$(func_parser_value "${lines[13]}") ...@@ -24,11 +28,13 @@ cpp_use_trt_list=$(func_parser_value "${lines[13]}")
cpp_precision_list=$(func_parser_value "${lines[14]}") cpp_precision_list=$(func_parser_value "${lines[14]}")
cpp_image_dir_value=$(func_parser_value "${lines[15]}") cpp_image_dir_value=$(func_parser_value "${lines[15]}")
cpp_benchmark_value=$(func_parser_value "${lines[16]}") cpp_benchmark_value=$(func_parser_value "${lines[16]}")
generate_yaml_cmd=$(func_parser_value "${lines[17]}")
transform_index_cmd=$(func_parser_value "${lines[18]}")
LOG_PATH="./test_tipc/output" LOG_PATH="./test_tipc/output"
mkdir -p ${LOG_PATH} mkdir -p ${LOG_PATH}
status_log="${LOG_PATH}/results_cpp.log" status_log="${LOG_PATH}/results_cpp.log"
generate_yaml_cmd="python3 test_tipc/generate_cpp_yaml.py" # generate_yaml_cmd="python3 test_tipc/generate_cpp_yaml.py"
function func_shitu_cpp_inference(){ function func_shitu_cpp_inference(){
IFS='|' IFS='|'
...@@ -53,8 +59,9 @@ function func_shitu_cpp_inference(){ ...@@ -53,8 +59,9 @@ function func_shitu_cpp_inference(){
fi fi
_save_log_path="${_log_path}/shitu_cpp_infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_precision_${precision}_batchsize_${batch_size}.log" _save_log_path="${_log_path}/shitu_cpp_infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_precision_${precision}_batchsize_${batch_size}.log"
command="${generate_yaml_cmd} --type shitu --batch_size ${batch_size} --mkldnn ${use_mkldnn} --gpu ${use_gpu} --cpu_thread ${threads} --tensorrt False --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --det_model_dir ${cpp_det_infer_model_dir}" command="${generate_yaml_cmd} --type shitu --batch_size ${batch_size} --mkldnn ${use_mkldnn} --gpu ${use_gpu} --cpu_thread ${threads} --tensorrt False --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --det_model_dir ${cpp_det_infer_model_dir} --gpu_id ${GPUID}"
eval $command eval $command
eval $transform_index_cmd
command="${_script} 2>&1|tee ${_save_log_path}" command="${_script} 2>&1|tee ${_save_log_path}"
eval $command eval $command
last_status=${PIPESTATUS[0]} last_status=${PIPESTATUS[0]}
...@@ -76,8 +83,9 @@ function func_shitu_cpp_inference(){ ...@@ -76,8 +83,9 @@ function func_shitu_cpp_inference(){
fi fi
for batch_size in ${cpp_batch_size_list[*]}; do for batch_size in ${cpp_batch_size_list[*]}; do
_save_log_path="${_log_path}/shitu_cpp_infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log" _save_log_path="${_log_path}/shitu_cpp_infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log"
command="${generate_yaml_cmd} --type shitu --batch_size ${batch_size} --mkldnn False --gpu ${use_gpu} --cpu_thread 1 --tensorrt ${use_trt} --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --det_model_dir ${cpp_det_infer_model_dir}" command="${generate_yaml_cmd} --type shitu --batch_size ${batch_size} --mkldnn False --gpu ${use_gpu} --cpu_thread 1 --tensorrt ${use_trt} --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --det_model_dir ${cpp_det_infer_model_dir} --gpu_id ${GPUID}"
eval $command eval $command
eval $transform_index_cmd
command="${_script} 2>&1|tee ${_save_log_path}" command="${_script} 2>&1|tee ${_save_log_path}"
eval $command eval $command
last_status=${PIPESTATUS[0]} last_status=${PIPESTATUS[0]}
...@@ -114,7 +122,7 @@ function func_cls_cpp_inference(){ ...@@ -114,7 +122,7 @@ function func_cls_cpp_inference(){
fi fi
_save_log_path="${_log_path}/cls_cpp_infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_precision_${precision}_batchsize_${batch_size}.log" _save_log_path="${_log_path}/cls_cpp_infer_cpu_usemkldnn_${use_mkldnn}_threads_${threads}_precision_${precision}_batchsize_${batch_size}.log"
command="${generate_yaml_cmd} --type cls --batch_size ${batch_size} --mkldnn ${use_mkldnn} --gpu ${use_gpu} --cpu_thread ${threads} --tensorrt False --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir}" command="${generate_yaml_cmd} --type cls --batch_size ${batch_size} --mkldnn ${use_mkldnn} --gpu ${use_gpu} --cpu_thread ${threads} --tensorrt False --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --gpu_id ${GPUID}"
eval $command eval $command
command1="${_script} 2>&1|tee ${_save_log_path}" command1="${_script} 2>&1|tee ${_save_log_path}"
eval ${command1} eval ${command1}
...@@ -137,7 +145,7 @@ function func_cls_cpp_inference(){ ...@@ -137,7 +145,7 @@ function func_cls_cpp_inference(){
fi fi
for batch_size in ${cpp_batch_size_list[*]}; do for batch_size in ${cpp_batch_size_list[*]}; do
_save_log_path="${_log_path}/cls_cpp_infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log" _save_log_path="${_log_path}/cls_cpp_infer_gpu_usetrt_${use_trt}_precision_${precision}_batchsize_${batch_size}.log"
command="${generate_yaml_cmd} --type cls --batch_size ${batch_size} --mkldnn False --gpu ${use_gpu} --cpu_thread 1 --tensorrt ${use_trt} --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir}" command="${generate_yaml_cmd} --type cls --batch_size ${batch_size} --mkldnn False --gpu ${use_gpu} --cpu_thread 1 --tensorrt ${use_trt} --precision ${precision} --data_dir ${_img_dir} --benchmark True --cls_model_dir ${cpp_infer_model_dir} --gpu_id ${GPUID}"
eval $command eval $command
command="${_script} 2>&1|tee ${_save_log_path}" command="${_script} 2>&1|tee ${_save_log_path}"
eval $command eval $command
...@@ -152,6 +160,7 @@ function func_cls_cpp_inference(){ ...@@ -152,6 +160,7 @@ function func_cls_cpp_inference(){
done done
} }
if [[ $cpp_infer_type == "cls" ]]; then if [[ $cpp_infer_type == "cls" ]]; then
cd deploy/cpp cd deploy/cpp
elif [[ $cpp_infer_type == "shitu" ]]; then elif [[ $cpp_infer_type == "shitu" ]]; then
...@@ -183,6 +192,7 @@ if [[ $cpp_infer_type == "shitu" ]]; then ...@@ -183,6 +192,7 @@ if [[ $cpp_infer_type == "shitu" ]]; then
eval "cmake -B build . -DFAISS_ENABLE_PYTHON=OFF -DCMAKE_INSTALL_PREFIX=${faiss_install_path}" eval "cmake -B build . -DFAISS_ENABLE_PYTHON=OFF -DCMAKE_INSTALL_PREFIX=${faiss_install_path}"
make -C build -j faiss make -C build -j faiss
make -C build install make -C build install
cd ..
fi fi
if [ -d "opencv-3.4.7/opencv3/" ] && [ $(md5sum opencv-3.4.7.tar.gz | awk -F ' ' '{print $1}') = "faa2b5950f8bee3f03118e600c74746a" ];then if [ -d "opencv-3.4.7/opencv3/" ] && [ $(md5sum opencv-3.4.7.tar.gz | awk -F ' ' '{print $1}') = "faa2b5950f8bee3f03118e600c74746a" ];then
...@@ -220,15 +230,14 @@ else ...@@ -220,15 +230,14 @@ else
make -j make -j
make install make install
cd ../ cd ../../
echo "################### build opencv finished ###################" echo "################### build opencv finished ###################"
fi fi
echo "################### build PaddleClas demo ####################" echo "################### build PaddleClas demo ####################"
OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/ OPENCV_DIR=$(pwd)/opencv-3.4.7/opencv3/
LIB_DIR=/work/project/project/test/paddle_inference/ # LIB_DIR=/work/project/project/test/paddle_inference/
# LIB_DIR=$(pwd)/Paddle/build/paddle_inference_install_dir/ LIB_DIR=$(pwd)/Paddle/build/paddle_inference_install_dir/
CUDA_LIB_DIR=$(dirname `find /usr -name libcudart.so`) CUDA_LIB_DIR=$(dirname `find /usr -name libcudart.so`)
CUDNN_LIB_DIR=$(dirname `find /usr -name libcudnn.so`) CUDNN_LIB_DIR=$(dirname `find /usr -name libcudnn.so`)
...@@ -247,7 +256,6 @@ if [[ $cpp_infer_type == cls ]]; then ...@@ -247,7 +256,6 @@ if [[ $cpp_infer_type == cls ]]; then
-DCUDNN_LIB=${CUDNN_LIB_DIR} \ -DCUDNN_LIB=${CUDNN_LIB_DIR} \
-DCUDA_LIB=${CUDA_LIB_DIR} \ -DCUDA_LIB=${CUDA_LIB_DIR} \
-DTENSORRT_DIR=${TENSORRT_DIR} -DTENSORRT_DIR=${TENSORRT_DIR}
echo "---------------------------"
else else
cmake ..\ cmake ..\
-DPADDLE_LIB=${LIB_DIR} \ -DPADDLE_LIB=${LIB_DIR} \
...@@ -259,7 +267,7 @@ else ...@@ -259,7 +267,7 @@ else
-DCUDNN_LIB=${CUDNN_LIB_DIR} \ -DCUDNN_LIB=${CUDNN_LIB_DIR} \
-DCUDA_LIB=${CUDA_LIB_DIR} \ -DCUDA_LIB=${CUDA_LIB_DIR} \
-DTENSORRT_DIR=${TENSORRT_DIR} \ -DTENSORRT_DIR=${TENSORRT_DIR} \
-DFAISS_DIR=${FAISS_DIR} \ -DFAISS_DIR=${faiss_install_path} \
-DFAISS_WITH_MKL=OFF -DFAISS_WITH_MKL=OFF
fi fi
make -j make -j
...@@ -269,14 +277,14 @@ echo "################### build PaddleClas demo finished ###################" ...@@ -269,14 +277,14 @@ echo "################### build PaddleClas demo finished ###################"
# set cuda device # set cuda device
GPUID=$2 # GPUID=$2
if [ ${#GPUID} -le 0 ];then # if [ ${#GPUID} -le 0 ];then
env=" " # env="export CUDA_VISIBLE_DEVICES=0"
else # else
env="export CUDA_VISIBLE_DEVICES=${GPUID}" # env="export CUDA_VISIBLE_DEVICES=${GPUID}"
fi # fi
set CUDA_VISIBLE_DEVICES # set CUDA_VISIBLE_DEVICES
eval $env # eval $env
echo "################### run test ###################" echo "################### run test ###################"
...@@ -287,9 +295,9 @@ for infer_model in ${cpp_infer_model_dir[*]}; do ...@@ -287,9 +295,9 @@ for infer_model in ${cpp_infer_model_dir[*]}; do
#run inference #run inference
is_quant=${infer_quant_flag[Count]} is_quant=${infer_quant_flag[Count]}
if [[ $cpp_infer_type == "cls" ]]; then if [[ $cpp_infer_type == "cls" ]]; then
func_cls_cpp_inference "${inference_cmd}" "${infer_model}" "${LOG_PATH}" "${cpp_image_dir_value}" ${is_quant} func_cls_cpp_inference "${inference_cmd}" "${infer_model}" "${LOG_PATH}" "${cpp_image_dir_value}" ${is_quant}
else else
func_shitu_cpp_inference "${inference_cmd}" "${infer_model}" "${LOG_PATH}" "${cpp_image_dir_value}" ${is_quant} func_shitu_cpp_inference "${inference_cmd}" "${infer_model}" "${LOG_PATH}" "${cpp_image_dir_value}" ${is_quant}
fi fi
Count=$(($Count + 1)) Count=$(($Count + 1))
done done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册