mmdetection
0. MMDetection
MMDetection 是一个基于 PyTorch 的目标检测开源工具箱。它是 OpenMMLab 项目的一部分。
主分支代码目前支持 PyTorch 1.8 及其以上的版本。
Github仓库 open-mmlab/mmdetection: OpenMMLab Detection Toolbox and Benchmark (github.com)
官方文档 Welcome to MMDetection’s documentation! — MMDetection 3.1.0 documentation
1. FasterRCNN
1.1 模型配置文件
在Model Zoo中找到你需要的检测模型
Faster R-CNN 的model zoo位于mmdetection/configs/faster_rcnn at main · open-mmlab/mmdetection (github.com)
预训练的结果与模型配置文件,模型文件可以在表格内找到
| Backbone | Style | Lr schd | Mem (GB) | Inf time (fps) | box AP | Config | Download |
|---|---|---|---|---|---|---|---|
| R-50-C4 | caffe | 1x | - | - | 35.6 | config | model | log |
| R-50-DC5 | caffe | 1x | - | - | 37.2 | config | model | log |
| R-50-FPN | caffe | 1x | 3.8 | 37.8 | config | model | log | |
| R-50-FPN | pytorch | 1x | 4.0 | 21.4 | 37.4 | config | model | log |
| R-50-FPN (FP16) | pytorch | 1x | 3.4 | 28.8 | 37.5 | config | model | log |
| R-50-FPN | pytorch | 2x | - | - | 38.4 | config | model | log |
| R-101-FPN | caffe | 1x | 5.7 | 39.8 | config | model | log | |
| R-101-FPN | pytorch | 1x | 6.0 | 15.6 | 39.4 | config | model | log |
| R-101-FPN | pytorch | 2x | - | - | 39.8 | config | model | log |
| X-101-32x4d-FPN | pytorch | 1x | 7.2 | 13.8 | 41.2 | config | model | log |
| X-101-32x4d-FPN | pytorch | 2x | - | - | 41.2 | config | model | log |
| X-101-64x4d-FPN | pytorch | 1x | 10.3 | 9.4 | 42.1 | config | model | log |
| X-101-64x4d-FPN | pytorch | 2x | - | - | 41.6 | config | model | log |
点击R-101-FPN对应的config即可进入该模型对应的配置文件。点击model即可下载该预训练模型。
R-101-FPN的配置文件如下:
1 | _base_ = './faster-rcnn_r50_fpn_2x_coco.py' |
R-101-FPN基于R-50-FPN,相对于R-50-FPN的区别仅为模型的backbone换为了深度为101层的resnet。
查看R-50-FPN的配置文件
1 | _base_ = [ |
包含了如下的四个配置文件,分别为
- faster-rcnn_r50_fpn.py 模型配置文件
- datasets/coco_detection.py 数据集配置文件
- schedules/schedule_2x.py
- default_runtime.py
查看faster-rcnn_r50_fpn.py配置文件
1 | # model settings |
模型由以下几个部分组成,通过配置文件传递参数
- data_preprocessor: 输入图像变换
- backbone: 使用ResNet-50
- neck:使用FPN
- rpn_head: 使用RPN
- roi_head: 使用StandardRoIHead
- train_cfg: 训练时使用的参数
- test_cfg: 测试时使用的参数
注释后的配置文件
1 | # model settings |
1.2 data_preprocessors
配置信息
1 | data_preprocessor=dict( # 数据预处理器,用于对数据进行预处理,包括归一化、paddding等 |
源代码位于mmdet\models\data_preprocessors\data_preprocessor.py
类:DetDataPreprocessor
参数:
- mean=[123.675, 116.28, 103.53]: The pixel mean of R, G, B channels
- std=[58.395, 57.12, 57.375]: The pixel standard deviation of R, G, B channels.
- bgr_to_rgb: convert image from BGR to RGB
- pad_size_divisor=32: The size of padded image should be divisible by
pad_size_divisor
1.3 backbone
配置信息
1 | backbone=dict( |
源代码位于mmdet\models\backbones\resnet.py
类:ResNet
参数:
- depth=50: 深度为50或101
- num_stages: Resnet stages
- out_indices = (0, 1, 2, 3): Output from which stages
- frozen_stages=1 : Stages to be frozen (stop grad and set eval mode).
- norm_cfg=dict(type=’BN’, requires_grad=True): Dictionary to construct and config norm layer
- norm_eval=True: Whether to set norm layers to eval mode, namely
- style:
pytorchorcaffe. If set to “pytorch”, the stride-two, layer is the 3x3 conv layer, otherwise the stride-two layer is the first 1x1 conv layer。 - init_cfg: 初始化配置
1.4 neck
配置信息
1 | neck=dict( |
源代码位于mmdet\models\necks\fpn.py
类:FPN
参数:
- in_channels: Number of input channels per scale.
- out_cheanels: Number of output channels (used at each scale)
- num_outs=5: Number of output scales
1.5 rpn_head
配置信息
1 | rpn_head=dict( |
源代码位于mmdet\models\dense_heads\rpn_head.py
类:RPNHead
参数:
- in_channels (int): Number of channels in the input feature map
其余参数配置位于父类:AnchorHead
位于mmdet\models\dense_heads\anchor_head.py
类:AnchorHead
参数:
- anchor_generator: Config dict for anchor generator
- bbox_coder: Config of bounding box coder
- loss_cls: Config of classification loss.
- loss_bbox: Config of localization loss.
1.6 roi_head
配置信息
1 | roi_head=dict( # RoIHead的配置 |
源代码位于mmdet\models\roi_heads\standard_roi_head.py
类:StandardRoIHead
参数位于父类:BaseRoIHead
源代码位于:mmdet/models/roi_heads/base_roi_head.py
类:BaseRoIHead
参数:
- bbox_roi_extractor: SingleRoIExtractor,Extract RoI features from a single level feature map
- bbox_head: Shared2FCBBoxHead,计算分类回归信息
1.7 train_config
配置信息
1 | # model training and testing settings |
训练时添加的超参数
参数rpn: 对应的应用信息位于mmdet/models/dense_heads/anchor_head.py内
相关应用信息位于类AnchorHead
1 | if self.train_cfg: |
将assigner, sampler进行应用
参数rcnn: 对应的应用信息位于mmdet/models/roi_heads/standard_roi_head.py内
1 | if self.train_cfg: |
1.8 test_config
配置信息:
1 | test_cfg=dict( # rpn和rcnn的测试配置 |
配置信息同train_cfg
2. coco数据集和评测器
2. 各个模型测试结果
2.1 COCO数据集预训练模型
2.1.1 FasterRCNN
1 | {"coco/bbox_mAP": 0.398, "coco/bbox_mAP_50": 0.601, "coco/bbox_mAP_75": 0.433, "coco/bbox_mAP_s": 0.225, "coco/bbox_mAP_m": 0.436, "coco/bbox_mAP_l": 0.528, "data_time": 0.14929865856170654, "time": 0.19665712566375732} |
2.1.2 SSD
config链接:https://github.com/open-mmlab/mmdetection/blob/main/configs/ssd/ssd512_coco.py
checkpoint链接:https://download.openmmlab.com/mmdetection/v2.0/ssd/ssd512_coco/ssd512_coco_20210803_022849-0a47a1ca.pth
1 | {"coco/bbox_mAP": 0.295, "coco/bbox_mAP_50": 0.493, "coco/bbox_mAP_75": 0.309, "coco/bbox_mAP_s": 0.121, "coco/bbox_mAP_m": 0.341, "coco/bbox_mAP_l": 0.449, "data_time": 0.010663883209228515, "time": 0.1468013153076172} |
2.1.3 Retinanet
config链接:https://github.com/open-mmlab/mmdetection/blob/main/configs/retinanet/retinanet_r101_fpn_2x_coco.py
1 | {"coco/bbox_mAP": 0.389, "coco/bbox_mAP_50": 0.58, "coco/bbox_mAP_75": 0.415, "coco/bbox_mAP_s": 0.21, "coco/bbox_mAP_m": 0.428, "coco/bbox_mAP_l": 0.524, "data_time": 0.003380171012878418, "time": 0.08712620434761047} |
2.1.4 centernet
1 | {"coco/bbox_mAP": 0.296, "coco/bbox_mAP_50": 0.462, "coco/bbox_mAP_75": 0.314, "coco/bbox_mAP_s": 0.102, "coco/bbox_mAP_m": 0.329, "coco/bbox_mAP_l": 0.467, "data_time": 0.003469311761856079, "time": 0.043782154369354245} |
2.1.5 centernet_update
1 | {"coco/bbox_mAP": 0.402, "coco/bbox_mAP_50": 0.583, "coco/bbox_mAP_75": 0.438, "coco/bbox_mAP_s": 0.234, "coco/bbox_mAP_m": 0.448, "coco/bbox_mAP_l": 0.516, "data_time": 0.0034139031887054443, "time": 0.08413881421089173} |
2.1.6 yolov3
config链接:https://github.com/open-mmlab/mmdetection/blob/main/configs/yolo/yolov3_d53_8xb8-ms-608-273e_coco.py
1 | {"coco/bbox_mAP": 0.338, "coco/bbox_mAP_50": 0.568, "coco/bbox_mAP_75": 0.352, "coco/bbox_mAP_s": 0.197, "coco/bbox_mAP_m": 0.373, "coco/bbox_mAP_l": 0.435, "data_time": 0.0026830642223358153, "time": 0.0734889976978302} |
2.2 pascal_voc数据集
2.2.1 FasterRCNN
1 | {"pascal_voc/mAP": 0.8035323023796082, "pascal_voc/AP50": 0.804, "data_time": 0.0025495167502679037, "time": 0.035022825628567206} |
2.2.2 Retinanet
1 | {"pascal_voc/mAP": 0.7738053798675537, "pascal_voc/AP50": 0.774, "data_time": 0.002849532541050087, "time": 0.03530912710314613} |
2.2.3 SSD
config链接:https://github.com/open-mmlab/mmdetection/blob/main/configs/pascal_voc/ssd512_voc0712.py
checkpoint链接:https://download.openmmlab.com/mmdetection/v2.0/pascal_voc/ssd512_voc0712/ssd512_voc0712_20220320_194717-03cefefe.pth
1 | {"pascal_voc/mAP": 0.7945083975791931, "pascal_voc/AP50": 0.795, "data_time": 0.0022496522339557406, "time": 0.025717813575787767} |