prepare.sh 17.3 KB
Newer Older
S
stephon 已提交
1 2 3
#!/bin/bash
FILENAME=$1

G
fix  
gaotingquan 已提交
4
# MODE be one of ['lite_train_lite_infer' 'lite_train_whole_infer' 'whole_train_whole_infer',
S
stephon 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#                 'whole_infer', 'klquant_whole_infer',
#                 'cpp_infer', 'serving_infer',  'lite_infer']

MODE=$2

dataline=$(cat ${FILENAME})
# parser params
IFS=$'\n'
lines=(${dataline})

function func_parser_key(){
    strs=$1
    IFS=":"
    array=(${strs})
    tmp=${array[0]}
    echo ${tmp}
}

function func_parser_value(){
    strs=$1
    IFS=":"
    array=(${strs})
    if [ ${#array[*]} = 2 ]; then
        echo ${array[1]}
    else
    	IFS="|"
    	tmp="${array[1]}:${array[2]}"
        echo ${tmp}
    fi
}

D
dongshuilong 已提交
36 37 38 39 40 41 42 43 44 45 46
function func_get_url_file_name(){
    strs=$1
    IFS="/"
    array=(${strs})
    tmp=${array[${#array[@]}-1]}
    echo ${tmp}
}

model_name=$(func_parser_value "${lines[1]}")

if [ ${MODE} = "cpp_infer" ];then
H
debug  
HydrogenSulfate 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    if [ -d "./deploy/cpp/opencv-3.4.7/opencv3/" ] && [ $(md5sum ./deploy/cpp/opencv-3.4.7.tar.gz | awk -F ' ' '{print $1}') = "faa2b5950f8bee3f03118e600c74746a" ];then
        echo "################### build opencv skipped ###################"
    else
        echo "################### build opencv ###################"
        rm -rf ./deploy/cpp/opencv-3.4.7.tar.gz ./deploy/cpp/opencv-3.4.7/
        pushd ./deploy/cpp/
        wget -nc https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/opencv-3.4.7.tar.gz
        tar -xf opencv-3.4.7.tar.gz

        cd opencv-3.4.7/
        install_path=$(pwd)/opencv3
        rm -rf build
        mkdir build
        cd build

        cmake .. \
                -DCMAKE_INSTALL_PREFIX=${install_path} \
                -DCMAKE_BUILD_TYPE=Release \
                -DBUILD_SHARED_LIBS=OFF \
                -DWITH_IPP=OFF \
                -DBUILD_IPP_IW=OFF \
                -DWITH_LAPACK=OFF \
                -DWITH_EIGEN=OFF \
                -DCMAKE_INSTALL_LIBDIR=lib64 \
                -DWITH_ZLIB=ON \
                -DBUILD_ZLIB=ON \
                -DWITH_JPEG=ON \
                -DBUILD_JPEG=ON \
                -DWITH_PNG=ON \
                -DBUILD_PNG=ON \
                -DWITH_TIFF=ON \
                -DBUILD_TIFF=ON

        make -j
        make install
        cd ../../
        popd
        echo "################### build opencv finished ###################"
    fi
    set_OPENCV_DIR_cmd="sed -i '1s#OPENCV_DIR=.*#OPENCV_DIR=../opencv-3.4.7/opencv3/#' './deploy/cpp/tools/build.sh'"
    eval ${set_OPENCV_DIR_cmd}
    if [ -d "./deploy/cpp/paddle_inference/" ]; then
        echo "################### build paddle inference lib skipped ###################"
    else
        pushd ./deploy/cpp/
        wget https://paddle-inference-lib.bj.bcebos.com/2.1.1-gpu-cuda10.2-cudnn8.1-mkl-gcc8.2/paddle_inference.tgz
        tar -xvf paddle_inference.tgz
        echo "################### build paddle inference lib finished ###################"
    fi
    set_LIB_DIR_cmd="sed -i '2s#LIB_DIR=.*#LIB_DIR=../paddle_inference/#' './deploy/cpp/tools/build.sh'"
    # echo ${set_LIB_DIR_cmd}
    eval ${set_LIB_DIR_cmd}
    # exit
    if [ -d "./deploy/cpp/build/" ]; then
        echo "################### build cpp inference skipped ###################"
    else
        pushd ./deploy/cpp/
        bash tools/build.sh
        popd
        echo "################### build cpp inference finished ###################"
    fi

    if [ ${model_name} == "ResNet50" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/ResNet50_infer.tar
        tar xf ResNet50_infer.tar
        cd ../../
    elif [ ${model_name} == "ResNet50_vd" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/ResNet50_vd_infer.tar
        tar xf ResNet50_vd_infer.tar
        cd ../../
    elif [ ${model_name} == "MobileNetV3_large_x1_0" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV3_large_x1_0_infer.tar
        tar xf MobileNetV3_large_x1_0_infer.tar
        cd ../../
    elif [ ${model_name} == "SwinTransformer_tiny_patch4_window7_224" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/SwinTransformer_tiny_patch4_window7_224_infer.tar
        tar xf SwinTransformer_tiny_patch4_window7_224_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x0_25" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_25_infer.tar
        tar xf PPLCNet_x0_25_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x0_35" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_35_infer.tar
        tar xf PPLCNet_x0_35_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x0_5" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_5_infer.tar
        tar xf PPLCNet_x0_5_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x0_75" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_75_infer.tar
        tar xf PPLCNet_x0_75_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x1_0" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_0_infer.tar
        tar xf PPLCNet_x1_0_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x1_5" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_5_infer.tar
        tar xf PPLCNet_x1_5_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x2_0" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_0_infer.tar
        tar xf PPLCNet_x2_0_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x2_5" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_5_infer.tar
        tar xf PPLCNet_x2_5_infer.tar
        cd ../../
    elif [ ${model_name} == "PP-ShiTu_general_rec" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar
        tar xf general_PPLCNet_x2_5_lite_v1.0_infer.tar
        cd ../../
    elif [ ${model_name} == "PP-ShiTu_mainbody_det" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
        tar xf picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNetV2_base" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNetV2_base_infer.tar
        tar xf PPLCNetV2_base_infer.tar
        cd ../../
    elif [ ${model_name} == "PPHGNet_tiny" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_tiny_infer.tar
        tar xf PPHGNet_tiny_infer.tar
        cd ../../
    elif [ ${model_name} == "PPHGNet_small" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_small_infer.tar
        tar xf PPHGNet_small_infer.tar
        cd ../../
    else
        echo "Not added into TIPC yet."
    fi
D
dongshuilong 已提交
248 249
fi

S
stephon 已提交
250 251 252 253
model_name=$(func_parser_value "${lines[1]}")
model_url_value=$(func_parser_value "${lines[35]}")
model_url_key=$(func_parser_key "${lines[35]}")

D
dongshuilong 已提交
254 255 256 257 258 259 260 261 262 263 264 265 266
if [[ $FILENAME == *GeneralRecognition* ]];then
   cd dataset
   rm -rf Aliproduct
   rm -rf train_reg_all_data.txt
   rm -rf demo_train
   wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/whole_chain/tipc_shitu_demo_data.tar
   tar -xf tipc_shitu_demo_data.tar
   ln -s tipc_shitu_demo_data Aliproduct
   ln -s tipc_shitu_demo_data/demo_train.txt train_reg_all_data.txt
   ln -s tipc_shitu_demo_data/demo_train demo_train
   cd tipc_shitu_demo_data
   ln -s demo_test.txt val_list.txt
   cd ../../
267 268
   eval "wget -nc $model_url_value"
   mv general_PPLCNet_x2_5_pretrained_v1.0.pdparams GeneralRecognition_PPLCNet_x2_5_pretrained.pdparams
D
dongshuilong 已提交
269 270 271
   exit 0
fi

L
lubin10 已提交
272 273 274 275 276
if [[ $FILENAME == *use_dali* ]];then
    python_name=$(func_parser_value "${lines[2]}")
    ${python_name} -m pip install --extra-index-url https://developer.download.nvidia.com/compute/redist/nightly --upgrade nvidia-dali-nightly-cuda102
fi

S
stephon 已提交
277 278 279 280 281 282 283
if [ ${MODE} = "lite_train_lite_infer" ] || [ ${MODE} = "lite_train_whole_infer" ];then
    # pretrain lite train data
    cd dataset
    rm -rf ILSVRC2012
    wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/whole_chain/whole_chain_little_train.tar
    tar xf whole_chain_little_train.tar
    ln -s whole_chain_little_train ILSVRC2012
G
fix  
gaotingquan 已提交
284
    cd ILSVRC2012
S
stephon 已提交
285 286
    mv train.txt train_list.txt
    mv val.txt val_list.txt
D
dongshuilong 已提交
287
    cp -r train/* val/
S
stephon 已提交
288
    cd ../../
D
dongshuilong 已提交
289
elif [ ${MODE} = "whole_infer" ] || [ ${MODE} = "klquant_whole_infer" ];then
S
stephon 已提交
290 291 292 293 294 295
    # download data
    cd dataset
    rm -rf ILSVRC2012
    wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/whole_chain/whole_chain_infer.tar
    tar xf whole_chain_infer.tar
    ln -s whole_chain_infer ILSVRC2012
G
fix  
gaotingquan 已提交
296
    cd ILSVRC2012
S
stephon 已提交
297 298 299 300 301 302 303 304 305
    mv val.txt val_list.txt
    ln -s val_list.txt train_list.txt
    cd ../../
    # download inference or pretrained model
    eval "wget -nc $model_url_value"
    if [[ $model_url_key == *inference* ]]; then
	rm -rf inference
	tar xf "${model_name}_inference.tar"
    fi
D
dongshuilong 已提交
306 307 308 309 310
    if [[ $model_name == "SwinTransformer_large_patch4_window7_224" || $model_name == "SwinTransformer_large_patch4_window12_384" ]];then
	cmd="mv ${model_name}_22kto1k_pretrained.pdparams ${model_name}_pretrained.pdparams"
	eval $cmd
    fi

S
stephon 已提交
311 312 313 314 315 316
elif [ ${MODE} = "whole_train_whole_infer" ];then
    cd dataset
    rm -rf ILSVRC2012
    wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/whole_chain/whole_chain_CIFAR100.tar
    tar xf whole_chain_CIFAR100.tar
    ln -s whole_chain_CIFAR100 ILSVRC2012
G
fix  
gaotingquan 已提交
317
    cd ILSVRC2012
S
stephon 已提交
318
    mv train.txt train_list.txt
D
dongshuilong 已提交
319
    mv test.txt val_list.txt
S
stephon 已提交
320 321 322 323 324 325 326 327 328 329 330 331 332 333
    cd ../../
fi

if [ ${MODE} = "serving_infer" ];then
    # prepare serving env
    python_name=$(func_parser_value "${lines[2]}")
    ${python_name} -m pip install install paddle-serving-server-gpu==0.6.1.post101
    ${python_name} -m pip install paddle_serving_client==0.6.1
    ${python_name} -m pip install paddle-serving-app==0.6.1
    unset http_proxy
    unset https_proxy
    cd ./deploy/paddleserving
    wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/ResNet50_vd_infer.tar && tar xf ResNet50_vd_infer.tar
fi
L
lubin10 已提交
334 335 336 337 338 339

if [ ${MODE} = "paddle2onnx_infer" ];then
    # prepare paddle2onnx env
    python_name=$(func_parser_value "${lines[2]}")
    ${python_name} -m pip install install paddle2onnx
    ${python_name} -m pip install onnxruntime
H
debug  
HydrogenSulfate 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
    if [ ${model_name} == "ResNet50" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/ResNet50_infer.tar
        tar xf ResNet50_infer.tar
        cd ../../
    elif [ ${model_name} == "ResNet50_vd" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/ResNet50_vd_infer.tar
        tar xf ResNet50_vd_infer.tar
        cd ../../
    elif [ ${model_name} == "MobileNetV3_large_x1_0" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV3_large_x1_0_infer.tar
        tar xf MobileNetV3_large_x1_0_infer.tar
        cd ../../
    elif [ ${model_name} == "SwinTransformer_tiny_patch4_window7_224" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/SwinTransformer_tiny_patch4_window7_224_infer.tar
        tar xf SwinTransformer_tiny_patch4_window7_224_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x0_25" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_25_infer.tar
        tar xf PPLCNet_x0_25_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x0_35" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_35_infer.tar
        tar xf PPLCNet_x0_35_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x0_5" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_5_infer.tar
        tar xf PPLCNet_x0_5_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x0_75" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_75_infer.tar
        tar xf PPLCNet_x0_75_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x1_0" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_0_infer.tar
        tar xf PPLCNet_x1_0_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x1_5" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_5_infer.tar
        tar xf PPLCNet_x1_5_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x2_0" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_0_infer.tar
        tar xf PPLCNet_x2_0_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNet_x2_5" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x2_5_infer.tar
        tar xf PPLCNet_x2_5_infer.tar
        cd ../../
    elif [ ${model_name} == "PP-ShiTu_general_rec" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar
        tar xf general_PPLCNet_x2_5_lite_v1.0_infer.tar
        cd ../../
    elif [ ${model_name} == "PP-ShiTu_mainbody_det" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
        tar xf picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer.tar
        cd ../../
    elif [ ${model_name} == "PPLCNetV2_base" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNetV2_base_infer.tar
        tar xf PPLCNetV2_base_infer.tar
        cd ../../
    elif [ ${model_name} == "PPHGNet_tiny" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_tiny_infer.tar
        tar xf PPHGNet_tiny_infer.tar
        cd ../../
    elif [ ${model_name} == "PPHGNet_small" ]; then
        # wget model
        cd deploy
        mkdir models
        cd models
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPHGNet_small_infer.tar
        tar xf PPHGNet_small_infer.tar
        cd ../../
    else
        echo "Not added into TIPC yet."
    fi
L
lubin10 已提交
479
fi
D
dongshuilong 已提交
480 481 482 483 484 485 486 487 488 489 490 491

if [ ${MODE} = "benchmark_train" ];then
    pip install -r requirements.txt
    cd dataset
    rm -rf ILSVRC2012
    wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/ImageNet1k/ILSVRC2012_val.tar
    tar xf ILSVRC2012_val.tar
    ln -s ILSVRC2012_val ILSVRC2012
    cd ILSVRC2012
    ln -s val_list.txt  train_list.txt
    cd ../../
fi