prepare.sh 9.0 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
#                 'whole_infer', 'klquant_whole_infer',
#                 'cpp_infer', 'serving_infer',  'lite_infer']

MODE=$2

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

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

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

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

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

H
HydrogenSulfate 已提交
46
if [[ ${MODE} = "cpp_infer" ]]; then
H
debug  
HydrogenSulfate 已提交
47
    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 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        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 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        -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 已提交
79 80 81 82 83 84 85

        make -j
        make install
        cd ../../
        popd
        echo "################### build opencv finished ###################"
    fi
H
debug  
HydrogenSulfate 已提交
86 87 88 89 90 91 92 93 94 95
    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"
            tar xf "${model_name}_infer.tar"
H
debug  
HydrogenSulfate 已提交
96

H
debug  
HydrogenSulfate 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            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 已提交
113

H
debug  
HydrogenSulfate 已提交
114 115 116 117 118 119 120
            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
        else
            echo "Wrong cpp type in config file in line 3. only support cls, shitu"
        fi
        exit 0
H
debug  
HydrogenSulfate 已提交
121
    else
H
debug  
HydrogenSulfate 已提交
122 123
        echo "use wrong config file"
        exit 1
H
debug  
HydrogenSulfate 已提交
124
    fi
D
dongshuilong 已提交
125 126
fi

S
stephon 已提交
127 128 129 130
model_name=$(func_parser_value "${lines[1]}")
model_url_value=$(func_parser_value "${lines[35]}")
model_url_key=$(func_parser_key "${lines[35]}")

H
debug  
HydrogenSulfate 已提交
131 132 133 134 135
if [[ $FILENAME == *GeneralRecognition* ]]; then
    cd dataset
    rm -rf Aliproduct
    rm -rf train_reg_all_data.txt
    rm -rf demo_train
H
debug  
HydrogenSulfate 已提交
136
    wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/whole_chain/tipc_shitu_demo_data.tar --no-check-certificate
H
debug  
HydrogenSulfate 已提交
137 138 139 140 141 142 143
    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 已提交
144
    eval "wget -nc $model_url_value --no-check-certificate"
H
debug  
HydrogenSulfate 已提交
145 146
    mv general_PPLCNet_x2_5_pretrained_v1.0.pdparams GeneralRecognition_PPLCNet_x2_5_pretrained.pdparams
    exit 0
D
dongshuilong 已提交
147 148
fi

H
debug  
HydrogenSulfate 已提交
149
if [[ $FILENAME == *use_dali* ]]; then
L
lubin10 已提交
150 151 152 153
    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

H
HydrogenSulfate 已提交
154
if [[ ${MODE} = "lite_train_lite_infer" ]] || [[ ${MODE} = "lite_train_whole_infer" ]]; then
S
stephon 已提交
155 156 157
    # pretrain lite train data
    cd dataset
    rm -rf ILSVRC2012
H
debug  
HydrogenSulfate 已提交
158
    wget -nc https://paddle-imagenet-models-name.bj.bcebos.com/data/whole_chain/whole_chain_little_train.tar --no-check-certificate
S
stephon 已提交
159 160
    tar xf whole_chain_little_train.tar
    ln -s whole_chain_little_train ILSVRC2012
G
fix  
gaotingquan 已提交
161
    cd ILSVRC2012
S
stephon 已提交
162 163
    mv train.txt train_list.txt
    mv val.txt val_list.txt
D
dongshuilong 已提交
164
    cp -r train/* val/
S
stephon 已提交
165
    cd ../../
H
HydrogenSulfate 已提交
166
elif [[ ${MODE} = "whole_infer" ]] || [[ ${MODE} = "klquant_whole_infer" ]]; then
S
stephon 已提交
167 168 169 170 171 172
    # 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 已提交
173
    cd ILSVRC2012
S
stephon 已提交
174 175 176 177 178 179
    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
H
debug  
HydrogenSulfate 已提交
180 181
        rm -rf inference
        tar xf "${model_name}_infer.tar"
S
stephon 已提交
182
    fi
H
debug  
HydrogenSulfate 已提交
183 184 185
    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 已提交
186 187
    fi

H
HydrogenSulfate 已提交
188
elif [[ ${MODE} = "whole_train_whole_infer" ]]; then
S
stephon 已提交
189 190 191 192 193
    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 已提交
194
    cd ILSVRC2012
S
stephon 已提交
195
    mv train.txt train_list.txt
D
dongshuilong 已提交
196
    mv test.txt val_list.txt
S
stephon 已提交
197 198 199
    cd ../../
fi

H
HydrogenSulfate 已提交
200
if [[ ${MODE} = "serving_infer" ]]; then
S
stephon 已提交
201
    # prepare serving env
202 203 204
    python_name=$(func_parser_value "${lines[2]}")
    ${python_name} -m pip install paddle_serving_client==0.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
    ${python_name} -m pip install paddle-serving-app==0.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
S
stephon 已提交
205
    python_name=$(func_parser_value "${lines[2]}")
H
debug  
HydrogenSulfate 已提交
206
    if [[ ${FILENAME} =~ "cpp" ]]; then
H
debug  
HydrogenSulfate 已提交
207
        pushd ./deploy/paddleserving
H
HydrogenSulfate 已提交
208
        bash build_server.sh ${python_name}
H
debug  
HydrogenSulfate 已提交
209
        popd
210
    else
211
        ${python_name} -m pip install install paddle-serving-server-gpu==0.9.0.post101 -i https://pypi.tuna.tsinghua.edu.cn/simple
212
    fi
H
debug  
HydrogenSulfate 已提交
213
    if [[ ${model_name} =~ "ShiTu" ]]; then
H
HydrogenSulfate 已提交
214
        ${python_name} -m pip install faiss-cpu==1.7.1post2 -i https://pypi.tuna.tsinghua.edu.cn/simple
H
debug  
HydrogenSulfate 已提交
215 216 217 218
        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}")
219
        cd ./deploy
H
HydrogenSulfate 已提交
220
        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
221 222 223 224 225
        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 已提交
226 227 228 229 230 231
    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
        wget -nc ${cls_inference_model_url} && tar xf ${cls_tar_name}
        cd ../../
232
    fi
S
stephon 已提交
233 234 235
    unset http_proxy
    unset https_proxy
fi
L
lubin10 已提交
236

H
HydrogenSulfate 已提交
237
if [[ ${MODE} = "paddle2onnx_infer" ]]; then
L
lubin10 已提交
238 239
    # prepare paddle2onnx env
    python_name=$(func_parser_value "${lines[2]}")
H
HydrogenSulfate 已提交
240 241 242
    inference_model_url=$(func_parser_value "${lines[10]}")
    tar_name=${inference_model_url##*/}

L
lubin10 已提交
243 244
    ${python_name} -m pip install install paddle2onnx
    ${python_name} -m pip install onnxruntime
H
HydrogenSulfate 已提交
245 246 247 248 249 250
    cd deploy
    mkdir models
    cd models
    wget -nc ${inference_model_url}
    tar xf ${tar_name}
    cd ../../
L
lubin10 已提交
251
fi
D
dongshuilong 已提交
252

H
HydrogenSulfate 已提交
253
if [[ ${MODE} = "benchmark_train" ]]; then
D
dongshuilong 已提交
254 255 256 257 258 259 260
    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
H
debug  
HydrogenSulfate 已提交
261
    ln -s val_list.txt train_list.txt
D
dongshuilong 已提交
262 263
    cd ../../
fi