-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_cifar100.sh
81 lines (68 loc) · 2.52 KB
/
train_cifar100.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
#!/usr/bin/env sh
############### Host ##############################
HOST=$(hostname)
echo "Current host is: $HOST"
# Automatic check the host and configure
case $HOST in
"alpha")
PYTHON="python3" #"/usr/bin/python3" # python environment path
TENSORBOARD='/home/elliot/anaconda3/envs/bindsnet/bin/tensorboard' # tensorboard environment path
data_path="/data1/cifar-10-batches-py" # dataset path
;;
esac
DATE=`date +%Y-%m-%d`
if [ ! -d "$DIRECTORY" ]; then
mkdir ./save/${DATE}/
fi
############### Configurations ########################
enable_tb_display=false # enable tensorboard displaymodel=deit_base_patch16_224_test
model=deit_base_2blocks_cifar100
optimizer='AdamW'
dataset='cifar100'
test_batch_size=256 # number of training examples used in every iteration # ZX: batch size for testing set
seed=17
attack_sample_size=128 # batch size for training set
n_iter=100 # of iterations for cross-layer search = # of total bits flipped
k_top=10 # only check k_top weights with top gradient ranking in each layer
lr=0.0001
epochs=100
save_path=/data1/Xuan_vit_ckp/${DATE}/${dataset}_${model}_${epochs}_${optimizer}
tb_path=/data1/Xuan_vit_ckp/${DATE}/${dataset}_${model}_${epochs}_${optimizer}_${quantize}/tb_log #tensorboard log path
############### Neural network ############################
{
python3 retrain.py --dataset ${dataset} --data_path /data1/ \
--arch ${model} --save_path ${save_path} \
--test_batch_size ${test_batch_size} --workers 8 --ngpu 2 \
--evaluate --learning_rate ${lr} \
--print_freq 1 --epochs ${epochs} \
--reset_weight --bfa --n_iter ${n_iter} --k_top ${k_top} --attack_sample_size ${attack_sample_size} \
--manualSeed ${seed} \
--optimizer ${optimizer} | tee log_Adam/train_attack_${model}_epoch${epochs}_lr1e-4_${dataset}.log
} &
# n_iter: number of iteration to perform BFA
# k_top: only check k_top weights with top gradient ranking in each layer (nb in paper)
# attack_sample_size: number of data used for BFA (batch_size in main.py)
# model: the ML model, related files can be found in models/vanilla_models. All models in this folder is pre-trained ResNet.
############## Tensorboard logging ##########################
{
if [ "$enable_tb_display" = true ]; then
sleep 30
wait
$TENSORBOARD --logdir $tb_path --port=6006
fi
} &
{
if [ "$enable_tb_display" = true ]; then
sleep 45
wait
case $HOST in
"Hydrogen")
firefox http://0.0.0.0:6006/
;;
"alpha")
google-chrome http://0.0.0.0:6006/
;;
esac
fi
} &
wait