pyg-team / pytorch_geometric

Graph Neural Network Library for PyTorch
https://pyg.org
MIT License
21.15k stars 3.64k forks source link

A question regarding Voxel_grid function #2955

Open edshkim98 opened 3 years ago

edshkim98 commented 3 years ago

From now on, we recommend using our discussion forum (https://github.com/rusty1s/pytorch_geometric/discussions) for general questions.

❓ Questions & Help

Hello, I am trying to use voxel_grid pooling function to downsample my point cloud, but I do not understand the return type.

x = next(iter(val_loader))
pts = x['points']
pts = pts.permute(0,2,1) #bs*c*pts => 2*3*2048
bs = torch.arange(pts.size(0))#.to(self.device)
bs = bs.repeat_interleave(pts.size(2))
pts = pts.reshape(pts.size(0)*pts.size(2),-1) # 4096,3
print(bs.shape, pts.shape) #torch.Size([4096]) torch.Size([4096, 3])

pooled= voxel_grid(pts,bs,0.1)
pooled

When I execute the code above, I get a list of numbers as follow.

tensor([2095, 2742, 2420, ..., 8575, 8232, 8252]) with size 4096.

However, the return values don't seem to correspond with the original point cloud or index values. Have I used the function properly? Could you please let me know what are the return values representing?

Thank you!

rusty1s commented 3 years ago

The return type sets an index for each point in your cloud. If the indices are the same for a set of points, they shall be "clustered" together. You can convert the return type into "consecutive" indices (where pooled.max() + 1== num_clusters via:

from torch_geometric.nn.pool.consecutive import consecutive_cluster
pooled, _ = consecutive_cluster(pooled)