Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit 9efdd05

Browse files
committed
Fix compiling code.
issue 5.
1 parent b7686fa commit 9efdd05

File tree

3 files changed

+23
-113
lines changed

3 files changed

+23
-113
lines changed

lib/__init__.py

Whitespace-only changes.

lib/model/roi_crop/modules/gridgen.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@ def forward(self, input):
3131

3232
# return self.f(input), loss.view(-1,1)
3333

34-
class CylinderGridGen(Module):
35-
def __init__(self, height, width, lr = 1, aux_loss = False):
36-
super(CylinderGridGen, self).__init__()
37-
self.height, self.width = height, width
38-
self.aux_loss = aux_loss
39-
self.f = CylinderGridGenFunction(self.height, self.width, lr=lr)
40-
self.lr = lr
41-
def forward(self, input):
4234

43-
if not self.aux_loss:
44-
return self.f(input)
45-
else:
46-
return self.f(input), torch.mul(input, input).view(-1,1)
35+
# class CylinderGridGen(Module):
36+
# def __init__(self, height, width, lr = 1, aux_loss = False):
37+
# super(CylinderGridGen, self).__init__()
38+
# self.height, self.width = height, width
39+
# self.aux_loss = aux_loss
40+
# self.f = CylinderGridGenFunction(self.height, self.width, lr=lr)
41+
# self.lr = lr
42+
# def forward(self, input):
43+
44+
# if not self.aux_loss:
45+
# return self.f(input)
46+
# else:
47+
# return self.f(input), torch.mul(input, input).view(-1,1)
4748

4849

4950
class AffineGridGenV2(Module):

lib/setup.py

Lines changed: 10 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,19 @@
1-
from __future__ import print_function
21
# --------------------------------------------------------
32
# Fast R-CNN
43
# Copyright (c) 2015 Microsoft
54
# Licensed under The MIT License [see LICENSE for details]
65
# Written by Ross Girshick
76
# --------------------------------------------------------
87

9-
import os
10-
from os.path import join as pjoin
11-
import numpy as np
12-
from distutils.core import setup
13-
from distutils.extension import Extension
14-
from Cython.Distutils import build_ext
15-
16-
17-
def find_in_path(name, path):
18-
"Find a file in a search path"
19-
# adapted fom http://code.activestate.com/recipes/52224-find-a-file-given-a-search-path/
20-
for dir in path.split(os.pathsep):
21-
binpath = pjoin(dir, name)
22-
if os.path.exists(binpath):
23-
return os.path.abspath(binpath)
24-
return None
25-
8+
from __future__ import print_function
269

27-
# def locate_cuda():
28-
# """Locate the CUDA environment on the system
29-
#
30-
# Returns a dict with keys 'home', 'nvcc', 'include', and 'lib64'
31-
# and values giving the absolute path to each directory.
32-
#
33-
# Starts by looking for the CUDAHOME env variable. If not found, everything
34-
# is based on finding 'nvcc' in the PATH.
35-
# """
36-
#
37-
# # first check if the CUDAHOME env variable is in use
38-
# if 'CUDAHOME' in os.environ:
39-
# home = os.environ['CUDAHOME']
40-
# nvcc = pjoin(home, 'bin', 'nvcc')
41-
# else:
42-
# # otherwise, search the PATH for NVCC
43-
# default_path = pjoin(os.sep, 'usr', 'local', 'cuda', 'bin')
44-
# nvcc = find_in_path('nvcc', os.environ['PATH'] + os.pathsep + default_path)
45-
# if nvcc is None:
46-
# raise EnvironmentError('The nvcc binary could not be '
47-
# 'located in your $PATH. Either add it to your path, or set $CUDAHOME')
48-
# home = os.path.dirname(os.path.dirname(nvcc))
49-
#
50-
# cudaconfig = {'home': home, 'nvcc': nvcc,
51-
# 'include': pjoin(home, 'include'),
52-
# 'lib64': pjoin(home, 'lib64')}
53-
# for k, v in cudaconfig.iteritems():
54-
# if not os.path.exists(v):
55-
# raise EnvironmentError('The CUDA %s path could not be located in %s' % (k, v))
56-
#
57-
# return cudaconfig
10+
from Cython.Build import cythonize
11+
from Cython.Distutils import build_ext
12+
from setuptools import Extension
13+
from setuptools import setup
5814

15+
import numpy as np
5916

60-
# CUDA = locate_cuda()
6117

6218
# Obtain the numpy include directory. This logic works across numpy versions.
6319
try:
@@ -66,70 +22,23 @@ def find_in_path(name, path):
6622
numpy_include = np.get_numpy_include()
6723

6824

69-
def customize_compiler_for_nvcc(self):
70-
"""inject deep into distutils to customize how the dispatch
71-
to gcc/nvcc works.
72-
73-
If you subclass UnixCCompiler, it's not trivial to get your subclass
74-
injected in, and still have the right customizations (i.e.
75-
distutils.sysconfig.customize_compiler) run on it. So instead of going
76-
the OO route, I have this. Note, it's kindof like a wierd functional
77-
subclassing going on."""
78-
79-
# tell the compiler it can processes .cu
80-
self.src_extensions.append('.cu')
81-
82-
# save references to the default compiler_so and _comple methods
83-
default_compiler_so = self.compiler_so
84-
super = self._compile
85-
86-
# now redefine the _compile method. This gets executed for each
87-
# object but distutils doesn't have the ability to change compilers
88-
# based on source extension: we add it.
89-
def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
90-
print(extra_postargs)
91-
if os.path.splitext(src)[1] == '.cu':
92-
# use the cuda for .cu files
93-
self.set_executable('compiler_so', CUDA['nvcc'])
94-
# use only a subset of the extra_postargs, which are 1-1 translated
95-
# from the extra_compile_args in the Extension class
96-
postargs = extra_postargs['nvcc']
97-
else:
98-
postargs = extra_postargs['gcc']
99-
100-
super(obj, src, ext, cc_args, postargs, pp_opts)
101-
# reset the default compiler_so, which we might have changed for cuda
102-
self.compiler_so = default_compiler_so
103-
104-
# inject our redefined _compile method into the class
105-
self._compile = _compile
106-
107-
108-
# run the customize_compiler
109-
class custom_build_ext(build_ext):
110-
def build_extensions(self):
111-
customize_compiler_for_nvcc(self.compiler)
112-
build_ext.build_extensions(self)
113-
114-
11525
ext_modules = [
11626
Extension(
11727
name='utils.cython_bbox',
11828
sources=['utils/cython_bbox.pyx'],
119-
extra_compile_args={'gcc': ['-Wno-cpp']},
29+
extra_compile_args=['-Wno-cpp'],
12030
include_dirs=[numpy_include]
12131
),
12232
Extension(
12333
name='utils.cython_nms',
12434
sources=['utils/cython_nms.pyx'],
125-
extra_compile_args={'gcc': ['-Wno-cpp']},
35+
extra_compile_args=['-Wno-cpp'],
12636
include_dirs=[numpy_include]
12737
)
12838
]
12939

13040
setup(
13141
name='mask_rcnn',
132-
ext_modules=ext_modules,
133-
# inject our custom trigger
134-
cmdclass={'build_ext': custom_build_ext},
42+
ext_modules=cythonize(ext_modules)
13543
)
44+

0 commit comments

Comments
 (0)