【Object Detection】【maskrcnn_benckmark】Windows10 下安装与设置

本文记录 Windows10 下安装 maskrcnn_benchmark 的过程.
安装环境:
Windows10
CUDA 9.0
python3.6

1. 简介

maskrcnn_benckmarkFacebook Research 下的一个项目。这个项目包含了多种通用目标检测(General Object Detection)算法的 PyTorch 实现。项目工程高度模块化,关键模块使用 cpp/cuda 实现,并将核心功能封装为 Python Package。

maskrcnn-benchmark已经冻结(maskrcnn-benchmark has been deprecated),即它将不再更新。

2. 安装

INSTALL

安装要求:

  • PyTorch 1.0 nightly or newer
  • torchvision
  • cocoapi
  • yacs
  • matplotlib
  • GCC >= 4.9
  • OpenCV

旧版本项目仅支持 pytorch 1.0 nightly.
现在版本可支持到 pytorch 1.3.
使用低于1.3版本的pytorch,运行需要修改源码。

2.1 准备并下载依赖项

创建虚拟环境:

>mkvirtualenv --no-site-packages -p "{path_to_python3.6_home}/python.exe" maskrcnn_benchmark

创建安装目录:

(maskrcnn-benchmark)>set ROOT_DIR=<path_to_the_parent_directory_OF_maskrcnn-benchmark>
(maskrcnn-benchmark)>md %ROOT_DIR%  # {ROOT_DIR} means the parent directory of maskrcnn-benchmark
(maskrcnn-benchmark)>cd %ROOT_DIR%

下载 maskrcnn_benckmark 和 cocoapi 依赖:

(maskrcnn-benchmark)>pip install ipython ninja yacs cython matplotlib tqdm opencv-python

2.2 安装 PyTorch

推荐使用 PyTorch 1.1.0
安装 pytorch 1.1.0 和 torchvision 0.3.0:

(maskrcnn-benchmark)>pip install torch==1.1.0 -f https://download.pytorch.org/whl/cu90/torch_stable.html
(maskrcnn-benchmark)>pip install torchvision==0.3.0

如果使用 PyTorch-nightly
安装 pytorch-nightly 和 torchvision-nightly:

(maskrcnn-benchmark)>pip install torch_nightly==1.0.0.dev20190409 -f https://download.pytorch.org/whl/nightly/cu90/torch_nightly.html
(maskrcnn-benchmark)>pip install torchvision-nightly==0.2.3

2.3 安装 pycocotools

cocoapi
安装 pycocotools:

(maskrcnn-benchmark)>cd %ROOT_DIR%
(maskrcnn-benchmark)>git clone https://github.com/cocodataset/cocoapi.git
(maskrcnn-benchmark)>cd cocoapi/PythonAPI

打开 setup.py,将第 14 行

extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],

修改为:

extra_compile_args={'gcc': ['/Qstd=c99']},

保存后开始安装

(maskrcnn-benchmark)>python setup.py build_ext install

2.4 安装 VS2017

后续安装过程需要先安装 VS2017. 并按照下图所示安装 VC++ 2017 版本 15.4 v14.11 工具集(VC++ 2017 version 15.4 v14.11 toolset).
在这里插入图片描述
在 cmd 中设置使用 VC++ 2017 version 15.4 v14.11 toolset

(maskrcnn_benchmark) > "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=14.11
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.20
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

检查是否设置成功:

(maskrcnn_benchmark) > cl -Bv
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.11.25548.2 版
版权所有(C) Microsoft Corporation。保留所有权利。

编译器扫描遍数:
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\cl.exe:
 版本 19.11.25548.2
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\c1.dll:
 版本 19.11.25548.2
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\c1xx.dll:
 版本 19.11.25548.2
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\c2.dll:
 版本 19.11.25548.2
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\link.exe:
 版本 14.11.25548.2
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\mspdb140.dll:  版本 14.11.25548.2
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\2052\clui.dll: 版本 19.11.25548.2

cl: 命令行 error D8003 :缺少源文件名

如果不进行上述设置,将会遇到下列报错.

D:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\V9.0\bin\nvcc.exe -c >csrc/multi_tensor_sgd_kernel.cu -o build\temp.win-amd64-3.6\Release\csrc/multi_tensor_sgd_kernel.obj ->Xcompiler /wd4819 -Xcompiler /MD -IF:\01_pyenvs\maskrcnn_benchmark\lib\site-packages\torch\inc
lude -IF:\01_pyenvs\maskrcnn_benchmark\lib\site-packages\torch\include\torch\csrc\api\include ->IF:\01_pyenvs\maskrcnn_benchmark\lib\site-packages\torch\include\TH ->IF:\01_pyenvs\maskrcnn_benchmark\lib\site-packages\torch\include\THC "-ID:\Program Files\NVIDIA GPU >Comp
uting Toolkit\CUDA\V9.0\include" "-Id:\program files\python36\include" "-Id:\program files\python36\include" >"-IC:\Program Files (x86)\Microsoft Visual >Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft >Visual Studio\2
017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows >Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" >"-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Progr
am Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows >Kits\10\include\10.0.17763.0\cppwinrt" -lineinfo -O3 --use_fast_math -DVERSION_GE_1_1 ->DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=amp_C ->D_GLIBCXX_USE_CXX11_ABI=0
multi_tensor_sgd_kernel.cu
d:\program files\nvidia gpu computing toolkit\cuda\v9.0\include\crt/host_config.h(133): fatal error C1189: >#error:  -- unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are >supported!
error: command 'D:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\V9.0\\bin\\nvcc.exe' failed with >exit status 2

在经过设置的 cmd 窗口中继续后面的安装过程. 关闭 cmd 窗口,设置将失效.
以上参考 issue1042msvc-toolsets-in-visual-studio-2017.

2.5 安装 apex

安装 apex:

(maskrcnn-benchmark)>cd %ROOT_DIR%
(maskrcnn-benchmark)>git clone https://github.com/NVIDIA/apex.git
(maskrcnn-benchmark)>cd apex
(maskrcnn-benchmark)>python setup.py install --cuda_ext --cpp_ext

2.6 安装 cityscapesScripts

(maskrcnn-benchmark)>cd %ROOT_DIR%
(maskrcnn-benchmark)>git clone https://github.com/mcordts/cityscapesScripts.git
(maskrcnn-benchmark)>cd cityscapesScripts/

打开 setup.py,将第 26 行

with open("README.md") as f:

修改为:

with open("README.md", encoding='UTF-8') as f:

保存后开始安装

(maskrcnn-benchmark)>python setup.py build_ext install

2.7 安装 maskrcnn_benckmark

安装 maskrcnn_benckmark:

(maskrcnn-benchmark)>cd %ROOT_DIR%
(maskrcnn-benchmark)>git clone https://github.com/facebookresearch/maskrcnn-benchmark.git
(maskrcnn-benchmark)>cd maskrcnn-benchmark
# the following will install the lib with
# symbolic links, so that you can modify
# the files if you want and won't need to
# re-build it
(maskrcnn-benchmark)>python setup.py build develop

测试:

(maskrcnn-benchmark)>python -c "import maskrcnn_benchmark"
(maskrcnn-benchmark)>

成功安装

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值