-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·114 lines (101 loc) · 3.11 KB
/
run.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
106
107
108
109
110
111
112
113
114
#!/bin/bash
display_help() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " --method METHOD Specify the training regime (default: simclr, options: byol)"
echo " --mode MODE Specify the mode (default: poisoned, options: clean)"
echo " --defense DEFENSE Specify the defense (default: None, options: blur)"
echo " --dataset DATASET Specify the dataset (default: cifar10)"
echo " --suffix SUFFIX Specify a suffix for the job name (default: empty)"
echo " --threat_model MODEL Specify the threat model (default: ctrl, options: fiba, htba)"
echo " --ctype CTYPE Specify the colorspace to evaluate model (default: RGB, options: YUV, Y, U, V, HLS, HSV, LUV, LAB, YCbCr)"
echo " -h, --help Display this help and exit"
exit 1
}
method="simclr"
mode="poisoned"
defense=""
dataset="cifar10"
threat_model="ctrl"
ctype="RGB"
suffix=""
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help) display_help; exit 0 ;;
esac
key="$1"
case $key in
--method)
method="$2"
shift
shift
;;
--mode)
mode="$2"
shift
shift
;;
--defense)
defense="$2"
shift
shift
;;
--dataset)
dataset="$2"
shift
shift
;;
--suffix)
suffix="$2"
shift
shift
;;
--threat_model)
threat_model="$2"
shift
shift
;;
--ctype)
ctype="$2"
shift
shift
;;
*)
# Unknown option
echo "Unknown option: $1"
exit 1
;;
esac
done
# # Check if required options are provided
# if [ -z "$mode" ] || [ -z "$defense" ]; then
# echo "Usage: $0 --mode <mode> --defense <defense>"
# exit 1
# fi
# Generate a unique job name
if [ "$mode" != "poisoned" ]; then
job_name="${method}_${mode}_${defense}_${dataset}${suffix}"
else
job_name="${method}_${defense}_${dataset}_${threat_model}${suffix}"
fi
poisoned="--mode normal --trial clean"
if [ "$mode" == "poisoned" ]; then
poisoned="--mode frequency --trial test"
fi
augmentation=""
if [ "$defense" == "blur" ]; then
augmentation="--blur"
elif [ "$defense" == "value" ]; then
augmentation="--value_channel"
elif [ "$defense" == "both" ]; then
augmentation="--blur --value_channel"
fi
poison_ratio=0.5
if [ "$dataset" != "cifar10" ]; then
poison_ratio=$(awk "BEGIN {print $poison_ratio / 5; exit}")
fi
# source your virtual environmenet, if any
# source ../ctrl/bin/activate
MYPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
python main_train.py $poisoned --dataset $dataset $augmentation --ctype $ctype --method $method --threat_model ${threat_model} --channel 1 2 --trigger_position 15 31 --poison_ratio $poison_ratio --lr 0.06 --wd 0.0005 --magnitude 100.0 --poisoning --epochs 800 --gpu 0 --window_size 32 --saved_path "${MYPATH}/saves/${job_name}/"