在win10下安装mmdetection

网上有不少安装mmdetection的教程,我发现都不是很完整,我按照这些教程踩了许多坑,在这我将我成功安装mmdetection的完整过程(包括踩过的坑)记录下来,严格按照这个方法,应该是可以成功安装的。

环境版本要求

本次安装的版本号:

python=3.6

cuda=10.0

cudnn=7.5.0

pytorch=1.2.0

torchversion=0.4.0

有人已经安装好Pytorch了,但最好别跟以前Pytorch放一个环境,我试过一次,安装过程会疯狂报错,原因未知。

安装vs2017

必须勾选c++环境,给mmdetection编译提供环境
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yZ6qyUQl-1608474859662)(./images/1608446285396.png)]

安装cuda10

安装时有关vs的相关选项需要选中
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6pLms5Cn-1608474859664)(./images/1608446322048.png)]

安装cudnn7.5.0

将压缩包中所有的文件夹直接复制粘贴到cuda安装目录下即可

安装anaconda

官网下载最新版本默认安装即可,需要提升anaconda文件夹权限为完全控制

安装pycharm

安装gitbash

从github上下载项目以及安装pycocotools都需要用到

下载地址:https://gitforwindows.org/

python环境搭建

以管理员身份运行Anaconda Prompt(windows安装一定要以管理员身份安装,不然有些东西会装不上去,没有权限)

  • 创建python3.6环境:conda create -n mmdetection python=3.6
  • 激活环境:conda activate mmdetection
  • 安装pytorch,window环境下稳定1.2.0版本:conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

注意!!!
这一步我下载了好几次都没有成功,原因是国外的源不好用。这里换成清华源镜像。


conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

conda config --set show_channel_urls yes

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

如果用的是清华源,记得删掉后面的-c pytorch,因为它表示从官网进行下载,不从清华镜像源下。

安装mmcv:

在cmd中依次输入:

git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
pip install -e .

再次注意!

平常在git无论是下载还是浏览页面都很慢,这里可以通过添加映射加快速度
打开路径:"C:\Windows\System32\drivers\etc\hosts"使用记事本打开,打开之后我们便可以追加ip信息
在最后输入:
192.30.253.112 github.com199.232.5.194 github.global.ssl.fastly.net
>[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XIXPCK04-1608474859665)(./images/1608447469135.png)]

安装mmdetection

在cmd中依次输入:

git clone https://github.com/open-mmlab/mmdetection.git

cd mmdetection

补充安装依赖包requirements:

pip install -r requirements.txt

我在安装的时候有红字的报错,最后出现黄字的提示,黄字内容如下:

DEPRECATION: mmpycocotools was installed using the legacy ‘setup.py install’ method, because a wheel could not be built for it. pip 21.0 will remove support for this functionality. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at https://github.com/pypa/pip/issues/8368.

但重新再执行一遍pip install -r requirements.txt后没有报错。

修改编译文件

因为在WIN10系统下安装,需要修改编译文件

D:\Anaconda3\envs\mmdetection\Lib\site-packages\torch\utils\cpp_extension.py所有decode()都改成decode("utf8","ignore")

修改C:\Windows\System32\mmcv\mmdetection\setup.py文件中extra_compile_args 相关代码:增加cxx的:"-DMS_WIN64","-MD"

def make_cuda_ext(name, module, sources, sources_cuda=[]):
define_macros = []
extra_compile_args = {'cxx': ["-DMS_WIN64","-MD"]} #####在这行#####

if torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1':
    define_macros += [('WITH_CUDA', None)]
    extension = CUDAExtension
    extra_compile_args['nvcc'] = [
        '-D__CUDA_NO_HALF_OPERATORS__',
        '-D__CUDA_NO_HALF_CONVERSIONS__',
        '-D__CUDA_NO_HALF2_OPERATORS__',
    ]
    sources += sources_cuda
else:
    print(f'Compiling {name} without CUDA')
    extension = CppExtension

return extension(
    name=f'{module}.{name}',
    sources=[os.path.join(*module.split('.'), p) for p in sources],
    define_macros=define_macros,
    extra_compile_args=extra_compile_args)

注意,下面的两行代码必须当前这个cmd下运行,不然会踩坑

python setup.py build_ext --inplace 进行编译
python setup.py install develop 完成安装

运行pip list 查看是否安装成功,成功的话会有mmdet包以及对应版本
在这里插入图片描述

最后一步

将~\Lib\site-packages\mmcv\utils中的config.py文件中的111行的
with open(filename, 'r',) as f:改成with open(filename, 'r', encoding='utf-8') as f:(网上说是在123行,但我自己的不是。自行判断吧。另外,我的config.py文件不是上面的地址,而是在C:\Windows\System32\mmcv\mmcv\utils,这个也自行判断吧)

至此,在windows10中就可以正常运行mmdetecion框架代码了。

参考文章:
https://blog.csdn.net/david_lee13/article/details/102940221
https://www.cnblogs.com/aimhabo/p/14119411.html
https://www.yht7.com/news/16747

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值