NVIDIA / MinkowskiEngine

Minkowski Engine is an auto-diff neural network library for high-dimensional sparse tensors
https://nvidia.github.io/MinkowskiEngine
Other
2.43k stars 360 forks source link

Wrong results with MinkowskiInterpolation() #477

Open PenguinPhysicist opened 2 years ago

PenguinPhysicist commented 2 years ago

Describe the bug

When trying to interpolate features to coordinates that are not present in the sparse tensor, 0 is returned instead of the interpolated features.


To Reproduce

import torch

coords = torch.tensor([[0,0,0,1], [0,0,1,0], [0,1,0,0], 
    [0,0,0,-1], [0,0,-1,0], [0,-1,0,0]])
features = torch.ones((6,1))

myTensor = ME.SparseTensor(features=features, coordinates=coords.int())
mySamples = torch.tensor([ [0.,0.,0.,1.] , [0.,0.,0.,0.] ])

myInt = ME.MinkowskiInterpolation()
myInt(myTensor, mySamples)

Expected behavior

This should yield tensor([[1.],[1.]]), but yields tensor([[1.],[0.]]). All directly neighboring voxels have the value 1, but the interpolation at the origin which is in the middle of all of them gives the value 0.


Desktop (please complete the following information):

==========System========== Linux-5.13.0-48-generic-x86_64-with-glibc2.31 3.9.12 (main, Apr 5 2022, 06:56:58) [GCC 7.5.0] ==========Pytorch========== 1.10.1+cu111 torch.cuda.is_available(): True ==========NVIDIA-SMI========== Driver Version 470.129.06 CUDA Version 11.4 VBIOS Version 92.00.25.00.08 Image Version 1001.0200.00.04 GSP Firmware Version N/A ==========NVCC========== ==========CC========== ==========MinkowskiEngine========== 0.5.4 MinkowskiEngine compiled with CUDA Support: True NVCC version MinkowskiEngine is compiled: 11010 CUDART version MinkowskiEngine is compiled: 11010


Additional context I have tried the same code for a structure around different points than 0 and with different features (e.g 3-dimensional) but that did not solve the issue.

RozDavid commented 2 years ago

Hey @PenguinPhysicist,

So I've been also struggling with this today, and tried to look into it. What I think is happening is that the interpolation try to get weights from all neighbouring voxels no matter if they are initialized or not. In my opinion this would make sense in a dense scenario, but not with sparse tensors.

So to test out this if you initialize a cube with all ones on the vertices the interpolation makes sense and returns the correct value

import torch

coords = torch.tensor([[0,0,0,1], [0,0,1,1], [0,1,0,1], [0,1,1,1], 
                        [0,0,0,0], [0,0,1,0], [0,1,0,0], [0,1,1,0]])
features = torch.cat((torch.ones((4,1)), torch.ones((4,1))))

myTensor = ME.SparseTensor(features=features, coordinates=coords.int())
mySamples = torch.tensor([[0.,0.5,0.5,0.5] ])

myInt = ME.MinkowskiInterpolation()
myInt(myTensor, mySamples)

##### Outputs #####
tensor([[1.]])

but if you remove one vertex, the interpolation value will also shift as if that vertex would be initialized with zero feature value:

import torch

coords = torch.tensor([[0,0,0,1], [0,0,1,1], [0,1,0,1], [0,1,1,1], 
                        [0,0,0,0], [0,0,1,0], [0,1,0,0]])
features = torch.cat((torch.ones((4,1)), torch.ones((3,1))))

myTensor = ME.SparseTensor(features=features, coordinates=coords.int())
mySamples = torch.tensor([[0.,0.5,0.5,0.5] ])

myInt = ME.MinkowskiInterpolation()
myInt(myTensor, mySamples)

##### Outputs #####
tensor([[0.8750]])

Can you look into it @chrischoy? Or just point me to the implementation, where I could fix it? My feeling is that it was implemented at some point here, but doesnt seem to work with the latest version.

ywyue commented 1 year ago

I also encounter this problem. I wonder are there any updates on this issue? Thanks @chrischoy

renezurbruegg commented 1 year ago

Same here. Are there any updates? Or alternatives to achieve this behavior?