DB icon indicating copy to clipboard operation
DB copied to clipboard

ImportError: cannot import name 'deform_conv_cuda'

Open Tian14267 opened this issue 4 years ago • 7 comments

在编译完之后,运行代码的时候,报下面这个错误: Traceback (most recent call last): File "train.py", line 71, in main() File "train.py", line 68, in main trainer.train() File "/home/hj/smbshare/fffan/Detector/DB-master/trainer.py", line 48, in train model = self.init_model() File "/home/hj/smbshare/fffan/Detector/DB-master/trainer.py", line 34, in init_model self.device, self.experiment.distributed, self.experiment.local_rank) File "/home/hj/smbshare/fffan/Detector/DB-master/structure/builder.py", line 25, in build distributed=distributed, local_rank=local_rank) File "/home/hj/smbshare/fffan/Detector/DB-master/structure/model.py", line 37, in init self.model = BasicModel(args) File "/home/hj/smbshare/fffan/Detector/DB-master/structure/model.py", line 15, in init self.backbone = getattr(backbones, args['backbone'])(**args.get('backbone_args', {})) File "/home/hj/smbshare/fffan/Detector/DB-master/backbones/resnet.py", line 267, in deformable_resnet18 stage_with_dcn=[False, True, True, True], **kwargs) File "/home/hj/smbshare/fffan/Detector/DB-master/backbones/resnet.py", line 192, in init block, 128, layers[1], stride=2, dcn=dcn) File "/home/hj/smbshare/fffan/Detector/DB-master/backbones/resnet.py", line 226, in _make_layer stride, downsample, dcn=dcn)) File "/home/hj/smbshare/fffan/Detector/DB-master/backbones/resnet.py", line 55, in init from assets.ops.dcn import ModulatedDeformConv File "/home/hj/smbshare/fffan/Detector/DB-master/assets/ops/dcn/init.py", line 1, in from .functions.deform_conv import deform_conv, modulated_deform_conv File "/home/hj/smbshare/fffan/Detector/DB-master/assets/ops/dcn/functions/deform_conv.py", line 5, in from .. import deform_conv_cuda ImportError: cannot import name 'deform_conv_cuda' 请问有人知道这个问题是怎么解决吗?

Tian14267 avatar May 19 '20 09:05 Tian14267

Hi @Tian14267 I faced with the same issue. You need to "build deformable convolution opertor" as mentioned in the README

build deformable convolution opertor make sure your cuda path of $CUDA_HOME is the same version as your cuda in PyTorch make sure GCC >= 4.9 you need to delete the build directory before you re-build it.

echo` $CUDA_HOME cd assets/ops/dcn/ python setup.py build_ext --inplace

hungnv21292 avatar May 26 '20 11:05 hungnv21292

@viethungtsdv Can you please guide me on how to build this? I tried this python setup.py build_ext --inplace but I am getting error It will be great if you can send me steps to build it from scratch? @Tian14267 @MhLiao

Akshay-Ijantkar avatar Sep 22 '20 03:09 Akshay-Ijantkar

@viethungtsdv Can you please guide me on how to build this? I tried this python setup.py build_ext --inplace but I am getting error It will be great if you can send me steps to build it from scratch? @Tian14267 @MhLiao

@Akshay-Ijantkar Did you resolve this? Actually I'm facing this problem. could you tell me what to do from scratch? It created a build folder but I get this at the end so I'm not sure whether everything was implemented perfectly

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA\v10.1\bin\nvcc -c src/deform_conv_cuda_kernel.cu -o build\temp.win-amd64-3.8\Release\src/deform_conv_cuda_kernel.obj -IC:\Users\HP\anaconda3\envs\DBresearch\lib\site-packages\torch\include -IC:\Users\HP\anaconda3\envs\DBresearch\lib\site-packages\torch\include\torch\csrc\api\include -IC:\Users\HP\anaconda3\envs\DBresearch\lib\site-packages\torch\include\TH -IC:\Users\HP\anaconda3\envs\DBresearch\lib\site-packages\torch\include\THC "-IC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA\v10.1\include" -IC:\Users\HP\anaconda3\envs\DBresearch\include -IC:\Users\HP\anaconda3\envs\DBresearch\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" -Xcompiler /EHsc -Xcompiler /wd4819 -Xcompiler /MD -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=deform_conv_cuda -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_50,code=sm_50 error: command 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA\v10.1\bin\nvcc' failed: No such file or directory

allenmatt98 avatar Nov 14 '20 07:11 allenmatt98

Hi @Tian14267 I faced with the same issue. You need to "build deformable convolution opertor" as mentioned in the README

build deformable convolution opertor make sure your cuda path of $CUDA_HOME is the same version as your cuda in PyTorch make sure GCC >= 4.9 you need to delete the build directory before you re-build it.

echo` $CUDA_HOME cd assets/ops/dcn/ python setup.py build_ext --inplace q请问eindows下可以吗

happy20200 avatar Mar 26 '22 14:03 happy20200

@viethungtsdv Can you please guide me on how to build this? I tried this python setup.py build_ext --inplace but I am getting error It will be great if you can send me steps to build it from scratch? @Tian14267 @MhLiao

i got error too, how did you soulve it?

happy20200 avatar Mar 27 '22 07:03 happy20200

I resolved this problem by replacing AT_CHECK calls by TORCH_CHECK call at both deform_conv_cuda.cpp and deform_pool_cuda.cpp referenced from here https://discuss.pytorch.org/t/my-pytorch-model-stop-logging-without-error/77686/7

jtlee91 avatar May 30 '22 06:05 jtlee91