这个目标检测框架十分强大,提供了许多网络,关键环境配起来也十分的简单。下面就来说说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)如果有所帮助请点个赞哈