-
Notifications
You must be signed in to change notification settings - Fork 193
/
benchmark_fast_adaptive_boundary.py
197 lines (178 loc) · 5.51 KB
/
benchmark_fast_adaptive_boundary.py
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
# Copyright (c) 2018-present, Royal Bank of Canada and other authors.
# See the AUTHORS.txt file for a list of contributors.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
#
#
# Automatically generated benchmark report (screen print of running this file)
#
# sysname: Linux
# release: 4.4.0-140-generic
# version: #166-Ubuntu SMP Wed Nov 14 20:09:47 UTC 2018
# machine: x86_64
# python: 3.7.3
# torch: 1.1.0
# torchvision: 0.3.0
# advertorch: 0.1.5
# attack type: FABAttack
# attack kwargs: norm=Linf
# n_restarts=1
# n_iter=20
# alpha_max=0.1
# eta=1.05
# beta=0.9
# loss_fn=None
# data: mnist_test
# model: MNIST LeNet5 standard training
# accuracy: 98.89%
# attack success rate: 100.0%
# Among successful attacks (Linf norm) on correctly classified examples:
# minimum distance: 0.0001396
# median distance: 0.112
# maximum distance: 0.2155
# average distance: 0.1092
# distance standard deviation: 0.03498
# attack type: FABAttack
# attack kwargs: norm=L2
# n_restarts=1
# n_iter=20
# alpha_max=0.1
# eta=1.05
# beta=0.9
# loss_fn=None
# data: mnist_test
# model: MNIST LeNet5 standard training
# accuracy: 98.89%
# attack success rate: 100.0%
# Among successful attacks (L2 norm) on correctly classified examples:
# minimum distance: 0.001726
# median distance: 1.423
# maximum distance: 3.01
# average distance: 1.412
# distance standard deviation: 0.4805
# attack type: FABAttack
# attack kwargs: norm=L1
# n_restarts=1
# n_iter=20
# alpha_max=0.1
# eta=1.05
# beta=0.9
# loss_fn=None
# data: mnist_test
# model: MNIST LeNet5 standard training
# accuracy: 98.89%
# attack success rate: 99.55%
# Among successful attacks (L1 norm) on correctly classified examples:
# minimum distance: 0.007688
# median distance: 7.61
# maximum distance: 36.06
# average distance: 8.365
# distance standard deviation: 4.42
# attack type: FABAttack
# attack kwargs: norm=Linf
# n_restarts=1
# n_iter=20
# alpha_max=0.1
# eta=1.05
# beta=0.9
# loss_fn=None
# data: mnist_test
# model: MNIST LeNet 5 PGD training according to Madry et al. 2018
# accuracy: 98.64%
# attack success rate: 99.86%
# Among successful attacks (Linf norm) on correctly classified examples:
# minimum distance: 0.001405
# median distance: 0.3509
# maximum distance: 0.6404
# average distance: 0.3476
# distance standard deviation: 0.05255
# attack type: FABAttack
# attack kwargs: norm=L2
# n_restarts=1
# n_iter=20
# alpha_max=0.1
# eta=1.05
# beta=0.9
# loss_fn=None
# data: mnist_test
# model: MNIST LeNet 5 PGD training according to Madry et al. 2018
# accuracy: 98.64%
# attack success rate: 98.35%
# Among successful attacks (L2 norm) on correctly classified examples:
# minimum distance: 0.003942
# median distance: 3.04
# maximum distance: 19.92
# average distance: 3.205
# distance standard deviation: 1.311
# attack type: FABAttack
# attack kwargs: norm=L1
# n_restarts=1
# n_iter=20
# alpha_max=0.1
# eta=1.05
# beta=0.9
# loss_fn=None
# data: mnist_test
# model: MNIST LeNet 5 PGD training according to Madry et al. 2018
# accuracy: 98.64%
# attack success rate: 94.33%
# Among successful attacks (L1 norm) on correctly classified examples:
# minimum distance: 0.00622
# median distance: 112.8
# maximum distance: 441.9
# average distance: 114.6
# distance standard deviation: 52.85
from advertorch_examples.utils import get_mnist_test_loader
from advertorch_examples.utils import get_mnist_lenet5_clntrained
from advertorch_examples.utils import get_mnist_lenet5_advtrained
from advertorch_examples.benchmark_utils import get_benchmark_sys_info
from advertorch.attacks import FABAttack
from advertorch_examples.benchmark_utils import benchmark_margin
batch_size = 100
device = "cuda"
lst_attack = [
(FABAttack, dict(
norm='Linf',
n_restarts=1,
n_iter=20,
alpha_max=0.1,
eta=1.05,
beta=0.9,
loss_fn=None)),
(FABAttack, dict(
norm='L2',
n_restarts=1,
n_iter=20,
alpha_max=0.1,
eta=1.05,
beta=0.9,
loss_fn=None)),
(FABAttack, dict(
norm='L1',
n_restarts=1,
n_iter=20,
alpha_max=0.1,
eta=1.05,
beta=0.9,
loss_fn=None)),
] # each element in the list is the tuple (attack_class, attack_kwargs)
mnist_clntrained_model = get_mnist_lenet5_clntrained().to(device)
mnist_advtrained_model = get_mnist_lenet5_advtrained().to(device)
mnist_test_loader = get_mnist_test_loader(batch_size=batch_size)
lst_setting = [
(mnist_clntrained_model, mnist_test_loader),
(mnist_advtrained_model, mnist_test_loader),
]
info = get_benchmark_sys_info()
lst_benchmark = []
for model, loader in lst_setting:
for attack_class, attack_kwargs in lst_attack:
lst_benchmark.append(benchmark_margin(
model, loader, attack_class, attack_kwargs,
norm=attack_kwargs["norm"]))
print(info)
for item in lst_benchmark:
print(item)