test_serving_infer_python.sh 13.0 KB
Newer Older
A
andyjpaddle 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash
source test_tipc/common_func.sh

function func_parser_model_config(){
    strs=$1
    IFS="/"
    array=(${strs})
    tmp=${array[-1]}
    echo ${tmp}
}

FILENAME=$1
dataline=$(awk 'NR==1, NR==23{print}'  $FILENAME)
A
andyjpaddle 已提交
14
MODE=$2
A
andyjpaddle 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

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

# parser serving
model_name=$(func_parser_value "${lines[1]}")
python_list=$(func_parser_value "${lines[2]}")
trans_model_py=$(func_parser_value "${lines[3]}")
det_infer_model_dir_key=$(func_parser_key "${lines[4]}")
det_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]}")
det_serving_server_key=$(func_parser_key "${lines[7]}")
det_serving_server_value=$(func_parser_value "${lines[7]}")
det_serving_client_key=$(func_parser_key "${lines[8]}")
det_serving_client_value=$(func_parser_value "${lines[8]}")
rec_infer_model_dir_key=$(func_parser_key "${lines[9]}")
rec_infer_model_dir_value=$(func_parser_value "${lines[9]}")
rec_serving_server_key=$(func_parser_key "${lines[10]}")
rec_serving_server_value=$(func_parser_value "${lines[10]}")
rec_serving_client_key=$(func_parser_key "${lines[11]}")
rec_serving_client_value=$(func_parser_value "${lines[11]}")
serving_dir_value=$(func_parser_value "${lines[12]}")
web_service_py=$(func_parser_value "${lines[13]}")
web_use_gpu_key=$(func_parser_key "${lines[14]}")
web_use_gpu_list=$(func_parser_value "${lines[14]}")
web_use_mkldnn_key=$(func_parser_key "${lines[15]}")
web_use_mkldnn_list=$(func_parser_value "${lines[15]}")
web_cpu_threads_key=$(func_parser_key "${lines[16]}")
web_cpu_threads_list=$(func_parser_value "${lines[16]}")
web_use_trt_key=$(func_parser_key "${lines[17]}")
web_use_trt_list=$(func_parser_value "${lines[17]}")
web_precision_key=$(func_parser_key "${lines[18]}")
web_precision_list=$(func_parser_value "${lines[18]}")
det_server_key=$(func_parser_key "${lines[19]}")
det_server_value=$(func_parser_model_config "${lines[7]}")
det_client_value=$(func_parser_model_config "${lines[8]}")
rec_server_key=$(func_parser_key "${lines[20]}")
rec_server_value=$(func_parser_model_config "${lines[10]}")
rec_client_value=$(func_parser_model_config "${lines[11]}")
pipeline_py=$(func_parser_value "${lines[21]}")
image_dir_key=$(func_parser_key "${lines[22]}")
image_dir_value=$(func_parser_value "${lines[22]}")

A
andyjpaddle 已提交
62
LOG_PATH="$(pwd)/test_tipc/output/${model_name}/${MODE}/python"
A
andyjpaddle 已提交
63 64 65 66 67 68 69 70 71 72 73
mkdir -p ${LOG_PATH}
status_log="${LOG_PATH}/results_python_serving.log"

