-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
50 lines (41 loc) · 1.57 KB
/
run.py
File metadata and controls
50 lines (41 loc) · 1.57 KB
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
import robustml
import tensorflow as tf
import argparse
from inception_v3 import InceptionV3
from attack import *
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('--start', type=int, default=0)
parser.add_argument('--end', type=int, default=100)
parser.add_argument('--attack', type=str, default='pgd', help='pgd | fgsm | none')
args = parser.parse_args()
# set up TensorFlow session
sess = tf.Session()
# initialize a model
model = InceptionV3(sess)
# initialize an attack (it's a white box attack, and it's allowed to look
# at the internals of the model in any way it wants)
if args.attack == 'fgsm':
attack = InceptionV3FGSMAttack(sess, model, model.threat_model.epsilon)
elif args.attack == 'pgd':
attack = InceptionV3PGDAttack(sess, model, model.threat_model.epsilon)
elif args.attack == 'none':
attack = NullAttack()
else:
raise ValueError('unknown attack: %s' % args.attack)
# initialize a data provider for ImageNet images
provider = robustml.provider.ImageNet(args.imagenet_path, (299, 299, 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()