Ubuntu安装mmcv和mmdetection

一.安装环境

安装环境:
Ubuntu16.04
cuda 10.2
pytorch 1.7.1

二.安装mmcv

不管是mmcv还是mmdetection都有官方文档的安装教程,下面是地址:
安装mmcv:https://github.com/open-mmlab/mmcv
安装mmdetection: https://github.com/open-mmlab/mmdetection

方法一:pip安装

1.安装lite版本:

pip install mmcv

2.安装full版本

(1)最简单的安装方法是直接运行指令:

pip install mmcv-full

(2)知道自己的cuda版本和pytorch版本之后可以使用如下指令来安装对应版本:

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html

其中{cu_version}是电脑的cuda版本,{torch_version}是pytorch版本,比如cuda11.0和pytorch1.7.0对应的安装指令如下:

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html

(3)如果要安装指定版本,可以使用如下指令:

pip install mmcv-full=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html

类似的安装1.2.2版本可以这样:

pip install mmcv-full==1.2.2 -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html

注意: mmcv和cuda的版本一定要对应,不然可能会出错。官方的GitHub仓库也给出了几个常用版本的cuda和pytorch版本的快速安装指令。

方法二:源码安装

源码安装的官方地址如下:
https://mmcv.readthedocs.io/en/latest/build.html
安装方法:

git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
MMCV_WITH_OPS=1 pip install -e .  # 安装full版本

这个方法可能会出现cuda版本不符的情况,我试了几次没有成功。

方法三:whl安装

下载地址:
https://download.openmmlab.com/mmcv/dist/index.html
从地址中找到对应的cuda、pytorch、Python和操作系统版本,下载下来之后使用如下指令安装:

pip install ***.whl

**是下载下来的whl文件的名字。

三.安装mmdetection

官方的安装教程:
https://github.com/open-mmlab/mmdetection
官方要求的基本配置为:

Linux or macOS (Windows is in experimental support)
Python 3.6+
PyTorch 1.3+
CUDA 9.2+ (If you build PyTorch from source, CUDA 9.0 is also compatible)
GCC 5+
MMCV

安装步骤:
1.下载源码:

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

2.安装依赖和mmdetection

pip install -r requirements/build.txt
pip install -v -e .  # or "python setup.py develop"

经过一段时间的等待之后mmdetection就安装完成了。

四.测试

首先需要下载想使用网络的模型,比如我想使用faster-rcnn,那么进入mmdetection/configs/faster_rcnn文件夹,里面有多个版本的faster-rcnn的配置文件,从里面选择一个,然后从README.md中下载对应的模型,将下载下来的pth文件放到checkpoints文件夹下。
可以在demo文件夹下新建demo.py,然后输入代码

from mmdet.apis import init_detector, inference_detector
import mmcv

# Specify the path to model config and checkpoint file
config_file = '../configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'  
checkpoint_file = '../checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'

# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# test a single image and show the results
img = 'demo.jpg'  # or img = mmcv.imread(img), which will only load it once
result = inference_detector(model, img)
# visualize the results in a new window
model.show_result(img, result)
# or save the visualization results to image files
model.show_result(img, result, out_file='result.jpg')


如果出现路径问题可以使用绝对路径。
结果:
在这里插入图片描述
安装成功。

  • 13
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值