-
Notifications
You must be signed in to change notification settings - Fork 88
/
run.py
145 lines (108 loc) · 4.63 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# --------------------------------------------------------
# mcan-vqa (Deep Modular Co-Attention Networks)
# Licensed under The MIT License [see LICENSE for details]
# Written by Yuhao Cui https://github.com/cuiyuhao1996
# --------------------------------------------------------
from cfgs.base_cfgs import Cfgs
from core.exec import Execution
import argparse, yaml
def parse_args():
'''
Parse input arguments
'''
parser = argparse.ArgumentParser(description='MCAN Args')
parser.add_argument('--RUN', dest='RUN_MODE',
choices=['train', 'val', 'test'],
help='{train, val, test}',
type=str, required=True)
parser.add_argument('--MODEL', dest='MODEL',
choices=['small', 'large'],
help='{small, large}',
default='small', type=str)
parser.add_argument('--SPLIT', dest='TRAIN_SPLIT',
choices=['train', 'train+val', 'train+val+vg'],
help="set training split, "
"eg.'train', 'train+val+vg'"
"set 'train' can trigger the "
"eval after every epoch",
type=str)
parser.add_argument('--EVAL_EE', dest='EVAL_EVERY_EPOCH',
help='set True to evaluate the '
'val split when an epoch finished'
"(only work when train with "
"'train' split)",
type=bool)
parser.add_argument('--SAVE_PRED', dest='TEST_SAVE_PRED',
help='set True to save the '
'prediction vectors'
'(only work in testing)',
type=bool)
parser.add_argument('--BS', dest='BATCH_SIZE',
help='batch size during training',
type=int)
parser.add_argument('--MAX_EPOCH', dest='MAX_EPOCH',
help='max training epoch',
type=int)
parser.add_argument('--PRELOAD', dest='PRELOAD',
help='pre-load the features into memory'
'to increase the I/O speed',
type=bool)
parser.add_argument('--GPU', dest='GPU',
help="gpu select, eg.'0, 1, 2'",
type=str)
parser.add_argument('--SEED', dest='SEED',
help='fix random seed',
type=int)
parser.add_argument('--VERSION', dest='VERSION',
help='version control',
type=str)
parser.add_argument('--RESUME', dest='RESUME',
help='resume training',
type=bool)
parser.add_argument('--CKPT_V', dest='CKPT_VERSION',
help='checkpoint version',
type=str)
parser.add_argument('--CKPT_E', dest='CKPT_EPOCH',
help='checkpoint epoch',
type=int)
parser.add_argument('--CKPT_PATH', dest='CKPT_PATH',
help='load checkpoint path, we '
'recommend that you use '
'CKPT_VERSION and CKPT_EPOCH '
'instead',
type=str)
parser.add_argument('--ACCU', dest='GRAD_ACCU_STEPS',
help='reduce gpu memory usage',
type=int)
parser.add_argument('--NW', dest='NUM_WORKERS',
help='multithreaded loading',
type=int)
parser.add_argument('--PINM', dest='PIN_MEM',
help='use pin memory',
type=bool)
parser.add_argument('--VERB', dest='VERBOSE',
help='verbose print',
type=bool)
parser.add_argument('--DATA_PATH', dest='DATASET_PATH',
help='vqav2 dataset root path',
type=str)
parser.add_argument('--FEAT_PATH', dest='FEATURE_PATH',
help='bottom up features root path',
type=str)
args = parser.parse_args()
return args
if __name__ == '__main__':
__C = Cfgs()
args = parse_args()
args_dict = __C.parse_to_dict(args)
cfg_file = "cfgs/{}_model.yml".format(args.MODEL)
with open(cfg_file, 'r') as f:
yaml_dict = yaml.load(f)
args_dict = {**yaml_dict, **args_dict}
__C.add_args(args_dict)
__C.proc()
print('Hyper Parameters:')
print(__C)
__C.check_path()
execution = Execution(__C)
execution.run(__C.RUN_MODE)