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

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

Open
mostafa501 opened this issue Sep 16, 2023 · 9 comments
Open

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

mostafa501 opened this issue Sep 16, 2023 · 9 comments

Comments

@mostafa501
Copy link

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 !!

@mostafa501 mostafa501 changed the title ow do I run this network with my own data? How do I run this network with my own data? Sep 18, 2023
@AllenXiangX
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

mostafa501 commented Oct 3, 2023

@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
Copy link

SWWdz commented Oct 10, 2023

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

@mostafa501
Copy link
Author

@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 " #23 (comment)"
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.

@guilherme-coelho-isi
Copy link

Is there an way to change the amount of points the pretrained model completes in the point cloud? I'm using the same code provided by @mostafa501, howver trying to change a bit of the configs didn't work for me.

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

4 participants