Ubuntu16.04下深度学习目标检测工具箱mmdetection的安装和测试,以及训练自己的训练集

一、环境的安装

本人的系统环境:

  • Ubuntu16.04

  • CUDA9.0+Cudnn7.4.2

  • Python3.7.1(mmdetection要求Python版本需要3.4+)

  • Anaconda 3

  • Pycharm2018

1. 使用conda创建Python虚拟环境

conda create -n mmdetection python=3.7.1
source activate mmdetection

2. 安装Pytorch 1.0

conda install pytorch=1.0 -c pytorch

3. 安装Cython

conda install  cython

4. 安装mmcv

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

5. 安装mmdetection

git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
./compile.sh
python setup.py install

到此为止就安装好了我们需要的环境,接下来测试官方的demo

二、demo的测试

将下方的代码写入py文件,并存放到mmdetection文件夹目录下,mmdetection文件夹在 home/mmcv/mmdetection ,然后打开Pycharm,设置下环境,File–Settings–Project:user–Project Interpreter下添加你刚刚创建的虚拟环境。该代码的功能是检测图片中的目标,测试模型是官方给出的Faster-RCNN-fpn-resnet50的模型,运行代码会自动下载模型。如果速度太慢,用下面百度网盘下载mmdetection(lmlu)。

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')
# 如果通过网盘下载,取消下一行代码的注释,并且注释掉上一行
#_ = load_checkpoint(model, 'faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth')

# 测试一张图片
img = mmcv.imread('test.jpg')
result = inference_detector(model, img, cfg)
show_result(img, result)

# 测试多张图片
imgs = ['test1.jpg', 'test2.jpg']
for i, result in enumerate(inference_detector(model, imgs, cfg, device='cuda:0')):
    print(i, imgs[i])
    show_result(imgs[i], result)

测试的结果:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值