-
Notifications
You must be signed in to change notification settings - Fork 53
/
run.py
71 lines (54 loc) · 1.81 KB
/
run.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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import pprint
from easydict import EasyDict as edict
from sacred import Experiment
from sacred.utils import apply_backspaces_and_linefeeds
import torch
import custom # import all custom modules for registering objects.
from kvt.initialization import initialize
from kvt.utils import ex
from kvt.apis.train import run as run_train
from kvt.apis.evaluate import run as run_evaluate
from kvt.apis.inference import run as run_inference
from kvt.apis.swa import run as run_swa
ex.captured_out_filter = apply_backspaces_and_linefeeds
@ex.main
def main(_run, _config):
config = edict(_config)
pprint.PrettyPrinter(indent=2).pprint(config)
@ex.command
def train(_run, _config):
config = edict(_config)
print('------------------------------------------------')
print('train')
pprint.PrettyPrinter(indent=2).pprint(config)
run_train(config)
@ex.command
def evaluate(_run, _config):
config = edict(_config)
print('------------------------------------------------')
print('evaluate')
pprint.PrettyPrinter(indent=2).pprint(config)
run_evaluate(config)
@ex.command
def inference(_run, _config):
config = edict(_config)
print('------------------------------------------------')
print('inference')
pprint.PrettyPrinter(indent=2).pprint(config)
run_inference(config)
@ex.command
def swa(_run, _config):
config = edict(_config)
print('------------------------------------------------')
print('swa')
pprint.PrettyPrinter(indent=2).pprint(config)
run_swa(config)
if __name__ == '__main__':
torch.multiprocessing.set_sharing_strategy('file_system')
torch.backends.cudnn.deterministic=True
initialize()
ex.run_commandline()