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

Can't restore the dense feature map #248

Open
WuZhaoyue opened this issue Aug 16, 2024 · 5 comments
Open

Can't restore the dense feature map #248

WuZhaoyue opened this issue Aug 16, 2024 · 5 comments

Comments

@WuZhaoyue
Copy link

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!!!
截图 2024-08-16 20-11-37

@bottler
Copy link
Contributor

bottler commented Aug 18, 2024

Not sure anyone can help, but can you share your code? It might help see what is happening.

@WuZhaoyue
Copy link
Author

WuZhaoyue commented Aug 19, 2024

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

####Creating a simple dense image data and zeroing out parts of the image to simulate sparse data
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)

####Visualize original and recovered images
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()
#########################################

@bottler
Copy link
Contributor

bottler commented Aug 19, 2024

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.

@btgraham
Copy link
Contributor

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

@WuZhaoyue
Copy link
Author

Ok, thank you very much for your friendly answers, I will try another solution based on your suggestions.

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

3 participants