prepare_js.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. set -o errexit
  3. set -o nounset
  4. shopt -s extglob
  5. # paddlejs prepare 主要流程
  6. # 1. 判断 node, npm 是否安装
  7. # 2. 下载测试模型,当前检测模型是 ch_PP-OCRv2_det_infer ,识别模型是 ch_PP-OCRv2_rec_infer [1, 3, 32, 320]。如果需要替换模型,可直接将模型文件放在test_tipc/web/models/目录下。
  8. # - 文本检测模型:https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar
  9. # - 文本识别模型:https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_infer.tar
  10. # - 文本识别模型[1, 3, 32, 320]:https://paddlejs.bj.bcebos.com/models/ch_PP-OCRv2_rec_infer.tar
  11. # - 保证较为准确的识别效果,需要将文本识别模型导出为输入shape[1, 3, 32, 320]的静态模型
  12. # 3. 转换模型, model.pdmodel model.pdiparams 转换为 model.json chunk.dat(检测模型保存地址:test_tipc/web/models/ch_PP-OCRv2/det,识别模型保存地址:test_tipc/web/models/ch_PP-OCRv2/rec)
  13. # 4. 安装最新版本 ocr sdk @paddlejs-models/ocr@latest
  14. # 5. 安装测试环境依赖 puppeteer、jest、jest-puppeteer,如果检查到已经安装,则不会进行二次安装
  15. # 判断是否安装了node
  16. if ! type node >/dev/null 2>&1; then
  17. echo -e "\033[31m node 未安装 \033[0m"
  18. exit
  19. fi
  20. # 判断是否安装了npm
  21. if ! type npm >/dev/null 2>&1; then
  22. echo -e "\033[31m npm 未安装 \033[0m"
  23. exit
  24. fi
  25. # MODE be 'js_infer'
  26. MODE=$1
  27. # js_infer MODE , load model file and convert model to js_infer
  28. if [ ${MODE} != "js_infer" ];then
  29. echo "Please change mode to 'js_infer'"
  30. exit
  31. fi
  32. # saved_model_name
  33. det_saved_model_name=ch_PP-OCRv2_det_infer
  34. rec_saved_model_name=ch_PP-OCRv2_rec_infer
  35. # model_path
  36. model_path=test_tipc/web/models/
  37. rm -rf $model_path
  38. echo ${model_path}${det_saved_model_name}
  39. echo ${model_path}${rec_saved_model_name}
  40. # download ocr_det inference model
  41. wget -nc -P $model_path https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar
  42. cd $model_path && tar xf ch_PP-OCRv2_det_infer.tar && cd ../../../
  43. # download ocr_rec inference model
  44. wget -nc -P $model_path https://paddlejs.bj.bcebos.com/models/ch_PP-OCRv2_rec_infer.tar
  45. cd $model_path && tar xf ch_PP-OCRv2_rec_infer.tar && cd ../../../
  46. MYDIR=`pwd`
  47. echo $MYDIR
  48. pip3 install paddlejsconverter
  49. # convert inference model to web model: model.json、chunk.dat
  50. paddlejsconverter \
  51. --modelPath=$model_path$det_saved_model_name/inference.pdmodel \
  52. --paramPath=$model_path$det_saved_model_name/inference.pdiparams \
  53. --outputDir=$model_path$det_saved_model_name/ \
  54. paddlejsconverter \
  55. --modelPath=$model_path$rec_saved_model_name/inference.pdmodel \
  56. --paramPath=$model_path$rec_saved_model_name/inference.pdiparams \
  57. --outputDir=$model_path$rec_saved_model_name/ \
  58. # always install latest ocr sdk
  59. cd test_tipc/web
  60. echo -e "\033[33m Installing the latest ocr sdk... \033[0m"
  61. npm install @paddlejs-models/ocr@latest
  62. npm info @paddlejs-models/ocr
  63. echo -e "\033[32m The latest ocr sdk installed completely.!~ \033[0m"
  64. # install dependencies
  65. if [ `npm list --dept 0 | grep puppeteer | wc -l` -ne 0 ] && [ `npm list --dept 0 | grep jest | wc -l` -ne 0 ];then
  66. echo -e "\033[32m Dependencies have installed \033[0m"
  67. else
  68. echo -e "\033[33m Installing dependencies ... \033[0m"
  69. npm install jest jest-puppeteer puppeteer
  70. echo -e "\033[32m Dependencies installed completely.!~ \033[0m"
  71. fi
  72. # del package-lock.json
  73. rm package-lock.json