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

ImportError: No module named 'knn' #23

Open
zcxxlshirley opened this issue May 1, 2021 · 5 comments
Open

ImportError: No module named 'knn' #23

zcxxlshirley opened this issue May 1, 2021 · 5 comments

Comments

@zcxxlshirley
Copy link

when I trying the command:
python train.py --exp_name=PUGAN-pytorch-master --gpu=0 --use_gan --batch_size=12
it appears the following error:
Traceback (most recent call last):
File "train.py", line 14, in
from network.networks import Generator,Discriminator
File "../network/networks.py", line 6, in
from knn_cuda import KNN
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/knn_cuda/init.py", line 38, in
_knn = load_cpp_ext("knn")
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/knn_cuda/init.py", line 33, in load_cpp_ext
with_cuda=True
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1091, in load
keep_intermediates=keep_intermediates)
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1317, in _jit_compile
return _import_module_from_library(name, build_directory, is_python_module)
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1701, in _import_module_from_library
file, path = imp.find_module(module_name, [path])
File "/media/cx/新加卷1/xxl1/lib/python3.7/imp.py", line 297, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'knn'

I have installed the KNN_CUDA mentioned in readme.md

I checked a lot on the Internet, but didn't solve the problem.

@Yasserelhaddar
Copy link

I get the same error whenever I try to import knn_cuda !
Can someone help us please?

import knn_cuda
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\49152\anaconda3\envs\torch\lib\site-packages\knn_cuda_init_.py", line 38, in
knn = load_cpp_ext("knn")
File "C:\Users\49152\anaconda3\envs\torch\lib\site-packages\knn_cuda_init
.py", line 26, in load_cpp_ext
ext = load(
File "C:\Users\49152\anaconda3\envs\torch\lib\site-packages\torch\utils\cpp_extension.py", line 1079, in load
return _jit_compile(
File "C:\Users\49152\anaconda3\envs\torch\lib\site-packages\torch\utils\cpp_extension.py", line 1317, in _jit_compile
return _import_module_from_library(name, build_directory, is_python_module)
File "C:\Users\49152\anaconda3\envs\torch\lib\site-packages\torch\utils\cpp_extension.py", line 1699, in _import_module_from_library
file, path, description = imp.find_module(module_name, [path])
File "C:\Users\49152\anaconda3\envs\torch\lib\imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'knn'

@njnj0314
Copy link

njnj0314 commented Sep 7, 2021

19/5000
I met the same problem, have you solved it?

@njnj0314
Copy link

njnj0314 commented Sep 7, 2021

when I trying the command:
python train.py --exp_name=PUGAN-pytorch-master --gpu=0 --use_gan --batch_size=12
it appears the following error:
Traceback (most recent call last):
File "train.py", line 14, in
from network.networks import Generator,Discriminator
File "../network/networks.py", line 6, in
from knn_cuda import KNN
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/knn_cuda/init.py", line 38, in
_knn = load_cpp_ext("knn")
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/knn_cuda/init.py", line 33, in load_cpp_ext
with_cuda=True
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1091, in load
keep_intermediates=keep_intermediates)
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1317, in _jit_compile
return _import_module_from_library(name, build_directory, is_python_module)
File "/media/cx/新加卷1/xxl1/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1701, in _import_module_from_library
file, path = imp.find_module(module_name, [path])
File "/media/cx/新加卷1/xxl1/lib/python3.7/imp.py", line 297, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'knn'

I have installed the KNN_CUDA mentioned in readme.md

I checked a lot on the Internet, but didn't solve the problem.

I met the same problem, have you solved it?

@Yasserelhaddar
Copy link

Yasserelhaddar commented Sep 7, 2021 via email

@fengyuan1993012
Copy link

the function torch.cdist cloud compute the distance. I have written the function
def knntry(pc,n_neighbors,r,h):
#
dist = torch.cdist(pc,pc)
distnew = -dist
neigbhors = distnew.topk(k=n_neighbors+1,dim=2,largest=False)
distvalue = neigbhors.values[:,:,1:]
distvalue = -distvalue
distvalue = torch.clamp(distvalue,0,r)
weight = torch.exp(-distvalue/h)
result = r - distvalue
nozerocount = torch.nonzero(result)
resum = torch.sum(result.mul(weight))
if resum<1e-6:

    re_loss = resum
else:
    re_loss = resum/nozerocount

return re_loss

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