MMDetection 开始
本文将引导快速使用 MMDetection ,记录了实践中需注意的一些问题。
环境准备
基础环境
- Nvidia 显卡的主机
- Ubuntu 18.04
- 系统安装,可见 制作 USB 启动盘,及系统安装
- Nvidia Driver
- 驱动安装,可见 Ubuntu 初始配置 - Nvidia 驱动
开发环境
下载并安装 Anaconda ,之后于 Terminal 执行:
# 创建 Python 虚拟环境
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
# 安装 PyTorch with CUDA
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.2 -c pytorch -y
# 安装 MMCV
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.6.0/index.html
# 安装 MMDetection
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e .
pytorch==1.7.0
时多卡训练会发生问题,需参考此 Issue。命令参考:
conda install pytorch==1.7.0 torchvision==0.8.1 cudatoolkit=10.2 -c pytorch -y
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.7.0/index.html
更多安装方式,可见官方文档:
现有模型进行推断
Faster RCNN
以 R-50-FPN 为例,
Backbone | Style | Lr schd | Mem (GB) | Inf time (fps) | box AP | Config | Download |
---|---|---|---|---|---|---|---|
R-50-FPN | pytorch | 1x | 4.0 | 21.4 | 37.4 | config | model | log |
下载 model
文件到 mmdetection/checkpoints/
。之后,进行推断,
conda activate open-mmlab
cd mmdetection/
python demo/image_demo.py \
demo/demo.jpg \
configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
现有模型进行测试
准备数据集
下载 COCO 数据集,如下放进 mmdetection/data/coco/
目录,
mmdetection
├── data
│ ├── coco
│ │ ├── annotations
│ │ ├── train2017
│ │ ├── val2017
│ │ ├── test2017
测试现有模型
cd mmdetection/
# single-gpu testing
python tools/test.py \
configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
--out results.pkl \
--eval bbox \
--show
# multi-gpu testing
bash tools/dist_test.sh \
configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
2 \
--out results.pkl \
--eval bbox
效果如下,
结果如下,
loading annotations into memory...
Done (t=0.33s)
creating index...
index created!
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 5000/5000, 15.3 task/s, elapsed: 328s, ETA: 0s
writing results to results.pkl
Evaluating bbox...
Loading and preparing results...
DONE (t=0.89s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=26.17s).
Accumulating evaluation results...
DONE (t=4.10s).
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.374
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=1000 ] = 0.581
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=1000 ] = 0.404
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.212
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = 0.410
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = 0.481
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.517
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=300 ] = 0.517
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=1000 ] = 0.517
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.326
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = 0.557
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = 0.648
OrderedDict([('bbox_mAP', 0.374), ('bbox_mAP_50', 0.581), ('bbox_mAP_75', 0.404), ('bbox_mAP_s', 0.212), ('bbox_mAP_m', 0.41), ('bbox_mAP_l', 0.481), ('bbox_mAP_copypaste', '0.374 0.581 0.404 0.212 0.410 0.481')])