Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

setup.py 6.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  1. import os
  2. import platform
  3. import subprocess
  4. import time
  5. from setuptools import Extension, dist, find_packages, setup
  6. from torch.utils.cpp_extension import BuildExtension, CUDAExtension
  7. dist.Distribution().fetch_build_eggs(['Cython', 'numpy>=1.11.1'])
  8. import numpy as np # noqa: E402
  9. from Cython.Build import cythonize # noqa: E402
  10. def readme():
  11. with open('README.md', encoding='utf-8') as f:
  12. content = f.read()
  13. return content
  14. MAJOR = 1
  15. MINOR = 0
  16. PATCH = ''
  17. SUFFIX = 'rc0'
  18. SHORT_VERSION = '{}.{}.{}{}'.format(MAJOR, MINOR, PATCH, SUFFIX)
  19. version_file = 'mmdet/version.py'
  20. def get_git_hash():
  21. def _minimal_ext_cmd(cmd):
  22. # construct minimal environment
  23. env = {}
  24. for k in ['SYSTEMROOT', 'PATH', 'HOME']:
  25. v = os.environ.get(k)
  26. if v is not None:
  27. env[k] = v
  28. # LANGUAGE is used on win32
  29. env['LANGUAGE'] = 'C'
  30. env['LANG'] = 'C'
  31. env['LC_ALL'] = 'C'
  32. out = subprocess.Popen(
  33. cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
  34. return out
  35. try:
  36. out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
  37. sha = out.strip().decode('ascii')
  38. except OSError:
  39. sha = 'unknown'
  40. return sha
  41. def get_hash():
  42. if os.path.exists('.git'):
  43. sha = get_git_hash()[:7]
  44. elif os.path.exists(version_file):
  45. try:
  46. from mmdet.version import __version__
  47. sha = __version__.split('+')[-1]
  48. except ImportError:
  49. raise ImportError('Unable to get git version')
  50. else:
  51. sha = 'unknown'
  52. return sha
  53. def write_version_py():
  54. content = """# GENERATED VERSION FILE
  55. # TIME: {}
  56. __version__ = '{}'
  57. short_version = '{}'
  58. """
  59. sha = get_hash()
  60. VERSION = SHORT_VERSION + '+' + sha
  61. with open(version_file, 'w') as f:
  62. f.write(content.format(time.asctime(), VERSION, SHORT_VERSION))
  63. def get_version():
  64. with open(version_file, 'r') as f:
  65. exec(compile(f.read(), version_file, 'exec'))
  66. return locals()['__version__']
  67. def make_cuda_ext(name, module, sources):
  68. return CUDAExtension(
  69. name='{}.{}'.format(module, name),
  70. sources=[os.path.join(*module.split('.'), p) for p in sources],
  71. extra_compile_args={
  72. 'cxx': [],
  73. 'nvcc': [
  74. '-D__CUDA_NO_HALF_OPERATORS__',
  75. '-D__CUDA_NO_HALF_CONVERSIONS__',
  76. '-D__CUDA_NO_HALF2_OPERATORS__',
  77. ]
  78. })
  79. def make_cython_ext(name, module, sources):
  80. extra_compile_args = None
  81. if platform.system() != 'Windows':
  82. extra_compile_args = {
  83. 'cxx': ['-Wno-unused-function', '-Wno-write-strings']
  84. }
  85. extension = Extension(
  86. '{}.{}'.format(module, name),
  87. [os.path.join(*module.split('.'), p) for p in sources],
  88. include_dirs=[np.get_include()],
  89. language='c++',
  90. extra_compile_args=extra_compile_args)
  91. extension, = cythonize(extension)
  92. return extension
  93. def get_requirements(filename='requirements.txt'):
  94. here = os.path.dirname(os.path.realpath(__file__))
  95. with open(os.path.join(here, filename), 'r') as f:
  96. requires = [line.replace('\n', '') for line in f.readlines()]
  97. return requires
  98. if __name__ == '__main__':
  99. write_version_py()
  100. setup(
  101. name='mmdet',
  102. version=get_version(),
  103. description='Open MMLab Detection Toolbox and Benchmark',
  104. long_description=readme(),
  105. author='OpenMMLab',
  106. author_email='chenkaidev@gmail.com',
  107. keywords='computer vision, object detection',
  108. url='https://github.com/open-mmlab/mmdetection',
  109. packages=find_packages(exclude=('configs', 'tools', 'demo')),
  110. package_data={'mmdet.ops': ['*/*.so']},
  111. classifiers=[
  112. 'Development Status :: 4 - Beta',
  113. 'License :: OSI Approved :: Apache Software License',
  114. 'Operating System :: OS Independent',
  115. 'Programming Language :: Python :: 2',
  116. 'Programming Language :: Python :: 2.7',
  117. 'Programming Language :: Python :: 3',
  118. 'Programming Language :: Python :: 3.4',
  119. 'Programming Language :: Python :: 3.5',
  120. 'Programming Language :: Python :: 3.6',
  121. ],
  122. license='Apache License 2.0',
  123. setup_requires=['pytest-runner', 'cython', 'numpy'],
  124. tests_require=['pytest', 'xdoctest'],
  125. install_requires=get_requirements(),
  126. ext_modules=[
  127. make_cython_ext(
  128. name='soft_nms_cpu',
  129. module='mmdet.ops.nms',
  130. sources=['src/soft_nms_cpu.pyx']),
  131. make_cuda_ext(
  132. name='nms_cpu',
  133. module='mmdet.ops.nms',
  134. sources=['src/nms_cpu.cpp']),
  135. make_cuda_ext(
  136. name='nms_cuda',
  137. module='mmdet.ops.nms',
  138. sources=['src/nms_cuda.cpp', 'src/nms_kernel.cu']),
  139. make_cuda_ext(
  140. name='roi_align_cuda',
  141. module='mmdet.ops.roi_align',
  142. sources=['src/roi_align_cuda.cpp', 'src/roi_align_kernel.cu']),
  143. make_cuda_ext(
  144. name='roi_pool_cuda',
  145. module='mmdet.ops.roi_pool',
  146. sources=['src/roi_pool_cuda.cpp', 'src/roi_pool_kernel.cu']),
  147. make_cuda_ext(
  148. name='deform_conv_cuda',
  149. module='mmdet.ops.dcn',
  150. sources=[
  151. 'src/deform_conv_cuda.cpp',
  152. 'src/deform_conv_cuda_kernel.cu'
  153. ]),
  154. make_cuda_ext(
  155. name='deform_pool_cuda',
  156. module='mmdet.ops.dcn',
  157. sources=[
  158. 'src/deform_pool_cuda.cpp',
  159. 'src/deform_pool_cuda_kernel.cu'
  160. ]),
  161. make_cuda_ext(
  162. name='sigmoid_focal_loss_cuda',
  163. module='mmdet.ops.sigmoid_focal_loss',
  164. sources=[
  165. 'src/sigmoid_focal_loss.cpp',
  166. 'src/sigmoid_focal_loss_cuda.cu'
  167. ]),
  168. make_cuda_ext(
  169. name='masked_conv2d_cuda',
  170. module='mmdet.ops.masked_conv',
  171. sources=[
  172. 'src/masked_conv2d_cuda.cpp', 'src/masked_conv2d_kernel.cu'
  173. ]),
  174. ],
  175. cmdclass={'build_ext': BuildExtension},
  176. zip_safe=False)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...