function func_serving(){
    IFS='|'
    _python=$1
    _script=$2
    _model_dir=$3
    # pdserving
    set_model_filename=$(func_set_params "${model_filename_key}" "${model_filename_value}")
    set_params_filename=$(func_set_params "${params_filename_key}" "${params_filename_value}")
文幕地方's avatar
文幕地方 已提交
74
    if [ ${model_name} = "ch_PP-OCRv2" ] || [ ${model_name} = "ch_PP-OCRv3" ] || [ ${model_name} = "ch_ppocr_mobile_v2_0" ] || [ ${model_name} = "ch_ppocr_server_v2_0" ]; then
A
andyjpaddle 已提交
75 76 77 78 79
        # trans det
        set_dirname=$(func_set_params "--dirname" "${det_infer_model_dir_value}")
        set_serving_server=$(func_set_params "--serving_server" "${det_serving_server_value}")
        set_serving_client=$(func_set_params "--serving_client" "${det_serving_client_value}")
        python_list=(${python_list})
A
andyjpaddle 已提交
80 81
        trans_det_log="${LOG_PATH}/python_trans_model_det.log"
        trans_model_cmd="${python_list[0]} ${trans_model_py} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_serving_server} ${set_serving_client} > ${trans_det_log} 2>&1 "
A
andyjpaddle 已提交
82 83 84 85 86 87
        eval $trans_model_cmd
        # trans rec
        set_dirname=$(func_set_params "--dirname" "${rec_infer_model_dir_value}")
        set_serving_server=$(func_set_params "--serving_server" "${rec_serving_server_value}")
        set_serving_client=$(func_set_params "--serving_client" "${rec_serving_client_value}")
        python_list=(${python_list})
A
andyjpaddle 已提交
88 89
        trans_rec_log="${LOG_PATH}/python_trans_model_rec.log"
        trans_model_cmd="${python_list[0]} ${trans_model_py} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_serving_server} ${set_serving_client} > ${trans_rec_log} 2>&1 "
A
andyjpaddle 已提交
90
        eval $trans_model_cmd
A
andyjpaddle 已提交
91
    elif [[ ${model_name} =~ "det" ]]; then
A
andyjpaddle 已提交
92 93 94 95 96
        # trans det
        set_dirname=$(func_set_params "--dirname" "${det_infer_model_dir_value}")
        set_serving_server=$(func_set_params "--serving_server" "${det_serving_server_value}")
        set_serving_client=$(func_set_params "--serving_client" "${det_serving_client_value}")
        python_list=(${python_list})
A
andyjpaddle 已提交
97 98
        trans_det_log="${LOG_PATH}/python_trans_model_det.log"
        trans_model_cmd="${python_list[0]} ${trans_model_py} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_serving_server} ${set_serving_client} > ${trans_det_log} 2>&1 "
A
andyjpaddle 已提交
99
        eval $trans_model_cmd
A
andyjpaddle 已提交
100
    elif [[ ${model_name} =~ "rec" ]]; then
A
andyjpaddle 已提交
101 102 103 104 105
        # trans rec
        set_dirname=$(func_set_params "--dirname" "${rec_infer_model_dir_value}")
        set_serving_server=$(func_set_params "--serving_server" "${rec_serving_server_value}")
        set_serving_client=$(func_set_params "--serving_client" "${rec_serving_client_value}")
        python_list=(${python_list})
A
andyjpaddle 已提交
106 107
        trans_rec_log="${LOG_PATH}/python_trans_model_rec.log"
        trans_model_cmd="${python_list[0]} ${trans_model_py} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_serving_server} ${set_serving_client} > ${trans_rec_log} 2>&1 "
A
andyjpaddle 已提交
108 109 110 111 112 113 114
        eval $trans_model_cmd
    fi
    set_image_dir=$(func_set_params "${image_dir_key}" "${image_dir_value}")
    python_list=(${python_list})
    
    cd ${serving_dir_value}
    python=${python_list[0]}
A
andyjpaddle 已提交
115
    
A
andyjpaddle 已提交
116 117 118 119 120 121
    # 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}")
A
andyjpaddle 已提交
122
                    server_log_path="${LOG_PATH}/python_server_cpu_usemkldnn_${use_mkldnn}_threads_${threads}.log"
文幕地方's avatar
文幕地方 已提交
123
                    if [ ${model_name} = "ch_PP-OCRv2" ] || [ ${model_name} = "ch_PP-OCRv3" ] || [ ${model_name} = "ch_ppocr_mobile_v2_0" ] || [ ${model_name} = "ch_ppocr_server_v2_0" ]; then
A
andyjpaddle 已提交
124 125
                        set_det_model_config=$(func_set_params "${det_server_key}" "${det_server_value}")
                        set_rec_model_config=$(func_set_params "${rec_server_key}" "${rec_server_value}")
A
andyjpaddle 已提交
126
                        web_service_cmd="nohup ${python} ${web_service_py} ${web_use_gpu_key}="" ${web_use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_det_model_config} ${set_rec_model_config} > ${server_log_path} 2>&1 &"
A
andyjpaddle 已提交
127 128
                        eval $web_service_cmd
                        last_status=${PIPESTATUS[0]}
Z
zhengya01 已提交
129
                        status_check $last_status "${web_service_cmd}" "${status_log}" "${model_name}" "${server_log_path}"
A
andyjpaddle 已提交
130
                    elif [[ ${model_name} =~ "det" ]]; then
A
andyjpaddle 已提交
131
                        set_det_model_config=$(func_set_params "${det_server_key}" "${det_server_value}")
A
andyjpaddle 已提交
132
                        web_service_cmd="nohup ${python} ${web_service_py} ${web_use_gpu_key}="" ${web_use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_det_model_config} > ${server_log_path} 2>&1 &"
A
andyjpaddle 已提交
133 134
                        eval $web_service_cmd
                        last_status=${PIPESTATUS[0]}
Z
zhengya01 已提交
135
                        status_check $last_status "${web_service_cmd}" "${status_log}" "${model_name}" "${server_log_path}"
A
andyjpaddle 已提交
136
                    elif [[ ${model_name} =~ "rec" ]]; then
A
andyjpaddle 已提交
137
                        set_rec_model_config=$(func_set_params "${rec_server_key}" "${rec_server_value}")
A
andyjpaddle 已提交
138
                        web_service_cmd="nohup ${python} ${web_service_py} ${web_use_gpu_key}="" ${web_use_mkldnn_key}=${use_mkldnn} ${set_cpu_threads} ${set_rec_model_config} > ${server_log_path} 2>&1 &"
A
andyjpaddle 已提交
139 140
                        eval $web_service_cmd
                        last_status=${PIPESTATUS[0]}
Z
zhengya01 已提交
141
                        status_check $last_status "${web_service_cmd}" "${status_log}" "${model_name}" "${server_log_path}"
A
andyjpaddle 已提交
142 143 144
                    fi
                    sleep 2s
                    for pipeline in ${pipeline_py[*]}; do
A
andyjpaddle 已提交
145
                        _save_log_path="${LOG_PATH}/python_client_cpu_${pipeline%_client*}_usemkldnn_${use_mkldnn}_threads_${threads}_batchsize_1.log"
A
andyjpaddle 已提交
146 147 148 149
                        pipeline_cmd="${python} ${pipeline} ${set_image_dir} > ${_save_log_path} 2>&1 "
                        eval $pipeline_cmd
                        last_status=${PIPESTATUS[0]}
                        eval "cat ${_save_log_path}"
Z
zhengya01 已提交
150
                        status_check $last_status "${pipeline_cmd}" "${status_log}" "${model_name}" "${_save_log_path}"
A
andyjpaddle 已提交
151 152
                        sleep 2s
                    done
X
xiaoting 已提交
153
                    ps ux | grep -E 'web_service' | awk '{print $2}' | xargs kill -s 9
A
andyjpaddle 已提交
154 155 156 157 158
                done
            done
        elif [ ${use_gpu} = "gpu" ]; then
            for use_trt in ${web_use_trt_list[*]}; do
                for precision in ${web_precision_list[*]}; do
A
andyjpaddle 已提交
159
                    server_log_path="${LOG_PATH}/python_server_gpu_usetrt_${use_trt}_precision_${precision}.log"
A
andyjpaddle 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172 173
                    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}")
                    if [ ${use_trt} = True ]; then
                        device_type=2
                    fi
                    set_precision=$(func_set_params "${web_precision_key}" "${precision}")
