Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

features_at, coords_at function error #100

Closed
whitealex95 opened this issue Mar 10, 2020 · 5 comments
Closed

features_at, coords_at function error #100

whitealex95 opened this issue Mar 10, 2020 · 5 comments

Comments

@whitealex95
Copy link

whitealex95 commented Mar 10, 2020

Hi, I have some trouble using features_at function
It seems to not work when there is a skip in the batch index

>>> import torch
>>> from MinkowskiEngine import SparseTensor
>>> f = torch.Tensor([1,1,1,1])
>>> c = torch.Tensor([[0,0],[0,1],[2,0],[2,1]])
>>> x = SparseTensor(f,c)
>>> x.features_at(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/whitealex95/.anaconda3/envs/arrgen-min/lib/python3.7/site-packages/MinkowskiEngine/SparseTensor.py", line 366, in features_at
    batch_index)
  File "/home/whitealex95/.anaconda3/envs/arrgen-min/lib/python3.7/site-packages/MinkowskiEngine/MinkowskiCoords.py", line 224, in get_row_indices_at
    coords_key.CPPCoordsKey, out_coords_key.CPPCoordsKey, batch_index)
RuntimeError: src/coords_manager.cpp:876, assertion (batch_index < batch_indices.size()) faild. Invalid batch index:  2 , batch_index exceeds current maximum batch size:  2  of a provided batch indices:  [0, 2]

Thanks

@chrischoy
Copy link
Contributor

Thanks for reporting the issue.
Yes, it currently assumes the index of the unique batch indices as the input, but I can see how this is a confusing name for the function. I'll update the function in the next version.

For now, to get unique batch indices, use

>>> x.coords_man.get_batch_indices()
{0, 2}

@whitealex95
Copy link
Author

Hi, thank you for the answer.

In case we have the continuous batch indices:

>>> x.coords_man.get_batch_indices()
{0,1, 2, 3}

I think the function features_at works fine with code:

>>> x.features_at(2)

giving out the features with the batch index 2

Is there a built-n function to get the same result in case of skipping batch indices?
I'm currently using a custom function:

def feats_at_idx(x: SparseTensor, idx: int):
    data_idx = x.C[:, 0] == idx
    return x.F[data_idx]

I just want to know if there's a better way for this job

Thanks

@chrischoy
Copy link
Contributor

chrischoy commented Mar 10, 2020

So currently using the batch indices would be the best work around for now.

def feats_at_idx(x, idx):
  bs = list(x.coords_man.get_batch_indices())
  if idx not in bs:
    return torch.FloatTensor([[]])
  unique_idx = bs.index(idx)
  return x.features_at(unique_idx)

@whitealex95
Copy link
Author

I'm sorry, but according to your function, the code

x.features_at(1)

should work in case of

>>> x.coords_man.get_batch_indices()
{0, 2}

However, I get the following error.

>>> import torch
>>> from MinkowskiEngine import SparseTensor
>>> f = torch.Tensor([1,1,1,1])
>>> c = torch.Tensor([[0,0],[0,1],[2,0],[2,1]])
>>> x = SparseTensor(f,c)
>>> x.features_at(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/whitealex95/.anaconda3/envs/arrgen-min/lib/python3.7/site-packages/MinkowskiEngine/SparseTensor.py", line 366, in features_at
    batch_index)
  File "/home/whitealex95/.anaconda3/envs/arrgen-min/lib/python3.7/site-packages/MinkowskiEngine/MinkowskiCoords.py", line 224, in get_row_indices_at
    coords_key.CPPCoordsKey, out_coords_key.CPPCoordsKey, batch_index)
RuntimeError: src/coords_manager.cpp:876, assertion (batch_index < batch_indices.size()) faild. Invalid batch index:  2 , batch_index exceeds current maximum batch size:  2  of a provided batch indices:  [0, 2]

Did I misunderstand your function?

@chrischoy
Copy link
Contributor

chrischoy commented Mar 10, 2020

Right, I just pushed the latest commit that will now work as expected with the batch index. Please let me know if there's a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants