test_paddle2onnx.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/bin/bash
  2. source test_tipc/common_func.sh
  3. FILENAME=$1
  4. dataline=$(cat ${FILENAME})
  5. lines=(${dataline})
  6. # common params
  7. model_name=$(func_parser_value "${lines[1]}")
  8. python=$(func_parser_value "${lines[2]}")
  9. # parser params
  10. dataline=$(awk 'NR==1, NR==17{print}' $FILENAME)
  11. IFS=$'\n'
  12. lines=(${dataline})
  13. # parser paddle2onnx
  14. model_name=$(func_parser_value "${lines[1]}")
  15. python=$(func_parser_value "${lines[2]}")
  16. padlle2onnx_cmd=$(func_parser_value "${lines[3]}")
  17. det_infer_model_dir_key=$(func_parser_key "${lines[4]}")
  18. det_infer_model_dir_value=$(func_parser_value "${lines[4]}")
  19. model_filename_key=$(func_parser_key "${lines[5]}")
  20. model_filename_value=$(func_parser_value "${lines[5]}")
  21. params_filename_key=$(func_parser_key "${lines[6]}")
  22. params_filename_value=$(func_parser_value "${lines[6]}")
  23. det_save_file_key=$(func_parser_key "${lines[7]}")
  24. det_save_file_value=$(func_parser_value "${lines[7]}")
  25. rec_infer_model_dir_key=$(func_parser_key "${lines[8]}")
  26. rec_infer_model_dir_value=$(func_parser_value "${lines[8]}")
  27. rec_save_file_key=$(func_parser_key "${lines[9]}")
  28. rec_save_file_value=$(func_parser_value "${lines[9]}")
  29. opset_version_key=$(func_parser_key "${lines[10]}")
  30. opset_version_value=$(func_parser_value "${lines[10]}")
  31. enable_onnx_checker_key=$(func_parser_key "${lines[11]}")
  32. enable_onnx_checker_value=$(func_parser_value "${lines[11]}")
  33. # parser onnx inference
  34. inference_py=$(func_parser_value "${lines[12]}")
  35. use_gpu_key=$(func_parser_key "${lines[13]}")
  36. use_gpu_list=$(func_parser_value "${lines[13]}")
  37. det_model_key=$(func_parser_key "${lines[14]}")
  38. rec_model_key=$(func_parser_key "${lines[15]}")
  39. image_dir_key=$(func_parser_key "${lines[16]}")
  40. image_dir_value=$(func_parser_value "${lines[16]}")
  41. LOG_PATH="./test_tipc/output/${model_name}/paddle2onnx"
  42. mkdir -p ${LOG_PATH}
  43. status_log="${LOG_PATH}/results_paddle2onnx.log"
  44. function func_paddle2onnx(){
  45. IFS='|'
  46. _script=$1
  47. # paddle2onnx
  48. 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
  49. # trans det
  50. set_dirname=$(func_set_params "--model_dir" "${det_infer_model_dir_value}")
  51. set_model_filename=$(func_set_params "${model_filename_key}" "${model_filename_value}")
  52. set_params_filename=$(func_set_params "${params_filename_key}" "${params_filename_value}")
  53. set_save_model=$(func_set_params "--save_file" "${det_save_file_value}")
  54. set_opset_version=$(func_set_params "${opset_version_key}" "${opset_version_value}")
  55. set_enable_onnx_checker=$(func_set_params "${enable_onnx_checker_key}" "${enable_onnx_checker_value}")
  56. trans_det_log="${LOG_PATH}/trans_model_det.log"
  57. trans_model_cmd="${padlle2onnx_cmd} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_save_model} ${set_opset_version} ${set_enable_onnx_checker} --enable_dev_version=False > ${trans_det_log} 2>&1 "
  58. eval $trans_model_cmd
  59. last_status=${PIPESTATUS[0]}
  60. status_check $last_status "${trans_model_cmd}" "${status_log}" "${model_name}" "${trans_det_log}"
  61. # trans rec
  62. set_dirname=$(func_set_params "--model_dir" "${rec_infer_model_dir_value}")
  63. set_model_filename=$(func_set_params "${model_filename_key}" "${model_filename_value}")
  64. set_params_filename=$(func_set_params "${params_filename_key}" "${params_filename_value}")
  65. set_save_model=$(func_set_params "--save_file" "${rec_save_file_value}")
  66. set_opset_version=$(func_set_params "${opset_version_key}" "${opset_version_value}")
  67. set_enable_onnx_checker=$(func_set_params "${enable_onnx_checker_key}" "${enable_onnx_checker_value}")
  68. trans_rec_log="${LOG_PATH}/trans_model_rec.log"
  69. trans_model_cmd="${padlle2onnx_cmd} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_save_model} ${set_opset_version} ${set_enable_onnx_checker} --enable_dev_version=False > ${trans_rec_log} 2>&1 "
  70. eval $trans_model_cmd
  71. last_status=${PIPESTATUS[0]}
  72. status_check $last_status "${trans_model_cmd}" "${status_log}" "${model_name}" "${trans_rec_log}"
  73. elif [[ ${model_name} =~ "det" ]]; then
  74. # trans det
  75. set_dirname=$(func_set_params "--model_dir" "${det_infer_model_dir_value}")
  76. set_model_filename=$(func_set_params "${model_filename_key}" "${model_filename_value}")
  77. set_params_filename=$(func_set_params "${params_filename_key}" "${params_filename_value}")
  78. set_save_model=$(func_set_params "--save_file" "${det_save_file_value}")
  79. set_opset_version=$(func_set_params "${opset_version_key}" "${opset_version_value}")
  80. set_enable_onnx_checker=$(func_set_params "${enable_onnx_checker_key}" "${enable_onnx_checker_value}")
  81. trans_det_log="${LOG_PATH}/trans_model_det.log"
  82. trans_model_cmd="${padlle2onnx_cmd} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_save_model} ${set_opset_version} ${set_enable_onnx_checker} --enable_dev_version=False > ${trans_det_log} 2>&1 "
  83. eval $trans_model_cmd
  84. last_status=${PIPESTATUS[0]}
  85. status_check $last_status "${trans_model_cmd}" "${status_log}" "${model_name}" "${trans_det_log}"
  86. elif [[ ${model_name} =~ "rec" ]]; then
  87. # trans rec
  88. set_dirname=$(func_set_params "--model_dir" "${rec_infer_model_dir_value}")
  89. set_model_filename=$(func_set_params "${model_filename_key}" "${model_filename_value}")
  90. set_params_filename=$(func_set_params "${params_filename_key}" "${params_filename_value}")
  91. set_save_model=$(func_set_params "--save_file" "${rec_save_file_value}")
  92. set_opset_version=$(func_set_params "${opset_version_key}" "${opset_version_value}")
  93. set_enable_onnx_checker=$(func_set_params "${enable_onnx_checker_key}" "${enable_onnx_checker_value}")
  94. trans_rec_log="${LOG_PATH}/trans_model_rec.log"
  95. trans_model_cmd="${padlle2onnx_cmd} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_save_model} ${set_opset_version} ${set_enable_onnx_checker} --enable_dev_version=False > ${trans_rec_log} 2>&1 "
  96. eval $trans_model_cmd
  97. last_status=${PIPESTATUS[0]}
  98. status_check $last_status "${trans_model_cmd}" "${status_log}" "${model_name}" "${trans_rec_log}"
  99. elif [ ${model_name} = "slanet" ] || [ ${model_name} = "en_table_structure" ]; then
  100. # trans det
  101. set_dirname=$(func_set_params "--model_dir" "${det_infer_model_dir_value}")
  102. set_model_filename=$(func_set_params "${model_filename_key}" "${model_filename_value}")
  103. set_params_filename=$(func_set_params "${params_filename_key}" "${params_filename_value}")
  104. set_save_model=$(func_set_params "--save_file" "${det_save_file_value}")
  105. set_opset_version=$(func_set_params "${opset_version_key}" "${opset_version_value}")
  106. set_enable_onnx_checker=$(func_set_params "${enable_onnx_checker_key}" "${enable_onnx_checker_value}")
  107. trans_det_log="${LOG_PATH}/trans_model_det.log"
  108. trans_model_cmd="${padlle2onnx_cmd} ${set_dirname} ${set_model_filename} ${set_params_filename} ${set_save_model} ${set_opset_version} ${set_enable_onnx_checker} --enable_dev_version=True > ${trans_det_log} 2>&1 "
  109. eval $trans_model_cmd
  110. last_status=${PIPESTATUS[0]}
  111. status_check $last_status "${trans_model_cmd}" "${status_log}" "${model_name}" "${trans_det_log}"
  112. fi
  113. # python inference
  114. for use_gpu in ${use_gpu_list[*]}; do
  115. if [ ${use_gpu} = "False" ] || [ ${use_gpu} = "cpu" ]; then
  116. _save_log_path="${LOG_PATH}/paddle2onnx_infer_cpu.log"
  117. set_gpu=$(func_set_params "${use_gpu_key}" "${use_gpu}")
  118. set_img_dir=$(func_set_params "${image_dir_key}" "${image_dir_value}")
  119. 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
  120. set_det_model_dir=$(func_set_params "${det_model_key}" "${det_save_file_value}")
  121. set_rec_model_dir=$(func_set_params "${rec_model_key}" "${rec_save_file_value}")
  122. infer_model_cmd="${python} ${inference_py} ${set_gpu} ${set_img_dir} ${set_det_model_dir} ${set_rec_model_dir} --use_onnx=True > ${_save_log_path} 2>&1 "
  123. elif [[ ${model_name} =~ "det" ]] || [ ${model_name} = "slanet" ] || [ ${model_name} = "en_table_structure" ]; then
  124. set_det_model_dir=$(func_set_params "${det_model_key}" "${det_save_file_value}")
  125. infer_model_cmd="${python} ${inference_py} ${set_gpu} ${set_img_dir} ${set_det_model_dir} --use_onnx=True > ${_save_log_path} 2>&1 "
  126. elif [[ ${model_name} =~ "rec" ]]; then
  127. set_rec_model_dir=$(func_set_params "${rec_model_key}" "${rec_save_file_value}")
  128. infer_model_cmd="${python} ${inference_py} ${set_gpu} ${set_img_dir} ${set_rec_model_dir} --use_onnx=True > ${_save_log_path} 2>&1 "
  129. fi
  130. eval $infer_model_cmd
  131. last_status=${PIPESTATUS[0]}
  132. eval "cat ${_save_log_path}"
  133. status_check $last_status "${infer_model_cmd}" "${status_log}" "${model_name}" "${_save_log_path}"
  134. elif [ ${use_gpu} = "True" ] || [ ${use_gpu} = "gpu" ]; then
  135. _save_log_path="${LOG_PATH}/paddle2onnx_infer_gpu.log"
  136. set_gpu=$(func_set_params "${use_gpu_key}" "${use_gpu}")
  137. set_img_dir=$(func_set_params "${image_dir_key}" "${image_dir_value}")
  138. 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
  139. set_det_model_dir=$(func_set_params "${det_model_key}" "${det_save_file_value}")
  140. set_rec_model_dir=$(func_set_params "${rec_model_key}" "${rec_save_file_value}")
  141. infer_model_cmd="${python} ${inference_py} ${set_gpu} ${set_img_dir} ${set_det_model_dir} ${set_rec_model_dir} --use_onnx=True > ${_save_log_path} 2>&1 "
  142. elif [[ ${model_name} =~ "det" ]]|| [ ${model_name} = "slanet" ] || [ ${model_name} = "en_table_structure" ]; then
  143. set_det_model_dir=$(func_set_params "${det_model_key}" "${det_save_file_value}")
  144. infer_model_cmd="${python} ${inference_py} ${set_gpu} ${set_img_dir} ${set_det_model_dir} --use_onnx=True > ${_save_log_path} 2>&1 "
  145. elif [[ ${model_name} =~ "rec" ]]; then
  146. set_rec_model_dir=$(func_set_params "${rec_model_key}" "${rec_save_file_value}")
  147. infer_model_cmd="${python} ${inference_py} ${set_gpu} ${set_img_dir} ${set_rec_model_dir} --use_onnx=True > ${_save_log_path} 2>&1 "
  148. fi
  149. eval $infer_model_cmd
  150. last_status=${PIPESTATUS[0]}
  151. eval "cat ${_save_log_path}"
  152. status_check $last_status "${infer_model_cmd}" "${status_log}" "${model_name}" "${_save_log_path}"
  153. else
  154. echo "Does not support hardware other than CPU and GPU Currently!"
  155. fi
  156. done
  157. }
  158. echo "################### run test ###################"
  159. export Count=0
  160. IFS="|"
  161. func_paddle2onnx