代码地址: https://github.com/POSTECH-CVLab/point-transformer/blob/master/util/data_util.py
def collate_fn(batch):
coord, feat, label = list(zip(*batch))
offset, count = [], 0
for item in coord:
count += item.shape[0]
offset.append(count)
return torch.cat(coord), torch.cat(feat), torch.cat(label), torch.IntTensor(offset)
由于点云每个batch中点的数目不同,因此需要重写collate_fn。
方法是直接把所有batch拼接,使用offset来记录每个batch的最后一个点的位置。
假设batch数目为4,四个sample中点的数目分别是74740,24149,45671和77110。则offset为[74740, 98889, 144560, 221670]。
得到的coord坐标尺寸为torch.Size([221670, 3])。
每个batch的总点数不同。如第一个batch拼接后221670个点,第二个batch拼接后282963个点。