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

Segment Fault due to resolution #246

Open
gitouni opened this issue Mar 24, 2024 · 0 comments
Open

Segment Fault due to resolution #246

gitouni opened this issue Mar 24, 2024 · 0 comments

Comments

@gitouni
Copy link

gitouni commented Mar 24, 2024

I use the unet to extract features (B, N, 32) from point clouds (B, N, 3). When I changed resolution from 50 to 24, the segment fault was thrown. This is not due to too low resolution, because it also threw segment fault in other data when I set resolution to 100. My Code snippet is shown below.

UNet

import torch.nn as nn
import sparseconvnet as scn
import torch
from typing import Iterable

class SCNet(nn.Module):
    def __init__(self, dimension=3, reps=1, m=32, nPlanes=[32, 64, 96, 128, 160], spatialSize=24*8, nClassesTotal=50):
        super(SCNet, self).__init__()
        self.sparseModel = scn.Sequential().add(
           scn.InputLayer(dimension, spatialSize, mode=4)).add(
           scn.SubmanifoldConvolution(dimension, 1, m, 3, False)).add(
           scn.UNet(dimension, reps, nPlanes, residual_blocks=False, downsample=[2,2])).add(
           scn.BatchNormReLU(m)).add(
           scn.OutputLayer(dimension))
        self.linear = nn.Linear(m, nClassesTotal)

    def forward(self,x) -> torch.Tensor:
        x = self.sparseModel(x)
        x = self.linear(x)
        return x
    
    def unet_foward(self,x) -> torch.Tensor:
        return self.sparseModel(x)

DataProcessing

def scn_input_wrapper(tensor_list: Iterable[torch.Tensor], scale:float, bias:float, device=None):
    D = tensor_list[0].shape[-1]
    device = device if device is not None else tensor_list[0].device
    coord_params = dict(dtype=torch.int64, device=device)
    feature_params = dict(dtype=torch.float32, device=device)
    C = torch.empty([0,D+1], **coord_params)  # (N, D+1) last dim for batch_idx
    F = torch.empty([0,1], **feature_params)  # (N,1) 1-dim feature for each point
    for b, tensor in enumerate(tensor_list):
        coords = torch.hstack([((tensor+bias)*scale).to(**coord_params), b*torch.ones([tensor.shape[0],1],**coord_params)])
        features = torch.ones([tensor.shape[0],1],**feature_params)
        C = torch.vstack([C,coords])
        F = torch.vstack([F,features])
    return [C, F]

def scn_output_wrapper(tensor:torch.Tensor, batch_idx:torch.Tensor, batch_size:int):
    batch = torch.zeros(batch_size, tensor.shape[0] // batch_size, tensor.shape[1], dtype=tensor.dtype, device=tensor.device)
    for bi in range(batch_size):
        bi_indices = batch_idx==bi
        batch[bi, ...] = tensor[bi_indices,:]
    return batch

Please download our data and unzip debug_pc1.npy and debug_pc2.npy and run the Main program.
debug_pc.zip

Main

pc1 = np.load('debug_pc1.npy')
pc2 = np.load('debug_pc2.npy')
scnet = SCNet()
# scnet.load_state_dict(torch.load("pretrained/scn.pth",map_location='cpu')) # here weights do not affect the results
scnet.eval()
scnet.cuda()
resolution = 24 # segment fault. But no fault emerged if resolution = 50
sinput1 = scn_input_wrapper([torch.from_numpy(pc1).cuda()],resolution,0)
sinput2 = scn_input_wrapper([torch.from_numpy(pc2).cuda()],resolution,0)
print("start scn forward") # segment fault is thrown right after this line
feat1 = scnet.unet_foward(sinput1).detach().cpu().numpy()
feat2 = scnet.unet_foward(sinput2).detach().cpu().numpy()
print("Feature extraction Finished.")

I annotate the segment fault in the above code snippet.
Thanks for your reply.

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

1 participant