一、介绍
1.1 简介
MMDetection 是一个基于 PyTorch 的目标检测开源工具箱。它是 OpenMMLab 项目的一部分。
主分支代码目前支持 PyTorch 1.3 以上的版本。
v1.x 的历史版本支持 PyTorch 1.1 到 1.4,但是我们强烈建议用户使用新的 2.x 的版本,新的版本速度更快,性能更高,有更优雅的代码设计,对用户使用也更加友好。
1.2 主要特性
-
模块化设计
MMDetection 将检测框架解耦成不同的模块组件,通过组合不同的模块组件,用户可以便捷地构建自定义的检测模型
-
丰富的即插即用的算法和模型
MMDetection 支持了众多主流的和最新的检测算法,例如 Faster R-CNN,Mask R-CNN,RetinaNet 等。
-
速度快
基本的框和 mask 操作都实现了 GPU 版本,训练速度比其他代码库更快或者相当,包括 Detectron2, maskrcnn-benchmark 和 SimpleDet。
-
性能高
MMDetection 这个算法库源自于 COCO 2018 目标检测竞赛的冠军团队 MMDet 团队开发的代码,我们在之后持续进行了改进和提升。
除了 MMDetection 之外,我们还开源了计算机视觉基础库 MMCV,MMCV 是 MMDetection 的主要依赖。
1.3 开源许可证
该项目采用 Apache 2.0 开源许可证。
二、安装
2.1 当前环境
- Ubuntu 16.04
- Anaconda conda 4.7.12
- CUDA Version 10.0.130
2.2 安装命令
基于以上环境,安装 工具库的 详细 命令 如下 (亲测有用)
conda create -n openmmlab python=3.7 -y
conda activate openmmlab
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch -y
# install the latest mmcv
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html
# install mmdetection
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e .
三、demo展示
3.1 新建demo代码
cd mmdetection/demo;
vi demo.py;
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 3 11:54:08 2021
@author: sagewang
"""
from mmdet.apis import init_detector, inference_detector
import mmcv
# 指定模型的配置文件和 checkpoint 文件路径
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
# 根据配置文件和 checkpoint 文件构建模型
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# 测试单张图片并展示结果
img = 'demo/demo.jpg' # 或者 img = mmcv.imread(img),这样图片仅会被读一次
result = inference_detector(model, img)
# 在一个新的窗口中将结果可视化
model.show_result(img, result)
# 或者将可视化结果保存为图片
model.show_result(img, result, out_file='demo/result.jpg')
3.2 运行demo代码
cd mmdetection;
python demo/demo.py;
$ python demo/demo.py
/data/Projects/SAIQ/2021-09/mmdetection/mmdet/core/anchor/builder.py:17: UserWarning: ``build_anchor_generator`` would be deprecated soon, please use ``build_prior_generator``
'``build_anchor_generator`` would be deprecated soon, please use '
Use load_from_local loader
/data/Projects/SAIQ/2021-09/mmdetection/mmdet/datasets/utils.py:69: UserWarning: "ImageToTensor" pipeline is replaced by "DefaultFormatBundle" for batch inference. It is recommended to manually replace it in the test data pipeline in your config file.
'data pipeline in your config file.', UserWarning)
/data/Projects/SAIQ/2021-09/mmdetection/mmdet/core/anchor/anchor_generator.py:324: UserWarning: ``grid_anchors`` would be deprecated soon. Please use ``grid_priors``
warnings.warn('``grid_anchors`` would be deprecated soon. '
/data/Projects/SAIQ/2021-09/mmdetection/mmdet/core/anchor/anchor_generator.py:361: UserWarning: ``single_level_grid_anchors`` would be deprecated soon. Please use ``single_level_grid_priors``
'``single_level_grid_anchors`` would be deprecated soon. '
demo.jpg
result.jpg
ok,到此本章就结束了,希望大家都有所收获~
参考资料
欢迎 各位小伙伴 在本文评论或者私信我。