forked from MILVLG/openvqa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
164 lines (129 loc) · 5.47 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# --------------------------------------------------------
# OpenVQA
# Written by Yuhao Cui https://github.com/cuiyuhao1996
# --------------------------------------------------------
from openvqa.models.model_loader import CfgLoader
from utils.exec import Execution
import argparse, yaml
def parse_args():
'''
Parse input arguments
'''
parser = argparse.ArgumentParser(description='OpenVQA 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=[
'mcan_small',
'mcan_large',
'ban_4',
'ban_8',
'mfb',
'mfh',
'mem',
'butd',
'mmnasnet'
]
,
help='{'
'mcan_small,'
'mcan_large,'
'ban_4,'
'ban_8,'
'mfb,'
'mfh,'
'butd,'
'mmnasnet,'
'}'
,
type=str, required=True)
parser.add_argument('--DATASET', dest='DATASET',
choices=['vqa', 'gqa', 'clevr'],
help='{'
'vqa,'
'gqa,'
'clevr,'
'}'
,
type=str, required=True)
parser.add_argument('--SPLIT', dest='TRAIN_SPLIT',
choices=['train', 'train+val', 'train+val+vg'],
help="set training split, "
"vqa: {'train', 'train+val', 'train+val+vg'}"
"gqa: {'train', 'train+val'}"
"clevr: {'train', 'train+val'}"
,
type=str)
parser.add_argument('--EVAL_EE', dest='EVAL_EVERY_EPOCH',
choices=['True', 'False'],
help='True: evaluate the val split when an epoch finished,'
'False: do not evaluate on local',
type=str)
parser.add_argument('--SAVE_PRED', dest='TEST_SAVE_PRED',
choices=['True', 'False'],
help='True: save the prediction vectors,'
'False: do not save the prediction vectors',
type=str)
parser.add_argument('--BS', dest='BATCH_SIZE',
help='batch size in training',
type=int)
parser.add_argument('--GPU', dest='GPU',
help="gpu choose, 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',
choices=['True', 'False'],
help='True: use checkpoint to resume training,'
'False: start training with random init',
type=str)
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, it will override'
'CKPT_VERSION and CKPT_EPOCH',
type=str)
parser.add_argument('--ACCU', dest='GRAD_ACCU_STEPS',
help='split batch to reduce gpu memory usage',
type=int)
parser.add_argument('--NW', dest='NUM_WORKERS',
help='multithreaded loading to accelerate IO',
type=int)
parser.add_argument('--PINM', dest='PIN_MEM',
choices=['True', 'False'],
help='True: use pin memory, False: not use pin memory',
type=str)
parser.add_argument('--VERB', dest='VERBOSE',
choices=['True', 'False'],
help='True: verbose print, False: simple print',
type=str)
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
cfg_file = "./configs/{}/{}.yml".format(args.DATASET, args.MODEL)
with open(cfg_file, 'r') as f:
yaml_dict = yaml.load(f)
__C = CfgLoader(yaml_dict['MODEL_USE']).load()
args = __C.str_to_bool(args)
args_dict = __C.parse_to_dict(args)
args_dict = {**yaml_dict, **args_dict}
__C.add_args(args_dict)
__C.proc()
print('Hyper Parameters:')
print(__C)
execution = Execution(__C)
execution.run(__C.RUN_MODE)