run.sh 3.4 KB
Newer Older
Y
Yan Chunwei 已提交
1
#!/bin/bash
2 3
set -x
PADDLE_ROOT=$1
L
Luo Tao 已提交
4 5
TURN_ON_MKL=$2 # use MKL or Openblas
TEST_GPU_CPU=$3 # test both GPU/CPU mode or only CPU mode
T
Tao Luo 已提交
6
DATA_DIR=$4 # dataset
N
nhzlx 已提交
7 8
TENSORRT_INCLUDE_DIR=$5 # TensorRT header file dir, defalut to /usr/local/TensorRT/include
TENSORRT_LIB_DIR=$6 # TensorRT lib file dir, default to /usr/local/TensorRT/lib
9
inference_install_dir=${PADDLE_ROOT}/build/fluid_inference_install_dir
N
nhzlx 已提交
10

T
Tao Luo 已提交
11 12
cd `dirname $0`
current_dir=`pwd`
13 14
if [ $2 == ON ]; then
  # You can export yourself if move the install path
15
  MKL_LIB=${inference_install_dir}/third_party/install/mklml/lib
16 17 18
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MKL_LIB}
fi
if [ $3 == ON ]; then
19
  use_gpu_list='true false'
Y
Yan Chunwei 已提交
20
else
21 22
  use_gpu_list='false'
fi
L
Luo Tao 已提交
23

N
nhzlx 已提交
24
USE_TENSORRT=OFF
N
nhzlx 已提交
25
if [ -d "$TENSORRT_INCLUDE_DIR" -a -d "$TENSORRT_LIB_DIR" ]; then
N
nhzlx 已提交
26 27 28
  USE_TENSORRT=ON
fi

D
dzhwinter 已提交
29
PREFIX=inference-vis-demos%2F
30
URL_ROOT=http://paddlemodels.bj.bcebos.com/${PREFIX}
D
dzhwinter 已提交
31

L
Luo Tao 已提交
32 33 34 35 36
# download vis_demo data
function download() {
  dir_name=$1
  mkdir -p $dir_name
  cd $dir_name
D
dzhwinter 已提交
37 38 39 40 41 42
  if [[ -e "${PREFIX}${dir_name}.tar.gz" ]]; then
    echo "${PREFIX}{dir_name}.tar.gz has been downloaded."
  else
      wget -q ${URL_ROOT}$dir_name.tar.gz
      tar xzf *.tar.gz
  fi
L
Luo Tao 已提交
43 44
  cd ..
}
T
Tao Luo 已提交
45 46
mkdir -p $DATA_DIR
cd $DATA_DIR
L
Luo Tao 已提交
47 48 49 50 51 52
vis_demo_list='se_resnext50 ocr mobilenet'
for vis_demo_name in $vis_demo_list; do
  download $vis_demo_name
done

# compile and test the demo
T
Tao Luo 已提交
53
cd $current_dir
L
Luo Tao 已提交
54 55 56
mkdir -p build
cd build

57
for WITH_STATIC_LIB in ON OFF; do
S
update  
superjomn 已提交
58 59 60
# TODO(Superjomn) reopen this
# something wrong with the TensorArray reset.
:<<D
L
Luo Tao 已提交
61
  # -----simple_on_word2vec-----
L
Luo Tao 已提交
62
  rm -rf *
63
  cmake .. -DPADDLE_LIB=${inference_install_dir} \
L
Luo Tao 已提交
64
    -DWITH_MKL=$TURN_ON_MKL \
L
Luo Tao 已提交
65
    -DDEMO_NAME=simple_on_word2vec \
L
Luo Tao 已提交
66
    -DWITH_GPU=$TEST_GPU_CPU \
T
Tao Luo 已提交
67
    -DWITH_STATIC_LIB=$WITH_STATIC_LIB
68
  make -j
69
  word2vec_model=$DATA_DIR'/word2vec/word2vec.inference.model'
70 71 72 73 74 75 76 77 78 79 80
  if [ -d $word2vec_model ]; then
    for use_gpu in $use_gpu_list; do
      ./simple_on_word2vec \
        --dirname=$word2vec_model \
        --use_gpu=$use_gpu
      if [ $? -ne 0 ]; then
        echo "simple_on_word2vec demo runs fail."
        exit 1
      fi
    done
  fi
S
update  
superjomn 已提交
81
D
L
Luo Tao 已提交
82 83
  # ---------vis_demo---------
  rm -rf *
84
  cmake .. -DPADDLE_LIB=${inference_install_dir} \
L
Luo Tao 已提交
85 86 87
    -DWITH_MKL=$TURN_ON_MKL \
    -DDEMO_NAME=vis_demo \
    -DWITH_GPU=$TEST_GPU_CPU \
T
Tao Luo 已提交
88
    -DWITH_STATIC_LIB=$WITH_STATIC_LIB
L
Luo Tao 已提交
89
  make -j
90
  for use_gpu in $use_gpu_list; do
Y
Yan Chunwei 已提交
91
    for vis_demo_name in $vis_demo_list; do
L
Luo Tao 已提交
92
      ./vis_demo \
T
Tao Luo 已提交
93 94 95
        --modeldir=$DATA_DIR/$vis_demo_name/model \
        --data=$DATA_DIR/$vis_demo_name/data.txt \
        --refer=$DATA_DIR/$vis_demo_name/result.txt \
L
Luo Tao 已提交
96 97 98 99 100 101 102
        --use_gpu=$use_gpu
      if [ $? -ne 0 ]; then
        echo "vis demo $vis_demo_name runs fail."
        exit 1
      fi
    done
  done
Y
Yan Chunwei 已提交
103

N
nhzlx 已提交
104 105 106
  # --------tensorrt mobilenet------
  if [ $USE_TENSORRT == ON -a $TEST_GPU_CPU == ON ]; then
    rm -rf *
107
    cmake .. -DPADDLE_LIB=${inference_install_dir} \
N
nhzlx 已提交
108
      -DWITH_MKL=$TURN_ON_MKL \
N
nhzlx 已提交
109
      -DDEMO_NAME=trt_mobilenet_demo \
N
nhzlx 已提交
110 111 112 113
      -DWITH_GPU=$TEST_GPU_CPU \
      -DWITH_STATIC_LIB=$WITH_STATIC_LIB \
      -DUSE_TENSORRT=$USE_TENSORRT \
      -DTENSORRT_INCLUDE_DIR=$TENSORRT_INCLUDE_DIR \
T
Tao Luo 已提交
114
      -DTENSORRT_LIB_DIR=$TENSORRT_LIB_DIR
Y
Yan Chunwei 已提交
115
    make -j
N
nhzlx 已提交
116
    ./trt_mobilenet_demo \
N
nhzlx 已提交
117 118
      --modeldir=$DATA_DIR/mobilenet/model \
      --data=$DATA_DIR/mobilenet/data.txt \
N
nhzlx 已提交
119
      --refer=$DATA_DIR/mobilenet/result.txt 
N
nhzlx 已提交
120 121 122 123
    if [ $? -ne 0 ]; then
      echo "trt demo trt_mobilenet_demo runs fail."
      exit 1
    fi
N
nhzlx 已提交
124
  fi
125 126
done
set +x