NVIDIA / MinkowskiEngine

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

Custom values for coordinates without features? #320

Open rwagner2017 opened 3 years ago

rwagner2017 commented 3 years ago

It looks like the API has change since #137. Is it possible to get a nan value (or some custom value) to differentiate between a coordinate with a feature value of zero vs a coordinate with no feature value? Here is an example:

coords = torch.IntTensor([[0, 1], [1, 2], [2, 1], [1, 0], [1, 1]]) feats = torch.FloatTensor([[1, 2.1, 3.2, 4.5, 0]]).t()

X = ME.SparseTensor(features=feats, coordinates=coords)
print(X.dense())

(tensor([[[0.0000, 1.0000, 0.0000]], [[4.5000, 0.0000, 2.1000]], [[0.0000, 3.2000, 0.0000]]]), tensor([[0]], dtype=torch.int32), tensor([1], dtype=torch.int32))

test_coords = torch.FloatTensor([[1, 1], [0, 2]])
sampled_feats = X.features_at_coordinates(test_coords).flatten()

for test_coord, sampled_feat in zip(test_coords, sampled_feats):
    print('[{:.2f}, {:.2f}] = {:.4f}'.format(test_coord[0], test_coord[1], sampled_feat))

[1.00, 1.00] = 0.0000 [0.00, 2.00] = 0.0000

It would be nice if [0, 2] == np.nan or some user defined val.

chrischoy commented 3 years ago

If you convolve a sparse tensor with some np.nan in its features, the output sparse tensor would have nans with all elements adjacent to the element with input nan features.

This nan value would spread out quickly after a few convolutions until you get nan on all sparse tensors. Also, the gradients would be invalid.

Could you explain some use cases for this?

Another option is to use one-hot vector to indicate that some elements have a specific property like what you described here.