test_inference_cpp.sh 1.8 KB
Newer Older
D
dongshuilong 已提交
1 2 3
#!/bin/bash
source test_tipc/common_func.sh

H
HydrogenSulfate 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
function func_parser_key_cpp(){
    strs=$1
    IFS=" "
    array=(${strs})
    tmp=${array[0]}
    echo ${tmp}
}

function func_parser_value_cpp(){
    strs=$1
    IFS=":"
    array=(${strs})
    tmp=${array[1]}
    echo ${tmp}
}

D
dongshuilong 已提交
20
FILENAME=$1
H
HydrogenSulfate 已提交
21 22 23

dataline=$(cat ${FILENAME})
lines=(${dataline})
D
dongshuilong 已提交
24 25

# parser params
H
HydrogenSulfate 已提交
26
dataline=$(awk 'NR==1, NR==14{print}'  $FILENAME)
D
dongshuilong 已提交
27 28 29
IFS=$'\n'
lines=(${dataline})

H
HydrogenSulfate 已提交
30 31 32 33 34
# parser load config
model_name=$(func_parser_value_cpp "${lines[1]}")
use_gpu_key=$(func_parser_key_cpp "${lines[2]}")
use_gpu_value=$(func_parser_value_cpp "${lines[2]}")
LOG_PATH="./test_tipc/output/${model_name}/infer_cpp"
D
dongshuilong 已提交
35
mkdir -p ${LOG_PATH}
H
HydrogenSulfate 已提交
36
status_log="${LOG_PATH}/results_infer_cpp.log"
D
dongshuilong 已提交
37

H
HydrogenSulfate 已提交
38 39 40 41
line_inference_model_dir=3
line_use_gpu=5
function func_infer_cpp(){
    # inference cpp
D
dongshuilong 已提交
42
    IFS='|'
H
HydrogenSulfate 已提交
43 44 45
    for use_gpu in ${use_gpu_value[*]}; do
        if [[ ${use_gpu} = "True" ]]; then
            _save_log_path="${LOG_PATH}/infer_cpp_use_gpu.log"
D
dongshuilong 已提交
46
        else
H
HydrogenSulfate 已提交
47
            _save_log_path="${LOG_PATH}/infer_cpp_use_cpu.log"
D
dongshuilong 已提交
48
        fi
H
HydrogenSulfate 已提交
49 50 51 52 53 54 55 56 57 58 59
        # run infer cpp
        inference_cpp_cmd="./deploy/cpp/build/clas_system"
        inference_cpp_cfg="./deploy/configs/inference_cls.yaml"
        set_model_name_cmd="sed -i '${line_inference_model_dir}s#: .*#: ./deploy/models/${model_name}_infer#' '${inference_cpp_cfg}'"
        set_use_gpu_cmd="sed -i '${line_use_gpu}s#: .*#: ${use_gpu}#' '${inference_cpp_cfg}'"
        eval $set_model_name_cmd
        eval $set_use_gpu_cmd
        infer_cpp_full_cmd="${inference_cpp_cmd} -c ${inference_cpp_cfg} > ${_save_log_path} 2>&1 "
        eval $infer_cpp_full_cmd
        last_status=${PIPESTATUS[0]}
        status_check $last_status "${infer_cpp_full_cmd}" "${status_log}"  "${model_name}"
D
dongshuilong 已提交
60 61 62
    done
}

H
HydrogenSulfate 已提交
63
echo "################### run test cpp inference ###################"
64

H
HydrogenSulfate 已提交
65
func_infer_cpp