AllenXiangX / SnowflakeNet

(TPAMI 2023) Snowflake Point Deconvolution for Point Cloud Completion and Generation with Skip-Transformer
MIT License
142 stars 16 forks source link

How do I run this network with my own data? #23

Open mostafa501 opened 9 months ago

mostafa501 commented 9 months ago

Hey all,

I see that you have a custom dataloader for the solution, but I was curious how to use this network on my own data. For example, say I have a PCD which is already incomplete, I do not have the ground truth for this. I just want to run inference on this data. How would be the best way to progress using this network? Any help on this would be very much appreciated. Thank you for the contribution !!

AllenXiangX commented 9 months ago

Hi, Thank you for your interest in this work. You may need to write a new script (python file) to complete your own data. The recommended steps are as follows:

  1. load the pretrained model as line 25-35 in test.py does.
  2. load you own pcd file with the _read_pcd function, turn it into a PyTorch tensor.
  3. feed the data into the pretrained model and get the completed point cloud, like this.
mostafa501 commented 9 months ago

Hi @AllenXiangX, first let me thank you for you kind reply, i tried to use the network as you illustrated to me in the above reply. As cleared in this attcahed file ("test_custom.py"), placed in same directory of original "test.py" file, I applied the 3 steps, and tried to run but it gives me an error that my data shape is different than the coded data shape, knowing that my data is point cloud is part of chair ("data_cluster_0.pcd") as attached also. Please, may you help me in solving this error:


"""(spd) navlab@navlab-ProLiant-DL380-Gen10:/media/navlab/GNSS/work/pc_completion/SnowflakeNet$ /home/navlab/anaconda3/envs/spd/bin/python /media/navlab/GNSS/work/pc_completion/SnowflakeNet/completion/test_custom.py Input point_cloud shape: torch.Size([5706127, 3]) Traceback (most recent call las python file and data.zip t): File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/completion/test_custom.py", line 58, in completed_point_cloud = complete_point_cloud(model, input_point_cloud) File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/completion/test_custom.py", line 40, in complete_point_cloud pcds_pred = model(input_point_cloud.contiguous()) File "/home/navlab/anaconda3/envs/spd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/home/navlab/anaconda3/envs/spd/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 159, in forward return self.module(*inputs[0], *kwargs[0]) File "/home/navlab/anaconda3/envs/spd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/models/model_completion.py", line 136, in forward point_cloud = point_cloud.permute(0, 2, 1).contiguous() RuntimeError: number of dims don't match in permute"""


AllenXiangX commented 9 months ago

Hi, sorry for the late response. The tensor shape required by the SnowflakeNet is (b, n, 3), where b is the batch size, n is the point number and 3 denotes xyz coordinates. It seems that your input point cloud tensor shape is (n, 3), so you can use input_point_cloud = input_point_cloud.unsqueeze(0) to add the batch size dimension (b)

mostafa501 commented 9 months ago

Hi @AllenXiangX, thank you for the reply. I have modified the data tensor size to be (b,n,3) as in my used script "test_custom_modified.py" attached with data file used. test_custom_modified.zip However, I got some errors and solved them, but finally I got another error related to different shapes of tensors in the "sample_and_group_knn" function within the utils.py file.


Here is the error: n/SnowflakeNet$ /home/navlab/anaconda3/envs/spd/bin/python /media/navlab/GNSS/work/pc_completion/SnowflakeNet/completion/test_custom.py Input point_cloud shape: torch.Size([1, 6877, 3]) Traceback (most recent call last): File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/completion/test_custom.py", line 67, in completed_point_cloud = complete_point_cloud(model, input_point_cloud) File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/completion/test_custom.py", line 46, in complete_point_cloud pcds_pred = model(point_cloud) File "/home/navlab/anaconda3/envs/spd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, kwargs) File "/home/navlab/anaconda3/envs/spd/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 159, in forward return self.module(*inputs[0], *kwargs[0]) File "/home/navlab/anaconda3/envs/spd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, kwargs) File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/models/model_completion.py", line 137, in forward feat = self.feat_extractor(point_cloud) File "/home/navlab/anaconda3/envs/spd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, *kwargs) File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/models/model_completion.py", line 32, in forward l1_xyz, l1_points, idx1 = self.sa_module_1(l0_xyz, l0_points) # (B, 3, 512), (B, 128, 512) File "/home/navlab/anaconda3/envs/spd/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(input, **kwargs) File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/models/utils.py", line 375, in forward new_xyz, new_points, idx, grouped_xyz = sample_and_group_knn(xyz, points, self.npoint, self.nsample, self.use_xyz, idx=idx) File "/media/navlab/GNSS/work/pc_completion/SnowflakeNet/models/utils.py", line 320, in sample_and_group_knn grouped_xyz -= new_xyz.unsqueeze(3).repeat(1, 1, 1, k) RuntimeError: The size of tensor a (3) must match the size of tensor b (16) at non-singleton dimension 3.


May you help me to solve this error and modify my custom_test script to complete the point cloud? I know it may be bothersome to you.But I think your help will enrich this issue for anyone who wants to apply inference to collected data. Best regards.

AllenXiangX commented 9 months ago

In the function "complete_point_cloud", delete the line point_cloud = input_point_cloud.permute(0, 2, 1).contiguous(). Because the input tensor shape is (b, n, c), not (b, c, n)

mostafa501 commented 9 months ago

@AllenXiangX, Thank you so much; the script is okay. Let me read the paper and please let me ask you more about the network (if needed), whether in this issue or another one. Regards.

SWWdz commented 8 months ago

I have the same problem in my work, can you give me some advice to run this network with my own data?

mostafa501 commented 8 months ago

@SWWdz , hi you can use the code i provided in this issue based on AllenXiangX advices. Please follow the following: 1-download the code from above replys " https://github.com/AllenXiangX/SnowflakeNet/issues/23#issuecomment-1744417001" 2-put the test_modified.py code at the same directory of original test.py code file 3-delete the line point_cloud = input_point_cloud.permute(0, 2, 1).contiguous(). Because the input tensor shape is (b, n, c), not (b, c, n). it will work with you.