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

Pytorch 1.6 and lib knn build with cuda 10.2 #170

Open
wants to merge 1 commit into
base: Pytorch-1.0
Choose a base branch
from

Conversation

drapado
Copy link

@drapado drapado commented Aug 19, 2020

I changed the Pytorch-1.0 branch to make it work with Pytorch 1.6.0 and CUDA 10.2 (on python 3.6.11).

To install you'll need to:

  1. Download the code with these changes
  2. Open a terminal and go to the densefusion directory
  3. Run the following commands:
pip install opencv-python scipy pyyaml
cd lib/knn
python setup.py install
cd dist
unzip knn_pytorch-0.1-py3.6-linux-x86_64.egg 
cp knn_pytorch/knn_pytorch.py ../knn_pytorch.py
cp knn_pytorch/knn_pytorch.cpython-36m-x86_64-linux-gnu.so ../knn_pytorch.cpython-36m-x86_64-linux-gnu.so
cd ../../..

The changes are:

  1. Line 38 on lib/knn/src/knn.h since THCState_getCurrentStream(state) is deprecated (see here and here)
  2. Adapted class KNearestNeighbor from /lib/knn/init.py and /lib/loss.py accordingly to solve the issue Legacy autograd function with non-static forward method is deprecated following the documentation

@drapado drapado mentioned this pull request Aug 19, 2020
@wjalex2000
Copy link

Hello, I have a question about this. When I applied the changes and ran the commands, I still get an error saying that

File "./tools/train.py", line 140, in main
loss, dis, new_points, new_target = criterion(pred_r, pred_t, pred_c, target, model_points, idx, points, opt.w, opt.refine_start)
File "/home/motion/anaconda3/envs/wj6d_env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/motion/anaconda3/envs/wj6d_env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 223, in _forward_unimplemented
raise NotImplementedError
NotImplementedError

Is it possible to get some help with this?
Thank you!

@drapado
Copy link
Author

drapado commented Sep 9, 2020

Mmm, are you sure you are using pytorch 1.6? The error seems to point to a non existing __init__ on class KNearestNeighbor(Function):. But from pytorch 1.3 you don't need it anymore because you use an static forward I think.

Also, are you using LineMOD or YCB?

@wjalex2000
Copy link

wjalex2000 commented Sep 9, 2020

Hi! That's weird... I just double-checked my pytorch version and I'm using 1.6.0. I'm using LineMOD right now. Again, thank you so much,

@drapado
Copy link
Author

drapado commented Sep 9, 2020

TBH I haven't checked with LineMOD, I tested the code with YCB so maybe there's a problem there. I'll try to test in LineMOD if I have some extra time

@wjalex2000
Copy link

Hmm... Ok, I'll try with YCB too. Let me know if you get time to try it! Thank you!

@emigmo
Copy link

emigmo commented Jun 10, 2021

great

@a-pizzi
Copy link

a-pizzi commented Jul 29, 2021

Hello, i followed step by step the instructions provided, but when the .egg file is generated it does not contain the file named "knn_pytorch.cpython-36m-x86_64-linux-gnu.so", but instead it's created a file named "knn_pytorch.so" that weights 3.5MB; i tried to rename it so to verify if it was just an error related to the name, but if i use it as .so file it returns me an error: unrecognized statement inside the .so file. I'm using pytorch 1.0.0, torchvision 0.2.2 and python 2.7.17 on an ubuntu environment.
The procedure i follow is:

  • clone the repository
  • install all the dependencies
  • download the datasets
  • follow the above instructions (provided by @drapado)

What am i doing wrong?

Thank you!

@gntoni
Copy link

gntoni commented Sep 16, 2021

loss_refiner.py should be modified similarly to loss.py

index 6496c9a..2e1b21c 100755
--- a/lib/loss_refiner.py
+++ b/lib/loss_refiner.py
@@ -10,7 +10,7 @@ from lib.knn.__init__ import KNearestNeighbor
 
 
 def loss_calculation(pred_r, pred_t, target, model_points, idx, points, num_point_mesh, sym_list):
-    knn = KNearestNeighbor(1)
+    #knn = KNearestNeighbor(1)
     pred_r = pred_r.view(1, 1, -1)
     pred_t = pred_t.view(1, 1, -1)
     bs, num_p, _ = pred_r.size()
@@ -41,7 +41,7 @@ def loss_calculation(pred_r, pred_t, target, model_points, idx, points, num_poin
     if idx[0].item() in sym_list:
         target = target[0].transpose(1, 0).contiguous().view(3, -1)
         pred = pred.permute(2, 0, 1).contiguous().view(3, -1)
-        inds = knn(target.unsqueeze(0), pred.unsqueeze(0))
+        inds = KNearestNeighbor.apply(target.unsqueeze(0), pred.unsqueeze(0))
         target = torch.index_select(target, 1, inds.view(-1) - 1)
         target = target.view(3, bs * num_p, num_point_mesh).permute(1, 2, 0).contiguous()
         pred = pred.view(3, bs * num_p, num_point_mesh).permute(1, 2, 0).contiguous()
@@ -60,7 +60,7 @@ def loss_calculation(pred_r, pred_t, target, model_points, idx, points, num_poin
     new_target = torch.bmm((new_target - ori_t), ori_base).contiguous()
 
     # print('------------> ', dis.item(), idx[0].item())
-    del knn
+    #del knn
     return dis, new_points.detach(), new_target.detach()

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

Successfully merging this pull request may close these issues.

6 participants