You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gen_trt_model.sh 1.8 kB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. CUR_DIR="$( cd "$(dirname $0)" >/dev/null 2>&1 ; pwd -P )"
  3. # find correct trtexec version, only works for internal ci and brainpp env setups
  4. CUDA_VERSION=$(nvcc --version | grep -o "[0-9].\.[0-9]*" | head -n 1)
  5. SEARCH_PATH=$(echo `which nvcc | xargs dirname`/../../)
  6. TRT_CANDIDATE=$(find `cd $SEARCH_PATH; pwd` -name "trtexec" | grep "bin/trtexec" | grep $CUDA_VERSION)
  7. TRT_CANDIDATE=${TRT_CANDIDATE%$'\n'*}
  8. TRT_LIB_PATH=$(readlink -f "`dirname $TRT_CANDIDATE`/../lib")
  9. MODELS_PATH=$(readlink -f "${CUR_DIR}/../model_source")
  10. # generate mge model
  11. rm -rf $MODELS_PATH/conv_demo_f32_without_data.mge
  12. python3 ${CUR_DIR}/conv_demo.py --dir $MODELS_PATH
  13. # generate caffe model with mge convert
  14. # INSTALL mgeconvert:
  15. # python3 -m pip install git+https://github.com/MegEngine/mgeconvert.git --user --install-option="--targets=caffe"
  16. rm -rf $MODELS_PATH/conv_demo.prototxt $MODELS_PATH/conv_demo.caffemodel
  17. convert mge_to_caffe -i $MODELS_PATH/conv_demo_f32_without_data.mge -c $MODELS_PATH/conv_demo.prototxt -b $MODELS_PATH/conv_demo.caffemodel
  18. # generate trt model
  19. rm -rf $MODELS_PATH/conv_demo.trt
  20. echo "WARNING: config cudnn and cublas path before run trtexec"
  21. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TRT_LIB_PATH
  22. echo $LD_LIBRARY_PATH
  23. $TRT_CANDIDATE --deploy="$MODELS_PATH/conv_demo.prototxt" --model="$MODELS_PATH/conv_demo.caffemodel" --output="conv1_Convolution" --batch=1 --saveEngine="$MODELS_PATH/conv_demo.trt"
  24. # redump trt model into mgb model
  25. rm -rf $MODELS_PATH/trt_conv_demo.pkl $MODELS_PATH/trt_conv_demo_with_data.mgb
  26. python3 $CUR_DIR/dump_trt.py $MODELS_PATH/conv_demo.trt $MODELS_PATH/trt_conv_demo.pkl --isize="1,3,4,4"
  27. $CUR_DIR/../../dump_with_testcase.py $MODELS_PATH/trt_conv_demo.pkl -o $MODELS_PATH/trt_conv_demo_with_data.mgb -d "#rand(0, 255)" --no-assert