Skip to content

Commit

Permalink
add kitti_utils.py for evaluating with KITTI metrics (#374)
Browse files Browse the repository at this point in the history
* add kitti_utils.py for evaluating with KITTI metrics
  • Loading branch information
sshaoshuai authored Nov 25, 2020
1 parent d5655a4 commit 5949628
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pcdet/datasets/kitti/kitti_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np
from ...utils import box_utils


def transform_annotations_to_kitti_format(annos, map_name_to_kitti=None, info_with_fakelidar=False):
"""
Args:
annos:
map_name_to_kitti: dict, map name to KITTI names (Car, Pedestrian, Cyclist)
info_with_fakelidar:
Returns:
"""
for anno in annos:
for k in range(anno['name'].shape[0]):
anno['name'][k] = map_name_to_kitti[anno['name'][k]]

anno['bbox'] = np.zeros((len(anno['name']), 4))
anno['bbox'][:, 2:4] = 50 # [0, 0, 50, 50]
anno['truncated'] = np.zeros(len(anno['name']))
anno['occluded'] = np.zeros(len(anno['name']))
if 'boxes_lidar' in anno:
gt_boxes_lidar = anno['boxes_lidar'].copy()
else:
gt_boxes_lidar = anno['gt_boxes_lidar'].copy()

if len(gt_boxes_lidar) > 0:
if info_with_fakelidar:
gt_boxes_lidar = box_utils.boxes3d_kitti_fakelidar_to_lidar(gt_boxes_lidar)

gt_boxes_lidar[:, 2] -= gt_boxes_lidar[:, 5] / 2
anno['location'] = np.zeros((gt_boxes_lidar.shape[0], 3))
anno['location'][:, 0] = -gt_boxes_lidar[:, 1] # x = -y_lidar
anno['location'][:, 1] = -gt_boxes_lidar[:, 2] # y = -z_lidar
anno['location'][:, 2] = gt_boxes_lidar[:, 0] # z = x_lidar
dxdydz = gt_boxes_lidar[:, 3:6]
anno['dimensions'] = dxdydz[:, [0, 2, 1]] # lwh ==> lhw
anno['rotation_y'] = -gt_boxes_lidar[:, 6] - np.pi / 2.0
anno['alpha'] = -np.arctan2(-gt_boxes_lidar[:, 1], gt_boxes_lidar[:, 0]) + anno['rotation_y']
else:
anno['location'] = anno['dimensions'] = np.zeros((0, 3))
anno['rotation_y'] = anno['alpha'] = np.zeros(0)

return annos

0 comments on commit 5949628

Please sign in to comment.