Commit 5437bf21 authored by vavanade's avatar vavanade Committed by ZwwWayne
Browse files

fix paths in `update_infos_to_v2` on Windows by using `pathlib` (#2031)

* fix paths on Windows by using `pathlib`

* refactor Path import
parent 0029612d
...@@ -12,6 +12,7 @@ import argparse ...@@ -12,6 +12,7 @@ import argparse
import copy import copy
import time import time
from os import path as osp from os import path as osp
from pathlib import Path
import mmengine import mmengine
import numpy as np import numpy as np
...@@ -283,8 +284,8 @@ def update_nuscenes_infos(pkl_path, out_dir): ...@@ -283,8 +284,8 @@ def update_nuscenes_infos(pkl_path, out_dir):
ori_info_dict['ego2global_translation']) ori_info_dict['ego2global_translation'])
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict.get( temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict.get(
'num_features', 5) 'num_features', 5)
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[ temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'lidar_path'].split('/')[-1] 'lidar_path']).name
temp_data_info['lidar_points'][ temp_data_info['lidar_points'][
'lidar2ego'] = convert_quaternion_to_matrix( 'lidar2ego'] = convert_quaternion_to_matrix(
ori_info_dict['lidar2ego_rotation'], ori_info_dict['lidar2ego_rotation'],
...@@ -314,8 +315,8 @@ def update_nuscenes_infos(pkl_path, out_dir): ...@@ -314,8 +315,8 @@ def update_nuscenes_infos(pkl_path, out_dir):
temp_data_info['images'] = {} temp_data_info['images'] = {}
for cam in ori_info_dict['cams']: for cam in ori_info_dict['cams']:
empty_img_info = get_empty_img_info() empty_img_info = get_empty_img_info()
empty_img_info['img_path'] = ori_info_dict['cams'][cam][ empty_img_info['img_path'] = Path(ori_info_dict['cams'][cam][
'data_path'].split('/')[-1] 'data_path']).name
empty_img_info['cam2img'] = ori_info_dict['cams'][cam][ empty_img_info['cam2img'] = ori_info_dict['cams'][cam][
'cam_intrinsic'].tolist() 'cam_intrinsic'].tolist()
empty_img_info['sample_data_token'] = ori_info_dict['cams'][cam][ empty_img_info['sample_data_token'] = ori_info_dict['cams'][cam][
...@@ -359,7 +360,7 @@ def update_nuscenes_infos(pkl_path, out_dir): ...@@ -359,7 +360,7 @@ def update_nuscenes_infos(pkl_path, out_dir):
ori_info_dict, nusc) ori_info_dict, nusc)
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info) temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(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) out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.') print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}') print(f'ignore classes: {ignore_class_name}')
...@@ -410,15 +411,15 @@ def update_kitti_infos(pkl_path, out_dir): ...@@ -410,15 +411,15 @@ def update_kitti_infos(pkl_path, out_dir):
temp_data_info['images']['CAM3']['cam2img'] = ori_info_dict['calib'][ temp_data_info['images']['CAM3']['cam2img'] = ori_info_dict['calib'][
'P3'].tolist() 'P3'].tolist()
temp_data_info['images']['CAM2']['img_path'] = ori_info_dict['image'][ temp_data_info['images']['CAM2']['img_path'] = Path(ori_info_dict['image'][
'image_path'].split('/')[-1] 'image_path']).name
h, w = ori_info_dict['image']['image_shape'] h, w = ori_info_dict['image']['image_shape']
temp_data_info['images']['CAM2']['height'] = h temp_data_info['images']['CAM2']['height'] = h
temp_data_info['images']['CAM2']['width'] = w temp_data_info['images']['CAM2']['width'] = w
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[ temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[
'point_cloud']['num_features'] 'point_cloud']['num_features']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[ temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'point_cloud']['velodyne_path'].split('/')[-1] 'point_cloud']['velodyne_path']).name
rect = ori_info_dict['calib']['R0_rect'].astype(np.float32) rect = ori_info_dict['calib']['R0_rect'].astype(np.float32)
Trv2c = ori_info_dict['calib']['Tr_velo_to_cam'].astype(np.float32) Trv2c = ori_info_dict['calib']['Tr_velo_to_cam'].astype(np.float32)
...@@ -498,7 +499,7 @@ def update_kitti_infos(pkl_path, out_dir): ...@@ -498,7 +499,7 @@ def update_kitti_infos(pkl_path, out_dir):
temp_data_info['cam_instances'] = cam_instances temp_data_info['cam_instances'] = cam_instances
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info) temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(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) out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.') print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}') print(f'ignore classes: {ignore_class_name}')
...@@ -532,12 +533,12 @@ def update_s3dis_infos(pkl_path, out_dir): ...@@ -532,12 +533,12 @@ def update_s3dis_infos(pkl_path, out_dir):
temp_data_info['sample_idx'] = i temp_data_info['sample_idx'] = i
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[ temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[
'point_cloud']['num_features'] 'point_cloud']['num_features']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[ temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'pts_path'].split('/')[-1] 'pts_path']).name
temp_data_info['pts_semantic_mask_path'] = ori_info_dict[ temp_data_info['pts_semantic_mask_path'] = Path(ori_info_dict[
'pts_semantic_mask_path'].split('/')[-1] 'pts_semantic_mask_path']).name
temp_data_info['pts_instance_mask_path'] = ori_info_dict[ temp_data_info['pts_instance_mask_path'] = Path(ori_info_dict[
'pts_instance_mask_path'].split('/')[-1] 'pts_instance_mask_path']).name
# TODO support camera # TODO support camera
# np.linalg.inv(info['axis_align_matrix'] @ extrinsic): depth2cam # np.linalg.inv(info['axis_align_matrix'] @ extrinsic): depth2cam
...@@ -567,7 +568,7 @@ def update_s3dis_infos(pkl_path, out_dir): ...@@ -567,7 +568,7 @@ def update_s3dis_infos(pkl_path, out_dir):
temp_data_info['instances'] = instance_list temp_data_info['instances'] = instance_list
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info) temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(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) out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.') print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}') print(f'ignore classes: {ignore_class_name}')
...@@ -606,12 +607,12 @@ def update_scannet_infos(pkl_path, out_dir): ...@@ -606,12 +607,12 @@ def update_scannet_infos(pkl_path, out_dir):
temp_data_info = get_empty_standard_data_info() temp_data_info = get_empty_standard_data_info()
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[ temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[
'point_cloud']['num_features'] 'point_cloud']['num_features']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[ temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'pts_path'].split('/')[-1] 'pts_path']).name
temp_data_info['pts_semantic_mask_path'] = ori_info_dict[ temp_data_info['pts_semantic_mask_path'] = Path(ori_info_dict[
'pts_semantic_mask_path'].split('/')[-1] 'pts_semantic_mask_path']).name
temp_data_info['pts_instance_mask_path'] = ori_info_dict[ temp_data_info['pts_instance_mask_path'] = Path(ori_info_dict[
'pts_instance_mask_path'].split('/')[-1] 'pts_instance_mask_path']).name
# TODO support camera # TODO support camera
# np.linalg.inv(info['axis_align_matrix'] @ extrinsic): depth2cam # np.linalg.inv(info['axis_align_matrix'] @ extrinsic): depth2cam
...@@ -641,7 +642,7 @@ def update_scannet_infos(pkl_path, out_dir): ...@@ -641,7 +642,7 @@ def update_scannet_infos(pkl_path, out_dir):
temp_data_info['instances'] = instance_list temp_data_info['instances'] = instance_list
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info) temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(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) out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.') print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}') print(f'ignore classes: {ignore_class_name}')
...@@ -678,8 +679,8 @@ def update_sunrgbd_infos(pkl_path, out_dir): ...@@ -678,8 +679,8 @@ def update_sunrgbd_infos(pkl_path, out_dir):
temp_data_info = get_empty_standard_data_info() temp_data_info = get_empty_standard_data_info()
temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[ temp_data_info['lidar_points']['num_pts_feats'] = ori_info_dict[
'point_cloud']['num_features'] 'point_cloud']['num_features']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[ temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'pts_path'].split('/')[-1] 'pts_path']).name
calib = ori_info_dict['calib'] calib = ori_info_dict['calib']
rt_mat = calib['Rt'] rt_mat = calib['Rt']
# follow Coord3DMode.convert_point # follow Coord3DMode.convert_point
...@@ -687,8 +688,8 @@ def update_sunrgbd_infos(pkl_path, out_dir): ...@@ -687,8 +688,8 @@ def update_sunrgbd_infos(pkl_path, out_dir):
]) @ rt_mat.transpose(1, 0) ]) @ rt_mat.transpose(1, 0)
depth2img = calib['K'] @ rt_mat depth2img = calib['K'] @ rt_mat
temp_data_info['images']['CAM0']['depth2img'] = depth2img.tolist() temp_data_info['images']['CAM0']['depth2img'] = depth2img.tolist()
temp_data_info['images']['CAM0']['img_path'] = ori_info_dict['image'][ temp_data_info['images']['CAM0']['img_path'] = Path(ori_info_dict['image'][
'image_path'].split('/')[-1] 'image_path']).name
h, w = ori_info_dict['image']['image_shape'] h, w = ori_info_dict['image']['image_shape']
temp_data_info['images']['CAM0']['height'] = h temp_data_info['images']['CAM0']['height'] = h
temp_data_info['images']['CAM0']['width'] = w temp_data_info['images']['CAM0']['width'] = w
...@@ -719,7 +720,7 @@ def update_sunrgbd_infos(pkl_path, out_dir): ...@@ -719,7 +720,7 @@ def update_sunrgbd_infos(pkl_path, out_dir):
temp_data_info['instances'] = instance_list temp_data_info['instances'] = instance_list
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info) temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(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) out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.') print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}') print(f'ignore classes: {ignore_class_name}')
...@@ -760,8 +761,8 @@ def update_lyft_infos(pkl_path, out_dir): ...@@ -760,8 +761,8 @@ def update_lyft_infos(pkl_path, out_dir):
temp_data_info['ego2global'] = convert_quaternion_to_matrix( temp_data_info['ego2global'] = convert_quaternion_to_matrix(
ori_info_dict['ego2global_rotation'], ori_info_dict['ego2global_rotation'],
ori_info_dict['ego2global_translation']) ori_info_dict['ego2global_translation'])
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[ temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'lidar_path'].split('/')[-1] 'lidar_path']).name
temp_data_info['lidar_points'][ temp_data_info['lidar_points'][
'lidar2ego'] = convert_quaternion_to_matrix( 'lidar2ego'] = convert_quaternion_to_matrix(
ori_info_dict['lidar2ego_rotation'], ori_info_dict['lidar2ego_rotation'],
...@@ -792,8 +793,8 @@ def update_lyft_infos(pkl_path, out_dir): ...@@ -792,8 +793,8 @@ def update_lyft_infos(pkl_path, out_dir):
temp_data_info['images'] = {} temp_data_info['images'] = {}
for cam in ori_info_dict['cams']: for cam in ori_info_dict['cams']:
empty_img_info = get_empty_img_info() empty_img_info = get_empty_img_info()
empty_img_info['img_path'] = ori_info_dict['cams'][cam][ empty_img_info['img_path'] = Path(ori_info_dict['cams'][cam][
'data_path'].split('/')[-1] 'data_path']).name
empty_img_info['cam2img'] = ori_info_dict['cams'][cam][ empty_img_info['cam2img'] = ori_info_dict['cams'][cam][
'cam_intrinsic'].tolist() 'cam_intrinsic'].tolist()
empty_img_info['sample_data_token'] = ori_info_dict['cams'][cam][ empty_img_info['sample_data_token'] = ori_info_dict['cams'][cam][
...@@ -829,7 +830,7 @@ def update_lyft_infos(pkl_path, out_dir): ...@@ -829,7 +830,7 @@ def update_lyft_infos(pkl_path, out_dir):
temp_data_info['instances'].append(empty_instance) temp_data_info['instances'].append(empty_instance)
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info) temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(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) out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.') print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}') print(f'ignore classes: {ignore_class_name}')
...@@ -896,7 +897,7 @@ def update_waymo_infos(pkl_path, out_dir): ...@@ -896,7 +897,7 @@ def update_waymo_infos(pkl_path, out_dir):
ori_info_dict['calib'][f'P{cam_idx}'] @ lidar2cam).tolist() ori_info_dict['calib'][f'P{cam_idx}'] @ lidar2cam).tolist()
# image path # 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): for cam_idx, cam_key in enumerate(camera_types):
temp_data_info['images'][cam_key]['timestamp'] = ori_info_dict[ temp_data_info['images'][cam_key]['timestamp'] = ori_info_dict[
...@@ -912,8 +913,8 @@ def update_waymo_infos(pkl_path, out_dir): ...@@ -912,8 +913,8 @@ def update_waymo_infos(pkl_path, out_dir):
'point_cloud']['num_features'] 'point_cloud']['num_features']
temp_data_info['lidar_points']['timestamp'] = ori_info_dict[ temp_data_info['lidar_points']['timestamp'] = ori_info_dict[
'timestamp'] 'timestamp']
temp_data_info['lidar_points']['lidar_path'] = ori_info_dict[ temp_data_info['lidar_points']['lidar_path'] = Path(ori_info_dict[
'point_cloud']['velodyne_path'].split('/')[-1] 'point_cloud']['velodyne_path']).name
# TODO discuss the usage of Tr_velo_to_cam in lidar # TODO discuss the usage of Tr_velo_to_cam in lidar
Trv2c = ori_info_dict['calib']['Tr_velo_to_cam'].astype(np.float32) Trv2c = ori_info_dict['calib']['Tr_velo_to_cam'].astype(np.float32)
...@@ -933,13 +934,13 @@ def update_waymo_infos(pkl_path, out_dir): ...@@ -933,13 +934,13 @@ def update_waymo_infos(pkl_path, out_dir):
lidar_sweep = get_single_lidar_sweep() lidar_sweep = get_single_lidar_sweep()
lidar_sweep['ego2global'] = ori_sweep['pose'] lidar_sweep['ego2global'] = ori_sweep['pose']
lidar_sweep['timestamp'] = ori_sweep['timestamp'] lidar_sweep['timestamp'] = ori_sweep['timestamp']
lidar_sweep['lidar_points']['lidar_path'] = ori_sweep[ lidar_sweep['lidar_points']['lidar_path'] = Path(ori_sweep[
'velodyne_path'].split('/')[-1] 'velodyne_path']).name
# image sweeps # image sweeps
image_sweep = get_single_image_sweep(camera_types) image_sweep = get_single_image_sweep(camera_types)
image_sweep['ego2global'] = ori_sweep['pose'] image_sweep['ego2global'] = ori_sweep['pose']
image_sweep['timestamp'] = ori_sweep['timestamp'] 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): for cam_idx, cam_key in enumerate(camera_types):
image_sweep['images'][cam_key]['img_path'] = img_path image_sweep['images'][cam_key]['img_path'] = img_path
...@@ -1036,7 +1037,7 @@ def update_waymo_infos(pkl_path, out_dir): ...@@ -1036,7 +1037,7 @@ def update_waymo_infos(pkl_path, out_dir):
temp_data_info, _ = clear_data_info_unused_keys(temp_data_info) temp_data_info, _ = clear_data_info_unused_keys(temp_data_info)
converted_list.append(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) out_path = osp.join(out_dir, pkl_name)
print(f'Writing to output file: {out_path}.') print(f'Writing to output file: {out_path}.')
print(f'ignore classes: {ignore_class_name}') print(f'ignore classes: {ignore_class_name}')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment