質問編集履歴
1
ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,3 +9,297 @@
|
|
9
9
|
setup.pyとcyvlfeat/init.pyそれぞれにどのようなコードをどこに追加すればいいか教えていただきたいです。
|
10
10
|
|
11
11
|
[https://qiita.com/knok/items/598052d17d0f1b26f77a](https://qiita.com/knok/items/598052d17d0f1b26f77a)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
### 該当のソースコード
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```python
|
20
|
+
|
21
|
+
import os
|
22
|
+
|
23
|
+
import platform
|
24
|
+
|
25
|
+
import site
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
from setuptools import setup, find_packages, Extension
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
SYS_PLATFORM = platform.system().lower()
|
36
|
+
|
37
|
+
IS_LINUX = 'linux' in SYS_PLATFORM
|
38
|
+
|
39
|
+
IS_OSX = 'darwin' == SYS_PLATFORM
|
40
|
+
|
41
|
+
IS_WIN = 'windows' == SYS_PLATFORM
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
# Get Numpy include path without importing it
|
48
|
+
|
49
|
+
NUMPY_INC_PATHS = [os.path.join(r, 'numpy', 'core', 'include')
|
50
|
+
|
51
|
+
for r in site.getsitepackages() if
|
52
|
+
|
53
|
+
os.path.isdir(os.path.join(r, 'numpy', 'core', 'include'))]
|
54
|
+
|
55
|
+
if len(NUMPY_INC_PATHS) == 0:
|
56
|
+
|
57
|
+
try:
|
58
|
+
|
59
|
+
import numpy as np
|
60
|
+
|
61
|
+
except ImportError:
|
62
|
+
|
63
|
+
raise ValueError("Could not find numpy include dir and numpy not installed before build - "
|
64
|
+
|
65
|
+
"cannot proceed with compilation of cython modules.")
|
66
|
+
|
67
|
+
else:
|
68
|
+
|
69
|
+
# just ask numpy for it's include dir
|
70
|
+
|
71
|
+
NUMPY_INC_PATHS = [np.get_include()]
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
elif len(NUMPY_INC_PATHS) > 1:
|
76
|
+
|
77
|
+
print("Found {} numpy include dirs: "
|
78
|
+
|
79
|
+
"{}".format(len(NUMPY_INC_PATHS), ', '.join(NUMPY_INC_PATHS)))
|
80
|
+
|
81
|
+
print("Taking first (highest precedence on path): {}".format(
|
82
|
+
|
83
|
+
NUMPY_INC_PATHS[0]))
|
84
|
+
|
85
|
+
NUMPY_INC_PATH = NUMPY_INC_PATHS[0]
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
# ---- C/C++ EXTENSIONS ---- #
|
92
|
+
|
93
|
+
# Stolen (and modified) from the Cython documentation:
|
94
|
+
|
95
|
+
# http://cython.readthedocs.io/en/latest/src/reference/compilation.html
|
96
|
+
|
97
|
+
def no_cythonize(extensions, **_ignore):
|
98
|
+
|
99
|
+
import os.path as op
|
100
|
+
|
101
|
+
for extension in extensions:
|
102
|
+
|
103
|
+
sources = []
|
104
|
+
|
105
|
+
for sfile in extension.sources:
|
106
|
+
|
107
|
+
path, ext = os.path.splitext(sfile)
|
108
|
+
|
109
|
+
if ext in ('.pyx', '.py'):
|
110
|
+
|
111
|
+
if extension.language == 'c++':
|
112
|
+
|
113
|
+
ext = '.cpp'
|
114
|
+
|
115
|
+
else:
|
116
|
+
|
117
|
+
ext = '.c'
|
118
|
+
|
119
|
+
sfile = path + ext
|
120
|
+
|
121
|
+
if not op.exists(sfile):
|
122
|
+
|
123
|
+
raise ValueError('Cannot find pre-compiled source file '
|
124
|
+
|
125
|
+
'({}) - please install Cython'.format(sfile))
|
126
|
+
|
127
|
+
sources.append(sfile)
|
128
|
+
|
129
|
+
extension.sources[:] = sources
|
130
|
+
|
131
|
+
return extensions
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
def build_extension_from_pyx(pyx_path, extra_sources_paths=None):
|
138
|
+
|
139
|
+
# If we are building from the conda folder,
|
140
|
+
|
141
|
+
# then we know we can manually copy some files around
|
142
|
+
|
143
|
+
# because we have control of the setup. If you are
|
144
|
+
|
145
|
+
# building this manually or pip installing, you must satisfy
|
146
|
+
|
147
|
+
# that the vlfeat vl folder is on the PATH (for the headers)
|
148
|
+
|
149
|
+
# and that the vl.dll file is visible to the build system
|
150
|
+
|
151
|
+
# as well.
|
152
|
+
|
153
|
+
include_dirs = [NUMPY_INC_PATH]
|
154
|
+
|
155
|
+
library_dirs = []
|
156
|
+
|
157
|
+
if IS_WIN:
|
158
|
+
|
159
|
+
include_dirs.append(os.environ['LIBRARY_INC'])
|
160
|
+
|
161
|
+
library_dirs.append(os.environ['LIBRARY_BIN'])
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
if extra_sources_paths is None:
|
166
|
+
|
167
|
+
extra_sources_paths = []
|
168
|
+
|
169
|
+
extra_sources_paths.insert(0, pyx_path)
|
170
|
+
|
171
|
+
ext = Extension(name=pyx_path[:-4].replace('/', '.'),
|
172
|
+
|
173
|
+
sources=extra_sources_paths,
|
174
|
+
|
175
|
+
include_dirs=include_dirs,
|
176
|
+
|
177
|
+
library_dirs=library_dirs,
|
178
|
+
|
179
|
+
libraries=['vl'],
|
180
|
+
|
181
|
+
language='c')
|
182
|
+
|
183
|
+
if IS_LINUX or IS_OSX:
|
184
|
+
|
185
|
+
ext.extra_compile_args.append('-Wno-unused-function')
|
186
|
+
|
187
|
+
if IS_OSX:
|
188
|
+
|
189
|
+
ext.extra_link_args.append('-headerpad_max_install_names')
|
190
|
+
|
191
|
+
return ext
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
try:
|
198
|
+
|
199
|
+
from Cython.Build import cythonize
|
200
|
+
|
201
|
+
except ImportError:
|
202
|
+
|
203
|
+
import warnings
|
204
|
+
|
205
|
+
cythonize = no_cythonize
|
206
|
+
|
207
|
+
warnings.warn('Unable to import Cython - attempting to build using the '
|
208
|
+
|
209
|
+
'pre-compiled C++ files.')
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
cython_modules = [
|
216
|
+
|
217
|
+
build_extension_from_pyx('cyvlfeat/fisher/cyfisher.pyx'),
|
218
|
+
|
219
|
+
build_extension_from_pyx('cyvlfeat/generic/generic.pyx'),
|
220
|
+
|
221
|
+
build_extension_from_pyx('cyvlfeat/gmm/cygmm.pyx'),
|
222
|
+
|
223
|
+
build_extension_from_pyx('cyvlfeat/hog/cyhog.pyx'),
|
224
|
+
|
225
|
+
build_extension_from_pyx('cyvlfeat/kmeans/cykmeans.pyx'),
|
226
|
+
|
227
|
+
build_extension_from_pyx('cyvlfeat/quickshift/cyquickshift.pyx'),
|
228
|
+
|
229
|
+
build_extension_from_pyx('cyvlfeat/sift/cysift.pyx'),
|
230
|
+
|
231
|
+
build_extension_from_pyx('cyvlfeat/vlad/cyvlad.pyx'),
|
232
|
+
|
233
|
+
]
|
234
|
+
|
235
|
+
cython_exts = cythonize(cython_modules, quiet=True)
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
def get_version_and_cmdclass(package_name):
|
242
|
+
|
243
|
+
import os
|
244
|
+
|
245
|
+
from importlib.util import module_from_spec, spec_from_file_location
|
246
|
+
|
247
|
+
spec = spec_from_file_location('version',
|
248
|
+
|
249
|
+
os.path.join(package_name, '_version.py'))
|
250
|
+
|
251
|
+
module = module_from_spec(spec)
|
252
|
+
|
253
|
+
spec.loader.exec_module(module)
|
254
|
+
|
255
|
+
return module.__version__, module.cmdclass
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
version, cmdclass = get_version_and_cmdclass('cyvlfeat')
|
262
|
+
|
263
|
+
setup(
|
264
|
+
|
265
|
+
name='cyvlfeat',
|
266
|
+
|
267
|
+
version=version,
|
268
|
+
|
269
|
+
cmdclass=cmdclass,
|
270
|
+
|
271
|
+
description='Cython wrapper of the VLFeat toolkit',
|
272
|
+
|
273
|
+
url='https://github.com/menpo/cyvlfeat',
|
274
|
+
|
275
|
+
author='Patrick Snape',
|
276
|
+
|
277
|
+
author_email='patricksnape@gmail.com',
|
278
|
+
|
279
|
+
ext_modules=cython_exts,
|
280
|
+
|
281
|
+
package_data={'cyvlfeat': ['data/*.mat', 'data/ascent.descr', 'data/ascent.frame']},
|
282
|
+
|
283
|
+
packages=find_packages()
|
284
|
+
|
285
|
+
)
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
```
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
### 試したこと
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
ここに問題に対して試したことを記載してください。
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
### 補足情報(FW/ツールのバージョンなど)
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
ここにより詳細な情報を記載してください。
|