tianweiy / CenterPoint

MIT License
1.89k stars 457 forks source link

using PointToVoxel as VoxelGenerator in spconv V2 #335

Open YoushaaMurhij opened 2 years ago

YoushaaMurhij commented 2 years ago

I am trying to use Spconv.V2 during inference. Here's my modification:

# from spconv.utils import VoxelGeneratorV2 as VoxelGenerator
from spconv.pytorch.utils import PointToVoxel as VoxelGenerator

self.voxel_generator = VoxelGenerator(
            vsize_xyz=self.voxel_size,
            coors_range_xyz=self.range,
            max_num_points_per_voxel=self.max_points_in_voxel,
            max_num_voxels=self.max_voxel_num,
            num_point_features=5,
            device=self.device,
        )

But, I got this error:

File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "centerpoint_gnn/src/det3d/models/detectors/point_pillars.py", line 48, in forward
    x = self.extract_feat(data)
  File "centerpoint_gnn/src/det3d/models/detectors/point_pillars.py", line 29, in extract_feat
    x = self.neck(x)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "centerpoint_gnn/src/det3d/models/necks/rpn.py", line 153, in forward
    x = self.blocks[i](x)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "centerpoint_gnn/src/det3d/models/utils/misc.py", line 93, in forward
    input = module(input)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/conv.py", line 446, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/conv.py", line 442, in _conv_forward
    return F.conv2d(input, weight, bias, self.stride,
RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "centerpoint_gnn/src/det3d/models/detectors/point_pillars.py", line 48, in forward
    x = self.extract_feat(data)
  File "centerpoint_gnn/src/det3d/models/detectors/point_pillars.py", line 29, in extract_feat
    x = self.neck(x)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "centerpoint_gnn/src/det3d/models/necks/rpn.py", line 157, in forward
    x = torch.cat(ups, dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 1 but got size 2 for tensor number 1 in the list.

Could you please tell me how to fix this error? Thanks

YoushaaMurhij commented 2 years ago

Update: Still getting:

RuntimeError: CUDA error: device-side assert triggered

Here is my modification:

        pts = torch.from_numpy(self.points).float().to(self.device)
        voxels, coords, num_points = self.voxel_generator(pts)

        num_voxels = np.array([voxels.shape[0]], dtype=np.int64)
        grid_size = self.voxel_generator.grid_size
        coords = np.pad(coords.cpu().numpy(), ((0, 0), (1, 0)), mode="constant", constant_values=0)

        voxels = voxels.half()
        coords = torch.tensor(coords, dtype=torch.int32, device=self.device)
        num_voxels = torch.tensor(num_voxels, dtype=torch.int32, device=self.device)

        self.inputs = dict(
            voxels=voxels,
            num_points=num_points,
            num_voxels=num_voxels,
            coordinates=coords,
            shape=[grid_size],
        )