-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.py
38 lines (31 loc) · 931 Bytes
/
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
import configparser
import sys
import os
import shutil
usage = "Usage: main.py [train|test] <config file>"
assert len(sys.argv) in [2, 3], usage
mode = sys.argv[1]
args = configparser.ConfigParser()
args.read('default.ini')
if len(sys.argv) == 3:
conf_file = sys.argv[2]
args.read(conf_file)
assert os.path.isfile(conf_file), "No such config file"
output_base_dir = args['checkpoints']['global_output_folder']
output_dir = os.path.join(output_base_dir, args['checkpoints']['base_name'])
args['checkpoints']['output_dir'] = output_dir
os.makedirs(output_dir, exist_ok=True)
with open(os.path.join(output_dir, 'conf.ini'), 'w') as f:
args.write(f)
if mode == 'train':
import train
train.train(args)
elif mode == 'test':
import evaluation
evaluation.test(args)
elif mode == 'generate':
import evaluation.generation
evaluation.generation.main(args)
else:
print(usage)
sys.exit(1)