Closed calebtung closed 4 years ago
@traveller59 Would you be able to provide clarification on this? Thank you!
Hello, if you want to get the same result, you should initialize the same weights and bias to them. I hope the code below would help you .
import numpy as np
import torch
import spconv
torch_tensor_dense = torch.rand(1, 4, 4, requires_grad = True)
torch_tensor_dense_to_sp = torch_tensor_dense.to_sparse()
indices_dense = torch_tensor_dense_to_sp.indices().permute(1, 0).contiguous().int()
features_dense = torch_tensor_dense_to_sp.values().view(-1, 1)
sp_tensor_dense = spconv.SparseConvTensor(features_dense, indices_dense, torch_tensor_dense.shape[1:], batch_size = 1)
weight = torch.randn(1,1,3,3)
bias = torch.tensor([-0.05])
conv_nn_nopad = torch.nn.Conv2d(1,1,3,1,0)
conv_nn_nopad.bias = torch.nn.Parameter(bias)
conv_nn_nopad.weight = torch.nn.Parameter(weight)
conv_sp_nopad = spconv.SparseConv2d(1,1,3,1,0)
conv_sp_nopad.bias = torch.nn.Parameter(bias)
conv_sp_nopad.weight = torch.nn.Parameter(weight.reshape([3,3,1,1]))
nnconv_input_dense = torch_tensor_dense.unsqueeze(1)
out_nnconv_dense = conv_nn_nopad(nnconv_input_dense)
out_nnconv_dense
out_spconv_dense = conv_sp_nopad(sp_tensor_dense)
out_spconv_dense.dense()
the prints of out_nnconv_dense and out_spconv_dense.dense() are same.
Thanks @sakura-iv, very helpful!
Hey @calebtung @sakura-iv Did you solve your issue? What if I have 3D data? I would like to just use sparse convolution with a 3D point cloud
@sakura-iv Have you compared the inference time of the two convolutions?
Thank you for the great work!
Even after reading #142 , I'm still a bit confused; how would I implement a basic Conv2d operation on an RGB image using spconv?
Let's say in regular PyTorch, I did the following:
How would I achieve the same thing with spconv? Specifically, I'm confused about the expected arguments for
features
,indices
, andspatial_shape
.I have this so far:
Any clarification on how to correctly implement this would be greatly appreciated; thank you!