1.数据准备
数据采用
shapenetcore_partanno_segmentation_benchmark_v0
数据下载地址:
https://shapenet.cs.stanford.edu/ericyi/shapenetcore_partanno_segmentation_benchmark_v0.zip
2.代码主题解读
cutdim, tree = make_cKDTree(point_set.numpy(), depth=levels)
将点云建立KDtree,返回Kd树结构,
cutdim可以理解为在kdtree建立过程中每个节点切割空间的维度。
tree是三阶张量。可以理解为分为12层的一个树状结构。
cutdim_v = [(torch.from_numpy(np.array(item).astype(np.int64))) for item in cutdim] points = torch.FloatTensor(tree[-1]) points_v = Variable(torch.unsqueeze(torch.squeeze(points), 0)).transpose(2, 1).cuda()
数据转为tensor,并对points进行转置,准备送入网络
3.网络主要内容解读 x = F.relu(conv(x))####self.conv1 = nn.Conv1d(3, 8 * 3, 1, 1)
数据变化:1*3*2048--->1*24*2048
x = x.view(-1, featdim, 3, dim)# 数据变化:1*24*2048--->1*8*3*2048
目的是将 数据转为 xyz*2048的格式,
x = x.view(-1, featdim, 3 * dim)##1*8*3*2048--->1*8*(6144=2048*3)
将2048个点 变为 :xyz,xyz,xyz.....xyz的格式
sel = Variable(sel + (torch.arange(0, dim) * 3).long())
x = torch.index_select(x, dim=2, index=sel)#根据KD-Tree每个节点切割空间的维度 选出对应XYZ中的数据,此时数据格式为:1*8*2048
根据KDtree在xyz中的哪个维度进行的分割? 将对应的数据提取出来
x = x.view(-1, featdim, int(dim / 2), 2) # 将数据调整为,KD-Tree的最底部的2个叶节点
数据变为1*8*1024*2 为什么要这样分割? 每个树最末端都有2个叶子。
x = torch.squeeze(torch.max(x, dim=-1, keepdim=True)[0], 3)
选取最大的那个叶子 最后将数据变为1*8*1024