MinkowskiEngine icon indicating copy to clipboard operation
MinkowskiEngine copied to clipboard

Wrong results with MinkowskiInterpolation()

Open PenguinPhysicist opened this issue 2 years ago • 3 comments

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):

  • OS: Ubuntu 20.04
  • Python version: 3.9.12
  • Pytorch version: 1.10.1+cu111
  • CUDA version: 11.1
  • NVIDIA Driver version: 470.129.06
  • Minkowski Engine version: 0.5.4
  • Output of the following command: wget -q https://raw.githubusercontent.com/NVIDIA/MinkowskiEngine/master/MinkowskiEngine/diagnostics.py ; python diagnostics.py DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS" /usr/bin/nvidia-smi /usr/bin/nvcc nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2020 NVIDIA Corporation Built on Mon_Oct_12_20:09:46_PDT_2020 Cuda compilation tools, release 11.1, V11.1.105 Build cuda_11.1.TC455_06.29190527_0 /usr/bin/c++ c++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

==========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.

PenguinPhysicist avatar Jun 09 '22 16:06 PenguinPhysicist

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.

RozDavid avatar Jul 01 '22 18:07 RozDavid

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

ywyue avatar Jan 14 '23 00:01 ywyue

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

renezurbruegg avatar Jun 13 '23 09:06 renezurbruegg