首先这边要去解读这份MotionNet中资料前处理的gen_data.py程式码
接下来会记录每个区块的函数以及变数所代表的意义
hyperparameters
scenes = np.load('data/split.npy', allow_pickle=True).item().get(args.split)print("Split: {}, which contains {} scenes.".format(args.split, len(scenes)))
这边读取已经存下来的场景编号'scene_37' 'scene_34' 'scene_817'
gen_data()
res_scenes = list() for s in scenes: s_id = s.split('_')[1] res_scenes.append(int(s_id))
把场景的编号存起来
for scene_idx in res_scenes: curr_scene = nusc.scene[scene_idx] #现在场景编号 first_sample_token = curr_scene['first_sample_token'] #取出第一个sample token curr_sample = nusc.get('sample', first_sample_token) # 取出sample的资料 curr_sample_data = nusc.get('sample_data', curr_sample['data']['LIDAR_TOP']) #取出sample中 lidar的资料 save_data_dict_list = list() # for storing consecutive sequences; the data consists of timestamps, points, etc save_box_dict_list = list() # for storing box annotations in consecutive sequences save_instance_token_list = list() adj_seq_cnt = 0 save_seq_cnt = 0 # only used for save data file name
while curr_sample_data['next'] != '': # Get the synchronized point clouds all_pc, all_times, trans_matrices = \ LidarPointCloud.from_file_multisweep_bf_sample_data (nusc, curr_sample_data,return_trans_matrix=True, nsweeps_back=nsweeps_back,nsweeps_forward=nsweeps_forward) # Store point cloud of each sweep pc = all_pc.points _, sort_idx = np.unique(all_times, return_index=True) unique_times = all_times[np.sort(sort_idx)] # Preserve the item order in unique_times num_sweeps = len(unique_times) # 如果没有足够的past 跟 future sweeps的话 要跳过一些keyframe #===================Skipping keyframe============================== # Make sure we have sufficient past and future sweeps if num_sweeps != (nsweeps_back + nsweeps_forward): # Skip some keyframes if necessary flag = False for _ in range(num_keyframe_skipped + 1): if curr_sample['next'] != '': curr_sample = nusc.get('sample', curr_sample['next']) else: flag = True break if flag: # No more keyframes break else: curr_sample_data = nusc.get('sample_data', curr_sample['data']['LIDAR_TOP']) # Reset adj_seq_cnt = 0 save_data_dict_list = list() save_box_dict_list = list() save_instance_token_list = list() continue #===================Skipping keyframe==============================
LidarPointCloud.from_file_multisweep_bf_sample_data
:
回传aggregate完的pointcloud 简单来说就是把过去的跟未来几个frame的pointcloud同步到当下的frame 回传的是很多point cloud组合而成的点云集合 可以利用unique time来把它还原成对应时间的sweep
# Prepare data dictionary for the next step (ie, generating BEV maps) save_data_dict = dict() box_data_dict = dict() # for remapping the instance ids, according to class_map curr_token_list = list() for tid in range(num_sweeps): _time = unique_times[tid] # 回传相同元素的index位置 points_idx = np.where(all_times == _time)[0] _pc = pc[:, points_idx] # 取出对应sweep时间当下的点云(4,nbr_points) save_data_dict['pc_' + str(tid)] = _pc save_data_dict['times'] = unique_times save_data_dict['num_sweeps'] = num_sweeps save_data_dict['trans_matrices'] = trans_matrices # Get the synchronized bounding boxes # First, we need to iterate all the instances, and then retrieve their corresponding bounding boxes num_instances = 0 # The number of instances within this sample corresponding_sample_token = curr_sample_data['sample_token'] corresponding_sample_rec = nusc.get('sample', corresponding_sample_token)
这边的unique time 是指每个sweep对应到的时间 (长度=backward+forward sweeps nums)all_times是把每个sweep所有的点都对应到该sweep的时间 (ex:[1,1,1,1,1...1],总共23456个点就有23456个时间)每个sample 中有每个sensor的资讯以及这个sample下的annotations以及sample当下的时间,及前跟后一个frame的token idprint(save_data_dict.keys())
会有 (pc_0 - pc_44 for test split), times, num_sweeps, trans_matrices