文幕地方's avatar
文幕地方 已提交
174
                    if [ ${model_name} = "ch_PP-OCRv2" ] || [ ${model_name} = "ch_PP-OCRv3" ] || [ ${model_name} = "ch_ppocr_mobile_v2_0" ] || [ ${model_name} = "ch_ppocr_server_v2_0" ]; then
A
andyjpaddle 已提交
175 176
                        set_det_model_config=$(func_set_params "${det_server_key}" "${det_server_value}")
                        set_rec_model_config=$(func_set_params "${rec_server_key}" "${rec_server_value}")
A
andyjpaddle 已提交
177
                        web_service_cmd="nohup ${python} ${web_service_py} ${set_tensorrt} ${set_precision} ${set_det_model_config} ${set_rec_model_config} > ${server_log_path} 2>&1 &"
A
andyjpaddle 已提交
178 179
                        eval $web_service_cmd
                        last_status=${PIPESTATUS[0]}
Z
zhengya01 已提交
180
                        status_check $last_status "${web_service_cmd}" "${status_log}" "${model_name}" "${server_log_path}"
A
andyjpaddle 已提交
181
                    elif [[ ${model_name} =~ "det" ]]; then
A
andyjpaddle 已提交
182
                        set_det_model_config=$(func_set_params "${det_server_key}" "${det_server_value}")
