upgrade_cv_devkits.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. DL_DIR="/tmp/_paddlers_cv_repos"
  3. MODELS_DIR="paddlers/models"
  4. IMPORT_PREFIX="paddlers.models."
  5. mkdir -p "${DL_DIR}"
  6. trap "rm -rf ${DL_DIR}" EXIT
  7. function update_apis_from_remote_repo() {
  8. local src_mod_name="$1"
  9. local repo_url="$2"
  10. local dst_mod_name="${src_mod_name}"
  11. local dl_path="${DL_DIR}/${dst_mod_name}"
  12. local src_mod_path="${dl_path}/${src_mod_name}"
  13. local dst_mod_path="${MODELS_DIR}/${dst_mod_name}"
  14. # Clone default branch
  15. git clone --depth 1 "${repo_url}" "${dl_path}"
  16. if [ -d "${src_mod_path}" ]; then
  17. if [ -d "${dst_mod_path}" ]; then
  18. echo ""
  19. read -p "${dst_mod_path} already exists. Do you want to remove it?" yes_or_no
  20. if [ "${yes_or_no}" = 'yes' ]; then
  21. rm -rf "${dst_mod_path}"
  22. else
  23. return 0
  24. fi
  25. fi
  26. else
  27. return 1
  28. fi
  29. cp -r "${src_mod_path}" "${dst_mod_path}"
  30. # Record commit id
  31. git -C "${dl_path}" rev-parse HEAD > "${dst_mod_path}/hash.txt"
  32. }
  33. function update_import_statements() {
  34. local mod_name="$1"
  35. for f in $(find "${MODELS_DIR}/${mod_name}" -type f -name '*.py'); do
  36. sed -i -E "s/^([\s]*)import ${mod_name}/\1import ${IMPORT_PREFIX}${mod_name}/g" "$f"
  37. sed -i -E "s/from ${mod_name}(.*) import/from ${IMPORT_PREFIX}${mod_name}\1 import/g" "$f"
  38. done
  39. }
  40. update_apis_from_remote_repo 'ppcls' https://github.com/PaddlePaddle/PaddleClas.git
  41. # For paddleclas, we trim the `configs` directory
  42. if [ -d "${MODELS_DIR}/ppcls/configs" ]; then
  43. rm -rf "${MODELS_DIR}/ppcls/configs"
  44. fi
  45. update_import_statements 'ppcls'
  46. update_apis_from_remote_repo 'ppdet' https://github.com/PaddlePaddle/PaddleDetection.git
  47. update_import_statements 'ppdet'
  48. update_apis_from_remote_repo 'paddleseg' https://github.com/PaddlePaddle/PaddleSeg.git
  49. update_import_statements 'paddleseg'
  50. update_apis_from_remote_repo 'ppgan' https://github.com/PaddlePaddle/PaddleGAN.git
  51. update_import_statements 'ppgan'