Open WuZhaoyue opened 3 months ago
Not sure anyone can help, but can you share your code? It might help see what is happening.
Not sure anyone can help, but can you share your code? It might help see what is happening. Hello, thank you for your kindly reply. Here is the code of a simple example
############################## import torch import sparseconvnet as scn import matplotlib.pyplot as plt
image = torch.randn(1, 3, 100, 100) # (batch_size, channels, height, width) image[:, :, 20:40, 30:50] = 0
dimension = 2 spatial_size = torch.Size([100, 100]) # spatial size dense_to_sparse = scn.DenseToSparse(dimension) sparse_image = dense_to_sparse(image)
sparse_to_dense = scn.SparseToDense(dimension, 3) # 3 is the number of channels restored_image = sparse_to_dense(sparse_image)
restored_image = restored_image.squeeze(0)
original_image_np = image.squeeze(0).permute(1, 2, 0).numpy() restored_image_np = restored_image.permute(1, 2, 0).numpy()
plt.figure(figsize=(12, 6)) plt.subplot(1, 2, 1) plt.title("Original Image") plt.imshow(original_image_np)
plt.subplot(1, 2, 2) plt.title("Restored Image") plt.imshow(restored_image_np)
plt.show() #########################################
Looking at the code in https://github.com/facebookresearch/SparseConvNet/blob/main/sparseconvnet/sparseToDense.py and https://github.com/facebookresearch/SparseConvNet/blob/main/sparseconvnet/denseToSparse.py, it seems that the shapes expected and produced are not quite the same. I think you need to take this into account manually.
Sorry, I am unable to maintain SparseConvNet any more. However, more recent implementations of submanifold SparseConvnets are more highly optimized , ie. TorchSparse https://github.com/mit-han-lab/torchsparse, MinkowskiEngine https://github.com/NVIDIA/MinkowskiEngine SpConv https://github.com/traveller59/spconv
Ok, thank you very much for your friendly answers, I will try another solution based on your suggestions.
Hello, thanks a lot for this great work. I have a question for you. When I use it on an image where some pixels are 0, I use scn.DenseToSparse to convert it to sparse input format, but when I don't do any processing and directly use scn.SparseToDense to restore this sparse tensor to the original dense tensor, it doesn't work as shown. I would like to ask what is the reason? Thanks a lot!!!