scripts/seg/ade20k/run_fs_annn_ade20k_seg.sh
#!/usr/bin/env bash

# check the enviroment info
nvidia-smi
PYTHON="python"
WORKDIR=$(cd $(dirname $0)/../../../;pwd)
export PYTHONPATH=${WORKDIR}:${PYTHONPATH}

cd ${WORKDIR}

DATASET="ade20k"

DATA_DIR=`cat data.conf|grep ${DATASET}|cut -d : -f 2`

BACKBONE="deepbase_resnet101_dilated8"
MODEL_NAME="annn"
CHECKPOINTS_NAME="fs_${MODEL_NAME}_${DATASET}_seg"$2
PRETRAINED_MODEL="./pretrained_models/3x3resnet101-imagenet.pth"

HYPES_FILE="hypes/seg/${DATASET}/fs_annn_${DATASET}_seg.json"
MAX_ITERS=150000
LOSS_TYPE="fs_auxohemce_loss"

LOG_DIR="${WORKDIR}/log/seg/${DATASET}/"
LOG_FILE="${LOG_DIR}${CHECKPOINTS_NAME}.log"

if [[ ! -d ${LOG_DIR} ]]; then
    echo ${LOG_DIR}" not exists!!!"
    mkdir -p ${LOG_DIR}
fi


if [ "$1"x == "train"x ]; then
  ${PYTHON} -u main.py --hypes ${HYPES_FILE} --drop_last y --phase train --gathered n --loss_balance y --include_val n \
                       --backbone ${BACKBONE} --model_name ${MODEL_NAME} --gpu 0 1 2 3 4 5 6 7 --log_to_file n \
                       --data_dir ${DATA_DIR} --loss_type ${LOSS_TYPE} --max_iters ${MAX_ITERS} --norm_type encsync_batchnorm \
                       --test_interval ${TEST_INTERVAL} \
                       --checkpoints_name ${CHECKPOINTS_NAME} --pretrained ${PRETRAINED_MODEL} 2>&1 | tee ${LOG_FILE}

elif [ "$1"x == "resume"x ]; then
  ${PYTHON} -u main.py --hypes ${HYPES_FILE} --drop_last y --phase train --gathered n --loss_balance y --include_val n \
                       --backbone ${BACKBONE} --model_name ${MODEL_NAME} --gpu 0 1 2 3 4 5 6 7 --log_to_file n\
                       --data_dir ${DATA_DIR} --loss_type ${LOSS_TYPE} --max_iters ${MAX_ITERS} --norm_type encsync_batchnorm \
                       --resume_continue y --resume ./checkpoints/seg/${DATASET}k/${CHECKPOINTS_NAME}_latest.pth \
                       --test_interval ${TEST_INTERVAL} \
                       --checkpoints_name ${CHECKPOINTS_NAME} --pretrained ${PRETRAINED_MODEL} --resume_val n 2>&1 | tee -a ${LOG_FILE}

elif [ "$1"x == "debug"x ]; then
  ${PYTHON} -u main.py --hypes ${HYPES_FILE}--phase debug --gpu 0 --log_to_file n  2>&1 | tee ${LOG_FILE}

elif [ "$1"x == "val"x ]; then
 ${PYTHON} -u main.py --hypes ${HYPES_FILE} --phase test --gpu 4 5 6 7 --log_to_file n --gathered n \
                      --backbone ${BACKBONE} --model_name ${MODEL_NAME} --checkpoints_name ${CHECKPOINTS_NAME} \
                      --resume ./checkpoints/seg/${DATASET}/${CHECKPOINTS_NAME}_latest.pth --resume_strict y \
                      --test_dir ${DATA_DIR}/val/image --out_dir val 2>&1 | tee -a ${LOG_FILE}

  ${PYTHON} -u metrics/seg/${DATASET}_evaluator.py --pred_dir results/seg/${DATASET}/${CHECKPOINTS_NAME}/val/label \
                                       --gt_dir ${DATA_DIR}/val/label --hypes_file ../../${HYPES_FILE}  2>&1 | tee -a ${LOG_FILE}

elif [ "$1"x == "test"x ]; then
  ${PYTHON} -u main.py --hypes ${HYPES_FILE} --phase test --gpu 0  --log_to_file n \
                       --backbone ${BACKBONE} --model_name ${MODEL_NAME} --checkpoints_name ${CHECKPOINTS_NAME} \
                       --resume ./checkpoints/seg/${DATASET}/${CHECKPOINTS_NAME}_latest.pth \
                       --test_dir ${DATA_DIR}/test --out_dir test 2>&1 | tee -a ${LOG_FILE}

else
  echo "$1"x" is invalid..."
fi
