forked from laoreja/HPLFlowNet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd_args.py
65 lines (50 loc) · 2.16 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
63
64
import socket
import numpy as np
import yaml
import os, sys
import os.path as osp
import datasets
import models
from utils.easydict import EasyDict
model_names = sorted(name for name in models.__dict__
if (not name.startswith("__"))
and ('Args' not in name)
and ('Block' not in name)
and ('net' in name or 'Net' in name)
and callable(models.__dict__[name])) + ['ICP']
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
# -------------------- arch --------------------
assert (args.arch in model_names)
# -------------------- 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
return args
def parse_args_from_yaml(yaml_path):
with open(yaml_path, 'r') as fd:
args = yaml.load(fd, Loader=yaml.FullLoader)
args = EasyDict(d=args)
args = postprocess(args)
return args