-
Notifications
You must be signed in to change notification settings - Fork 36
/
params.py
247 lines (200 loc) · 8.08 KB
/
params.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
import os
import datetime
import torch
import fnmatch
import re
import numpy as np
torch.set_printoptions(linewidth=1024, precision=10)
np.set_printoptions(linewidth=1024)
np.random.seed(0)
torch.manual_seed(0)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
class AttrDict(dict):
def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
self.__dict__ = self
class Parameters(object):
__instance = None
def __new__(cls, *args, **kwargs):
if not cls.__instance:
cls.__instance = super(Parameters, cls).__new__(cls, *args, **kwargs)
return cls.__instance
def __init__(self):
self.timestamp = datetime.datetime.today()
self.n_processors = 8
self.n_gpu = 1
# Path Parameters
self.project_dir = "/home/cs4li/Dev/deep_ekf_vio/"
self.data_dir = os.path.join(self.project_dir, "data")
self.results_coll_dir = os.path.join(self.project_dir, "results")
self.pose_dir = os.path.join(self.data_dir, 'pose_GT')
self.results_dir = os.path.join(self.results_coll_dir,
"train" + "_%s" % self.timestamp.strftime('%Y%m%d-%H-%M-%S'))
self.seq_len = 32
self.sample_times = 3
self.exclude_resume_weights = ["imu_noise_covar_weights", "init_covar_diag_sqrt"]
# VO Model parameters
self.fix_vo_weights = False
self.hybrid_recurrency = False
self.rnn_hidden_size = 1000
self.rnn_num_layers = 2
self.conv_dropout = (0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.5)
self.rnn_dropout_out = 0.5
self.rnn_dropout_between = 0 # 0: no dropout
self.clip = None
self.batch_norm = True
self.stateful_training = True
# EKF parameters
self.enable_ekf = True
self.T_imu_cam_override = np.eye(4, 4)
self.cal_override_enable = True
self.train_init_covar = False
self.train_imu_noise_covar = False
self.vis_meas_covar_use_fixed = False
# Training parameters
self.epochs = 400
self.batch_size = 16
self.pin_mem = True
self.cache_image = True
self.optimizer = torch.optim.Adam
self.optimizer_args = {'lr': 1e-4}
self.param_specific_lr = {
"init_covar_diag_sqrt": 1e-1,
"imu_noise_covar_weights.*": 1e-1
}
# data augmentation
self.data_aug_rand_color = AttrDict({
"enable": True,
"params": {
"brightness": 0.1,
"contrast": 0.1,
"saturation": 0.1,
"hue": 0.05
}
})
# Pretrain, Resume training
self.pretrained_flownet = os.path.join(self.project_dir, './pretrained/flownets_bn_EPE2.459.pth.tar')
# Choice:
# None
# './pretrained/flownets_bn_EPE2.459.pth.tar'
# './pretrained/flownets_EPE1.951.pth.tar'
def wc(self, seqs):
available_seqs = [d for d in os.listdir(self.data_dir) if os.path.isdir(os.path.join(self.data_dir, d))]
ret_seqs = []
for seq in seqs:
regex = re.compile(fnmatch.translate(seq))
start_cnt = len(ret_seqs)
for available_seq in sorted(available_seqs):
if regex.match(available_seq):
ret_seqs.append(available_seq)
if not (len(ret_seqs) > start_cnt):
print("WARN!!! len(ret_seqs) > start_cnt")
return ret_seqs
def dataset(self):
raise NotImplementedError("Dataset no specified")
class KITTIParams(Parameters):
def __init__(self):
Parameters.__init__(self)
self.all_seqs = self.wc(['K00_*', 'K01', 'K02_*', 'K04', 'K05_*', 'K06', 'K07', 'K08', 'K09', 'K10'])
self.eval_seq = "K07"
self.train_seqs = [x for x in self.all_seqs if not x == self.eval_seq]
self.valid_seqs = [self.eval_seq]
# self.train_seqs = self.wc(['K00_*', 'K01', 'K02_*', 'K05_*', 'K08', 'K09'])
# self.valid_seqs = ['K04', 'K06', 'K07', 'K10']
# self.train_seqs = ['K08']
# self.valid_seqs = ['K07']
self.img_w = 320
self.img_h = 96
self.img_means = (-0.138843, -0.119405, -0.123209)
self.img_stds = (1, 1, 1)
self.minus_point_5 = True
#
self.init_covar_diag_sqrt = np.array([1e-4, 1e-4, 1e-4, # g
0, 0, 0, 0, 0, 0, # C, r
1e-2, 1e-2, 1e-2, # v
1e-8, 1e-8, 1e-8, # bw
1e-1, 1e-1, 1e-1]) # ba
self.init_covar_diag_eps = 1e-12
#
self.imu_noise_covar_diag = np.array([1e-7, # w
1e-7, # bw
1e-2, # a
1e-3]) # ba
self.imu_noise_covar_beta = 4
self.imu_noise_covar_gamma = 1
self.vis_meas_fixed_covar = np.array([1e0, 1e0, 1e0,
1e0, 1e0, 1e0])
self.vis_meas_covar_init_guess = 1e1
self.vis_meas_covar_beta = 3
self.vis_meas_covar_gamma = 1
# -----------------------------------------
self.k1 = 100 # rel loss angle multiplier
self.k2 = 500. # abs loss angle multiplier
self.k3 = { # (1-k3)*abs + k3*rel weighting, not actually used
0: 0.5,
}
# error scale for covar loss, not really used,
# but must be 1.0 for self.gaussian_pdf_loss = False
self.k4 = 1.0
self.gaussian_pdf_loss = False
self.data_aug_transforms = AttrDict({
"enable": True,
"lr_flip": True,
"ud_flip": False,
"lrud_flip": False,
"reverse": True,
})
def dataset(self):
return "KITTI"
class EUROCParams(Parameters):
def __init__(self):
Parameters.__init__(self)
self.all_seqs = ['MH_01', 'MH_02', 'MH_03', 'MH_04', 'MH_05', "V1_01", "V1_02", "V1_03", "V2_01", "V2_02"]
self.eval_seq = "MH_01"
self.train_seqs = [x for x in self.all_seqs if not x == self.eval_seq]
self.valid_seqs = [self.eval_seq]
# self.train_seqs = ['MH_01', 'MH_02', 'MH_03', 'MH_04', "V1_01", "V1_02", "V2_01"]
# self.valid_seqs = ['MH_05', "V1_03", "V2_02"]
self.img_w = 235
self.img_h = 150
self.img_means = (0,)
self.img_stds = (1,)
self.minus_point_5 = True
#
self.init_covar_diag_sqrt = np.array([1e-1, 1e-1, 1e-1, # g
0, 0, 0, 0, 0, 0, # C, r
1e-2, 1e-2, 1e-2, # v
1e-1, 1e-1, 1e-1, # bw
1e1, 1e1, 1e1]) # ba
self.init_covar_diag_eps = 1e-12
#
self.imu_noise_covar_diag = np.array([1e-3, # w
1e-5, # bw
1e-1, # a
1e-2]) # ba
self.imu_noise_covar_beta = 4
self.imu_noise_covar_gamma = 1
self.vis_meas_fixed_covar = np.array([1e0, 1e0, 1e0,
1e0, 1e0, 1e0])
self.vis_meas_covar_init_guess = 1e1
self.vis_meas_covar_beta = 3
self.vis_meas_covar_gamma = 1
self.k1 = 100 # rel loss angle multiplier
self.k2 = 500. # abs loss angle multiplier
self.k3 = { # (1-k3)*abs + k3*rel weighting
0: 0.5,
}
self.k4 = 100. # error scale for covar loss
self.gaussian_pdf_loss = True
self.data_aug_transforms = AttrDict({
"enable": False,
"lr_flip": True,
"ud_flip": False,
"lrud_flip": False,
"reverse": True,
})
def dataset(self):
return "EUROC"
par = KITTIParams()
# par = EUROCParams()