這篇文章要繼續解讀 MotionNet 中 gen_data的第二部份。
for ann_token in corresponding_sample_rec['anns']:
#取得一個instance的annotation_record
ann_rec = nusc.get('sample_annotation', ann_token)
#print(ann_rec)
category_name = ann_rec['category_name']
instance_token = ann_rec['instance_token']
# 把文字的類別 轉換成數字代表 如果不存在一開始預設的類別則設定為Other類別 = 4
flag = False
for c, v in class_map.items():
if category_name.startswith(c):
box_data_dict['category_' + instance_token] = v
flag = True
break
if not flag:
box_data_dict['category_' + instance_token] = 4 # Other category
#取得當下這個instsance的過去幾個sweep跟未來的幾個bounding box 資訊 還有每個sweep對應到的timestamp
instance_boxes, instance_all_times, _, _ = LidarPointCloud. \
get_instance_boxes_multisweep_sample_data(nusc, curr_sample_data,
instance_token,
nsweeps_back=nsweeps_back,
nsweeps_forward=nsweeps_forward)
assert np.array_equal(unique_times, instance_all_times), "The sweep and instance times are inconsistent!"
assert num_sweeps == len(instance_boxes), "The number of instance boxes does not match that of sweeps!"
# Each row corresponds to a box annotation; the column consists of box center, box size, and quaternion
# 這邊把bounding box的資訊都記錄下來
box_data = np.zeros((len(instance_boxes), 3 + 3 + 4), dtype=np.float32)
box_data.fill(np.nan)
for r, box in enumerate(instance_boxes):
if box is not None:
row = np.concatenate([box.center, box.wlh, box.orientation.elements])
box_data[r] = row[:]
# 這邊的話把box_data存進box_data_dict對應的instance_token下 會是(total sweeps,10)的格式
# Save the box data for current instance
box_data_dict['instance_boxes_' + instance_token] = box_data
num_instances += 1
curr_token_list.append(instance_token)
#把所有instance_token都存進一個list中
save_data_dict['num_instances'] = num_instances
save_data_dict_list.append(save_data_dict)
save_box_dict_list.append(box_data_dict)
save_instance_token_list.append(curr_token_list)
#把對應的資料存進dict中