【mmdetection】测试单张图像

64 篇文章 9 订阅

本人刚入门目标检测,发现了一个开源的工具箱mmdetection,便自己使用里面的模型试着测试一张图片,网上大多数博客写的还是不够详细,所以想自己写一篇,方便大家及自己今后可以回顾。

首先,mmdetection的安装就不用多说了,网上有很多。

1、克隆mmdetection到自己的文件夹中(安装mmdetection时已经克隆就不需要在克隆了),

在终端服务器中输入

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

cd mmdetection

2、下载已经训练好的训练模型。

https://github.com/open-mmlab/mmdetection/blob/master/docs/MODEL_ZOO.md

本人下载的是faster_rcnn_r101_fpn_1x_20181129-d1468807.pth

在mmdetection中创建models文件夹,将其放入其中

3、在mmdetection中在mmdetection中创建mycode文件夹,再在mycode下创建test文件夹,新建test.py

#coding=utf-8

from mmdet.apis import init_detector
from mmdet.apis import inference_detector
from mmdet.apis import show_result

# 模型配置文件
config_file = '../../configs/faster_rcnn_r101_fpn_1x.py'

# 预训练模型文件
checkpoint_file = '../../models/faster_rcnn_r101_fpn_1x_20181129-d1468807.pth'

# 通过模型配置文件与预训练文件构建模型
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# 测试单张图片并进行展示
img = 'test1.jpg'
result = inference_detector(model, img)
show_result(img, result, model.CLASSES)

 其中,faster_rcnn_r101_fpn_1x.py文件是mmdetection中存在的,需与下载的pth文件相对应。图片存放在test文件夹中。

使ç¨mmdetectionæµè¯å¾ç_第1å¼ å¾ç

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值