mit-han-lab / torchsparse

[MICRO'23, MLSys'22] TorchSparse: Efficient Training and Inference Framework for Sparse Convolution on GPUs.
https://torchsparse.mit.edu
MIT License
1.15k stars 131 forks source link

[BUG] Conv3d with stride = 2 output no point #268

Closed zhou745 closed 7 months ago

zhou745 commented 7 months ago

Is there an existing issue for this?

Current Behavior

I am using the lastest version 2.1.0, and run into this problem when I am downsampling a sparse tensor. Then I conducted some unit test, the input of my testing tensor is:

device_test = torch.device("cuda:0") from torchsparse import SparseTensor

xyz = torch.tensor([[i,i,i,0] for i in range(16)]).to(torch.int32) feature = torch.tensor([[i+1,i+1,i+1] for i in range(16)]).to(torch.float32)

test_sparse = SparseTensor(feature,xyz,stride=1).to(device_test) print(test_sparse.C) print(test_sparse.F)

Then I passed it into the following model:

import torchsparse.nn as spnn

class sp_model(torch.nn.Module): def init(self,inch, outch): super().init() self.conv0 = spnn.Conv3d(inch,3,kernel_size=3,stride=1) self.conv1 = spnn.Conv3d(3,outch,kernel_size=3,stride=2)

    #set weight init
    weight_0 = torch.ones_like(self.conv0.kernel.data)
    self.conv0.kernel.data = weight_0
    weight_1 = torch.ones_like(self.conv1.kernel.data)
    self.conv1.kernel.data = weight_1

def forward(self,x):
    h0 = self.conv0(x)
    h1 = self.conv1(h0)

    return(h0,h1)

model = sp_model(3,3).to(device_test)

The output of the first conv layer is normal, however, the second conv layer with stride =2 outputs an sparse tensor without any points.

![Uploading image.png…]()

Expected Behavior

No response

Environment

- GCC:
- NVCC:
- PyTorch:
- PyTorch CUDA:
- TorchSparse:

Anything else?

No response

ys-2020 commented 7 months ago

Hi. You should put the batch index to the first dimension in xyz = torch.tensor([[i,i,i,0] for i in range(16)]).to(torch.int32)