-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_imagnet128.sh
198 lines (146 loc) · 8.78 KB
/
main_imagnet128.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
# bash main_imagnet128.sh &> log_evaluation/imagenet128/all.log
function log_msg {
echo "`date` $@"
}
# DATASETS=(cif10 cif10vgg cif100 cif100vgg imagenet imagenet32 imagenet64 imagenet128 celebaHQ32 celebaHQ64 celebaHQ128)
DATASETS="imagenet128"
# ATTACKS="fgsm bim pgd std df cw"
ATTACKS="cw"
# ATTACKS="fgsm bim pgd df cw"
# ATTACKS="fgsm bim pgd std df"
EPSILONS="4./255. 2./255. 1./255. 0.5/255."
EPSILONS="8./255."
# DETECTORS="InputPFS LayerPFS InputMFS LayerMFS LID Mahalanobis"
DETECTORS="LayerMFS"
CLF="LR"
IMAGENET32CLASSES="25 50 100 250 1000"
# NRSAMPLES="300 500 1000 1200 1500 2000"
NRSAMPLES="1500"
#-----------------------------------------------------------------------------------------------------------------------------------
log_msg "Networks are already trained!"
#-----------------------------------------------------------------------------------------------------------------------------------
genereratecleandata ()
{
log_msg "Generate Clean Data for Foolbox Attacks and Autoattack!"
for net in $DATASETS; do
if [ "$net" == imagenet128 ]; then
python -u generate_clean_data.py --net "$net" --num_classes 1000 --img_size 128
fi
done
}
#-----------------------------------------------------------------------------------------------------------------------------------
attacks ()
{
log_msg "Attack Clean Data with Foolbox Attacks and Autoattack!"
for net in $DATASETS; do
for att in $ATTACKS; do
if [ "$net" == imagenet128 ]; then
python -u attacks.py --net "$net" --num_classes 1000 --attack "$att" --img_size 128 --batch_size 64
fi
done
done
}
#-----------------------------------------------------------------------------------------------------------------------------------
extractcharacteristics ()
{
log_msg "Extract Characteristics"
for net in $DATASETS; do
for att in $ATTACKS; do
for eps in $EPSILONS; do
for det in $DETECTORS; do
python -u extract_characteristics.py --net "$net" --attack "$att" --detector "$det" --num_classes 1000 --img_size 128 --wanted_samples 1600 --eps "$eps"
done
done
done
done
}
# #-----------------------------------------------------------------------------------------------------------------------------------
detectadversarials ()
{
log_msg "Detect Adversarials!"
for net in $DATASETS; do
for att in $ATTACKS; do
for eps in $EPSILONS; do
for det in $DETECTORS; do
for nrsamples in $NRSAMPLES; do
for classifier in $CLF; do
python -u detect_adversarials.py --net "$net" --attack "$att" --detector "$det" --wanted_samples "$nrsamples" --clf "$classifier" --num_classes 1000 --eps "$eps"
done
done
done
done
done
done
}
# extractcharacteristics
detectadversarials
# python attacks.py --net imagenet128 --att std --batch_size 64 --num_classes 1000 --img_size 128 --eps 4./255.
# python attacks.py --net imagenet128 --att std --batch_size 64 --num_classes 1000 --img_size 128 --eps 2./255.
# python attacks.py --net imagenet128 --att std --batch_size 64 --num_classes 1000 --img_size 128 --eps 1./255.
# python attacks.py --net imagenet128 --att std --batch_size 64 --num_classes 1000 --img_size 128 --eps 0.5/255.
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack fgsm
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack bim
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack std
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack pgd
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack df
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack cw
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack fgsm
# sleep 3
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack bim
# sleep 3
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack std
# sleep 3
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack pgd
# sleep 3
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack df
# sleep 3
# python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack cw
# for nr in {1,2,3,4}; do
# echo "Generate Clean Data: run: $nr"
# python -c "import evaluate_detection; evaluate_detection.clean_root_folders( root='./data/clean_data', net=['imagenet128'] )"
# genereratecleandata
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/clean_data', net=['imagenet128'], dest='./log_evaluation/imagenet128', run_nr=$nr)"
# done
# for nr in 4; do
# echo "Attacks: run: $nr"
# python -c "import evaluate_detection; evaluate_detection.copy_run_to_root(root='./data', net=['imagenet128'], dest='./log_evaluation/imagenet128', run_nr=$nr)"
# attacks
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/attacks', net=['imagenet128'], dest='./log_evaluation/imagenet128', run_nr=$nr)"
# done
# imagenet128
# for nr in 1; do
# # python -c "import evaluate_detection; evaluate_detection.copy_run_to_root(root='./data', net=['imagenet128'], dest='./log_evaluation/imagenet128', run_nr=$nr)"
# extractcharacteristics
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/extracted_characteristics', net=['imagenet128'], dest='./log_evaluation/imagenet128', run_nr=$nr)"
# done
# for nr in 1; do
# detectadversarials
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/detection', net=['imagenet128'], dest='./log_evaluation/imagenet128', run_nr=$nr)"
# done
# python -c "import evaluate_detection; evaluate_detection.clean_root_folders( root='./data/clean_data', net=['imagenet128'] )"
# python -c "import evaluate_detection; evaluate_detection.clean_root_folders( root='./data/attacks', net=['imagenet128'] )"
# genereratecleandata
# attacks
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/clean_data', net=['imagenet128'], dest='./log_evaluation/imagenet128', run_nr=2)"
# python -c "import evaluate_detection; evaluate_detection.copy_run_dest(root='./data/attacks', net=['imagenet128'], dest='./log_evaluation/imagenet128', run_nr=2)"
# extractcharacteristics
# detectadversarials
# #-----------------------------------------------------------------------------------------------------------------------------------
log_msg "finished"
exit 0
# : <<'END'
# just a comment!
# END
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack fgsm
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack bim
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack std
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack pgd
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack df
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector InputMFS --img_size 128 --attack cw
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack fgsm
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack bim
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack std
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack pgd
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack df
python -u extract_characteristics.py --net imagenet128 --num_classes 1000 --detector LayerMFS --img_size 128 --attack cw