Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 42 additions & 41 deletions tools/dataset_converters/update_infos_to_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import copy
import time
from os import path as osp
from pathlib import Path

import mmengine
import numpy as np
Expand Down Expand Up @@ -283,8 +284,8 @@ def update_nuscenes_infos(pkl_path, out_dir):
ori_info_dict['ego2global_translation'])
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict.get(
'num_features', 5)
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[
'lidar_path'].split('/')[-1]
temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'lidar_path']).name
temp_data_info['lidar_points'][
'lidar2ego'] = convert_quaternion_to_matrix(
ori_info_dict['lidar2ego_rotation'],
Expand Down Expand Up @@ -314,8 +315,8 @@ def update_nuscenes_infos(pkl_path, out_dir):
temp_data_info['images'] = {}
for cam in ori_info_dict['cams']:
empty_img_info = get_empty_img_info()
empty_img_info['img_path'] = ori_info_dict['cams'][cam][
'data_path'].split('/')[-1]
empty_img_info['img_path'] = Path(ori_info_dict['cams'][cam][
'data_path']).name
empty_img_info['cam2img'] = ori_info_dict['cams'][cam][
'cam_intrinsic'].tolist()
empty_img_info['sample_data_token'] = ori_info_dict['cams'][cam][
Expand Down Expand Up @@ -359,7 +360,7 @@ def update_nuscenes_infos(pkl_path, out_dir):
ori_info_dict, nusc)
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(temp_data_info)
pkl_name = pkl_path.split('/')[-1]
pkl_name = Path(pkl_path).name
out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}')
Expand Down Expand Up @@ -410,15 +411,15 @@ def update_kitti_infos(pkl_path, out_dir):
temp_data_info['images']['CAM3']['cam2img'] = ori_info_dict['calib'][
'P3'].tolist()

temp_data_info['images']['CAM2']['img_path'] = ori_info_dict['image'][
'image_path'].split('/')[-1]
temp_data_info['images']['CAM2']['img_path'] = Path(ori_info_dict['image'][
'image_path']).name
h, w = ori_info_dict['image']['image_shape']
temp_data_info['images']['CAM2']['height'] = h
temp_data_info['images']['CAM2']['width'] = w
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[
'point_cloud']['num_features']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[
'point_cloud']['velodyne_path'].split('/')[-1]
temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'point_cloud']['velodyne_path']).name

rect = ori_info_dict['calib']['R0_rect'].astype(np.float32)
Trv2c = ori_info_dict['calib']['Tr_velo_to_cam'].astype(np.float32)
Expand Down Expand Up @@ -498,7 +499,7 @@ def update_kitti_infos(pkl_path, out_dir):
temp_data_info['cam_instances'] = cam_instances
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(temp_data_info)
pkl_name = pkl_path.split('/')[-1]
pkl_name = Path(pkl_path).name
out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}')
Expand Down Expand Up @@ -532,12 +533,12 @@ def update_s3dis_infos(pkl_path, out_dir):
temp_data_info['sample_idx'] = i
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[
'point_cloud']['num_features']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[
'pts_path'].split('/')[-1]
temp_data_info['pts_semantic_mask_path'] = ori_info_dict[
'pts_semantic_mask_path'].split('/')[-1]
temp_data_info['pts_instance_mask_path'] = ori_info_dict[
'pts_instance_mask_path'].split('/')[-1]
temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'pts_path']).name
temp_data_info['pts_semantic_mask_path'] = Path(ori_info_dict[
'pts_semantic_mask_path']).name
temp_data_info['pts_instance_mask_path'] = Path(ori_info_dict[
'pts_instance_mask_path']).name

# TODO support camera
# np.linalg.inv(info['axis_align_matrix'] @ extrinsic): depth2cam
Expand Down Expand Up @@ -567,7 +568,7 @@ def update_s3dis_infos(pkl_path, out_dir):
temp_data_info['instances'] = instance_list
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(temp_data_info)
pkl_name = pkl_path.split('/')[-1]
pkl_name = Path(pkl_path).name
out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}')
Expand Down Expand Up @@ -606,12 +607,12 @@ def update_scannet_infos(pkl_path, out_dir):
temp_data_info = get_empty_standard_data_info()
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[
'point_cloud']['num_features']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[
'pts_path'].split('/')[-1]
temp_data_info['pts_semantic_mask_path'] = ori_info_dict[
'pts_semantic_mask_path'].split('/')[-1]
temp_data_info['pts_instance_mask_path'] = ori_info_dict[
'pts_instance_mask_path'].split('/')[-1]
temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'pts_path']).name
temp_data_info['pts_semantic_mask_path'] = Path(ori_info_dict[
'pts_semantic_mask_path']).name
temp_data_info['pts_instance_mask_path'] = Path(ori_info_dict[
'pts_instance_mask_path']).name

# TODO support camera
# np.linalg.inv(info['axis_align_matrix'] @ extrinsic): depth2cam
Expand Down Expand Up @@ -641,7 +642,7 @@ def update_scannet_infos(pkl_path, out_dir):
temp_data_info['instances'] = instance_list
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(temp_data_info)
pkl_name = pkl_path.split('/')[-1]
pkl_name = Path(pkl_path).name
out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}')
Expand Down Expand Up @@ -678,17 +679,17 @@ def update_sunrgbd_infos(pkl_path, out_dir):
temp_data_info = get_empty_standard_data_info()
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[
'point_cloud']['num_features']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[
'pts_path'].split('/')[-1]
temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'pts_path']).name
calib = ori_info_dict['calib']
rt_mat = calib['Rt']
# follow Coord3DMode.convert_point
rt_mat = np.array([[1, 0, 0], [0, 0, -1], [0, 1, 0]
]) @ rt_mat.transpose(1, 0)
depth2img = calib['K'] @ rt_mat
temp_data_info['images']['CAM0']['depth2img'] = depth2img.tolist()
temp_data_info['images']['CAM0']['img_path'] = ori_info_dict['image'][
'image_path'].split('/')[-1]
temp_data_info['images']['CAM0']['img_path'] = Path(ori_info_dict['image'][
'image_path']).name
h, w = ori_info_dict['image']['image_shape']
temp_data_info['images']['CAM0']['height'] = h
temp_data_info['images']['CAM0']['width'] = w
Expand Down Expand Up @@ -719,7 +720,7 @@ def update_sunrgbd_infos(pkl_path, out_dir):
temp_data_info['instances'] = instance_list
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(temp_data_info)
pkl_name = pkl_path.split('/')[-1]
pkl_name = Path(pkl_path).name
out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}')
Expand Down Expand Up @@ -760,8 +761,8 @@ def update_lyft_infos(pkl_path, out_dir):
temp_data_info['ego2global'] = convert_quaternion_to_matrix(
ori_info_dict['ego2global_rotation'],
ori_info_dict['ego2global_translation'])
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[
'lidar_path'].split('/')[-1]
temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'lidar_path']).name
temp_data_info['lidar_points'][
'lidar2ego'] = convert_quaternion_to_matrix(
ori_info_dict['lidar2ego_rotation'],
Expand Down Expand Up @@ -792,8 +793,8 @@ def update_lyft_infos(pkl_path, out_dir):
temp_data_info['images'] = {}
for cam in ori_info_dict['cams']:
empty_img_info = get_empty_img_info()
empty_img_info['img_path'] = ori_info_dict['cams'][cam][
'data_path'].split('/')[-1]
empty_img_info['img_path'] = Path(ori_info_dict['cams'][cam][
'data_path']).name
empty_img_info['cam2img'] = ori_info_dict['cams'][cam][
'cam_intrinsic'].tolist()
empty_img_info['sample_data_token'] = ori_info_dict['cams'][cam][
Expand Down Expand Up @@ -829,7 +830,7 @@ def update_lyft_infos(pkl_path, out_dir):
temp_data_info['instances'].append(empty_instance)
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(temp_data_info)
pkl_name = pkl_path.split('/')[-1]
pkl_name = Path(pkl_path).name
out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}')
Expand Down Expand Up @@ -896,7 +897,7 @@ def update_waymo_infos(pkl_path, out_dir):
ori_info_dict['calib'][f'P{cam_idx}'] @ lidar2cam).tolist()

# image path
base_img_path = ori_info_dict['image']['image_path'].split('/')[-1]
base_img_path = Path(ori_info_dict['image']['image_path']).name

for cam_idx, cam_key in enumerate(camera_types):
temp_data_info['images'][cam_key]['timestamp'] = ori_info_dict[
Expand All @@ -912,8 +913,8 @@ def update_waymo_infos(pkl_path, out_dir):
'point_cloud']['num_features']
temp_data_info['lidar_points']['timestamp'] = ori_info_dict[
'timestamp']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[
'point_cloud']['velodyne_path'].split('/')[-1]
temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'point_cloud']['velodyne_path']).name

# TODO discuss the usage of Tr_velo_to_cam in lidar
Trv2c = ori_info_dict['calib']['Tr_velo_to_cam'].astype(np.float32)
Expand All @@ -933,13 +934,13 @@ def update_waymo_infos(pkl_path, out_dir):
lidar_sweep = get_single_lidar_sweep()
lidar_sweep['ego2global'] = ori_sweep['pose']
lidar_sweep['timestamp'] = ori_sweep['timestamp']
lidar_sweep['lidar_points']['lidar_path'] = ori_sweep[
'velodyne_path'].split('/')[-1]
lidar_sweep['lidar_points']['lidar_path'] = Path(ori_sweep[
'velodyne_path']).name
# image sweeps
image_sweep = get_single_image_sweep(camera_types)
image_sweep['ego2global'] = ori_sweep['pose']
image_sweep['timestamp'] = ori_sweep['timestamp']
img_path = ori_sweep['image_path'].split('/')[-1]
img_path = Path(ori_sweep['image_path']).name
for cam_idx, cam_key in enumerate(camera_types):
image_sweep['images'][cam_key]['img_path'] = img_path

Expand Down Expand Up @@ -1036,7 +1037,7 @@ def update_waymo_infos(pkl_path, out_dir):

temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(temp_data_info)
pkl_name = pkl_path.split('/')[-1]
pkl_name = Path(pkl_path).name
out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}')
Expand Down