-
Notifications
You must be signed in to change notification settings - Fork 4
/
cmd_args.py
63 lines (47 loc) · 1.88 KB
/
cmd_args.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
import socket
import numpy as np
import yaml
import os, sys
import os.path as osp
import datasets
from utils.easydict import EasyDict
dataset_names = sorted(name for name in datasets.__dict__
if not name.startswith("__"))
def postprocess(args):
# -------------------- miscellaneous --------------------
args.allow_less_points = hasattr(args, 'allow_less_points') and args.allow_less_points
# -------------------- dataset --------------------
assert (args.dataset in dataset_names)
assert hasattr(args, 'data_root')
# -------------------- learning --------------------
if not args.evaluate:
# -------------------- init --------------------
if not hasattr(args, 'init'):
args.init = 'xavier'
if not hasattr(args, 'gain'):
args.gain = 1.
# -------------------- custom lr --------------------
if hasattr(args, 'custom_lr') and args.custom_lr:
args.lrs = [float(item) for item in args.lrs.split(',')][::-1]
args.lr_switch_epochs = [int(item) for item in args.lr_switch_epochs.split(',')][::-1]
assert (len(args.lrs) == len(args.lr_switch_epochs))
diffs = [second - first for first, second in zip(args.lr_switch_epochs, args.lr_switch_epochs[1:])]
assert (np.all(np.array(diffs) < 0))
args.lr = args.lrs[-1]
# -------------------- resume --------------------
if args.evaluate:
assert (hasattr(args, 'resume'))
assert args.resume is not False
'''
if not hasattr(args, 'multi_gpu'):
args.multi_gpu = None
if not hasattr(args, 'pretrain'):
args.pretrain = None
'''
return args
def parse_args_from_yaml(yaml_path):
with open(yaml_path, 'r') as fd:
args = yaml.safe_load(fd)
args = EasyDict(d=args)
args = postprocess(args)
return args