具体参考来自于https://github.com/MrGF/py-faster-rcnn-windows

由于编译gpu版本比较麻烦,所以需要将gpu部分注释掉,只编译cpu即可(GPU版本可以根据本文章顶部链接自行修改)

进入到M2Det/utils目录下,将该目录下的build.py修改为如下形式:

# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------import os
from os.path import join as pjoin
import numpy as np
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext#change for windows, by MrX
nvcc_bin = 'nvcc.exe'
lib_dir = 'lib/x64'def find_in_path(name, path):"Find a file in a search path"# adapted fom http://code.activestate.com/recipes/52224-find-a-file-given-a-search-path/for dir in path.split(os.pathsep):binpath = pjoin(dir, name)if os.path.exists(binpath):return os.path.abspath(binpath)return Nonedef locate_cuda():"""Locate the CUDA environment on the systemReturns a dict with keys 'home', 'nvcc', 'include', and 'lib64'and values giving the absolute path to each directory.Starts by looking for the CUDAHOME env variable. If not found, everythingis based on finding 'nvcc' in the PATH."""# first check if the CUDAHOME env variable is in use# if 'CUDAHOME' in os.environ:if True:# home = os.environ['CUDA_PATH']home = r"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0"print("home = %s\n" % home)nvcc = pjoin(home, 'bin', nvcc_bin)else:# otherwise, search the PATH for NVCCdefault_path = pjoin(os.sep, 'usr', 'local', 'cuda', 'bin')nvcc = find_in_path(nvcc_bin, os.environ['PATH'] + os.pathsep + default_path)if nvcc is None:raise EnvironmentError('The nvcc binary could not be ''located in your $PATH. Either add it to your path, or set $CUDA_PATH')home = os.path.dirname(os.path.dirname(nvcc))print("home = %s, nvcc = %s\n" % (home, nvcc))cudaconfig = {'home':home, 'nvcc':nvcc,'include': pjoin(home, 'include'),'lib64': pjoin(home, lib_dir)}for k, v in cudaconfig.items():if not os.path.exists(v):raise EnvironmentError('The CUDA %s path could not be located in %s' % (k, v))return cudaconfigCUDA = locate_cuda()# Obtain the numpy include directory.  This logic works across numpy versions.
try:numpy_include = np.get_include()
except AttributeError:numpy_include = np.get_numpy_include()def customize_compiler_for_nvcc(self):"""inject deep into distutils to customize how the dispatchto gcc/nvcc works.If you subclass UnixCCompiler, it's not trivial to get your subclassinjected in, and still have the right customizations (i.e.distutils.sysconfig.customize_compiler) run on it. So instead of goingthe OO route, I have this. Note, it's kindof like a wierd functionalsubclassing going on."""# tell the compiler it can processes .cu# self.src_extensions.append('.cu')# save references to the default compiler_so and _comple methods# default_compiler_so = self.spawn# default_compiler_so = self.rcsuper = self.compile# now redefine the _compile method. This gets executed for each# object but distutils doesn't have the ability to change compilers# based on source extension: we add it.def compile(sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None,extra_postargs=None, depends=None):postfix = os.path.splitext(sources[0])[1]if postfix == '.cu':# use the cuda for .cu files# self.set_executable('compiler_so', CUDA['nvcc'])# use only a subset of the extra_postargs, which are 1-1 translated# from the extra_compile_args in the Extension classpostargs = extra_postargs['nvcc']else:postargs = extra_postargs['gcc']return super(sources, output_dir, macros, include_dirs, debug, extra_preargs, postargs, depends)# reset the default compiler_so, which we might have changed for cuda# self.rc = default_compiler_so# inject our redefined _compile method into the classself.compile = compile# run the customize_compiler
class custom_build_ext(build_ext):def build_extensions(self):customize_compiler_for_nvcc(self.compiler)build_ext.build_extensions(self)ext_modules = [Extension("nms.cpu_nms",["nms\\cpu_nms.pyx"],# extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]},# include_dirs=[numpy_include]extra_compile_args={'gcc': []},include_dirs=[numpy_include]),# Extension('nms.gpu_nms',#           ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],#           library_dirs=[CUDA['lib64']],#           libraries=['cudart'],#           language='c++',#           runtime_library_dirs=[CUDA['lib64']],#           # this syntax is specific to this build system#           # we're only going to use certain compiler args with nvcc and not with gcc#           # the implementation of this trick is in customize_compiler() below#           extra_compile_args={'gcc': ["-Wno-unused-function"],#                               'nvcc': ['-arch=sm_52',#                                        '--ptxas-options=-v',#                                        '-c',#                                        '--compiler-options',#                                        "'-fPIC'"]},#           include_dirs=[numpy_include, CUDA['include']]#           ),Extension('pycocotools._mask',# sources=['pycocotools/maskApi.c', 'pycocotools/_mask.pyx'],# include_dirs=[numpy_include, 'pycocotools'],# extra_compile_args={#     'gcc': ['-Wno-cpp', '-Wno-unused-function', '-std=c99']},sources=['pycocotools\\maskApi.c', 'pycocotools\\_mask.pyx'],include_dirs = [numpy_include, 'pycocotools'],extra_compile_args={'gcc': ['/Qstd=c99']},),
]setup(name='mot_utils',ext_modules=ext_modules,# inject our custom triggercmdclass={'build_ext': custom_build_ext},
)

在cmd终端下,进入到M2Det/utils文件夹下,然后使用命令

python build.py build

即可生成build文件夹。然后将build文件夹下pyd文件复制到对应文件下,然后重命名。

修改M2Det/utils/nms_wrapper.py文件中,将使用GPU的注释掉,具体如下所示

# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------from .nms.cpu_nms import cpu_nms, cpu_soft_nms
# from .nms.gpu_nms import gpu_nms# def nms(dets, thresh, force_cpu=False):
#     """Dispatch to either CPU or GPU NMS implementations."""
#
#     if dets.shape[0] == 0:
#         return []
#     if cfg.USE_GPU_NMS and not force_cpu:
#         return gpu_nms(dets, thresh, device_id=cfg.GPU_ID)
#     else:
#         return cpu_nms(dets, thresh)def nms(dets, thresh, force_cpu=False):"""Dispatch to either CPU or GPU NMS implementations."""if dets.shape[0] == 0:return []if force_cpu:return cpu_soft_nms(dets, thresh, method = 1)#return cpu_nms(dets, thresh)# return gpu_nms(dets, thresh)return cpu_nms(dets, thresh, method=1)

常见问题

1、setup2.py 需要添加numpy库。见无法打开包括文件: “numpy/arrayobject.h”: No such file or directory

from distutils.core import setup
from Cython.Build import cythonize
import numpy as npsetup(name = 'nms_module',ext_modules = cythonize('nums_py2.pyx'),include_dirs=[np.get_include()])

2、nums_py2.pyx, line 29将 np.int_t(整型)改为 np.intp_t(长整型)。见问题7;关于 np.int_t 的更多介绍,见MSeifert的回答。

3、我发现了好几个版本的代码,但是只有M2Det/utils的nms和pycocotools可以进行编译,所以推荐将你需要调试的代码的nms和pycocotools文件夹中的文件都替换为M2Det/utils中的nms和pycocotools中的文件。

【M2Det】编译Cython版本NMS相关推荐

  1. 【ijkplayer】编译 Android 版本的 ijkplayer ② ( 切换到 k0.8.8 分支 | 执行 init-android.sh 脚本进行初始化操作 )

    文章目录 一.进入 ijkplayer-android 目录 二.切换到 k0.8.8 分支 三.执行 init-android.sh 脚本进行初始化操作 参考 https://github.com/ ...

  2. 【错误记录】编译 Android 版本的 ijkplayer 报错 ( ./init-android.sh: 第 37 行: cd: android/contrib/: 没有那个文件或目录 )

    文章目录 一.报错信息 二.解决方案 一.报错信息 编译 Android 版本的 ijkplayer 时 , 执行 init-android.sh 脚本 , 报如下错误 ; root@octopus: ...

  3. android 模块不编译错误,Android 编译出错版本匹配问题解决办法

    Android 编译出错版本匹配问题解决办法 解决问题的关键在于版本匹配, compileSdkVersion compileSdkVersion targetSdkVersion 这三个参数的整数值 ...

  4. AndroidStuido编译release版本apk(非签名apk)

    AndroidStuido编译release版本apk(非签名apk) Project Structure--->Modules--->Build Types下debug改为release ...

  5. 编译Android版本TensorFlow

    在Ubuntu 18.04 LTS 下编译Tensorflow的Android库的步骤: 安装Android Studio/Android sdk 安装Android NDK(Android NDK可 ...

  6. 重新编译CDH版本hadoop报错:Non-resolvable parent POM: Could not transfer artifact com.

    重新编译CDH版本hadoop报错: Could not transfer artifact com.cloudera.cdh:cdh-root:pom:5.14.0 from/to cdh.repo ...

  7. HDF5 windows编译 release版本、Debug版本

    由于最近急需的一个项目,需要hdf5库,误打误撞,编译成功.特此记录 1.下载源代码 官网下载地址:https://portal.hdfgroup.org/display/support/HDF5+1 ...

  8. android只编译release版本

    通常,无论是app还是lib,直接编译,编译出来的是Debug版本. 如何直接编译release版本.参考如下: 在android studio界面的最左下脚,有两个icon:"Build ...

  9. 安卓编译Release版本

    背景: 一般在Android Studio里编译出来的是Debug,那如何编译Release版本呢? 解决方案: 访问菜单"Build">"Select Build ...

最新文章

  1. 可解释机器学习发展和常见方法!
  2. 字节跳动开源最新GAN压缩算法,算力消耗可减少至1/46
  3. 【BZOJ5461】 【PKUWC2018】—Minimax(线段树合并优化dp)
  4. mysql 定时任务实例_mysql定时任务与存储过程实例
  5. C#开发笔记之13-如何用C#分隔字符串并返回字符串数组?
  6. 【转】C/C++的64位整型 不同编译器间的比较
  7. 实验2.3 使用重载函数模板重新实现上小题中的函数Max1
  8. bzoj 3388: [Usaco2004 Dec]Cow Ski Area雪场缆车(Tarjan)
  9. GetHashCode 方法 并不能保证值唯一
  10. Atitit 代理CGLIB 动态代理 AspectJ静态代理区别
  11. 三星或将80%手机生产转至越南
  12. MessageBox的用法
  13. 计算机硬盘被配置成动态磁盘,动态硬盘
  14. 中国机读目录格式(CNMARC)
  15. 2019年度十大网络小说:玄幻小说独占六部,都市小说一本超神
  16. 微信公众平台开发-PHP版
  17. 我为什么选择使用Go语言?
  18. JavaScript高效学习方法,看完透彻了...最适合web前端初学者的学习方法
  19. arcos的matlab定义,基于MATLAB编程软的齿轮设计
  20. 退休后多长时间能领到工资

热门文章

  1. Dev-C++当遇到 [error] stray ‘\241‘ in program ... 时发生错误的解决方法
  2. js将秒转换成几天几小时几分几秒,每秒刷新
  3. 波士顿动力真的无可企及吗?一步步剖析四足机器人技术(一)
  4. 第三方物流概念问题探讨
  5. 安卓8.0彻底改变 或告别卡慢耗电现象
  6. 云豹直播2022带货语音聊天室三端app源码
  7. Linux 操作系统原理 — 进程管理 — Namespace 系统资源隔离
  8. Veritas Backup Exec™ 22.1 (Windows) 下载 - 面向中小型企业的数据备份和恢复
  9. CloudSim云仿真的使用及论文阅读
  10. Eclipse安装与汉化