run.sh 7.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/bin/bash

# Copyright (c) 2021 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.

set -x
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
TENSORRT_ROOT_DIR=$5 # TensorRT ROOT dir, default to /usr/local/TensorRT
MSVC_STATIC_CRT=$6
inference_install_dir=${PADDLE_ROOT}/build/paddle_inference_install_dir
EXIT_CODE=0 # init default exit code
26
WIN_DETECT=$(echo `uname` | grep "Win") # detect current platform
27

28 29 30 31
export RED='\033[0;31m' # red color
export NC='\033[0m' # no color
export YELLOW='\033[33m' # yellow color

32 33
cd `dirname $0`
current_dir=`pwd`
34 35
build_dir=${current_dir}/build
log_dir=${current_dir}/log
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
if [ $2 == ON ]; then
  # You can export yourself if move the install path
  MKL_LIB=${inference_install_dir}/third_party/install/mklml/lib
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MKL_LIB}
fi
if [ $3 == ON ]; then
  use_gpu_list='true false'
else
  use_gpu_list='false'
fi

USE_TENSORRT=OFF
if [ -d "$TENSORRT_ROOT_DIR" ]; then
  USE_TENSORRT=ON
fi

52

53 54 55 56 57 58 59 60
function download() {
  url_prefix=$1
  model_name=$2
  mkdir -p $model_name
  cd $model_name
  if [[ -e "${model_name}.tgz" ]]; then
    echo "${model_name}.tgz has been downloaded."
  else
61 62 63 64 65 66 67
      if [ $WIN_DETECT != "" ]; then
        wget -q -Y off ${url_prefix}/${model_name}.tgz
        tar xzf *.tgz
      else
        wget -q --no-proxy ${url_prefix}/${model_name}.tgz
        tar xzf *.tgz
      fi
68 69 70 71 72 73 74 75 76 77 78 79
  fi
  cd ..
}

mkdir -p $DATA_DIR
cd $DATA_DIR
download_list='resnet50'
for model_name in $download_list; do
    url_prefix="https://paddle-inference-dist.bj.bcebos.com/Paddle-Inference-Demo"
    download $url_prefix $model_name
done

80 81 82 83 84 85 86 87 88 89 90 91
ocr_download_list='ocr_det_mv3_db'
for model_name in $ocr_download_list; do
    url_prefix="https://paddle-qa.bj.bcebos.com/inference_model/2.1.1/ocr"
    download $url_prefix $model_name
done

clas_download_list='LeViT'
for model_name in $clas_download_list; do
    url_prefix="https://paddle-qa.bj.bcebos.com/inference_model/2.1.1/class"
    download $url_prefix $model_name
done

92 93 94 95 96 97
nlp_download_list='ernie_text_cls'
for model_name in $nlp_download_list; do
    url_prefix="https://paddle-qa.bj.bcebos.com/inference_model/2.1.1/nlp"
    download $url_prefix $model_name
done

98 99 100 101 102 103
det_download_list='yolov3 ppyolo_mbv3 ppyolov2_r50vd'
for model_name in $det_download_list; do
    url_prefix="https://paddle-qa.bj.bcebos.com/inference_model/2.1.1/detection"
    download $url_prefix $model_name
done

104 105 106 107 108 109
unknown_download_list='resnet50_quant'
for model_name in $unknown_download_list; do
    url_prefix="https://paddle-qa.bj.bcebos.com/inference_model/unknown"
    download $url_prefix $model_name
done

110 111 112 113
function compile_test() {
    mkdir -p ${build_dir}
    cd ${build_dir}
    TEST_NAME=$1
114 115
    if [ $WIN_DETECT != "" ]; then
        cmake .. -G "Visual Studio 15 2017" -A x64 -T host=x64 -DPADDLE_LIB=${inference_install_dir} \
116 117 118 119 120 121
             -DWITH_MKL=$TURN_ON_MKL \
             -DDEMO_NAME=${TEST_NAME} \
             -DWITH_GPU=$TEST_GPU_CPU \
             -DWITH_STATIC_LIB=OFF \
             -DUSE_TENSORRT=$USE_TENSORRT \
             -DTENSORRT_ROOT=$TENSORRT_ROOT_DIR \
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
             -DMSVC_STATIC_CRT=$MSVC_STATIC_CRT \
             -DWITH_GTEST=ON \
             -DCMAKE_CXX_FLAGS='/std:c++17' \
             -DCMAKE_BUILD_TYPE=Release
        msbuild /maxcpucount /property:Configuration=Release ALL_BUILD.vcxproj
    else
        cmake .. -DPADDLE_LIB=${inference_install_dir} \
                 -DWITH_MKL=$TURN_ON_MKL \
                 -DDEMO_NAME=${TEST_NAME} \
                 -DWITH_GPU=$TEST_GPU_CPU \
                 -DWITH_STATIC_LIB=OFF \
                 -DUSE_TENSORRT=$USE_TENSORRT \
                 -DTENSORRT_ROOT=$TENSORRT_ROOT_DIR \
                 -DWITH_GTEST=ON
        make -j$(nproc)
    fi;
138 139 140 141
    cd -
}


142 143
# compile and run test
cd $current_dir
144 145 146
mkdir -p ${build_dir}
mkdir -p ${log_dir}
cd ${build_dir}
147 148
rm -rf *

