|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# $1 code path |
| 4 | +# $2 dataset path |
| 5 | +# $3 train or test |
| 6 | +# $4 log_suffix |
| 7 | + |
| 8 | +PYTHON="/opt/conda/bin/python" |
| 9 | +${PYTHON} -c "import torch; print(torch.__version__)" |
| 10 | + |
| 11 | +${PYTHON} -m pip install yacs |
| 12 | + |
| 13 | +export PYTHONPATH=$1:$PYTHONPATH |
| 14 | + |
| 15 | +DATA_DIR="$2/face_parse/CelebAMask-HQ" |
| 16 | +SAVE_DIR="$2/seg_result/celeba/" |
| 17 | +BACKBONE="hrnet48" |
| 18 | + |
| 19 | +CONFIGS="configs/celeba/H_48_D_4.json" |
| 20 | +CONFIGS_TEST="configs/celeba/H_48_D_4_TEST.json" |
| 21 | + |
| 22 | +MODEL_NAME="hrnet_w48_ocr" |
| 23 | +LOSS_TYPE="fs_auxce_loss" |
| 24 | +CHECKPOINTS_NAME="${MODEL_NAME}_${BACKBONE}_"$4 |
| 25 | +LOG_FILE="./log/celeba/${CHECKPOINTS_NAME}.log" |
| 26 | +echo "Logging to $LOG_FILE" |
| 27 | +mkdir -p `dirname $LOG_FILE` |
| 28 | +PRETRAINED_MODEL="./pretrained_model/hrnetv2_w48_imagenet_pretrained.pth" |
| 29 | +MAX_ITERS=150000 |
| 30 | + |
| 31 | +if [ "$3"x == "train"x ]; then |
| 32 | + ${PYTHON} -u main.py --configs ${CONFIGS} \ |
| 33 | + --drop_last y \ |
| 34 | + --nbb_mult 10 \ |
| 35 | + --phase train \ |
| 36 | + --gathered n \ |
| 37 | + --loss_balance y \ |
| 38 | + --log_to_file n \ |
| 39 | + --backbone ${BACKBONE} \ |
| 40 | + --model_name ${MODEL_NAME} \ |
| 41 | + --gpu 0 1 2 3 \ |
| 42 | + --data_dir ${DATA_DIR} \ |
| 43 | + --loss_type ${LOSS_TYPE} \ |
| 44 | + --max_iters ${MAX_ITERS} \ |
| 45 | + --checkpoints_name ${CHECKPOINTS_NAME} \ |
| 46 | + --pretrained ${PRETRAINED_MODEL} \ |
| 47 | + 2>&1 | tee ${LOG_FILE} |
| 48 | + |
| 49 | + |
| 50 | +elif [ "$3"x == "resume"x ]; then |
| 51 | + ${PYTHON} -u main.py --configs ${CONFIGS} \ |
| 52 | + --drop_last y \ |
| 53 | + --nbb_mult 10 \ |
| 54 | + --phase train \ |
| 55 | + --gathered n \ |
| 56 | + --loss_balance y \ |
| 57 | + --log_to_file n \ |
| 58 | + --backbone ${BACKBONE} \ |
| 59 | + --model_name ${MODEL_NAME} \ |
| 60 | + --max_iters ${MAX_ITERS} \ |
| 61 | + --data_dir ${DATA_DIR} \ |
| 62 | + --loss_type ${LOSS_TYPE} \ |
| 63 | + --gpu 0 1 2 3 \ |
| 64 | + --resume_continue y \ |
| 65 | + --resume ./checkpoints/coco_stuff/${CHECKPOINTS_NAME}_latest.pth \ |
| 66 | + --checkpoints_name ${CHECKPOINTS_NAME} \ |
| 67 | + 2>&1 | tee -a ${LOG_FILE} |
| 68 | + |
| 69 | + |
| 70 | +elif [ "$3"x == "val"x ]; then |
| 71 | + ${PYTHON} -u main.py --configs ${CONFIGS_TEST} \ |
| 72 | + --data_dir ${DATA_DIR} \ |
| 73 | + --backbone ${BACKBONE} \ |
| 74 | + --model_name ${MODEL_NAME} \ |
| 75 | + --checkpoints_name ${CHECKPOINTS_NAME} \ |
| 76 | + --phase test \ |
| 77 | + --gpu 0 1 2 3 \ |
| 78 | + --resume ./checkpoints/coco_stuff/${CHECKPOINTS_NAME}_latest.pth \ |
| 79 | + --test_dir ${DATA_DIR}/val/image \ |
| 80 | + --log_to_file n \ |
| 81 | + --out_dir ${SAVE_DIR}${CHECKPOINTS_NAME}_val_ms |
| 82 | + |
| 83 | + cd lib/metrics |
| 84 | + ${PYTHON} -u ade20k_evaluator.py --configs ../../${CONFIGS_TEST} \ |
| 85 | + --pred_dir ${SAVE_DIR}${CHECKPOINTS_NAME}_val_ms/label \ |
| 86 | + --gt_dir ${DATA_DIR}/val/label |
| 87 | + |
| 88 | + |
| 89 | +elif [ "$3"x == "test"x ]; then |
| 90 | + if [ "$5"x == "ss"x ]; then |
| 91 | + echo "[single scale] test" |
| 92 | + ${PYTHON} -u main.py --configs ${CONFIGS} --drop_last y \ |
| 93 | + --backbone ${BACKBONE} --model_name ${MODEL_NAME} --checkpoints_name ${CHECKPOINTS_NAME} \ |
| 94 | + --phase test --gpu 0 1 2 3 --resume ./checkpoints/coco_stuff/${CHECKPOINTS_NAME}_latest.pth \ |
| 95 | + --test_dir ${DATA_DIR}/test --log_to_file n \ |
| 96 | + --out_dir ${SAVE_DIR}${CHECKPOINTS_NAME}_test_ss |
| 97 | + else |
| 98 | + echo "[multiple scale + flip] test" |
| 99 | + ${PYTHON} -u main.py --configs ${CONFIGS_TEST} --drop_last y \ |
| 100 | + --backbone ${BACKBONE} --model_name ${MODEL_NAME} --checkpoints_name ${CHECKPOINTS_NAME} \ |
| 101 | + --phase test --gpu 0 1 2 3 --resume ./checkpoints/coco_stuff/${CHECKPOINTS_NAME}_latest.pth \ |
| 102 | + --test_dir ${DATA_DIR}/test --log_to_file n \ |
| 103 | + --out_dir ${SAVE_DIR}${CHECKPOINTS_NAME}_test_ms |
| 104 | + fi |
| 105 | + |
| 106 | + |
| 107 | +else |
| 108 | + echo "$3"x" is invalid..." |
| 109 | +fi |
0 commit comments