PUGAN-pytorch
PUGAN-pytorch copied to clipboard
ImportError: No module named 'knn'
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
I have installed the KNN_CUDA mentioned in readme.md
I checked a lot on the Internet, but didn't solve the problem.
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'
19/5000 I met the same problem, have you solved it?
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?
Try this function:
def knn(pc,n_neighbors=11): dist = torch.cdist(pc,pc) neigbhors = dist.topk(k=n_neighbors,dim=2,largest=False) #print(neigbhors.indices.shape) knn_values = pc[:,torch.squeeze(neigbhors.indices[:,:,1:n_neighbors+1])] l2 = torch.tensor(0) h = 20 #eps = 1 for j in range(5): l2 = l2 + torch.sum((torch.squeeze(knn_values)[:, j, :] - torch.squeeze(pc))**2)
#dist2 = torch.max(l2, torch.tensor(eps))
dist2 = l2
dist = torch.sqrt(dist2)
weight = torch.exp(- dist2 / h ** 2)
# uniform_loss = torch.mean((self.radius - dist) * weight)
uniform_loss = torch.mean((0.01 - dist) * weight) # punet
return uniform_loss
Le mar. 7 sept. 2021 à 03:56, njnj0314 @.***> a écrit :
19/5000 I met the same problem, have you solved it?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/UncleMEDM/PUGAN-pytorch/issues/23#issuecomment-913934228, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJBI2W72HJZDK3Q7J3FLTQLUAVWL7ANCNFSM436DX43Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
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