test_lite_arm_cpp.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/bin/bash
  2. source ./common_func.sh
  3. export LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH
  4. FILENAME=$1
  5. dataline=$(cat $FILENAME)
  6. # parser params
  7. IFS=$'\n'
  8. lines=(${dataline})
  9. # parser lite inference
  10. inference_cmd=$(func_parser_value "${lines[1]}")
  11. runtime_device=$(func_parser_value "${lines[2]}")
  12. det_model_list=$(func_parser_value "${lines[3]}")
  13. rec_model_list=$(func_parser_value "${lines[4]}")
  14. cls_model_list=$(func_parser_value "${lines[5]}")
  15. cpu_threads_list=$(func_parser_value "${lines[6]}")
  16. det_batch_size_list=$(func_parser_value "${lines[7]}")
  17. rec_batch_size_list=$(func_parser_value "${lines[8]}")
  18. infer_img_dir_list=$(func_parser_value "${lines[9]}")
  19. config_dir=$(func_parser_value "${lines[10]}")
  20. rec_dict_dir=$(func_parser_value "${lines[11]}")
  21. benchmark_value=$(func_parser_value "${lines[12]}")
  22. if [[ $inference_cmd =~ "det" ]]; then
  23. lite_model_list=${det_lite_model_list}
  24. elif [[ $inference_cmd =~ "rec" ]]; then
  25. lite_model_list=(${rec_lite_model_list[*]} ${cls_lite_model_list[*]})
  26. elif [[ $inference_cmd =~ "system" ]]; then
  27. lite_model_list=(${det_lite_model_list[*]} ${rec_lite_model_list[*]} ${cls_lite_model_list[*]})
  28. else
  29. echo "inference_cmd is wrong, please check."
  30. exit 1
  31. fi
  32. LOG_PATH="./output"
  33. mkdir -p ${LOG_PATH}
  34. status_log="${LOG_PATH}/results.log"
  35. function func_test_det(){
  36. IFS='|'
  37. _script=$1
  38. _det_model=$2
  39. _log_path=$3
  40. _img_dir=$4
  41. _config=$5
  42. if [[ $_det_model =~ "slim" ]]; then
  43. precision="INT8"
  44. else
  45. precision="FP32"
  46. fi
  47. # lite inference
  48. for num_threads in ${cpu_threads_list[*]}; do
  49. for det_batchsize in ${det_batch_size_list[*]}; do
  50. _save_log_path="${_log_path}/lite_${_det_model}_runtime_device_${runtime_device}_precision_${precision}_det_batchsize_${det_batchsize}_threads_${num_threads}.log"
  51. command="${_script} ${_det_model} ${runtime_device} ${precision} ${num_threads} ${det_batchsize} ${_img_dir} ${_config} ${benchmark_value} > ${_save_log_path} 2>&1"
  52. eval ${command}
  53. status_check $? "${command}" "${status_log}"
  54. done
  55. done
  56. }
  57. function func_test_rec(){
  58. IFS='|'
  59. _script=$1
  60. _rec_model=$2
  61. _cls_model=$3
  62. _log_path=$4
  63. _img_dir=$5
  64. _config=$6
  65. _rec_dict_dir=$7
  66. if [[ $_det_model =~ "slim" ]]; then
  67. _precision="INT8"
  68. else
  69. _precision="FP32"
  70. fi
  71. # lite inference
  72. for num_threads in ${cpu_threads_list[*]}; do
  73. for rec_batchsize in ${rec_batch_size_list[*]}; do
  74. _save_log_path="${_log_path}/lite_${_rec_model}_${cls_model}_runtime_device_${runtime_device}_precision_${_precision}_rec_batchsize_${rec_batchsize}_threads_${num_threads}.log"
  75. command="${_script} ${_rec_model} ${_cls_model} ${runtime_device} ${_precision} ${num_threads} ${rec_batchsize} ${_img_dir} ${_config} ${_rec_dict_dir} ${benchmark_value} > ${_save_log_path} 2>&1"
  76. eval ${command}
  77. status_check $? "${command}" "${status_log}"
  78. done
  79. done
  80. }
  81. function func_test_system(){
  82. IFS='|'
  83. _script=$1
  84. _det_model=$2
  85. _rec_model=$3
  86. _cls_model=$4
  87. _log_path=$5
  88. _img_dir=$6
  89. _config=$7
  90. _rec_dict_dir=$8
  91. if [[ $_det_model =~ "slim" ]]; then
  92. _precision="INT8"
  93. else
  94. _precision="FP32"
  95. fi
  96. # lite inference
  97. for num_threads in ${cpu_threads_list[*]}; do
  98. for det_batchsize in ${det_batch_size_list[*]}; do
  99. for rec_batchsize in ${rec_batch_size_list[*]}; do
  100. _save_log_path="${_log_path}/lite_${_det_model}_${_rec_model}_${_cls_model}_runtime_device_${runtime_device}_precision_${_precision}_det_batchsize_${det_batchsize}_rec_batchsize_${rec_batchsize}_threads_${num_threads}.log"
  101. command="${_script} ${_det_model} ${_rec_model} ${_cls_model} ${runtime_device} ${_precision} ${num_threads} ${det_batchsize} ${_img_dir} ${_config} ${_rec_dict_dir} ${benchmark_value} > ${_save_log_path} 2>&1"
  102. eval ${command}
  103. status_check $? "${command}" "${status_log}"
  104. done
  105. done
  106. done
  107. }
  108. echo "################### run test ###################"
  109. if [[ $inference_cmd =~ "det" ]]; then
  110. IFS="|"
  111. det_model_list=(${det_model_list[*]})
  112. for i in {0..1}; do
  113. #run lite inference
  114. for img_dir in ${infer_img_dir_list[*]}; do
  115. func_test_det "${inference_cmd}" "${det_model_list[i]}_opt.nb" "${LOG_PATH}" "${img_dir}" "${config_dir}"
  116. done
  117. done
  118. elif [[ $inference_cmd =~ "rec" ]]; then
  119. IFS="|"
  120. rec_model_list=(${rec_model_list[*]})
  121. cls_model_list=(${cls_model_list[*]})
  122. for i in {0..1}; do
  123. #run lite inference
  124. for img_dir in ${infer_img_dir_list[*]}; do
  125. func_test_rec "${inference_cmd}" "${rec_model}_opt.nb" "${cls_model_list[i]}_opt.nb" "${LOG_PATH}" "${img_dir}" "${rec_dict_dir}" "${config_dir}"
  126. done
  127. done
  128. elif [[ $inference_cmd =~ "system" ]]; then
  129. IFS="|"
  130. det_model_list=(${det_model_list[*]})
  131. rec_model_list=(${rec_model_list[*]})
  132. cls_model_list=(${cls_model_list[*]})
  133. for i in {0..1}; do
  134. #run lite inference
  135. for img_dir in ${infer_img_dir_list[*]}; do
  136. func_test_system "${inference_cmd}" "${det_model_list[i]}_opt.nb" "${rec_model_list[i]}_opt.nb" "${cls_model_list[i]}_opt.nb" "${LOG_PATH}" "${img_dir}" "${config_dir}" "${rec_dict_dir}"
  137. done
  138. done
  139. fi