-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain2.sh
executable file
·105 lines (91 loc) · 3.49 KB
/
train2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
#!/usr/bin/env bash
# Variables to modify ---------------------------------------------------------
MODEL_NAME=inception_resnet_v2
MODEL_ARG_SCOPE=InceptionResnetV2
PRETRAINED_MODEL_FILE=pretrained/inception_resnet_v2_2016_08_30.ckpt
NUM_TRAIN_RUNS=5
NUM_CLONES=2
BATCH_SIZE=32
# -----------------------------------------------------------------------------
# Loop over each dataset
DATASET_NAME=ImageCLEFmed2016partial-ara-autocrop
DATASET_DIR=datasets/${DATASET_NAME}
TRAIN_DIR_BASE=models/${MODEL_NAME}/${DATASET_NAME}
for((CURRENT_TRAINING_RUN=0; CURRENT_TRAINING_RUN<${NUM_TRAIN_RUNS}; CURRENT_TRAINING_RUN++))
do
# Set training dir for current run
TRAIN_DIR=${TRAIN_DIR_BASE}/run_${CURRENT_TRAINING_RUN}
LOG_FILE=${TRAIN_DIR}/log.txt
# Check if run was already trained successfully
if test -e ${TRAIN_DIR}/DONE;then
continue
fi
# Create train dir for log file
mkdir -p ${TRAIN_DIR}
# Fine-tune new layer for 10 epochs
python slim/train_image_classifier.py \
--train_dir=${TRAIN_DIR} \
--dataset_dir=${DATASET_DIR} \
--dataset_name=ImageCLEFmed2016 \
--dataset_split_name=train \
--preprocessing_name=ImageCLEFmed2016 \
--model_name=${MODEL_NAME} \
--batch_size=${BATCH_SIZE} \
--num_clones=${NUM_CLONES} \
--max_number_of_steps=1298 \
--learning_rate=0.0001 \
--learning_rate_decay_type=fixed \
--weight_decay=0.0001 \
--save_summaries_secs=30 \
--save_interval_secs=1800 \
--checkpoint_path=${PRETRAINED_MODEL_FILE} \
--checkpoint_exclude_scopes=${MODEL_ARG_SCOPE}/Logits,${MODEL_ARG_SCOPE}/AuxLogits \
--trainable_scopes=${MODEL_ARG_SCOPE}/Logits,${MODEL_ARG_SCOPE}/AuxLogits \
2>&1 | tee ${LOG_FILE}
python slim/eval_image_classifier.py \
--checkpoint_path=${TRAIN_DIR} \
--eval_dir=${TRAIN_DIR} \
--dataset_dir=${DATASET_DIR} \
--dataset_name=ImageCLEFmed2016 \
--dataset_split_name=validation \
--preprocessing_name=ImageCLEFmed2016 \
--model_name=${MODEL_NAME} \
2>&1 | tee -a ${LOG_FILE}
# Fine-tune all layers for 20 epochs
python slim/train_image_classifier.py \
--train_dir=${TRAIN_DIR}/all \
--dataset_dir=${DATASET_DIR} \
--dataset_name=ImageCLEFmed2016 \
--dataset_split_name=train \
--preprocessing_name=ImageCLEFmed2016 \
--model_name=${MODEL_NAME} \
--batch_size=${BATCH_SIZE} \
--num_clones=${NUM_CLONES} \
--max_number_of_steps=2595 \
--learning_rate=0.01 \
--end_learning_rate=0.0001 \
--learning_rate_decay_type=polynomial \
--polynomial_decay_power=2.0 \
--decay_steps=2000 \
--weight_decay=0.0001 \
--save_summaries_secs=30 \
--save_interval_secs=1800 \
--checkpoint_path=${TRAIN_DIR} \
2>&1 | tee -a ${LOG_FILE}
python slim/eval_image_classifier.py \
--checkpoint_path=${TRAIN_DIR}/all \
--eval_dir=${TRAIN_DIR}/all \
--dataset_dir=${DATASET_DIR} \
--dataset_name=ImageCLEFmed2016 \
--dataset_split_name=validation \
--preprocessing_name=ImageCLEFmed2016 \
--model_name=${MODEL_NAME} \
2>&1 | tee -a ${LOG_FILE}
# Append accuracy to file
grep "eval/Accuracy" ${LOG_FILE} \
| tail --lines=1 \
| grep -o "0\.[[:digit:]]*" \
>> ${TRAIN_DIR_BASE}/results.txt
# Create empty file to flag this run as done
touch ${TRAIN_DIR}/DONE
done