-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
181 lines (145 loc) · 6.39 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# --------------------------------------------------------
# OpenVQA
# Written by Yuhao Cui https://github.com/cuiyuhao1996
# Modified at FrostLabs
# --------------------------------------------------------
from openvqa.models.model_loader import CfgLoader
from utils.exec_module 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}',
default='train',
type=str, required=False)
parser.add_argument('--MODEL', dest='MODEL',
choices=[
'mfb',
'mfh',
'butd',
]
,
help='{'
'mfb,'
'mfh,'
'butd,'
'}'
,
type=str, required=True)
parser.add_argument('--DATASET', dest='DATASET',
choices=['vqa', 'gqa', 'clevr'],
help='{'
'vqa,'
'gqa,'
'clevr,'
'}'
,
default='vqa',
type=str, required=False)
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'}"
,
default='train', required=False,
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',
default='True',
required=False,
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',
default='True',
required=False,
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, ...'",
default='0, 1',
type=str)
parser.add_argument('--SEED', dest='SEED',
help='fix random seed',
type=int)
parser.add_argument('--VERSION', dest='VERSION',
help='Enter descriptive name here (eg baseline_wa_gru), will be used for WANDB and for version',
required=True,
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)
parser.add_argument('--USE_NEW_QUESTION', dest='USE_NEW_QUESTION',
choices=['True', 'False'],
help='whether to use new question while testing',
default='False',
type=str)
parser.add_argument('--NEW_QUESTION', dest='NEW_QUESTION',
help='the new question to be asked while testing',
type=str)
parser.add_argument('--IMAGE_ID', dest='IMAGE_ID',
help='image id on which the questions to be asked',
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:
# Loads the yaml file
yaml_dict = yaml.load(f)
# Loads the model_cfgs + base_cfgs
__C = CfgLoader(yaml_dict['MODEL_USE']).load()
# Loads the command line cfgs
args = __C.str_to_bool(args)
args_dict = __C.parse_to_dict(args)
# {**dict1, **dict2} creates a new dictionary by merging dict1 and dict2, using dict2 for key clashes
args_dict = {**yaml_dict, **args_dict}
__C.add_args(args_dict)
__C.proc()
# FINAL PREFERENCE OF CFGS:
# COMMAND LINE > YAML FILE > MODEL CFGS > BASE CFGS
print('Hyper Parameters:')
print(__C)
execution = Execution(__C)
execution.run(__C.RUN_MODE)