关于ubuntu下mmdetection的安装步骤和心得

这个目标检测框架十分强大,提供了许多网络,关键环境配起来也十分的简单。下面就来说说mmdetection的环境是如何搭配,以及后面是如何测试他们的demo的。

1)前置环境

python版本3.7
这里我使用了anaconda建立了新环境。conda命令如下:
conda create -n mmdetection python=3.7
并激活环境:
source activate mmdetection

2)在环境中安装pytorch以及torchvision

pytorch1.1以上
conda install pytorch=1.3.1 torchvision

3)从github中把该环境给git clone下来:

在命令行中进入你经常放代码的目录
git clone https://github.com/open-mmlab/mmdetection.git
进入mmdetection文件夹
cd mmdetection

4)安装mmdetection提供的专属包mmcv

pip install mmcv

5)使用pip根据文件目录下的requirements.txt安装所需要的包

pip install -r requirements.txt

6)编译,大功告成

python setup.py develop 

7)编译完成后,在demo文件夹下已经提供了demo.py这个程序,不过该程序是调用摄像头的,各位可以稍微改一下这个程序。官方提供模型的百度云链接似乎有问题,下载不了,这里提供一个faster-rcnn的模型

模型下载地址:https://s3.ap-northeast-2.amazonaws.com/open-mmlab/mmdetection/models/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth
下载后在mmdetection文件夹中新建一个checkpoints文件夹,把下载后的模型放进去就可以了

8)改一下给的demo.py

import argparse
import cv2
import torch
from mmdet.apis import inference_detector, init_detector, show_result

def parse_args():
    parser = argparse.ArgumentParser(description='MMDetection webcam demo')
    parser.add_argument('--config', default='../configs/faster_rcnn_r50_fpn_1x.py', help='test config file path')
    parser.add_argument('--checkpoint', default='../checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth',
                        help='checkpoint file')
    parser.add_argument('--device', type=int, default=0, help='CUDA device id')
    parser.add_argument(
        '--camera-id', type=int, default=0, help='camera device id')
    parser.add_argument(
        '--score-thr', type=float, default=0.5, help='bbox score threshold')
    args = parser.parse_args()
    return args

args = parse_args()
model = init_detector(
        args.config, args.checkpoint, device=torch.device('cuda', args.device))
img = 'testing image you want to detect.jpg'
show_img = inference_detector(model, img)
show_result(img, show_img, model.CLASSES, score_thr=args.score_thr)

9)show一下结果

在这里插入图片描述
10)如果有所帮助请点个赞哈

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值