run.sh 7.0 KB
Newer Older
Y
Yan Chunwei 已提交
1
#!/bin/bash
W
Wilber 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

17
set -x
I
iducn 已提交
18 19 20 21
PADDLE_ROOT=$1
TURN_ON_MKL=$2 # use MKL or Openblas
TEST_GPU_CPU=$3 # test both GPU/CPU mode or only CPU mode
DATA_DIR=$4 # dataset
22 23
TENSORRT_ROOT_DIR=$5 # TensorRT root dir, default to /usr
MSVC_STATIC_CRT=$6
I
iducn 已提交
24
inference_install_dir=${PADDLE_ROOT}/build/paddle_inference_install_dir
25
WIN_DETECT=$(echo `uname` | grep "Win") # detect current platform
N
nhzlx 已提交
26

I
iducn 已提交
27 28 29
cd `dirname $0`
current_dir=`pwd`
if [ $2 == ON ]; then
30
  # You can export yourself if move the install path
I
iducn 已提交
31 32
  MKL_LIB=${inference_install_dir}/third_party/install/mklml/lib
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MKL_LIB}
33
fi
I
iducn 已提交
34
if [ $3 == ON ]; then
35
  use_gpu_list='true false'
Y
Yan Chunwei 已提交
36
else
37 38
  use_gpu_list='false'
fi
L
Luo Tao 已提交
39

N
nhzlx 已提交
40
USE_TENSORRT=OFF
41
if [ -d "$TENSORRT_ROOT_DIR" ]; then
N
nhzlx 已提交
42 43 44
  USE_TENSORRT=ON
fi

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

L
Luo Tao 已提交
48 49
# download vis_demo data
function download() {
I
iducn 已提交
50 51 52
  dir_name=$1
  mkdir -p $dir_name
  cd $dir_name
D
dzhwinter 已提交
53
  if [[ -e "${PREFIX}${dir_name}.tar.gz" ]]; then
54
    echo "${PREFIX}${dir_name}.tar.gz has been downloaded."
D
dzhwinter 已提交
55
  else
56 57 58 59 60
      if [ $WIN_DETECT != "" ]; then
        wget -q -Y off ${URL_ROOT}$dir_name.tar.gz
      else
        wget -q --no-proxy ${URL_ROOT}$dir_name.tar.gz
      fi
I
iducn 已提交
61
      tar xzf *.tar.gz
D
dzhwinter 已提交
62
  fi
I
iducn 已提交
63
  cd ..
L
Luo Tao 已提交
64
}
I
iducn 已提交
65 66
mkdir -p $DATA_DIR
cd $DATA_DIR
L
Luo Tao 已提交
67 68
vis_demo_list='se_resnext50 ocr mobilenet'
for vis_demo_name in $vis_demo_list; do
I
iducn 已提交
69
  download $vis_demo_name
L
Luo Tao 已提交
70 71
done

72 73
# download word2vec data
mkdir -p word2vec
I
iducn 已提交
74
cd word2vec
75 76 77 78
if [[ -e "word2vec.inference.model.tar.gz" ]]; then
  echo "word2vec.inference.model.tar.gz has been downloaded."
else
    wget -q http://paddle-inference-dist.bj.bcebos.com/word2vec.inference.model.tar.gz
I
iducn 已提交
79
    tar xzf *.tar.gz
80 81
fi

L
Luo Tao 已提交
82
# compile and test the demo
I
iducn 已提交
83
cd $current_dir
L
Luo Tao 已提交
84
mkdir -p build
I
iducn 已提交
85 86
cd build
rm -rf *
L
Luo Tao 已提交
87

88
for WITH_STATIC_LIB in ON OFF; do
I
iducn 已提交
89
  if [ $(echo `uname` | grep "Win") != "" ]; then
W
Wilber 已提交
90 91
    # TODO(wilber, T8T9): Do we still need to support windows gpu static library
    if [ $TEST_GPU_CPU == ON ] && [ $WITH_STATIC_LIB == ON ]; then
Z
Zhou Wei 已提交
92
      continue
W
Wilber 已提交
93
    fi
94
    # -----simple_on_word2vec on windows-----
95
    cmake .. -G "Visual Studio 15 2017" -A x64 -T host=x64 -DPADDLE_LIB=${inference_install_dir} \
I
iducn 已提交
96
      -DWITH_MKL=$TURN_ON_MKL \
97
      -DDEMO_NAME=simple_on_word2vec \
I
iducn 已提交
98 99 100
      -DWITH_GPU=$TEST_GPU_CPU \
      -DWITH_STATIC_LIB=$WITH_STATIC_LIB \
      -DMSVC_STATIC_CRT=$MSVC_STATIC_CRT
101 102 103
    msbuild  /maxcpucount /property:Configuration=Release cpp_inference_demo.sln
    for use_gpu in $use_gpu_list; do
      Release/simple_on_word2vec.exe \
I
iducn 已提交
104 105 106
        --dirname=$DATA_DIR/word2vec/word2vec.inference.model \
        --use_gpu=$use_gpu
      if [ $? -ne 0 ]; then
107 108 109 110 111 112
        echo "simple_on_word2vec demo runs fail."
        exit 1
      fi
    done

    # -----vis_demo on windows-----
I
iducn 已提交
113
    rm -rf *
114
    cmake .. -G "Visual Studio 15 2017" -A x64 -T host=x64 -DPADDLE_LIB=${inference_install_dir} \
I
iducn 已提交
115
      -DWITH_MKL=$TURN_ON_MKL \
116
      -DDEMO_NAME=vis_demo \
