forked from DAMNETS/DAMNETS_ICML_2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_exp.py
57 lines (50 loc) · 1.63 KB
/
run_exp.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
import argparse
import os
import numpy as np
import torch
import random
from runner import Runner
from utils.arg_helper import get_config
def parse_arguments():
parser = argparse.ArgumentParser(
description="DAMNETS - A Deep Autoregressive Markovian NTS Generator")
parser.add_argument('-t', '--test', help="Test model", action='store_true')
parser.add_argument(
'-c',
'--config_file',
type=str,
help="Path of config file, if empty and -t flag is given will test from the last model trained.",
nargs='?',
const=''
)
args = parser.parse_args()
return args
def main():
c_args = parse_arguments()
if c_args.test:
if c_args.config_file == '':
with open('experiment_files/last_train.txt', 'r') as f:
config_file = os.path.join(f.readline(), 'config.yaml')
else:
config_file = c_args.config_file
args = get_config(config_file, is_test=True)
random.seed(args.seed)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.cuda.manual_seed_all(args.seed)
runner = Runner(args, is_test=True)
runner.test()
else:
args = get_config(os.path.join('experiment_configs', c_args.config_file))
random.seed(args.seed)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.cuda.manual_seed_all(args.seed)
runner = Runner(args)
try:
runner.train()
except KeyboardInterrupt:
print('Stopping Training')
runner.save_training_info()
if __name__ == '__main__':
main()