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

how to align the order of indices #713

Open
repoww opened this issue Jul 24, 2024 · 2 comments
Open

how to align the order of indices #713

repoww opened this issue Jul 24, 2024 · 2 comments

Comments

@repoww
Copy link

repoww commented Jul 24, 2024

pooling = spconv.SparseAvgPool3d(kernel_size=2, stride=2)
conv1= spconv.SparseConv3d(
        3,
        3,
        2,
        stride=2,
        padding=0,
        dilation=1,
        bias=False
    )
data = spconv.SparseConvTensor(
        features=features.cuda(),
        indices=batch_indices.cuda(),
        spatial_shape=batch_indices.max(0)[0][1:] + 1,
        batch_size=1
    )
coordinates = spconv.SparseConvTensor(
        features=raw_coordinates.cuda(),
        indices=batch_indices.cuda(),
        spatial_shape=batch_indices.max(0)[0][1:] + 1,
        batch_size=1
    )

coords = pooling(coordinates)
embeddings = conv1(data)

How can I align the indices of coords and embbeddings to be the same to use coords as input of positional encoding.
The two inputs share the same indices, with conv(stride=2) and pooling(stride=2), the output indices should be the same?

Looks like the set of the conv output and pooling output indices are the same but in different orders.

Thanks

@repoww
Copy link
Author

repoww commented Jul 24, 2024

Probably, I should do pooling of raw_coordinates based on the indice_dict from embeddings and just replace the features of embeddings

@RobotDogCyberslacking
Copy link

Probably, I should do pooling of raw_coordinates based on the indice_dict from embeddings and just replace the features of embeddings

I don't think it will work

test_pooling = spconv.SparseAvgPool3d(kernel_size=2,stride=2,padding=0,indice_key='test')

sp_conv = spconv.SparseConv3d(3,3,kernel_size=2,stride = 2,bias= False,indice_key='test').cuda()

test_pooled_coords = test_pooling(coordinates)

test_conv_coords = sp_conv(coordinates)

assert(test_pooled_coords.indices == test_conv_coords.indices).all() # False

and replace_feature function does not take indices of new features as input, it will simply replace the features(with incurract indices)
https://github.com/traveller59/spconv/blob/125a194d895b1bc3ad6ff907bc72641548397b32/spconv/pytorch/core.py#L198

The best way I can think of indices alignment is to reorder the features, you can reference the code like sparse_add
https://github.com/traveller59/spconv/pull/395

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