I
iducn 已提交
117 118 119
      -DWITH_GPU=$TEST_GPU_CPU \
      -DWITH_STATIC_LIB=$WITH_STATIC_LIB \
      -DMSVC_STATIC_CRT=$MSVC_STATIC_CRT
120 121 122 123
    msbuild  /maxcpucount /property:Configuration=Release cpp_inference_demo.sln
    for use_gpu in $use_gpu_list; do
      for vis_demo_name in $vis_demo_list; do
        Release/vis_demo.exe \
I
iducn 已提交
124 125 126 127 128
          --modeldir=$DATA_DIR/$vis_demo_name/model \
          --data=$DATA_DIR/$vis_demo_name/data.txt \
          --refer=$DATA_DIR/$vis_demo_name/result.txt \
          --use_gpu=$use_gpu
        if [ $? -ne 0 ]; then
129 130 131 132 133
          echo "vis demo $vis_demo_name runs fail."
          exit 1
        fi
      done
    done
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

    # --------tensorrt mobilenet on windows------
    if [ $USE_TENSORRT == ON -a $TEST_GPU_CPU == ON ]; then
      rm -rf *
      cmake .. -G "Visual Studio 15 2017" -A x64 -T host=x64 -DPADDLE_LIB=${inference_install_dir} \
        -DWITH_MKL=$TURN_ON_MKL \
        -DDEMO_NAME=trt_mobilenet_demo \
        -DWITH_GPU=$TEST_GPU_CPU \
        -DWITH_STATIC_LIB=$WITH_STATIC_LIB \
        -DMSVC_STATIC_CRT=$MSVC_STATIC_CRT \
        -DUSE_TENSORRT=$USE_TENSORRT \
        -DTENSORRT_ROOT=$TENSORRT_ROOT_DIR
      msbuild  /maxcpucount /property:Configuration=Release cpp_inference_demo.sln
      Release/trt_mobilenet_demo.exe \
        --modeldir=$DATA_DIR/mobilenet/model \
        --data=$DATA_DIR/mobilenet/data.txt \
        --refer=$DATA_DIR/mobilenet/result.txt 
      if [ $? -ne 0 ]; then
        echo "trt demo trt_mobilenet_demo runs fail."
        exit 1
      fi
    fi
156
  else
157
    # -----simple_on_word2vec on linux/mac-----
I
iducn 已提交
158 159 160
    rm -rf *
    cmake .. -DPADDLE_LIB=${inference_install_dir} \
      -DWITH_MKL=$TURN_ON_MKL \
161
      -DDEMO_NAME=simple_on_word2vec \
I
iducn 已提交
162 163 164 165 166
      -DWITH_GPU=$TEST_GPU_CPU \
      -DWITH_STATIC_LIB=$WITH_STATIC_LIB
    make -j$(nproc)
    word2vec_model=$DATA_DIR'/word2vec/word2vec.inference.model'
    if [ -d $word2vec_model ]; then
167 168
      for use_gpu in $use_gpu_list; do
        ./simple_on_word2vec \
I
iducn 已提交
169 170 171
          --dirname=$DATA_DIR/word2vec/word2vec.inference.model \
          --use_gpu=$use_gpu
        if [ $? -ne 0 ]; then
172 173 174 175 176 177
          echo "simple_on_word2vec demo runs fail."
          exit 1
        fi
      done
    fi
    # ---------vis_demo on linux/mac---------
I
iducn 已提交
178 179 180
    rm -rf *
    cmake .. -DPADDLE_LIB=${inference_install_dir} \
      -DWITH_MKL=$TURN_ON_MKL \
181
      -DDEMO_NAME=vis_demo \
I
iducn 已提交
182 183 184
      -DWITH_GPU=$TEST_GPU_CPU \
      -DWITH_STATIC_LIB=$WITH_STATIC_LIB
    make -j$(nproc)
185 186 187
    for use_gpu in $use_gpu_list; do
      for vis_demo_name in $vis_demo_list; do
        ./vis_demo \
I
iducn 已提交
188 189 190 191 192
          --modeldir=$DATA_DIR/$vis_demo_name/model \
          --data=$DATA_DIR/$vis_demo_name/data.txt \
          --refer=$DATA_DIR/$vis_demo_name/result.txt \
          --use_gpu=$use_gpu
        if [ $? -ne 0 ]; then
193 194 195 196 197 198
          echo "vis demo $vis_demo_name runs fail."
          exit 1
        fi
      done
    done
    # --------tensorrt mobilenet on linux/mac------
I
iducn 已提交
199 200 201 202
    if [ $USE_TENSORRT == ON -a $TEST_GPU_CPU == ON ]; then
      rm -rf *
      cmake .. -DPADDLE_LIB=${inference_install_dir} \
        -DWITH_MKL=$TURN_ON_MKL \
203
        -DDEMO_NAME=trt_mobilenet_demo \
I
iducn 已提交
204 205 206
        -DWITH_GPU=$TEST_GPU_CPU \
        -DWITH_STATIC_LIB=$WITH_STATIC_LIB \
        -DUSE_TENSORRT=$USE_TENSORRT \
207
        -DTENSORRT_ROOT=$TENSORRT_ROOT_DIR
I
iducn 已提交
208
      make -j$(nproc)
209
      ./trt_mobilenet_demo \
I
iducn 已提交
210 211 212 213
        --modeldir=$DATA_DIR/mobilenet/model \
        --data=$DATA_DIR/mobilenet/data.txt \
        --refer=$DATA_DIR/mobilenet/result.txt 
      if [ $? -ne 0 ]; then
214 215 216
        echo "trt demo trt_mobilenet_demo runs fail."
        exit 1
      fi
N
nhzlx 已提交
217
    fi
218 219
  fi
done
220
set +x