-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
82 lines (67 loc) · 3.66 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os, yaml, argparse
from time import sleep
from generator import Generator
from processor import Proccessor
def main():
parser = init_parser()
args = parser.parse_args()
args = update_parameters(parser, args)
sleep(args.delay_hours * 3600)
if args.generate_data:
g = Generator(args)
g.start()
elif args.extract:
p = Proccessor(args)
p.extract()
else:
p = Proccessor(args)
p.start()
def init_parser():
parser = argparse.ArgumentParser(description='Method for Skeleton-based Action Recognition')
# Setting
parser.add_argument('--config', '-c', type=str, default='', help='ID of the using config', required=True)
parser.add_argument('--gpus', '-g', type=int, nargs='+', default=[], help='Using GPUs')
parser.add_argument('--seed', '-s', type=int, default=1, help='Random seed')
parser.add_argument('--pretrained_path', '-pp', type=str, default='', help='Path to pretrained models')
parser.add_argument('--work_dir', '-w', type=str, default='', help='Work dir')
parser.add_argument('--no_progress_bar', '-np', default=False, action='store_true', help='Do not show progress bar')
parser.add_argument('--delay_hours', '-dh', type=float, default=0, help='Delay to run')
# Processing
parser.add_argument('--debug', '-db', default=False, action='store_true', help='Debug')
parser.add_argument('--static', '-st', default=False, action='store_true', help='Debug')
parser.add_argument('--resume', '-r', default=False, action='store_true', help='Resume from checkpoint')
parser.add_argument('--evaluate', '-e', default=False, action='store_true', help='Evaluate')
parser.add_argument('--extract', '-ex', default=False, action='store_true', help='Extract')
parser.add_argument('--visualize', '-v', default=False, action='store_true', help='Visualization')
parser.add_argument('--generate_data', '-gd', default=False, action='store_true', help='Generate skeleton data')
# Dataloader
parser.add_argument('--dataset', '-d', type=str, default='', help='Select dataset')
parser.add_argument('--dataset_args', default=dict(), help='Args for creating dataset')
# Model
parser.add_argument('--model_type', '-mt', type=str, default='', help='Args for creating model')
parser.add_argument('--model_args', default=dict(), help='Args for creating model')
# Optimizer
parser.add_argument('--optimizer', '-o', type=str, default='', help='Initial optimizer')
parser.add_argument('--optimizer_args', default=dict(), help='Args for optimizer')
# LR_Scheduler
parser.add_argument('--lr_scheduler', '-ls', type=str, default='', help='Initial learning rate scheduler')
parser.add_argument('--scheduler_args', default=dict(), help='Args for scheduler')
return parser
def update_parameters(parser, args):
if os.path.exists('./configs/{}.yaml'.format(args.config)):
with open('./configs/{}.yaml'.format(args.config), 'r') as f:
try:
yaml_arg = yaml.safe_load(f, Loader=yaml.FullLoader)
except:
yaml_arg = yaml.safe_load(f)
default_arg = vars(args)
for k in yaml_arg.keys():
if k not in default_arg.keys():
raise ValueError('Do NOT exist this parameter {}'.format(k))
parser.set_defaults(**yaml_arg)
else:
raise ValueError('Do NOT exist this file in \'configs\' folder: {}.yaml!'.format(args.config))
return parser.parse_args()
if __name__ == '__main__':
os.chdir(os.path.dirname(os.path.abspath(__file__)))
main()