149
# ---------tensorrt gpu tests on linux---------
150 151
if [ $USE_TENSORRT == ON -a $TEST_GPU_CPU == ON ]; then
    rm -rf *
152

153 154 155 156 157 158
    if [ $WIN_DETECT != "" ]; then
        exe_dir=${build_dir}/Release
    else
        exe_dir=${build_dir}
    fi;

159 160
    printf "${YELLOW} start test_resnet50 ${NC} \n";
    compile_test "test_resnet50"
161
    ${exe_dir}/test_resnet50 \
162
        --modeldir=$DATA_DIR/resnet50/resnet50 \
163
        --gtest_output=xml:${log_dir}/test_resnet50.xml
164
    if [ $? -ne 0 ]; then
165
        echo "test_resnet50 runs failed" >> ${exe_dir}/test_summary.txt
166 167 168
        EXIT_CODE=1
    fi

169 170
    printf "${YELLOW} start test_det_mv3_db ${NC} \n";
    compile_test "test_det_mv3_db"
171
    ${exe_dir}/test_det_mv3_db \
172
        --modeldir=$DATA_DIR/ocr_det_mv3_db/ocr_det_mv3_db \
173
        --gtest_output=xml:${log_dir}/test_det_mv3_db.xml
174
    if [ $? -ne 0 ]; then
175
        echo "test_det_mv3_db runs failed" >> ${exe_dir}/test_summary.txt
176 177 178
        EXIT_CODE=1
    fi

179 180
    printf "${YELLOW} start test_LeViT ${NC} \n";
    compile_test "test_LeViT"
181
    ${exe_dir}/test_LeViT \
182
        --modeldir=$DATA_DIR/LeViT/LeViT \
183
        --gtest_output=xml:${log_dir}/test_LeViT.xml
184
    if [ $? -ne 0 ]; then
185
        echo "test_LeViT runs failed" >> ${exe_dir}/test_summary.txt
186 187 188
        EXIT_CODE=1
    fi

189 190
    printf "${YELLOW} start test_ernie_text_cls ${NC} \n";
    compile_test "test_ernie_text_cls"
191
    ${exe_dir}/test_ernie_text_cls \
192
        --modeldir=$DATA_DIR/ernie_text_cls/ernie_text_cls \
193
        --gtest_output=xml:${log_dir}/test_ernie_text_cls.xml
194
    if [ $? -ne 0 ]; then
195
        echo "test_ernie_text_cls runs failed" >> ${exe_dir}/test_summary.txt
196 197
        EXIT_CODE=1
    fi
198 199 200

    printf "${YELLOW} start test_yolov3 ${NC} \n";
    compile_test "test_yolov3"
201
    ${exe_dir}/test_yolov3 \
202
        --modeldir=$DATA_DIR/yolov3/yolov3 \
203
        --gtest_output=xml:${log_dir}/test_yolov3.xml
204
    if [ $? -ne 0 ]; then
205
        echo "test_yolov3 runs failed" >> ${exe_dir}/test_summary.txt
206 207 208 209 210
        EXIT_CODE=1
    fi

    printf "${YELLOW} start test_ppyolo_mbv3 ${NC} \n";
    compile_test "test_ppyolo_mbv3"
211
    ${exe_dir}/test_ppyolo_mbv3 \
212
        --modeldir=$DATA_DIR/ppyolo_mbv3/ppyolo_mbv3 \
213
        --gtest_output=xml:${log_dir}/test_ppyolo_mbv3.xml
214
    if [ $? -ne 0 ]; then
215
        echo "test_ppyolo_mbv3 runs failed" >> ${exe_dir}/test_summary.txt
216 217 218 219 220
        EXIT_CODE=1
    fi

    printf "${YELLOW} start test_ppyolov2_r50vd ${NC} \n";
    compile_test "test_ppyolov2_r50vd"
221
    ${exe_dir}/test_ppyolov2_r50vd \
222
        --modeldir=$DATA_DIR/ppyolov2_r50vd/ppyolov2_r50vd \
223
        --gtest_output=xml:${log_dir}/test_ppyolov2_r50vd.xml
224
    if [ $? -ne 0 ]; then
225
        echo "test_ppyolov2_r50vd runs failed" >> ${exe_dir}/test_summary.txt
226 227 228
        EXIT_CODE=1
    fi

229 230
    printf "${YELLOW} start test_resnet50_quant ${NC} \n";
    compile_test "test_resnet50_quant"
231
    ${exe_dir}/test_resnet50_quant \
232 233 234
        --int8dir=$DATA_DIR/resnet50_quant/resnet50_quant/resnet50_quant \
        --modeldir=$DATA_DIR/resnet50/resnet50 \
        --datadir=$DATA_DIR/resnet50_quant/resnet50_quant/imagenet-eval-binary/9.data \
235
        --gtest_output=xml:${log_dir}/test_resnet50_quant.xml
236
    if [ $? -ne 0 ]; then
237
        echo "test_resnet50_quant runs failed" >> ${exe_dir}/test_summary.txt
238 239
        EXIT_CODE=1
    fi
240 241
fi

242

243
if [[ -f ${exe_dir}/test_summary.txt ]];then
244
  echo "=====================test summary======================"
245
  cat ${exe_dir}/test_summary.txt
246 247
  echo "========================================================"
fi
248 249 250 251

# tar Gtest output report
tar -zcvf infer_ut_log.tgz ${log_dir}

252 253
echo "infer_ut script finished"
exit ${EXIT_CODE}