-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
51 lines (40 loc) · 1.43 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import yaml
import argparse
import os
from pathlib import Path
from pprint import pprint
from group.group import Group
from group.utils.distributed_utils import dist_init, dist_init_pytorch
def parse_args():
"""
parse args
:return:args
"""
new_parser = argparse.ArgumentParser(
description='PyTorch Density parser..')
new_parser.add_argument('--config', help='model config file path')
new_parser.add_argument('--checkpoint', default=None, help='the checkpoint file')
new_parser.add_argument('--resume', default=None, help='the checkpoint file to resume from')
new_parser.add_argument('--evaluate', action='store_true', default=False, help='train or test')
return new_parser.parse_args()
def main():
# rank, world_size = dist_init("23332")
rank, world_size = dist_init_pytorch("23332")
# parse args and load config
args = parse_args()
with open(args.config) as f:
config = yaml.load(f, Loader=yaml.FullLoader)
config['checkpoint'] = args.checkpoint
config['resume'] = args.resume
config['evaluate'] = args.evaluate
config['basedir'] = os.getcwd() + '/experiments/' + Path(args.config).resolve().stem
if rank == 0:
pprint(config)
group_helper = Group(config, work_dir=config['basedir'])
if args.evaluate:
group_helper.epoch=0
group_helper.val()
else:
group_helper.train()
if __name__ == '__main__':
main()