A
andyjpaddle 已提交
183
                        web_service_cmd="nohup ${python} ${web_service_py} ${set_tensorrt} ${set_precision} ${set_det_model_config} > ${server_log_path} 2>&1 &"
A
andyjpaddle 已提交
184 185
                        eval $web_service_cmd
                        last_status=${PIPESTATUS[0]}
Z
zhengya01 已提交
186
                        status_check $last_status "${web_service_cmd}" "${status_log}" "${model_name}" "${server_log_path}"
A
andyjpaddle 已提交
187
                    elif [[ ${model_name} =~ "rec" ]]; then
A
andyjpaddle 已提交
188
                        set_rec_model_config=$(func_set_params "${rec_server_key}" "${rec_server_value}")
A
andyjpaddle 已提交
189
                        web_service_cmd="nohup ${python} ${web_service_py} ${set_tensorrt} ${set_precision} ${set_rec_model_config} > ${server_log_path} 2>&1 &"
A
andyjpaddle 已提交
190 191
                        eval $web_service_cmd
                        last_status=${PIPESTATUS[0]}
Z
zhengya01 已提交
192
                        status_check $last_status "${web_service_cmd}" "${status_log}" "${model_name}" "${server_log_path}"
A
andyjpaddle 已提交
193 194 195
                    fi
                    sleep 2s
                    for pipeline in ${pipeline_py[*]}; do
A
andyjpaddle 已提交
196
                        _save_log_path="${LOG_PATH}/python_client_gpu_${pipeline%_client*}_usetrt_${use_trt}_precision_${precision}_batchsize_1.log"
A
andyjpaddle 已提交
197 198 199 200
                        pipeline_cmd="${python} ${pipeline} ${set_image_dir}> ${_save_log_path} 2>&1"
                        eval $pipeline_cmd
                        last_status=${PIPESTATUS[0]}
                        eval "cat ${_save_log_path}"
Z
zhengya01 已提交
201
                        status_check $last_status "${pipeline_cmd}" "${status_log}" "${model_name}" "${_save_log_path}"
A
andyjpaddle 已提交
202 203
                        sleep 2s
                    done
X
xiaoting 已提交
204
                    ps ux | grep -E 'web_service' | awk '{print $2}' | xargs kill -s 9
A
andyjpaddle 已提交
205 206 207 208 209 210 211 212 213 214
                done
            done
        else
            echo "Does not support hardware other than CPU and GPU Currently!"
        fi
    done
}


#set cuda device
A
andyjpaddle 已提交
215
GPUID=$3
A
andyjpaddle 已提交
216 217 218 219 220 221 222 223 224 225 226 227 228 229
if [ ${#GPUID} -le 0 ];then
    env="export CUDA_VISIBLE_DEVICES=0"
else
    env="export CUDA_VISIBLE_DEVICES=${GPUID}"
fi
eval $env
echo $env


echo "################### run test ###################"

export Count=0
IFS="|"
func_serving "${web_service_cmd}"