run_infer.sh 3.0 KB
Newer Older
C
chenzomi 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/env bash
# Copyright 2020 Huawei Technologies Co., Ltd
#
# 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.
# ============================================================================
P
Payne 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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



run_ascend()
{
    # check checkpoint file
    if [ ! -f $3 ]
    then
        echo "error: CHECKPOINT_PATH=$3 is not a file"
    exit 1
    fi

    # set environment
    BASEPATH=$(cd "`dirname $0`" || exit; pwd)
    export PYTHONPATH=${BASEPATH}:$PYTHONPATH
    export DEVICE_ID=0
    export RANK_ID=0
    export RANK_SIZE=1
    if [ -d "../eval" ];
    then
        rm -rf ../eval
    fi
    mkdir ../eval
    cd ../eval || exit

    # launch
    python ${BASEPATH}/../eval.py \
            --platform=$1 \
            --dataset_path=$2 \
            --pretrain_ckpt=$3 \
            --head_ckpt=$4 \
            &> ../infer.log &  # dataset val folder path
}

run_gpu()
{
    # check checkpoint file
    if [ ! -f $3 ]
    then
        echo "error: CHECKPOINT_PATH=$3 is not a file"
    exit 1
    fi

    BASEPATH=$(cd "`dirname $0`" || exit; pwd)
    export PYTHONPATH=${BASEPATH}:$PYTHONPATH
    if [ -d "../eval" ];
    then
        rm -rf ../eval
    fi
    mkdir ../eval
    cd ../eval || exit

    python ${BASEPATH}/../eval.py \
        --platform=$1 \
        --dataset_path=$2 \
        --pretrain_ckpt=$3 \
        --head_ckpt=$4 \
        &> ../infer.log &  # dataset train folder
}

run_cpu()
{
    # check checkpoint file
    if [ ! -f $3 ]
    then
        echo "error: BACKBONE_CKPT=$3 is not a file"
    exit 1
    fi

    # check checkpoint file
    if [ ! -f $4 ]
    then
        echo "error: HEAD_CKPT=$4 is not a file"
    exit 1
    fi


    BASEPATH=$(cd "`dirname $0`" || exit; pwd)
    export PYTHONPATH=${BASEPATH}:$PYTHONPATH
    if [ -d "../eval" ];
    then
        rm -rf ../eval
    fi
    mkdir ../eval
    cd ../eval || exit

    python ${BASEPATH}/../eval.py \
        --platform=$1 \
        --dataset_path=$2 \
        --pretrain_ckpt=$3 \
        --head_ckpt=$4 \
        &> ../infer.log &  # dataset train folder
}


if [ $# -gt 4 ] || [ $# -lt 3 ]
C
chenzomi 已提交
112
then
P
Payne 已提交
113 114 115
    echo "Ascend: sh run_infer.sh [PLATFORM] [DATASET_PATH] [PRETRAIN_CKPT] \
          GPU: sh run_infer.sh [PLATFORM] [DATASET_PATH] [PRETRAIN_CKPT]
          CPU: sh run_infer.sh [PLATFORM] [DATASET_PATH] [BACKBONE_CKPT] [HEAD_CKPT]"
C
chenzomi 已提交
116 117 118 119 120 121 122 123 124 125
exit 1
fi

# check dataset path
if [ ! -d $2 ]
then
    echo "error: DATASET_PATH=$2 is not a directory"
exit 1
fi

P
Payne 已提交
126 127 128 129 130 131 132 133 134
if [ $1 = "CPU" ] ; then
    run_cpu "$@"
elif [ $1 = "GPU" ] ; then
    run_gpu "$@"
elif [ $1 = "Ascend" ] ; then
    run_ascend "$@"
else
    echo "Unsupported device_target."
fi;