您的位置:首页 > 其它

pytorch环境下mmdection目标检测库安装所有步骤

2019-05-05 19:03 435 查看

商汤科技(2018 COCO 目标检测挑战赛冠军)和香港中文大学最近开源了一个基于Pytorch实现的深度学习目标检测工具箱mmdetection,支持Faster-RCNN,Mask-RCNN,Fast-RCNN等主流的目标检测框架,现在又加入Cascade-RCNN、SSD以及其他一系列目标检测框架。目前没有yolo的计划hhh。

相比于Facebook开源的Detectron框架,作者声称mmdetection有三点优势:performance稍高、训练速度稍快、所需显存稍小。

项目需要,这个项目开源的时间又比较短,相关教程比较少啦,就记录下自己踩的坑给别人铺路吧。

本人的系统环境:

Ubuntu 16.04
Cuda 9.0 + Cudnn 7.4.2
Python 3.5 (mmdetection要求Python版本需要3.4+)

Anaconda 3 (可选)
这里推荐大家使用Anaconda,可以比较方便的创建Python虚拟环境,避免不同的Python库之间产生冲突。

在安装mmdetection之前,需要安装以下几个依赖库:
PyTorch1.0.0 和 torchvision
Cython
mmcv

参考作者

作者:张正昊今天也要努力鸭
来源:CSDN
原文:https://blog.csdn.net/qq_36302589/article/details/85798060
版权声明:本文为博主原创文章,转载请附上博文链接!

本文离线下载pytorch 1.0.0 升级pip3下载 torchvision

其中的经历也很波折,下载pip3按理是

sudo apt install pip3

但是中间出现了问题,因此python2.7没有下载pip,在python3里用了如下方法
升级pip3

安装

Install mmdetection

  1. Install PyTorch 1.0 and torchvision following the official instructions.

检测pytorch,torchvision是否下载成功

import torch
import torchvision

2.安装cython

pip install  cython

3.安装mmcv

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

4. Clone the mmdetection repository.
本文同过github手动下载

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

c. Compile cuda extensions.

cd mmdetection
pip install cython  # or "conda install cython" if you prefer conda
./compile.sh  # or "PYTHON=python3 ./compile.sh" if you use system python3 without virtual environments
如果为python3,则在文档里改正python——python3

d. Install mmdetection (other dependencies will be installed automatically).

python(3) setup.py install  # add --user if you want to install it locally
# or "pip install ."

Note: You need to run the last step each time you pull updates from github.
The git commit id will be written to the version number and also saved in trained models.

到此,我们就完成了mmdetection及其依赖库的安装

7.测试demo

将下方的代码写入py文件,并存放到mmdetection文件夹目录下,然后运行。该代码的功能是检测图片中的目标,测试模型是官方给出的Faster-RCNN-fpn-resnet50的模型,运行代码会自动下载模型。由于模型是存储在亚马逊云服务器上,速度可能会稍慢。

import mmcv
from mmcv.runner import load_checkpoint
from mmdet.models import build_detector
from mmdet.apis import inference_detector, show_result

cfg = mmcv.Config.fromfile('configs/faster_rcnn_r50_fpn_1x.py')
cfg.model.pretrained = None

# 构建网络,载入模型
model = build_detector(cfg.model, test_cfg=cfg.test_cfg)

_ = load_checkpoint(model, 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/mmdetection/models/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth')

# 测试一张图片
img = mmcv.imread('test.jpg')
result = inference_detector(model, img, cfg)
show_result(img, result)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: