test_serving.sh 10.3 KB
Newer Older
M
MissPenguin 已提交
1
#!/bin/bash
L
rename  
LDOUBLEV 已提交
2
source test_tipc/common_func.sh
M
MissPenguin 已提交
3 4

FILENAME=$1
T
tink2123 已提交
5
dataline=$(awk 'NR==1, NR==18{print}'  $FILENAME)
M
MissPenguin 已提交
6 7 8 9 10 11

# parser params
IFS=$'\n'
lines=(${dataline})

# parser serving
T
tink2123 已提交
12
model_name=$(func_parser_value "${lines[1]}")
T
tink2123 已提交
13
python_list=$(func_parser_value "${lines[2]}")
T
tink2123 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
trans_model_py=$(func_parser_value "${lines[3]}")
infer_model_dir_key=$(func_parser_key "${lines[4]}")
infer_model_dir_value=$(func_parser_value "${lines[4]}")
model_filename_key=$(func_parser_key "${lines[5]}")
model_filename_value=$(func_parser_value "${lines[5]}")
params_filename_key=$(func_parser_key "${lines[6]}")
params_filename_value=$(func_parser_value "${lines[6]}")
serving_server_key=$(func_parser_key "${lines[7]}")
serving_server_value=$(func_parser_value "${lines[7]}")
serving_client_key=$(func_parser_key "${lines[8]}")
serving_client_value=$(func_parser_value "${lines[8]}")
serving_dir_value=$(func_parser_value "${lines[9]}")
web_service_py=$(func_parser_value "${lines[10]}")
web_use_gpu_key=$(func_parser_key "${lines[11]}")
web_use_gpu_list=$(func_parser_value "${lines[11]}")
web_use_mkldnn_key=$(func_parser_key "${lines[12]}")
web_use_mkldnn_list=$(func_parser_value "${lines[12]}")
web_cpu_threads_key=$(func_parser_key "${lines[13]}")
web_cpu_threads_list=$(func_parser_value "${lines[13]}")
web_use_trt_key=$(func_parser_key "${lines[14]}")
web_use_trt_list=$(func_parser_value "${lines[14]}")
web_precision_key=$(func_parser_key "${lines[15]}")
web_precision_list=$(func_parser_value "${lines[15]}")
pipeline_py=$(func_parser_value "${lines[16]}")
T
tink2123 已提交
38 39
image_dir_key=$(func_parser_key "${lines[17]}")
image_dir_value=$(func_parser_value "${lines[17]}")
M
MissPenguin 已提交
40

41 42
LOG_PATH="$(pwd)/test_tipc/output/pdserving/${model_name}"
mkdir -p ${LOG_PATH}
M
MissPenguin 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55
status_log="${LOG_PATH}/results_serving.log"

function func_serving(){
    IFS='|'
    _python=$1
    _script=$2
    _model_dir=$3
    # pdserving
    set_dirname=$(func_set_params "${infer_model_dir_key}" "${infer_model_dir_value}")
    set_model_filename=$(func_set_params "${model_filename_key}" "${model_filename_value}")
    set_params_filename=$(func_set_params "${params_filename_key}" "${params_filename_value}")
    set_serving_server=$(func_set_params "${serving_server_key}" "${serving_server_value}")
    set_serving_client=$(func_set_params "${serving_client_key}" "${serving_client_value}")
T
tink2123 已提交
56
    set_image_dir=$(func_set_params "${image_dir_key}" "${image_dir_value}")
T
tink2123 已提交
57 58
    python_list=(${python_list})
    trans_model_cmd="${python_list[0]} ${trans_model_py} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_serving_server} ${set_serving_client}"
M
MissPenguin 已提交
59 60 61 62
    eval $trans_model_cmd
    cd ${serving_dir_value}
    unset https_proxy
    unset http_proxy
T
tink2123 已提交
63 64
    for python in ${python_list[*]}; do
        if [ ${python} = "cpp" ]; then
T
tink2123 已提交
65 66
            for use_gpu in ${web_use_gpu_list[*]}; do
                if [ ${use_gpu} = "null" ]; then
67 68 69 70 71
                    if [ ${model_name} = "ocr_det_mobile" ]; then
                        web_service_cpp_cmd="${python_list[0]} -m paddle_serving_server.serve --model ppocr_det_mobile_2.0_serving/ ppocr_rec_mobile_2.0_serving/ --op GeneralDetectionOp GeneralInferOp --port 9293"
                    elif [ ${model_name} = "ocr_det_v3" ] || [ ${model_name} = "ocr_rec_v3" ]; then
                        web_service_cpp_cmd="${python_list[0]} -m paddle_serving_server.serve --model ppocr_det_v3_serving/ ppocr_rec_v3_serving/ --op GeneralDetectionOp GeneralInferOp --port 9293"
                    fi
T
tink2123 已提交
72 73 74
                    eval $web_service_cpp_cmd
                    last_status=${PIPESTATUS[0]}
                    status_check $last_status "${web_service_cpp_cmd}" "${status_log}"
M
MissPenguin 已提交
75
                    sleep 2s
T
tink2123 已提交
76
                    _save_log_path="${LOG_PATH}/server_infer_cpp_cpu_pipeline_usemkldnn_False_threads_4_batchsize_1.log"
77 78 79 80 81
                    if [ ${model_name} = "ocr_det_mobile" ]; then
                        pipeline_cmd="${python_list[0]}  ocr_cpp_client.py ppocr_det_mobile_2.0_client/ ppocr_rec_mobile_2.0_client/"
                    elif [ ${model_name} = "ocr_det_v3" ] || [ ${model_name} = "ocr_rec_v3" ]; then
                        pipeline_cmd="${python_list[0]}  ocr_cpp_client.py ppocr_det_v3_client/ ppocr_rec_v3_client/"
                    fi
M
MissPenguin 已提交
82
                    eval $pipeline_cmd
T
tink2123 已提交
83
                    last_status=${PIPESTATUS[0]}
M
MissPenguin 已提交
84 85 86
                    status_check $last_status "${pipeline_cmd}" "${status_log}"
                    sleep 2s
                    ps ux | grep -E 'web_service|pipeline' | awk '{print $2}' | xargs kill -s 9
T
tink2123 已提交
87
                else
88 89 90 91 92
                    if [ ${model_name} = "ocr_det_mobile" ]; then
                        web_service_cpp_cmd="${python_list[0]}  -m paddle_serving_server.serve --model ppocr_det_mobile_2.0_serving/ ppocr_rec_mobile_2.0_serving/ --op GeneralDetectionOp GeneralInferOp --port 9293 --gpu_id=0"
                    elif [ ${model_name} = "ocr_det_v3" ] || [ ${model_name} = "ocr_rec_v3" ]; then
                        web_service_cpp_cmd="${python_list[0]}  -m paddle_serving_server.serve --model ppocr_det_v3_serving/ ppocr_rec_v3_serving/ --op GeneralDetectionOp GeneralInferOp --port 9293 --gpu_id=0"
                    fi
T
tink2123 已提交
93
                    eval $web_service_cpp_cmd
T
tink2123 已提交
94 95
                    sleep 2s
                    _save_log_path="${LOG_PATH}/server_infer_cpp_cpu_pipeline_usemkldnn_False_threads_4_batchsize_1.log"
96 97 98 99 100
                    if [ ${model_name} = "ocr_det_mobile" ]; then
                        pipeline_cmd="${python_list[0]}  ocr_cpp_client.py ppocr_det_mobile_2.0_client/ ppocr_rec_mobile_2.0_client/"
                    elif [ ${model_name} = "ocr_det_v3" ] || [ ${model_name} = "ocr_rec_v3" ]; then
                        pipeline_cmd="${python_list[0]}  ocr_cpp_client.py ppocr_det_v3_client/ ppocr_rec_v3_client/"
                    fi
T
tink2123 已提交
101
                    eval $pipeline_cmd
T
tink2123 已提交
102
                    last_status=${PIPESTATUS[0]}
T
tink2123 已提交
103 104 105 106
                    status_check $last_status "${pipeline_cmd}" "${status_log}"
                    sleep 2s
                    ps ux | grep -E 'web_service|pipeline' | awk '{print $2}' | xargs kill -s 9                
                fi
M
MissPenguin 已提交
107 108
            done
        else
T
tink2123 已提交
109 110 111 112 113 114
            # python serving
            for use_gpu in ${web_use_gpu_list[*]}; do
                if [ ${use_gpu} = "null" ]; then
                    for use_mkldnn in ${web_use_mkldnn_list[*]}; do
                        for threads in ${web_cpu_threads_list[*]}; do
                            set_cpu_threads=$(func_set_params "${web_cpu_threads_key}" "${threads}")
T
tink2123 已提交
115
                            web_service_cmd="${python} ${web_service_py} ${web_use_gpu_key}="" ${web_use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} &"
T
tink2123 已提交
116
                            eval $web_service_cmd
T
tink2123 已提交
117 118
                            last_status=${PIPESTATUS[0]}
                            status_check $last_status "${web_service_cmd}" "${status_log}"
T
tink2123 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131
                            sleep 2s
                            for pipeline in ${pipeline_py[*]}; do
                                _save_log_path="${LOG_PATH}/server_infer_cpu_${pipeline%_client*}_usemkldnn_${use_mkldnn}_threads_${threads}_batchsize_1.log"
                                pipeline_cmd="${python} ${pipeline} ${set_image_dir} > ${_save_log_path} 2>&1 "
                                eval $pipeline_cmd
                                last_status=${PIPESTATUS[0]}
                                eval "cat ${_save_log_path}"
                                status_check $last_status "${pipeline_cmd}" "${status_log}"
                                sleep 2s
                            done
                            ps ux | grep -E 'web_service|pipeline' | awk '{print $2}' | xargs kill -s 9
                        done
                    done
132
                elif [ ${use_gpu} = "gpu" ]; then
T
tink2123 已提交
133 134 135 136 137 138 139 140 141 142 143 144
                    for use_trt in ${web_use_trt_list[*]}; do
                        for precision in ${web_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
                            set_tensorrt=$(func_set_params "${web_use_trt_key}" "${use_trt}")
T
tink2123 已提交
145 146 147
                            if [ ${use_trt} = True ]; then
                                device_type=2
                            fi
T
tink2123 已提交
148
                            set_precision=$(func_set_params "${web_precision_key}" "${precision}")
149
                            web_service_cmd="${python} ${web_service_py} ${set_tensorrt} ${set_precision} & "
T
tink2123 已提交
150
                            eval $web_service_cmd
T
tink2123 已提交
151 152
                            last_status=${PIPESTATUS[0]}
                            status_check $last_status "${web_service_cmd}" "${status_log}"
T
tink2123 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
                        
                            sleep 2s
                            for pipeline in ${pipeline_py[*]}; do
                                _save_log_path="${LOG_PATH}/server_infer_gpu_${pipeline%_client*}_usetrt_${use_trt}_precision_${precision}_batchsize_1.log"
                                pipeline_cmd="${python} ${pipeline} ${set_image_dir}> ${_save_log_path} 2>&1"
                                eval $pipeline_cmd
                                last_status=${PIPESTATUS[0]}
                                eval "cat ${_save_log_path}"
                                status_check $last_status "${pipeline_cmd}" "${status_log}"
                                sleep 2s
                            done
                            ps ux | grep -E 'web_service|pipeline' | awk '{print $2}' | xargs kill -s 9
                        done
                    done
                else
                    echo "Does not support hardware other than CPU and GPU Currently!"
                fi
            done
M
MissPenguin 已提交
171 172 173 174 175
        fi
    done
}


T
tink2123 已提交
176
#set cuda device
M
MissPenguin 已提交
177 178
GPUID=$2
if [ ${#GPUID} -le 0 ];then
T
tink2123 已提交
179
    env="export CUDA_VISIBLE_DEVICES=0"
M
MissPenguin 已提交
180 181 182 183
else
    env="export CUDA_VISIBLE_DEVICES=${GPUID}"
fi
eval $env
T
tink2123 已提交
184
echo $env
M
MissPenguin 已提交
185 186 187


echo "################### run test ###################"
T
tink2123 已提交
188 189 190

export Count=0
IFS="|"
T
tink2123 已提交
191
func_serving "${web_service_cmd}"