-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment_runner.py
44 lines (32 loc) · 1.69 KB
/
experiment_runner.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
import os
import argparse
import subprocess
from datetime import datetime
import logging
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.DEBUG)
import setGPU
from utils import mkdirs
from attacks import FGSM, BIM, PGD, JSMA
attacks = [FGSM, BIM, PGD] # JSMA
if __name__ == '__main__':
formatter = argparse.ArgumentDefaultsHelpFormatter
parser = argparse.ArgumentParser(formatter_class=formatter)
parser.add_argument("dataset", help="Dataset", type=str, choices=['mnist', 'cifar10'])
parser.add_argument("model", help="Model type", type=str, choices=['basic_cnn', 'cnn'])
parser.add_argument("layers", help="Layers to attach the detector", type=str, nargs='+')
args = parser.parse_args()
output = os.path.join("Experiments", datetime.now().strftime("%d.%m.%y-%H:%M:%S"))
logging.getLogger().addHandler(logging.FileHandler(mkdirs(os.path.join(output, 'experiment.log'))))
logging.debug(" +++ START EXPERIMENT +++ ")
logging.debug("\n === CONFIG === ")
logging.debug("- Dataset: {0}".format(args.dataset))
logging.debug("- Model: {0}".format(args.model))
logging.debug("- Output: {0}".format(output))
logging.debug("\n === GENERATE CW SAMPLES === ")
subprocess.run(["python", "generate_CW.py", args.dataset, args.model, output])
logging.debug("\n === GENERATE ATTACK SAMPLES === ")
for attack in attacks:
subprocess.run(["python", "generate_attack_samples.py", args.dataset, args.model, attack.__name__, output])
logging.debug("\n === COMPUTE SECURITY CURVES === ")
subprocess.run(["python", "main.py", args.dataset, args.model, args.layers, output])
logging.debug("\n +++ END EXPERIMENT +++ ")