forked from xiadingZ/video-caption.pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.py
executable file
·273 lines (233 loc) · 6.08 KB
/
opts.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import argparse
def parse_opt():
parser = argparse.ArgumentParser()
# Data input settings
parser.add_argument(
'--caption_csv',
type=str,
default='data/train_data.csv',
help='path to the CSV file containing video captions'
)
parser.add_argument(
'--video_root',
type=str,
default='data/videos/',
help='root path to the video files'
)
parser.add_argument(
'--feature_type',
type=str,
default='resnet152',
help='type of feature extractor to use'
)
parser.add_argument(
'--min_word_count',
type=int,
default=5,
help='minimum word count threshold for vocabulary'
)
parser.add_argument(
'--vocab_save_path',
type=str,
default='data/vocab.json',
help='path to save generated vocabulary'
)
# 保留原参数,但设置为可选
parser.add_argument(
'--input_json',
type=str,
default=None,
help='path to the json file containing video info (optional)'
)
parser.add_argument(
'--info_json',
type=str,
default=None,
help='path to the json file containing additional info and vocab (optional)'
)
parser.add_argument(
'--caption_json',
type=str,
default=None,
help='path to the processed video caption json (optional)'
)
parser.add_argument(
'--feats_dir',
nargs='*',
type=str,
default=['data/features/'],
help='path to the directory containing the preprocessed features'
)
parser.add_argument(
'--c3d_feats_dir',
type=str,
default='data/c3d_feats'
)
parser.add_argument(
'--with_c3d',
type=int,
default=0,
help='whether to use c3d features'
)
parser.add_argument(
'--cached_tokens',
type=str,
default='msr-all-idxs',
help='Cached token file for calculating cider score during self critical training.'
)
# Model settings
parser.add_argument(
"--model",
type=str,
default='S2VTModel',
help="which model to use"
)
parser.add_argument(
"--max_len",
type=int,
default=30,
help='max length of captions(containing <sos>,<eos>)'
)
parser.add_argument(
"--bidirectional",
type=int,
default=0,
help="0 for disable, 1 for enable. encoder/decoder bidirectional."
)
parser.add_argument(
'--dim_hidden',
type=int,
default=512,
help='size of the rnn hidden layer'
)
parser.add_argument(
'--num_layers',
type=int,
default=1,
help='number of layers in the RNN'
)
parser.add_argument(
'--input_dropout_p',
type=float,
default=0.2,
help='strength of dropout in the Language Model RNN'
)
parser.add_argument(
'--rnn_type',
type=str,
default='gru',
help='lstm or gru'
)
parser.add_argument(
'--rnn_dropout_p',
type=float,
default=0.5,
help='strength of dropout in the Language Model RNN'
)
parser.add_argument(
'--dim_word',
type=int,
default=512,
help='the encoding size of each token in the vocabulary, and the video.'
)
parser.add_argument(
'--dim_vid',
type=int,
default=2048,
help='dim of features of video frames'
)
# Optimization: General
parser.add_argument(
'--epochs',
type=int,
default=100, # 修改默认epoch数
help='number of epochs'
)
parser.add_argument(
'--batch_size',
type=int,
default=32, # 修改默认batch size
help='minibatch size'
)
parser.add_argument(
'--grad_clip',
type=float,
default=5,
help='clip gradients at this value'
)
parser.add_argument(
'--self_crit_after',
type=int,
default=-1,
help='After what epoch do we start finetuning the CNN? (-1 = disable; never finetune, 0 = finetune from start)'
)
parser.add_argument(
'--learning_rate',
type=float,
default=4e-4,
help='learning rate'
)
parser.add_argument(
'--learning_rate_decay_every',
type=int,
default=20, # 修改默认衰减间隔
help='every how many epochs to decay LR'
)
parser.add_argument(
'--learning_rate_decay_rate',
type=float,
default=0.8
)
parser.add_argument(
'--optim_alpha',
type=float,
default=0.9,
help='alpha for adam'
)
parser.add_argument(
'--optim_beta',
type=float,
default=0.999,
help='beta used for adam'
)
parser.add_argument(
'--optim_epsilon',
type=float,
default=1e-8,
help='epsilon that goes into denominator for smoothing'
)
parser.add_argument(
'--weight_decay',
type=float,
default=5e-4,
help='weight_decay. strength of weight regularization'
)
parser.add_argument(
'--save_checkpoint_every',
type=int,
default=5, # 修改默认保存间隔
help='how often to save a model checkpoint (in epoch)?'
)
parser.add_argument(
'--checkpoint_path',
type=str,
default='save',
help='directory to store checkpointed models'
)
parser.add_argument(
'--gpu',
type=str,
default='0',
help='gpu device number'
)
args = parser.parse_args()
# 参数后处理
if args.caption_csv:
# 如果使用CSV格式,将json相关参数设为None
args.input_json = None
args.info_json = None
args.caption_json = None
return args
if __name__ == '__main__':
opt = parse_opt()
print(opt)