|
|
|
|
|
import mmcv |
|
|
from typing import Dict, List |
|
|
import pickle as pkl |
|
|
|
|
|
def sort_data(data_dict: Dict): |
|
|
return data_dict["token"] |
|
|
|
|
|
FRAME_INTERVAL = 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MAX_FRAME_SEQ = 10000 |
|
|
|
|
|
predroot = '/mnt/hdd2/datasets/carla_1.0/carla_data_0414/data_val_nusc_format.pkl' |
|
|
|
|
|
pkl_data: Dict = mmcv.load(predroot) |
|
|
|
|
|
|
|
|
info_data: List[Dict] = pkl_data["infos"] |
|
|
info_data.sort(key=sort_data) |
|
|
|
|
|
|
|
|
new_info_data: List[Dict] = [] |
|
|
scene_token = None |
|
|
for index in range(len(info_data)): |
|
|
data_frame = info_data[index] |
|
|
scene_token_cur = data_frame['scene_token'] |
|
|
frame_id_cur = data_frame['frame_idx'] |
|
|
|
|
|
|
|
|
if frame_id_cur > MAX_FRAME_SEQ: |
|
|
continue |
|
|
|
|
|
print(data_frame['token']) |
|
|
print(data_frame['scene_token']) |
|
|
print(data_frame['frame_idx']) |
|
|
|
|
|
|
|
|
if scene_token is None or scene_token_cur != scene_token: |
|
|
frame_idx = frame_id_cur |
|
|
scene_token = scene_token_cur |
|
|
|
|
|
|
|
|
else: |
|
|
frame_idx += FRAME_INTERVAL |
|
|
new_info_data.append(data_frame) |
|
|
|
|
|
|
|
|
assert frame_idx == frame_id_cur, f'frame id wrong, {frame_idx} vs {frame_id_cur}' |
|
|
|
|
|
print(f'total number of frames is {len(new_info_data)}') |
|
|
|
|
|
|
|
|
new_pkl_data = { |
|
|
'infos': new_info_data, |
|
|
} |
|
|
for key in pkl_data.keys(): |
|
|
if key == 'infos': |
|
|
continue |
|
|
else: |
|
|
new_pkl_data[key] = pkl_data[key] |
|
|
|
|
|
|
|
|
output_path = f'/mnt/hdd2/datasets/carla_1.0/carla_data_0414/data_val_nusc_format_partial_{MAX_FRAME_SEQ}.pkl' |
|
|
with open(output_path, "wb") as f: |
|
|
pkl.dump(new_pkl_data, f) |
|
|
|