12
12
import copy
13
13
import time
14
14
from os import path as osp
15
+ from pathlib import Path
15
16
16
17
import mmengine
17
18
import numpy as np
@@ -283,8 +284,8 @@ def update_nuscenes_infos(pkl_path, out_dir):
283
284
ori_info_dict ['ego2global_translation' ])
284
285
temp_data_info ['lidar_points' ]['num_pts_feats' ] = ori_info_dict .get (
285
286
'num_features' , 5 )
286
- temp_data_info ['lidar_points' ]['lidar_path' ] = ori_info_dict [
287
- 'lidar_path' ]. split ( '/' )[ - 1 ]
287
+ temp_data_info ['lidar_points' ]['lidar_path' ] = Path ( ori_info_dict [
288
+ 'lidar_path' ]). name
288
289
temp_data_info ['lidar_points' ][
289
290
'lidar2ego' ] = convert_quaternion_to_matrix (
290
291
ori_info_dict ['lidar2ego_rotation' ],
@@ -314,8 +315,8 @@ def update_nuscenes_infos(pkl_path, out_dir):
314
315
temp_data_info ['images' ] = {}
315
316
for cam in ori_info_dict ['cams' ]:
316
317
empty_img_info = get_empty_img_info ()
317
- empty_img_info ['img_path' ] = ori_info_dict ['cams' ][cam ][
318
- 'data_path' ]. split ( '/' )[ - 1 ]
318
+ empty_img_info ['img_path' ] = Path ( ori_info_dict ['cams' ][cam ][
319
+ 'data_path' ]). name
319
320
empty_img_info ['cam2img' ] = ori_info_dict ['cams' ][cam ][
320
321
'cam_intrinsic' ].tolist ()
321
322
empty_img_info ['sample_data_token' ] = ori_info_dict ['cams' ][cam ][
@@ -359,7 +360,7 @@ def update_nuscenes_infos(pkl_path, out_dir):
359
360
ori_info_dict , nusc )
360
361
temp_data_info , _ = clear_data_info_unused_keys (temp_data_info )
361
362
converted_list .append (temp_data_info )
362
- pkl_name = pkl_path . split ( '/' )[ - 1 ]
363
+ pkl_name = Path ( pkl_path ). name
363
364
out_path = osp .join (out_dir , pkl_name )
364
365
print (f'Writing to output file: { out_path } .' )
365
366
print (f'ignore classes: { ignore_class_name } ' )
@@ -410,15 +411,15 @@ def update_kitti_infos(pkl_path, out_dir):
410
411
temp_data_info ['images' ]['CAM3' ]['cam2img' ] = ori_info_dict ['calib' ][
411
412
'P3' ].tolist ()
412
413
413
- temp_data_info ['images' ]['CAM2' ]['img_path' ] = ori_info_dict ['image' ][
414
- 'image_path' ]. split ( '/' )[ - 1 ]
414
+ temp_data_info ['images' ]['CAM2' ]['img_path' ] = Path ( ori_info_dict ['image' ][
415
+ 'image_path' ]). name
415
416
h , w = ori_info_dict ['image' ]['image_shape' ]
416
417
temp_data_info ['images' ]['CAM2' ]['height' ] = h
417
418
temp_data_info ['images' ]['CAM2' ]['width' ] = w
418
419
temp_data_info ['lidar_points' ]['num_pts_feats' ] = ori_info_dict [
419
420
'point_cloud' ]['num_features' ]
420
- temp_data_info ['lidar_points' ]['lidar_path' ] = ori_info_dict [
421
- 'point_cloud' ]['velodyne_path' ]. split ( '/' )[ - 1 ]
421
+ temp_data_info ['lidar_points' ]['lidar_path' ] = Path ( ori_info_dict [
422
+ 'point_cloud' ]['velodyne_path' ]). name
422
423
423
424
rect = ori_info_dict ['calib' ]['R0_rect' ].astype (np .float32 )
424
425
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
499
temp_data_info ['cam_instances' ] = cam_instances
499
500
temp_data_info , _ = clear_data_info_unused_keys (temp_data_info )
500
501
converted_list .append (temp_data_info )
501
- pkl_name = pkl_path . split ( '/' )[ - 1 ]
502
+ pkl_name = Path ( pkl_path ). name
502
503
out_path = osp .join (out_dir , pkl_name )
503
504
print (f'Writing to output file: { out_path } .' )
504
505
print (f'ignore classes: { ignore_class_name } ' )
@@ -532,12 +533,12 @@ def update_s3dis_infos(pkl_path, out_dir):
532
533
temp_data_info ['sample_idx' ] = i
533
534
temp_data_info ['lidar_points' ]['num_pts_feats' ] = ori_info_dict [
534
535
'point_cloud' ]['num_features' ]
535
- temp_data_info ['lidar_points' ]['lidar_path' ] = ori_info_dict [
536
- 'pts_path' ]. split ( '/' )[ - 1 ]
537
- temp_data_info ['pts_semantic_mask_path' ] = ori_info_dict [
538
- 'pts_semantic_mask_path' ]. split ( '/' )[ - 1 ]
539
- temp_data_info ['pts_instance_mask_path' ] = ori_info_dict [
540
- 'pts_instance_mask_path' ]. split ( '/' )[ - 1 ]
536
+ temp_data_info ['lidar_points' ]['lidar_path' ] = Path ( ori_info_dict [
537
+ 'pts_path' ]). name
538
+ temp_data_info ['pts_semantic_mask_path' ] = Path ( ori_info_dict [
539
+ 'pts_semantic_mask_path' ]). name
540
+ temp_data_info ['pts_instance_mask_path' ] = Path ( ori_info_dict [
541
+ 'pts_instance_mask_path' ]). name
541
542
542
543
# TODO support camera
543
544
# np.linalg.inv(info['axis_align_matrix'] @ extrinsic): depth2cam
@@ -567,7 +568,7 @@ def update_s3dis_infos(pkl_path, out_dir):
567
568
temp_data_info ['instances' ] = instance_list
568
569
temp_data_info , _ = clear_data_info_unused_keys (temp_data_info )
569
570
converted_list .append (temp_data_info )
570
- pkl_name = pkl_path . split ( '/' )[ - 1 ]
571
+ pkl_name = Path ( pkl_path ). name
571
572
out_path = osp .join (out_dir , pkl_name )
572
573
print (f'Writing to output file: { out_path } .' )
573
574
print (f'ignore classes: { ignore_class_name } ' )
@@ -606,12 +607,12 @@ def update_scannet_infos(pkl_path, out_dir):
606
607
temp_data_info = get_empty_standard_data_info ()
607
608
temp_data_info ['lidar_points' ]['num_pts_feats' ] = ori_info_dict [
608
609
'point_cloud' ]['num_features' ]
609
- temp_data_info ['lidar_points' ]['lidar_path' ] = ori_info_dict [
610
- 'pts_path' ]. split ( '/' )[ - 1 ]
611
- temp_data_info ['pts_semantic_mask_path' ] = ori_info_dict [
612
- 'pts_semantic_mask_path' ]. split ( '/' )[ - 1 ]
613
- temp_data_info ['pts_instance_mask_path' ] = ori_info_dict [
614
- 'pts_instance_mask_path' ]. split ( '/' )[ - 1 ]
610
+ temp_data_info ['lidar_points' ]['lidar_path' ] = Path ( ori_info_dict [
611
+ 'pts_path' ]). name
612
+ temp_data_info ['pts_semantic_mask_path' ] = Path ( ori_info_dict [
613
+ 'pts_semantic_mask_path' ]). name
614
+ temp_data_info ['pts_instance_mask_path' ] = Path ( ori_info_dict [
615
+ 'pts_instance_mask_path' ]). name
615
616
616
617
# TODO support camera
617
618
# np.linalg.inv(info['axis_align_matrix'] @ extrinsic): depth2cam
@@ -641,7 +642,7 @@ def update_scannet_infos(pkl_path, out_dir):
641
642
temp_data_info ['instances' ] = instance_list
642
643
temp_data_info , _ = clear_data_info_unused_keys (temp_data_info )
643
644
converted_list .append (temp_data_info )
644
- pkl_name = pkl_path . split ( '/' )[ - 1 ]
645
+ pkl_name = Path ( pkl_path ). name
645
646
out_path = osp .join (out_dir , pkl_name )
646
647
print (f'Writing to output file: { out_path } .' )
647
648
print (f'ignore classes: { ignore_class_name } ' )
@@ -678,17 +679,17 @@ def update_sunrgbd_infos(pkl_path, out_dir):
678
679
temp_data_info = get_empty_standard_data_info ()
679
680
temp_data_info ['lidar_points' ]['num_pts_feats' ] = ori_info_dict [
680
681
'point_cloud' ]['num_features' ]
681
- temp_data_info ['lidar_points' ]['lidar_path' ] = ori_info_dict [
682
- 'pts_path' ]. split ( '/' )[ - 1 ]
682
+ temp_data_info ['lidar_points' ]['lidar_path' ] = Path ( ori_info_dict [
683
+ 'pts_path' ]). name
683
684
calib = ori_info_dict ['calib' ]
684
685
rt_mat = calib ['Rt' ]
685
686
# follow Coord3DMode.convert_point
686
687
rt_mat = np .array ([[1 , 0 , 0 ], [0 , 0 , - 1 ], [0 , 1 , 0 ]
687
688
]) @ rt_mat .transpose (1 , 0 )
688
689
depth2img = calib ['K' ] @ rt_mat
689
690
temp_data_info ['images' ]['CAM0' ]['depth2img' ] = depth2img .tolist ()
690
- temp_data_info ['images' ]['CAM0' ]['img_path' ] = ori_info_dict ['image' ][
691
- 'image_path' ]. split ( '/' )[ - 1 ]
691
+ temp_data_info ['images' ]['CAM0' ]['img_path' ] = Path ( ori_info_dict ['image' ][
692
+ 'image_path' ]). name
692
693
h , w = ori_info_dict ['image' ]['image_shape' ]
693
694
temp_data_info ['images' ]['CAM0' ]['height' ] = h
694
695
temp_data_info ['images' ]['CAM0' ]['width' ] = w
@@ -719,7 +720,7 @@ def update_sunrgbd_infos(pkl_path, out_dir):
719
720
temp_data_info ['instances' ] = instance_list
720
721
temp_data_info , _ = clear_data_info_unused_keys (temp_data_info )
721
722
converted_list .append (temp_data_info )
722
- pkl_name = pkl_path . split ( '/' )[ - 1 ]
723
+ pkl_name = Path ( pkl_path ). name
723
724
out_path = osp .join (out_dir , pkl_name )
724
725
print (f'Writing to output file: { out_path } .' )
725
726
print (f'ignore classes: { ignore_class_name } ' )
@@ -760,8 +761,8 @@ def update_lyft_infos(pkl_path, out_dir):
760
761
temp_data_info ['ego2global' ] = convert_quaternion_to_matrix (
761
762
ori_info_dict ['ego2global_rotation' ],
762
763
ori_info_dict ['ego2global_translation' ])
763
- temp_data_info ['lidar_points' ]['lidar_path' ] = ori_info_dict [
764
- 'lidar_path' ]. split ( '/' )[ - 1 ]
764
+ temp_data_info ['lidar_points' ]['lidar_path' ] = Path ( ori_info_dict [
765
+ 'lidar_path' ]). name
765
766
temp_data_info ['lidar_points' ][
766
767
'lidar2ego' ] = convert_quaternion_to_matrix (
767
768
ori_info_dict ['lidar2ego_rotation' ],
@@ -792,8 +793,8 @@ def update_lyft_infos(pkl_path, out_dir):
792
793
temp_data_info ['images' ] = {}
793
794
for cam in ori_info_dict ['cams' ]:
794
795
empty_img_info = get_empty_img_info ()
795
- empty_img_info ['img_path' ] = ori_info_dict ['cams' ][cam ][
796
- 'data_path' ]. split ( '/' )[ - 1 ]
796
+ empty_img_info ['img_path' ] = Path ( ori_info_dict ['cams' ][cam ][
797
+ 'data_path' ]). name
797
798
empty_img_info ['cam2img' ] = ori_info_dict ['cams' ][cam ][
798
799
'cam_intrinsic' ].tolist ()
799
800
empty_img_info ['sample_data_token' ] = ori_info_dict ['cams' ][cam ][
@@ -829,7 +830,7 @@ def update_lyft_infos(pkl_path, out_dir):
829
830
temp_data_info ['instances' ].append (empty_instance )
830
831
temp_data_info , _ = clear_data_info_unused_keys (temp_data_info )
831
832
converted_list .append (temp_data_info )
832
- pkl_name = pkl_path . split ( '/' )[ - 1 ]
833
+ pkl_name = Path ( pkl_path ). name
833
834
out_path = osp .join (out_dir , pkl_name )
834
835
print (f'Writing to output file: { out_path } .' )
835
836
print (f'ignore classes: { ignore_class_name } ' )
@@ -896,7 +897,7 @@ def update_waymo_infos(pkl_path, out_dir):
896
897
ori_info_dict ['calib' ][f'P{ cam_idx } ' ] @ lidar2cam ).tolist ()
897
898
898
899
# image path
899
- base_img_path = ori_info_dict ['image' ]['image_path' ]. split ( '/' )[ - 1 ]
900
+ base_img_path = Path ( ori_info_dict ['image' ]['image_path' ]). name
900
901
901
902
for cam_idx , cam_key in enumerate (camera_types ):
902
903
temp_data_info ['images' ][cam_key ]['timestamp' ] = ori_info_dict [
@@ -912,8 +913,8 @@ def update_waymo_infos(pkl_path, out_dir):
912
913
'point_cloud' ]['num_features' ]
913
914
temp_data_info ['lidar_points' ]['timestamp' ] = ori_info_dict [
914
915
'timestamp' ]
915
- temp_data_info ['lidar_points' ]['lidar_path' ] = ori_info_dict [
916
- 'point_cloud' ]['velodyne_path' ]. split ( '/' )[ - 1 ]
916
+ temp_data_info ['lidar_points' ]['lidar_path' ] = Path ( ori_info_dict [
917
+ 'point_cloud' ]['velodyne_path' ]). name
917
918
918
919
# TODO discuss the usage of Tr_velo_to_cam in lidar
919
920
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
934
lidar_sweep = get_single_lidar_sweep ()
934
935
lidar_sweep ['ego2global' ] = ori_sweep ['pose' ]
935
936
lidar_sweep ['timestamp' ] = ori_sweep ['timestamp' ]
936
- lidar_sweep ['lidar_points' ]['lidar_path' ] = ori_sweep [
937
- 'velodyne_path' ]. split ( '/' )[ - 1 ]
937
+ lidar_sweep ['lidar_points' ]['lidar_path' ] = Path ( ori_sweep [
938
+ 'velodyne_path' ]). name
938
939
# image sweeps
939
940
image_sweep = get_single_image_sweep (camera_types )
940
941
image_sweep ['ego2global' ] = ori_sweep ['pose' ]
941
942
image_sweep ['timestamp' ] = ori_sweep ['timestamp' ]
942
- img_path = ori_sweep ['image_path' ]. split ( '/' )[ - 1 ]
943
+ img_path = Path ( ori_sweep ['image_path' ]). name
943
944
for cam_idx , cam_key in enumerate (camera_types ):
944
945
image_sweep ['images' ][cam_key ]['img_path' ] = img_path
945
946
@@ -1036,7 +1037,7 @@ def update_waymo_infos(pkl_path, out_dir):
1036
1037
1037
1038
temp_data_info , _ = clear_data_info_unused_keys (temp_data_info )
1038
1039
converted_list .append (temp_data_info )
1039
- pkl_name = pkl_path . split ( '/' )[ - 1 ]
1040
+ pkl_name = Path ( pkl_path ). name
1040
1041
out_path = osp .join (out_dir , pkl_name )
1041
1042
print (f'Writing to output file: { out_path } .' )
1042
1043
print (f'ignore classes: { ignore_class_name } ' )
0 commit comments