-
Notifications
You must be signed in to change notification settings - Fork 445
/
kitti.py
627 lines (511 loc) · 21.5 KB
/
kitti.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Train models on KITTI data."""
import os
from lingvo import compat as tf
from lingvo import model_registry
from lingvo.core import base_model_params
from lingvo.core import cluster_factory
from lingvo.core import datasource
from lingvo.core import optimizer
from lingvo.core import py_utils
from lingvo.tasks.car import input_preprocessors
from lingvo.tasks.car import kitti_input_generator
from lingvo.tasks.car import lr_util
from lingvo.tasks.car import starnet
import numpy as np
# Set $KITTI_DIR to the base path of where all the KITTI files can be found.
#
# E.g., 'gs://your-bucket/kitti/3d'
_KITTI_BASE = os.environ.get('KITTI_DIR', 'FILL-ME-IN')
# Specifications for the different dataset splits.
def KITTITrainSpec(params):
p = params.Copy()
p.file_datasource.file_pattern = (
'kitti_object_3dop_train.tfrecord-*-of-00100')
p.num_samples = 3712
return p
def KITTIValSpec(params):
p = params.Copy()
p.file_datasource.file_pattern = ('kitti_object_3dop_val.tfrecord-*-of-00100')
p.num_samples = 3769
return p
def KITTITestSpec(params):
p = params.Copy()
p.file_datasource.file_pattern = ('kitti_object_test.tfrecord-*-of-00100')
p.num_samples = 7518
return p
class KITTITrain(kitti_input_generator.KITTILaser):
"""KITTI train set with raw laser data."""
@classmethod
def Params(cls):
"""Defaults params."""
p = super().Params()
return KITTITrainSpec(p)
class KITTIValidation(kitti_input_generator.KITTILaser):
"""KITTI validation set with raw laser data."""
@classmethod
def Params(cls):
"""Defaults params."""
p = super().Params()
return KITTIValSpec(p)
class KITTITest(kitti_input_generator.KITTILaser):
"""KITTI test set with raw laser data."""
@classmethod
def Params(cls):
p = super().Params()
return KITTITestSpec(p)
class KITTIGridTrain(kitti_input_generator.KITTIGrid):
"""KITTI train set with grid laser data."""
@classmethod
def Params(cls):
p = super().Params()
return KITTITrainSpec(p)
class KITTIGridValidation(kitti_input_generator.KITTIGrid):
"""KITTI validation set with grid laser data."""
@classmethod
def Params(cls):
p = super().Params()
return KITTIValSpec(p)
class KITTIGridTest(kitti_input_generator.KITTIGrid):
"""KITTI validation set with grid laser data."""
@classmethod
def Params(cls):
p = super().Params()
return KITTITestSpec(p)
class KITTISparseLaserTrain(kitti_input_generator.KITTISparseLaser):
"""KITTI train set with sparse laser data."""
@classmethod
def Params(cls):
p = super().Params()
return KITTITrainSpec(p)
class KITTISparseLaserValidation(kitti_input_generator.KITTISparseLaser):
"""KITTI validation set with sparse laser data."""
@classmethod
def Params(cls):
p = super().Params()
return KITTIValSpec(p)
class KITTISparseLaserTest(kitti_input_generator.KITTISparseLaser):
"""KITTI test set with sparse laser data."""
@classmethod
def Params(cls):
p = super().Params()
return KITTITestSpec(p)
def _MaybeRemove(values, key):
"""Remove the entry 'key' from 'values' if present."""
if key in values:
values.remove(key)
def AddLaserAndCamera(params):
"""Adds laser and camera extractors."""
cluster = cluster_factory.Current()
job = cluster.job
if job != 'decoder':
return params
extractor_params = list(dict(params.extractors.IterParams()).values())
extractor_classes = [p.cls for p in extractor_params]
# Add images if not present.
if kitti_input_generator.KITTIImageExtractor not in extractor_classes:
params.extractors.Define('images',
kitti_input_generator.KITTIImageExtractor.Params(),
'')
# Add raw lasers if not present.
if kitti_input_generator.KITTILaserExtractor not in extractor_classes:
labels = None
for p in extractor_params:
if p.cls == kitti_input_generator.KITTILabelExtractor:
labels = p
if labels is None:
labels = kitti_input_generator.KITTILabelExtractor.Params()
params.extractors.Define(
'lasers', kitti_input_generator.KITTILaserExtractor.Params(labels), '')
return params
################################################################################
# StarNet
################################################################################
@model_registry.RegisterSingleTaskModel
class StarNetCarsBase(base_model_params.SingleTaskModelParams):
"""StarNet model for cars."""
RUN_LOCALLY = False
NUM_ANCHOR_BBOX_OFFSETS = 25
NUM_ANCHOR_BBOX_ROTATIONS = 4
NUM_ANCHOR_BBOX_DIMENSIONS = 1
FOREGROUND_ASSIGNMENT_THRESHOLD = 0.6
BACKGROUND_ASSIGNMENT_THRESHOLD = 0.45
INCLUDED_CLASSES = ['Car']
class AnchorBoxSettings(input_preprocessors.SparseCarV1AnchorBoxSettings):
ROTATIONS = [0, np.pi / 2, 3. * np.pi / 4, np.pi / 4]
def _configure_input(self, p):
"""Base function managing the delegation of job specific input configs."""
self._configure_generic_input(p)
cluster = cluster_factory.Current()
job = cluster.job
if job.startswith('trainer'):
self._configure_trainer_input(p)
elif job.startswith('decoder'):
self._configure_decoder_input(p)
elif job.startswith('evaler'):
self._configure_evaler_input(p)
else:
tf.logging.info('There are no input configuration changes to for '
'job {}.'.format(job))
if self.RUN_LOCALLY:
p.num_batcher_threads = 1
p.file_buffer_size = 1
p.file_parallelism = 1
def _configure_generic_input(self, p):
"""Update input_config `p` for all jobs."""
p.file_datasource.file_pattern_prefix = _KITTI_BASE
# Perform frustum dropping before ground removal (keep_xyz_range).
p.preprocessors.Define(
'remove_out_of_frustum',
(input_preprocessors.KITTIDropPointsOutOfFrustum.Params()), '')
p.preprocessors_order.insert(
p.preprocessors_order.index('keep_xyz_range'), 'remove_out_of_frustum')
# Approximate ground removal.
p.preprocessors.keep_xyz_range.keep_z_range = (-1.35, np.inf)
# Max num points can be smaller since we have dropped points out of frustum.
p.preprocessors.pad_lasers.max_num_points = 32768
# TODO(jngiam): Analyze if these settings are optimal.
p.preprocessors.select_centers.num_cell_centers = 256
p.preprocessors.gather_features.num_points_per_cell = 512
p.preprocessors.gather_features.sample_neighbors_uniformly = True
p.preprocessors.gather_features.max_distance = 3.0
p.preprocessors.assign_anchors.foreground_assignment_threshold = (
self.FOREGROUND_ASSIGNMENT_THRESHOLD)
p.preprocessors.assign_anchors.background_assignment_threshold = (
self.BACKGROUND_ASSIGNMENT_THRESHOLD)
# Apply car anchor box settings.
tile_anchors_p = p.preprocessors.tile_anchors
self.AnchorBoxSettings.Update(p.preprocessors.tile_anchors)
num_anchor_configs = (
self.NUM_ANCHOR_BBOX_OFFSETS * self.NUM_ANCHOR_BBOX_ROTATIONS *
self.NUM_ANCHOR_BBOX_DIMENSIONS)
assert len(tile_anchors_p.anchor_box_dimensions) == num_anchor_configs
assert len(tile_anchors_p.anchor_box_rotations) == num_anchor_configs
assert len(tile_anchors_p.anchor_box_offsets) == num_anchor_configs
# Filter label extractor for anchors and visualization.
if 'labels' in p.extractors:
filtered_labels = [
kitti_input_generator.KITTILabelExtractor.KITTI_CLASS_NAMES.index(
class_name) for class_name in self.INCLUDED_CLASSES
]
p.extractors.labels.filter_labels = filtered_labels
p = AddLaserAndCamera(p)
def _configure_trainer_input(self, p):
"""Update input_config `p` for jobs running training."""
# TODO(bencaine): Change the default in input_generator to be False
# and only set this true in _configure_decoder_input
p.extractors.images.decode_image = False
_MaybeRemove(p.preprocessors_order, 'count_points')
_MaybeRemove(p.preprocessors_order, 'viz_copy')
p.preprocessors.Define(
'rot_box', (input_preprocessors.RandomBBoxTransform.Params().Set(
max_rotation=np.pi / 20.)), '')
p.preprocessors.Define('random_flip',
input_preprocessors.RandomFlipY.Params(), '')
p.preprocessors.Define(
'global_rot',
(input_preprocessors.RandomWorldRotationAboutZAxis.Params().Set(
max_rotation=np.pi / 4.)), '')
p.preprocessors.Define(
'world_scaling',
(input_preprocessors.WorldScaling.Params().Set(scaling=[0.95, 1.05])),
'')
# Do per object transforms, then random flip, then global rotation, then
# global scaling.
preprocessor_order = [
'rot_box', 'random_flip', 'global_rot', 'world_scaling'
]
insert_index = p.preprocessors_order.index('select_centers')
p.preprocessors_order = (
p.preprocessors_order[:insert_index] + preprocessor_order +
p.preprocessors_order[insert_index:])
# Add ground truth augmenter to before all preprocessors.
allowed_label_ids = [
kitti_input_generator.KITTILabelExtractor.KITTI_CLASS_NAMES.index(
class_name) for class_name in self.INCLUDED_CLASSES
]
groundtruth_db = datasource.PrefixedDataSource.Params()
groundtruth_db.file_pattern_prefix = _KITTI_BASE
groundtruth_db.file_pattern = ('kitti_train_object_cls.tfrecord-*-of-00100')
p.preprocessors.Define(
'bbox_aug', (input_preprocessors.GroundTruthAugmentor.Params().Set(
groundtruth_database=groundtruth_db,
num_db_objects=19700,
filter_min_points=5,
max_augmented_bboxes=15,
label_filter=allowed_label_ids,
)), '')
p.preprocessors_order = ['bbox_aug'] + p.preprocessors_order
p.preprocessors.Define('frustum_dropout',
(input_preprocessors.FrustumDropout.Params().Set(
theta_width=0.03, phi_width=0.0)), '')
p.preprocessors_order.insert(
p.preprocessors_order.index('gather_features'), 'frustum_dropout')
p.batch_size = 2
p.file_parallelism = 64
p.num_batcher_threads = 64
def _configure_decoder_input(self, p):
"""Update input_config `p` for jobs running decoding."""
p.batch_size = 4
p.file_parallelism = 8
p.num_batcher_threads = 8
p.file_buffer_size = 500
def _configure_evaler_input(self, p):
"""Update input_config `p` for jobs running evaluation."""
# TODO(bencaine): Change the default in input_generator to be False
# and only set this true in _configure_decoder_input
p.extractors.images.decode_image = False
_MaybeRemove(p.preprocessors_order, 'count_points')
_MaybeRemove(p.preprocessors_order, 'viz_copy')
p.batch_size = 4
p.file_parallelism = 8
p.num_batcher_threads = 8
p.file_buffer_size = 500
def Train(self):
p = KITTISparseLaserTrain.Params()
self._configure_input(p)
return p
def Test(self):
p = KITTISparseLaserTest.Params()
self._configure_input(p)
return p
def Dev(self):
p = KITTISparseLaserValidation.Params()
self._configure_input(p)
return p
def Task(self):
num_classes = len(
kitti_input_generator.KITTILabelExtractor.KITTI_CLASS_NAMES)
p = starnet.ModelV2.Params(
num_classes,
num_anchor_bboxes_offsets=self.NUM_ANCHOR_BBOX_OFFSETS,
num_anchor_bboxes_rotations=self.NUM_ANCHOR_BBOX_ROTATIONS,
num_anchor_bboxes_dimensions=self.NUM_ANCHOR_BBOX_DIMENSIONS)
p.name = 'sparse_detector'
tp = p.train
tp.optimizer = optimizer.Adam.Params()
tp.clip_gradient_norm_to_value = 5
ep = p.eval
# Evaluate the whole dataset.
ep.samples_per_summary = 0
# To be tuned.
p.train.l2_regularizer_weight = 1e-4
# Adapted from V1 tuning.
tp.ema_decay = 0.99
# TODO(b/148537111): consider setting this to True.
tp.ema_decay_moving_vars = False
tp.learning_rate = 0.001
lr_util.SetExponentialLR(
train_p=tp,
train_input_p=self.Train(),
exp_start_epoch=150,
total_epoch=650)
p.dimension_loss_weight = .3
p.location_loss_weight = 3.
p.loss_weight_classification = 1.
p.loss_weight_localization = 3.
p.rotation_loss_weight = 0.3
return p
@model_registry.RegisterSingleTaskModel
class StarNetCarModel0701(StarNetCarsBase):
"""StarNet Car model trained on KITTI."""
class AnchorBoxSettings(input_preprocessors.SparseCarV1AnchorBoxSettings):
CENTER_X_OFFSETS = np.linspace(-1.294, 1.294, 5)
CENTER_Y_OFFSETS = np.linspace(-1.294, 1.294, 5)
def _configure_generic_input(self, p):
super()._configure_generic_input(p)
# For selecting centers, drop points out of frustum and do approximate
# ground removal.
p.preprocessors.select_centers.features_preparation_layers = [
input_preprocessors.KITTIDropPointsOutOfFrustum.Params(),
input_preprocessors.DropLaserPointsOutOfRange.Params().Set(
keep_z_range=(-1., np.inf)),
]
# Remove frustum dropping from original preprocessors.
p.preprocessors_order.remove('remove_out_of_frustum')
# Keep all points in front of the car for featurizing, do not remove ground.
p.preprocessors.keep_xyz_range.keep_x_range = (0., np.inf)
p.preprocessors.keep_xyz_range.keep_y_range = (-40., 40.)
p.preprocessors.keep_xyz_range.keep_z_range = (-np.inf, np.inf)
p.preprocessors.pad_lasers.max_num_points = 72000
p.preprocessors.select_centers.sampling_method = 'farthest_point'
p.preprocessors.select_centers.num_cell_centers = 768
p.preprocessors.gather_features.max_distance = 3.75
p.preprocessors.assign_anchors.foreground_assignment_threshold = 0.567087
# Disable ignore class, by setting background threshold > foreground.
p.preprocessors.assign_anchors.background_assignment_threshold = 1.0
p.preprocessors.select_centers.features_preparation_layers = [
input_preprocessors.KITTIDropPointsOutOfFrustum.Params(),
input_preprocessors.DropLaserPointsOutOfRange.Params().Set(
keep_z_range=(-1.4, np.inf)),
]
def _configure_trainer_input(self, p):
super()._configure_trainer_input(p)
p.preprocessors.Define(
'global_loc_noise',
(input_preprocessors.GlobalTranslateNoise.Params().Set(
noise_std=[0., 0., 0.35])), '')
p.preprocessors_order.insert(
p.preprocessors_order.index('world_scaling') + 1, 'global_loc_noise')
def Task(self):
p = super().Task()
# Builder configuration.
builder = starnet.Builder()
builder.linear_params_init = py_utils.WeightInit.KaimingUniformFanInRelu()
gin_layer_sizes = [32, 256, 512, 256, 256, 128]
num_laser_features = 1
gin_layers = [
# Each layer should expect as input - 2 * dims of the last layer's
# output. We assume a middle layer that's the size of 2 * dim_out.
[dim_in * 2, dim_out * 2, dim_out]
for (dim_in, dim_out) in zip(gin_layer_sizes[:-1], gin_layer_sizes[1:])
]
p.cell_feature_dims = sum(gin_layer_sizes)
p.cell_featurizer = builder.GINFeaturizerV2(
name='feat',
fc_dims=gin_layer_sizes[0],
mlp_dims=gin_layers,
num_laser_features=num_laser_features,
fc_use_bn=False)
p.anchor_projected_feature_dims = 512
# Loss and training params
p.train.learning_rate = 0.001 / 2. # Divide by batch size.
p.focal_loss_alpha = 0.2
p.focal_loss_gamma = 3.0
class_name_to_idx = kitti_input_generator.KITTILabelExtractor.KITTI_CLASS_NAMES
num_classes = len(class_name_to_idx)
p.per_class_loss_weight = [0.] * num_classes
p.per_class_loss_weight[class_name_to_idx.index('Car')] = 1.
# Decoding / NMS params.
p.use_oriented_per_class_nms = True
p.max_nms_boxes = 512
p.nms_iou_threshold = [0.0] * num_classes
p.nms_iou_threshold[class_name_to_idx.index('Car')] = 0.0831011
p.nms_score_threshold = [1.0] * num_classes
p.nms_score_threshold[class_name_to_idx.index('Car')] = 0.321310
p.output_decoder.truncation_threshold = 0.65
p.output_decoder.filter_predictions_outside_frustum = True
return p
@model_registry.RegisterSingleTaskModel
class StarNetPedCycModel0704(StarNetCarsBase):
"""StarNet Ped/Cyc model trained on KITTI."""
INCLUDED_CLASSES = ['Pedestrian', 'Cyclist']
FOREGROUND_ASSIGNMENT_THRESHOLD = 0.48
# Any value > FOREGROUND is equivalent.
BACKGROUND_ASSIGNMENT_THRESHOLD = 0.80
NUM_ANCHOR_BBOX_OFFSETS = 9
NUM_ANCHOR_BBOX_ROTATIONS = 4
NUM_ANCHOR_BBOX_DIMENSIONS = 3
class AnchorBoxSettings(input_preprocessors.SparseCarV1AnchorBoxSettings):
# PointPillars priors for pedestrian/cyclists.
DIMENSION_PRIORS = [(0.6, 0.8, 1.7), (0.6, 0.6, 1.2), (0.6, 1.76, 1.73)]
ROTATIONS = [0, np.pi / 2, 3. * np.pi / 4, np.pi / 4]
CENTER_X_OFFSETS = np.linspace(-0.31, 0.31, 3)
CENTER_Y_OFFSETS = np.linspace(-0.31, 0.31, 3)
CENTER_Z_OFFSETS = [-0.6]
def _configure_generic_input(self, p):
super()._configure_generic_input(p)
# For selecting centers, drop points out of frustum and do approximate
# ground removal.
p.preprocessors.select_centers.features_preparation_layers = [
input_preprocessors.KITTIDropPointsOutOfFrustum.Params(),
input_preprocessors.DropLaserPointsOutOfRange.Params().Set(
keep_z_range=(-1., np.inf)),
]
# Remove frustum dropping from original preprocessors.
p.preprocessors_order.remove('remove_out_of_frustum')
# Keep all points in front of the car for featurizing, do not remove ground.
p.preprocessors.keep_xyz_range.keep_x_range = (0., 48.0)
p.preprocessors.keep_xyz_range.keep_y_range = (-20., 20.)
p.preprocessors.keep_xyz_range.keep_z_range = (-np.inf, np.inf)
p.preprocessors.pad_lasers.max_num_points = 72000
p.preprocessors.select_centers.sampling_method = 'farthest_point'
p.preprocessors.select_centers.num_cell_centers = 512
p.preprocessors.select_centers.features_preparation_layers = [
input_preprocessors.KITTIDropPointsOutOfFrustum.Params(),
input_preprocessors.DropLaserPointsOutOfRange.Params().Set(
keep_z_range=(-1.4, np.inf)),
]
p.preprocessors.gather_features.max_distance = 2.55
def _configure_trainer_input(self, p):
super()._configure_trainer_input(p)
allowed_label_ids = [
kitti_input_generator.KITTILabelExtractor.KITTI_CLASS_NAMES.index(
class_name) for class_name in self.INCLUDED_CLASSES
]
p.preprocessors.bbox_aug.Set(
num_db_objects=19700,
filter_min_difficulty=2,
filter_min_points=7,
max_augmented_bboxes=2,
max_num_points_per_bbox=1558,
label_filter=allowed_label_ids,
)
p.batch_size = 2
def _configure_decoder_input(self, p):
"""Update input_config `p` for jobs running decoding."""
super()._configure_decoder_input(p)
p.batch_size = 4
def _configure_evaler_input(self, p):
"""Update input_config `p` for jobs running evaluation."""
super()._configure_evaler_input(p)
p.batch_size = 4
def Task(self):
p = super().Task()
p.train.learning_rate = 7e-4
builder = starnet.Builder()
builder.linear_params_init = py_utils.WeightInit.KaimingUniformFanInRelu()
gin_layer_sizes = [32, 256, 512, 256, 256, 128]
num_laser_features = 1
gin_layers = [
# Each layer should expect as input - 2 * dims of the last layer's
# output. We assume a middle layer that's the size of 2 * dim_out.
[dim_in * 2, dim_out * 2, dim_out]
for (dim_in, dim_out) in zip(gin_layer_sizes[:-1], gin_layer_sizes[1:])
]
p.cell_feature_dims = sum(gin_layer_sizes)
# Disable BN on first layer
p.cell_featurizer = builder.GINFeaturizerV2(
'feat',
gin_layer_sizes[0],
gin_layers,
num_laser_features,
fc_use_bn=False)
p.anchor_projected_feature_dims = 512
class_name_to_idx = kitti_input_generator.KITTILabelExtractor.KITTI_CLASS_NAMES
num_classes = len(class_name_to_idx)
p.per_class_loss_weight = [0.] * num_classes
p.per_class_loss_weight[class_name_to_idx.index('Pedestrian')] = 3.5
p.per_class_loss_weight[class_name_to_idx.index('Cyclist')] = 3.25
p.focal_loss_alpha = 0.9
p.focal_loss_gamma = 1.25
p.use_oriented_per_class_nms = True
p.max_nms_boxes = 1024
p.nms_iou_threshold = [0.0] * num_classes
p.nms_iou_threshold[class_name_to_idx.index('Cyclist')] = 0.49
p.nms_iou_threshold[class_name_to_idx.index('Pedestrian')] = 0.32
p.nms_score_threshold = [1.0] * num_classes
p.nms_score_threshold[class_name_to_idx.index('Cyclist')] = 0.11
p.nms_score_threshold[class_name_to_idx.index('Pedestrian')] = 0.23
p.output_decoder.filter_predictions_outside_frustum = True
p.output_decoder.truncation_threshold = 0.65
# Equally weight pedestrian and cyclist moderate classes.
p.output_decoder.ap_metric.metric_weights = {
'easy': np.array([0.0, 0.0, 0.0]),
'moderate': np.array([0.0, 1.0, 1.0]),
'hard': np.array([0.0, 0.0, 0.0])
}
return p