-
Notifications
You must be signed in to change notification settings - Fork 11
/
robustml_eval.py
55 lines (47 loc) · 1.83 KB
/
robustml_eval.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
from robustml_model import *
from robustml_attack import *
import tensorflow as tf
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--imagenet-path', type=str, required=True,
help='directory containing `val.txt` and `val/` folder')
parser.add_argument('--checkpoint-path', type=str, default='imagenet64_alp025_2018_06_26.ckpt',
help='path to imagenet64 checkpoint')
parser.add_argument('--start', type=int, default=0)
parser.add_argument('--end', type=int, default=100)
parser.add_argument('--attack', type=str, default='pgd', help='none | pgd')
parser.add_argument('--attack-iterations', type=int, default=1000)
parser.add_argument('--attack-step-size', type=float, default=0.005)
parser.add_argument('--debug', action='store_true')
parser.add_argument('--quantize', action='store_true')
args = parser.parse_args()
sess = tf.Session()
model = ALP(sess, args.checkpoint_path, quantize=args.quantize)
if args.attack == 'none':
attack = NullAttack()
elif args.attack == 'pgd':
attack = PGDAttack(
sess,
model,
model.threat_model.epsilon,
debug=args.debug,
max_steps=args.attack_iterations,
step_size=args.attack_step_size,
quantize=args.quantize
)
else:
raise ValueError('invalid attack: %s' % args.attack)
provider = robustml.provider.ImageNet(args.imagenet_path, shape=(64, 64, 3))
success_rate = robustml.evaluate.evaluate(
model,
attack,
provider,
start=args.start,
end=args.end,
deterministic=True,
debug=True
)
print('attack success rate: %.2f%% (over %d data points)' % (success_rate*100, args.end - args.start))
if __name__ == '__main__':
main()