prepare.sh 13.7 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',
H
HydrogenSulfate 已提交
5
#                 'whole_infer', 'cpp_infer', 'serving_infer',  'lite_infer']
S
stephon 已提交
6 7 8 9 10 11 12 13

MODE=$2

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

H
debug  
HydrogenSulfate 已提交
14
function func_parser_key() {
S
stephon 已提交
15 16 17 18 19 20 21
    strs=$1
    IFS=":"
    array=(${strs})
    tmp=${array[0]}
    echo ${tmp}
}

H
debug  
HydrogenSulfate 已提交
22
function func_parser_value() {
S
stephon 已提交
23 24 25 26 27 28
    strs=$1
    IFS=":"
    array=(${strs})
    if [ ${#array[*]} = 2 ]; then
        echo ${array[1]}
    else
H
debug  
HydrogenSulfate 已提交
29 30
        IFS="|"
        tmp="${array[1]}:${array[2]}"
S
stephon 已提交
31 32 33 34
        echo ${tmp}
    fi
}

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

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

G
gaotingquan 已提交
45
# install paddleclas whl
46
python setup.py install
G
gaotingquan 已提交
47

H
HydrogenSulfate 已提交
48
if [[ ${MODE} = "cpp_infer" ]]; then
H
debug  
HydrogenSulfate 已提交
49
    if [ -d "./deploy/cpp/opencv-3.4.7/opencv3/" ] && [ $(md5sum ./deploy/cpp/opencv-3.4.7.tar.gz | awk -F ' ' '{print $1}') = "faa2b5950f8bee3f03118e600c74746a" ]; then
H
debug  
HydrogenSulfate 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
        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 .. \
H
debug  
HydrogenSulfate 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
        -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
H
debug  
HydrogenSulfate 已提交
81 82 83 84 85 86 87

        make -j
        make install
        cd ../../
        popd
        echo "################### build opencv finished ###################"
    fi
88 89
    if [[ ! -d "./deploy/cpp/paddle_inference/" ]]; then
        pushd ./deploy/cpp/
90
        PADDLEInfer=$3
91
        if [ "" = "$PADDLEInfer" ]; then
92
            wget -nc https://paddle-inference-lib.bj.bcebos.com/2.2.2/cxx_c/Linux/GPU/x86-64_gcc8.2_avx_mkl_cuda10.1_cudnn7.6.5_trt6.0.1.5/paddle_inference.tgz --no-check-certificate
93
            tar xf paddle_inference.tgz
94 95
        else
            wget -nc ${PADDLEInfer} --no-check-certificate
96 97 98
            tar_name=$(func_get_url_file_name "$PADDLEInfer")
            tar xf ${tar_name}
            if [ ! -d "paddle_inference" ]; then
99
                ln -s paddle_inference_install_dir paddle_inference
100
            fi
101
        fi
102 103
        popd
    fi
H
debug  
HydrogenSulfate 已提交
104 105 106 107 108 109 110 111 112
    if [[ $FILENAME == *infer_cpp_linux_gpu_cpu.txt ]]; then
        cpp_type=$(func_parser_value "${lines[2]}")
        cls_inference_model_dir=$(func_parser_value "${lines[3]}")
        det_inference_model_dir=$(func_parser_value "${lines[4]}")
        cls_inference_url=$(func_parser_value "${lines[5]}")
        det_inference_url=$(func_parser_value "${lines[6]}")

        if [[ $cpp_type == "cls" ]]; then
            eval "wget -nc $cls_inference_url"
H
HydrogenSulfate 已提交
113 114 115
            tar_name=$(func_get_url_file_name "$cls_inference_url")
            model_dir=${tar_name%.*}
            eval "tar xf ${tar_name}"
H
debug  
HydrogenSulfate 已提交
116

H
debug  
HydrogenSulfate 已提交
117 118 119 120 121 122 123 124
            # move '_int8' suffix in pact models
            if [[ ${tar_name} =~ "pact_infer" ]]; then
                cd ${cls_inference_model_dir}
                mv inference_int8.pdiparams inference.pdiparams
                mv inference_int8.pdmodel inference.pdmodel
                cd ..
            fi

H
debug  
HydrogenSulfate 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
            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
            cd ..
        elif [[ $cpp_type == "shitu" ]]; then
            eval "wget -nc $cls_inference_url"
            tar_name=$(func_get_url_file_name "$cls_inference_url")
            model_dir=${tar_name%.*}
            eval "tar xf ${tar_name}"

            eval "wget -nc $det_inference_url"
            tar_name=$(func_get_url_file_name "$det_inference_url")
            model_dir=${tar_name%.*}
            eval "tar xf ${tar_name}"
H
debug  
HydrogenSulfate 已提交
141

H
debug  
HydrogenSulfate 已提交
142 143 144
            cd dataset
            wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v1.0.tar
            tar -xf drink_dataset_v1.0.tar
145 146
            wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v2.0.tar
            tar -xf drink_dataset_v2.0.tar
H
debug  
HydrogenSulfate 已提交
147 148 149 150
        else
            echo "Wrong cpp type in config file in line 3. only support cls, shitu"
        fi
        exit 0
H
debug  
HydrogenSulfate 已提交
151
    else
H
debug  
HydrogenSulfate 已提交
152 153
        echo "use wrong config file"
        exit 1
H
debug  
HydrogenSulfate 已提交
154
    fi
D
dongshuilong 已提交
155 156
fi

S
stephon 已提交
157 158 159 160
model_name=$(func_parser_value "${lines[1]}")
model_url_value=$(func_parser_value "${lines[35]}")
model_url_key=$(func_parser_key "${lines[35]}")

161
if [[ $model_name == *ShiTu* ]]; then
H
debug  
HydrogenSulfate 已提交
162 163 164 165
    cd dataset
    rm -rf Aliproduct
    rm -rf train_reg_all_data.txt
    rm -rf demo_train
H
debug  
HydrogenSulfate 已提交
166
    wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/whole_chain/tipc_shitu_demo_data.tar --no-check-certificate
H
debug  
HydrogenSulfate 已提交
167 168 169 170 171 172 173
    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 ../../
H
debug  
HydrogenSulfate 已提交
174
    eval "wget -nc $model_url_value --no-check-certificate"
175 176 177
    if [[ -d "./general_PPLCNet_x2_5_pretrained_v1.0.pdparams" ]]; then
        mv general_PPLCNet_x2_5_pretrained_v1.0.pdparams GeneralRecognition_PPLCNet_x2_5_pretrained.pdparams
    fi
D
dongshuilong 已提交
178 179
fi

G
gaotingquan 已提交
180
if [[ ${FILENAME} == *ultra* ]] || [[ ${FILENAME} == *dali* ]]; then
L
lubin10 已提交
181
    python_name=$(func_parser_value "${lines[2]}")
G
gaotingquan 已提交
182
    ${python_name} -m pip install https://paddle-wheel.bj.bcebos.com/benchmark/nvidia_dali_cuda110-1.25.0-7922357-py3-none-manylinux2014_x86_64.whl
L
lubin10 已提交
183 184
fi

H
HydrogenSulfate 已提交
185
if [[ ${MODE} = "lite_train_lite_infer" ]] || [[ ${MODE} = "lite_train_whole_infer" ]]; then
186 187 188 189 190 191 192 193 194 195 196 197 198
    if [[ ${model_name} =~ "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 --no-check-certificate
        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 ../../
199 200 201 202 203
    elif [[ ${model_name} =~ "MetaBIN_ResNet50" ]]; then
        cd dataset
        wget -nc https://paddleclas.bj.bcebos.com/data/TIPC/duke_market.zip --no-check-certificate
        unzip duke_market.zip
        cd ../
204 205 206 207 208 209 210 211 212 213 214 215 216
    else
        # 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 --no-check-certificate
        tar xf whole_chain_little_train.tar
        ln -s whole_chain_little_train ILSVRC2012
        cd ILSVRC2012
        mv train.txt train_list.txt
        mv val.txt val_list.txt
        cp -r train/* val/
        cd ../../
    fi
H
HydrogenSulfate 已提交
217 218 219 220 221 222 223 224
    if [[ ${FILENAME} =~ "pact_infer" ]]; then
        # download pretrained model for PACT training
        pretrpretrained_model_url=$(func_parser_value "${lines[35]}")
        mkdir pretrained_model
        cd pretrained_model
        wget -nc ${pretrpretrained_model_url} --no-check-certificate
        cd ..
    fi
H
HydrogenSulfate 已提交
225
elif [[ ${MODE} = "whole_infer" ]]; then
S
stephon 已提交
226
    # download data
H
HydrogenSulfate 已提交
227 228 229 230 231 232 233 234 235 236 237
    if [[ ${model_name} =~ "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 --no-check-certificate
        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
238
        rm -rf val_list.txt
H
HydrogenSulfate 已提交
239 240 241 242 243 244 245 246 247 248
        ln -s demo_test.txt val_list.txt
        cd ../../
    else
        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
        cd ILSVRC2012
        mv val.txt val_list.txt
249
        rm -rf train_list.txt
H
HydrogenSulfate 已提交
250 251 252
        ln -s val_list.txt train_list.txt
        cd ../../
    fi
S
stephon 已提交
253
    # download inference or pretrained model
H
HydrogenSulfate 已提交
254
    eval "wget -nc ${model_url_value}"
255 256
    if [[ ${model_url_value} =~ ".tar" ]]; then
        tar_name=$(func_get_url_file_name "${model_url_value}")
H
HydrogenSulfate 已提交
257 258
        echo ${tar_name}
        eval "tar -xf ${tar_name}"
H
HydrogenSulfate 已提交
259
        rm -f ${tar_name}
S
stephon 已提交
260
    fi
H
debug  
HydrogenSulfate 已提交
261 262 263
    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
D
dongshuilong 已提交
264 265
    fi

H
HydrogenSulfate 已提交
266
elif [[ ${MODE} = "whole_train_whole_infer" ]]; then
S
stephon 已提交
267 268 269 270 271
    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 已提交
272
    cd ILSVRC2012
S
stephon 已提交
273
    mv train.txt train_list.txt
D
dongshuilong 已提交
274
    mv test.txt val_list.txt
S
stephon 已提交
275
    cd ../../
H
HydrogenSulfate 已提交
276 277 278 279 280 281 282 283
    if [[ ${FILENAME} =~ "pact_infer" ]]; then
        # download pretrained model for PACT training
        pretrpretrained_model_url=$(func_parser_value "${lines[35]}")
        mkdir pretrained_model
        cd pretrained_model
        wget -nc ${pretrpretrained_model_url} --no-check-certificate
        cd ..
    fi
S
stephon 已提交
284 285
fi

H
HydrogenSulfate 已提交
286
if [[ ${MODE} = "serving_infer" ]]; then
S
stephon 已提交
287
    # prepare serving env
288
    python_name=$(func_parser_value "${lines[2]}")
289
    if [[ ${model_name} =~ "PPShiTu" ]]; then
H
debug  
HydrogenSulfate 已提交
290 291 292 293
        cls_inference_model_url=$(func_parser_value "${lines[3]}")
        cls_tar_name=$(func_get_url_file_name "${cls_inference_model_url}")
        det_inference_model_url=$(func_parser_value "${lines[4]}")
        det_tar_name=$(func_get_url_file_name "${det_inference_model_url}")
294
        cd ./deploy
H
HydrogenSulfate 已提交
295 296
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v1.0.tar --no-check-certificate
        tar -xf drink_dataset_v1.0.tar
297 298
        wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/data/drink_dataset_v2.0.tar --no-check-certificate
        tar -xf drink_dataset_v2.0.tar
299 300 301 302 303
        mkdir models
        cd models
        wget -nc ${cls_inference_model_url} && tar xf ${cls_tar_name}
        wget -nc ${det_inference_model_url} && tar xf ${det_tar_name}
        cd ..
H
debug  
HydrogenSulfate 已提交
304 305 306 307
    else
        cls_inference_model_url=$(func_parser_value "${lines[3]}")
        cls_tar_name=$(func_get_url_file_name "${cls_inference_model_url}")
        cd ./deploy/paddleserving
H
debug  
HydrogenSulfate 已提交
308 309 310 311 312 313 314 315 316 317 318 319
        wget -nc ${cls_inference_model_url}
        tar xf ${cls_tar_name}

        # move '_int8' suffix in pact models
        if [[ ${cls_tar_name} =~ "pact_infer" ]]; then
            cls_inference_model_dir=${cls_tar_name%%.tar}
            cd ${cls_inference_model_dir}
            mv inference_int8.pdiparams inference.pdiparams
            mv inference_int8.pdmodel inference.pdmodel
            cd ..
        fi

H
debug  
HydrogenSulfate 已提交
320
        cd ../../
321
    fi
S
stephon 已提交
322 323 324
    unset http_proxy
    unset https_proxy
fi
L
lubin10 已提交
325

H
HydrogenSulfate 已提交
326
if [[ ${MODE} = "paddle2onnx_infer" ]]; then
L
lubin10 已提交
327 328
    # prepare paddle2onnx env
    python_name=$(func_parser_value "${lines[2]}")
H
HydrogenSulfate 已提交
329
    inference_model_url=$(func_parser_value "${lines[10]}")
G
gaotingquan 已提交
330
    tar_name=$(func_get_url_file_name "$inference_model_url")
331

H
HydrogenSulfate 已提交
332
    ${python_name} -m pip install onnx
333
    ${python_name} -m pip install paddle2onnx
L
lubin10 已提交
334
    ${python_name} -m pip install onnxruntime
335 336 337 338 339 340 341 342 343 344 345
    if [[ ${model_name} =~ "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 --no-check-certificate
        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
346
        rm -rf val_list.txt
347 348 349
        ln -s demo_test.txt val_list.txt
        cd ../../
    fi
H
HydrogenSulfate 已提交
350 351 352 353
    cd deploy
    mkdir models
    cd models
    wget -nc ${inference_model_url}
H
HydrogenSulfate 已提交
354
    eval "tar -xf ${tar_name}"
H
HydrogenSulfate 已提交
355
    cd ../../
L
lubin10 已提交
356
fi
D
dongshuilong 已提交
357

H
HydrogenSulfate 已提交
358
if [[ ${MODE} = "benchmark_train" ]]; then
D
dongshuilong 已提交
359 360
    pip install -r requirements.txt
    cd dataset
361 362 363 364 365 366 367 368 369 370 371 372 373 374

    if [[ $model_name == *GeneralRecognition* ]]; then
        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 --no-check-certificate
        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
    else
        rm -rf ILSVRC2012
G
gaotingquan 已提交
375 376 377
        wget -nc https://paddleclas.bj.bcebos.com/data/TIPC/ILSVRC2012_benchmark.tar
        tar xf ILSVRC2012_benchmark.tar
        mv ILSVRC2012_benchmark ILSVRC2012
378
    fi
379
    cd ../
380

D
dongshuilong 已提交
381
fi