MinkowskiEngine icon indicating copy to clipboard operation
MinkowskiEngine copied to clipboard

Custom values for coordinates without features?

Open rwagner2017 opened this issue 4 years ago • 1 comments
trafficstars

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.

rwagner2017 avatar Feb 25 '21 21:02 rwagner2017

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.

chrischoy avatar Mar 14 '21 01:03 chrischoy