-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·86 lines (70 loc) · 2.4 KB
/
main.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
#!/usr/bin/env python3
"""
Main File to start an evaluation experiment of SEBA.
Strong Evaluation of Biometric Anonymizations
Julian Todt, Simon Hanisch & Thorsten Strufe
Karlsruhe Institute of Technology (KIT) and Technical University Dresden (TUD)
(C) 2022
Licensed under MIT.
"""
import logging
import os
import os.path
import sys
import yaml
import code
import copy
import time
import argparse
from src.lib.run import Run
def create_parser():
parser = argparse.ArgumentParser(prog="main.py")
parser.add_argument("-v", "--verbose", action="count", default=0, help="Increase verbosity (0x = INFO, 1x = DEBUG, 2x = ALL)")
parser.add_argument("-i", "--interactive", dest="interactive", default=False, action="store_true", help="Enter interactive mode")
parser.add_argument(
"-s",
"--save-result",
dest="save_result",
default=False,
action="store_true",
help="Store the full result file and not just the calculated metrics.",
)
parser.add_argument("config", default=None, help="The config file to use.")
return parser
parser = create_parser()
__doc__ += parser.format_help()
if __name__ == "__main__":
os.makedirs("logs", exist_ok=True)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
handlers=[logging.FileHandler("logs/" + time.strftime("%Y-%m-%d_%H-%M") + ".log"), logging.StreamHandler(sys.stdout)],
force=True,
)
_LOGGER = logging.getLogger("seba")
_CONFIG = []
args = parser.parse_args()
if args.verbose >= 1:
_LOGGER.setLevel(10)
if args.interactive:
code.interact(local=dict(globals(), **locals()))
sys.exit(0)
if not os.path.exists(args.config):
_LOGGER.critical("Config file does not exist!")
sys.exit(1)
try:
with open(args.config, "r") as file:
_CONFIG = yaml.load(file, Loader=yaml.SafeLoader)
except Exception as e:
_LOGGER.critical("Failed to load config")
_LOGGER.exception(e)
sys.exit(1)
for cfg in _CONFIG:
for round in range(cfg["repeat"]):
try:
run = Run(copy.deepcopy(cfg["config"]), round=round, save_result=args.save_result)
run.run()
except Exception as e:
_LOGGER.warning("Run failed.")
_LOGGER.exception(e)
continue