export_weights.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. ##
  3. # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. # # Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # # Redistributions in binary form must reproduce the above copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution.
  12. # # Neither the name of the NVIDIA CORPORATION nor the
  13. # names of its contributors may be used to endorse or promote products
  14. # derived from this software without specific prior written permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. # DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
  20. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. #
  27. NVIDIA_VISIBLE_DEVICES="${NVIDIA_VISIBLE_DEVICES:-0}"
  28. DOCKER_FILE="$(realpath Dockerfile.export_weights)"
  29. IMAGE_NAME="trt-tacotron2-waveglow.weight_export"
  30. CONTAINER_NAME="trt-tacotron2-waveglow.weight_export.container"
  31. die() {
  32. echo "ERROR: ${@}" 1>&2
  33. exit 1
  34. }
  35. die_and_remove_image() {
  36. #docker rmi "${IMAGE_NAME}"
  37. die "${@}"
  38. }
  39. if [[ "${#}" != 3 ]]; then
  40. echo "Invalid arguments: ${@}"
  41. echo "USAGE:"
  42. echo " ${0} <tacotron2 checkpoint> <waveglow checkpoint> <output directory>"
  43. exit 1
  44. fi
  45. TACOTRON2_PT="${1}"
  46. WAVEGLOW_PT="${2}"
  47. MODEL_DIR="$(realpath ${3})"
  48. TACOTRON2_DIR="$(dirname $(realpath ${TACOTRON2_PT}))"
  49. TACOTRON2_NAME="$(basename ${TACOTRON2_PT})"
  50. WAVEGLOW_DIR="$(dirname $(realpath ${WAVEGLOW_PT}))"
  51. WAVEGLOW_NAME="$(basename ${WAVEGLOW_PT})"
  52. DLE_DIR="../"
  53. # remove docker container if it exists
  54. docker rm "${CONTAINER_NAME}" &> /dev/null
  55. pushd "${DLE_DIR}"
  56. docker build . -f "${DOCKER_FILE}" -t "${IMAGE_NAME}" || die "Failed to build container"
  57. # export taoctron2
  58. nvidia-docker run \
  59. --rm \
  60. -e "NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES}" \
  61. --name "${CONTAINER_NAME}" \
  62. -v "${TACOTRON2_DIR}:/checkpoints" \
  63. -v "${MODEL_DIR}:/models" \
  64. "${IMAGE_NAME}" "./scripts/tacotron2_to_json.py \"/checkpoints/${TACOTRON2_NAME}\" /models/tacotron2.json" || \
  65. die_and_remove_image "Failed to export tacotron2."
  66. # export waveglow
  67. nvidia-docker run \
  68. --rm \
  69. -e "NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES}" \
  70. --name "${CONTAINER_NAME}" \
  71. -v "${WAVEGLOW_DIR}:/checkpoints" \
  72. -v "${MODEL_DIR}:/models" \
  73. "${IMAGE_NAME}" \
  74. "./scripts/waveglow_to_onnx.py -W \"${DLE_DIR}\" -w \"/checkpoints/${WAVEGLOW_NAME}\" -o /models/waveglow.onnx" || \
  75. die_and_remove_image "Failed to export waveglow."
  76. # export denoiser
  77. nvidia-docker run \
  78. --rm \
  79. -e "NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES}" \
  80. --name "${CONTAINER_NAME}" \
  81. -v "${WAVEGLOW_DIR}:/checkpoints" \
  82. -v "${MODEL_DIR}:/models" \
  83. "${IMAGE_NAME}" \
  84. "./scripts/denoiser_to_json.py \"${DLE_DIR}\" \"/checkpoints/${WAVEGLOW_NAME}\" /models/denoiser.json" || \
  85. die_and_remove_image "Failed to export the denoiser."
  86. docker rmi "${IMAGE_NAME}"