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 to adapt /lib/nms/build.py to support pytorch1.0? #146

Open
xiangyangli-cn opened this issue Jun 11, 2019 · 1 comment
Open

How to adapt /lib/nms/build.py to support pytorch1.0? #146

xiangyangli-cn opened this issue Jun 11, 2019 · 1 comment

Comments

@xiangyangli-cn
Copy link

I changed the lib/nms/build.py as:

import os
import torch
#from torch.utils.ffi import create_extension
from torch.utils.cpp_extension import BuildExtension

sources = ['src/nms.c']
headers = ['src/nms.h']
defines = []
with_cuda = False

if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/nms_cuda.c']
headers += ['src/nms_cuda.h']
defines += [('WITH_CUDA', None)]
with_cuda = True

this_file = os.path.dirname(os.path.realpath(file))
print(this_file)
extra_objects = ['src/cuda/nms_kernel.cu.o']
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]

#BuildExtension
#create_extension
ffi = BuildExtension(
'_ext.nms',
headers=headers,
sources=sources,
define_macros=defines,
relative_to=file,
with_cuda=with_cuda,
extra_objects=extra_objects
)

if name == 'main':
ffi.build()

But the Errors are:

cd nms/src/cuda;
pwd;
echo "Compiling nms kernels by nvcc...";
nvcc -c -o nms_kernel.cu.o nms_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_52;
cd ../..;
python build.py;
cd ..;\

/home/isia/d1/000-REC/mask-faster-rcnn-lxy/lib/nms/src/cuda
Compiling nms kernels by nvcc...
Including CUDA code.
/home/isia/d1/000-REC/mask-faster-rcnn-lxy/lib/nms
Traceback (most recent call last):
File "build.py", line 33, in
extra_objects=extra_objects
File "/usr/local/lib/python2.7/dist-packages/torch/utils/cpp_extension.py", line 228, in init
super(BuildExtension, self).init(*args, **kwargs)
File "build/bdist.linux-x86_64/egg/setuptools/init.py", line 163, in init

File "/usr/lib/python2.7/distutils/cmd.py", line 59, in init
raise TypeError, "dist must be a Distribution instance"
TypeError: dist must be a Distribution instance
cd layer_utils/roi_pooling/src/cuda;
pwd;
echo "Compiling roi_pooling kernels by nvcc...";
nvcc -c -o roi_pooling_kernel.cu.o roi_pooling_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_52;
cd ../..;
python build.py;
cd ../../..
/home/isia/d1/000-REC/mask-faster-rcnn-lxy/lib/layer_utils/roi_pooling/src/cuda
Compiling roi_pooling kernels by nvcc...
Including CUDA code.
/home/isia/d1/000-REC/mask-faster-rcnn-lxy/lib/layer_utils/roi_pooling
Traceback (most recent call last):
File "build.py", line 33, in
extra_objects=extra_objects
File "/usr/local/lib/python2.7/dist-packages/torch/utils/cpp_extension.py", line 228, in init
super(BuildExtension, self).init(*args, **kwargs)
File "build/bdist.linux-x86_64/egg/setuptools/init.py", line 163, in init

File "/usr/lib/python2.7/distutils/cmd.py", line 59, in init
raise TypeError, "dist must be a Distribution instance"
TypeError: dist must be a Distribution instance

@Spark001
Copy link

torch.utils.cpp_extension is for C++ to create extension.
However, nms module is written in C code here.

So it doesn't work that you just replace create_extension to BuildExtension when import packages.

You need rewrite the nms.c to C++ code if you want use the cpp_extension and you can refer the whole procedure that rewrote C code with C++ extensions like pytorch/audio/commit/18c01be.

Or just use pytorch 0.4.x instead : )

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

2 participants