tensorrt_build.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. for i in "$@"; do
  3. case $i in
  4. --tensorrt_dir=*)
  5. TENSORRT_DIR="${i#*=}"
  6. shift
  7. ;;
  8. --tensorrt_header=*)
  9. TENSORRT_HEADER="${i#*=}"
  10. shift
  11. ;;
  12. --cuda_dir=*)
  13. CUDA_DIR="${i#*=}"
  14. shift
  15. ;;
  16. *)
  17. # unknown option
  18. exit 1
  19. ;;
  20. esac
  21. done
  22. if [ $TENSORRT_DIR ];then
  23. echo "TENSORRT_DIR = $TENSORRT_DIR"
  24. else
  25. echo "TENSORRT_DIR is not exist, please set by --tensorrt_dir"
  26. exit 1
  27. fi
  28. if [ $CUDA_DIR ];then
  29. echo "CUDA_DIR = $CUDA_DIR"
  30. else
  31. echo "CUDA_DIR is not exist, please set by --cuda_dir"
  32. exit 1
  33. fi
  34. if [ $TENSORRT_HEADER ];then
  35. echo " TENSORRT_HEADER= $TENSORRT_HEADER"
  36. else
  37. echo "TENSORRT_HEADER is not exist, please set by --tensorrt_header"
  38. exit 1
  39. fi
  40. # download opencv library
  41. OPENCV_DIR=$(pwd)/deps/opencv3.4.6gcc4.8ffmpeg/
  42. {
  43. bash $(pwd)/scripts/bootstrap.sh ${OPENCV_DIR} # 下载预编译版本的加密工具和opencv依赖库
  44. } || {
  45. echo "Fail to execute script/bootstrap.sh"
  46. exit -1
  47. }
  48. # download glog library
  49. GLOG_DIR=$(pwd)/deps/glog/
  50. GLOG_URL=https://bj.bcebos.com/paddlex/deploy/glog.tar.gz
  51. if [ ! -d $(pwd)deps/ ]; then
  52. mkdir -p deps
  53. fi
  54. if [ ! -d ${GLOG_DIR} ]; then
  55. cd deps
  56. wget -c ${GLOG_URL} -O glog.tar.gz
  57. tar -zxvf glog.tar.gz
  58. rm -rf glog.tar.gz
  59. cd ..
  60. fi
  61. # download gflags library
  62. GFLAGS_DIR=$(pwd)/deps/gflags/
  63. GFLAGS_URL=https://bj.bcebos.com/paddlex/deploy/gflags.tar.gz
  64. if [ ! -d ${GFLAGS_DIR} ]; then
  65. cd deps
  66. wget -c ${GFLAGS_URL} -O gflags.tar.gz
  67. tar -zxvf gflags.tar.gz
  68. rm -rf gflags.tar.gz
  69. cd ..
  70. fi
  71. # install libpng needed by opencv
  72. ldconfig -p | grep png16 > log
  73. if [ $? -ne 0 ];then
  74. apt-get install libpng16-16
  75. fi
  76. # install libjasper1 needed by opencv
  77. ldconfig -p | grep libjasper > log
  78. if [ $? -ne 0 ];then
  79. add-apt-repository > log
  80. if [ $? -ne 0 ]; then
  81. apt-get install software-properties-common
  82. fi
  83. add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
  84. apt update
  85. apt install libjasper1 libjasper-dev
  86. fi
  87. rm -rf log
  88. rm -rf build
  89. mkdir -p build
  90. cd build
  91. cmake ../demo/onnx_tensorrt/ \
  92. -DTENSORRT_DIR=${TENSORRT_DIR} \
  93. -DTENSORRT_HEADER=${TENSORRT_HEADER} \
  94. -DCUDA_DIR=${CUDA_DIR} \
  95. -DOPENCV_DIR=${OPENCV_DIR} \
  96. -DGLOG_DIR=${GLOG_DIR} \
  97. -DGFLAGS_DIR=${GFLAGS_DIR}
  98. make -j16