深入理解Detectron 2 — Part 1 基础网络架构和代码库结构(Basic Network Architecture and Repo Structure)

什么是Detectron 2 ² ?

Detectron 2 ² 是 Facebook AI Research 的下一代开源对象检测系统。通过github上开源的存储库 ,您​​可以使用和训练各种最先进的模型来执行检测任务,例如边界框检测、实例和语义分割以及人体关键点检测。
您可以按照存储库的说明运行演示 — [安装] 和 [入门] — 但如果您想更进一步,而不仅仅是运行示例命令,则有必要了解该存储库的工作原理。

Faster R-CNN FPN 架构

作为示例,我选择具有Feature Pyramid Network³ (Base-RCNN-FPN) 的 Base (Faster) R-CNN,它是可扩展到 Mask R-CNN⁴ 的基本边界框检测器。具有 FPN 主干的 Faster R-CNN⁵ 检测器是一种多尺度检测器,可实现高精度检测微小到大型物体,使其成为事实上的标准检测器(见图 1)。

让我们看一下 Base R-CNN FPN 的结构:

                                 Figure 2. Meta architecture of Base RCNN FPN.

上图显示了网络的元架构。现在你可以看到里面有三个块,分别是:
1.骨干网络(Backbone Network):从输入图像中提取不同尺度的特征图。 Base-RCNN-FPN 的输出特征称为 P2(1/4 比例)、P3(1/8)、P4(1/16)、P5(1/32)和 P6(1/64)。请注意,非 FPN(‘C4’)架构的输出特征仅来自 1/16 比例。
2. 区域提议网络(Region Proposal Network)
:从多尺度特征中检测对象区域(object regions)。获得了 1000 个具有置信度分数的推荐框(box proposals)(默认情况下)。
3. Box Head:使用proposal box将特征图裁剪和变形成多个固定大小的特征,并通过全连接层获得微调的框位置和分类结果。最后,使用非最大抑制 (NMS) 过滤掉最大 100 个框(默认情况下)。 box head是 ROI Heads 的子类之一。例如Mask R-CNN有更多的ROI head,比如mask head。

每个块里面是什么?图 3 显示了详细的架构:

           Figure 3. Detailed architecture of Base-RCNN-FPN. Blue labels represent class names.

好吧,它更复杂!现在让我们暂时离开它并查看存储库。
 

Detectron2 代码存储库的结构

下面是detectron 2的目录树(在‘detectron2’目录下⁶)。请查看“modeling”目录。 Base-RCNN-FPN架构是由该目录下的几个类构建的。

detectron2
├─checkpoint <- checkpointer and model catalog handlers
├─config <- default configs and handlers
├─data <- dataset handlers and data loaders
├─engine <- predictor and trainer engines
├─evaluation <- evaluator for each dataset
├─export <- converter of detectron2 models to caffe2 (ONNX)
├─layers <- custom layers e.g. deformable conv.
├─model_zoo <- pre-trained model links and handler
├─modeling
│ ├─meta_arch <- meta architecture e.g. R-CNN, RetinaNet
│ ├─backbone <- backbone network e.g. ResNet, FPN
│ ├─proposal_generator <- region proposal network
│ └─roi_heads <- head networks for pooled ROIs e.g. box, mask heads
├─solver <- optimizer and scheduler builders
├─structures <- structure classes e.g. Boxes, Instances, etc
└─utils <- utility modules e.g. visualizer, logger, etc

Meta Architecture:
GeneralizedRCNN (meta_arch/rcnn.py)
这部分包含以下模块:

  1. Backbone Network:
    FPN (backbone/fpn.py)
    └ ResNet (backbone/resnet.py)
  2. Region Proposal Network:
    RPN(proposal_generator/rpn.py)
    ├ StandardRPNHead (proposal_generator/rpn.py)
    └ RPNOutput (proposal_generator/rpn_outputs.py)
  3. ROI Heads (Box Head):
    StandardROIHeads (roi_heads/roi_heads.py)
    ├ ROIPooler (poolers.py)
    ├ FastRCNNConvFCHead (roi_heads/box_heads.py)
    ├ FastRCNNOutputLayers (roi_heads/fast_rcnn.py)
    └ FastRCNNOutputs (roi_heads/fast_rcnn.py)

每个模块都有一个主类和子类。 现在请看图 3 上的蓝色标签。您可以看到哪个类对应于管道的哪个部分。我将在下一部分展示每个类的详细信息。

这里我添加了没有类名的架构图。

Figure 4. Detailed architecture of Base-RCNN-FPN (without class names).

[1] This is a personal article and the opinions expressed here are my own and not those of my employer.
[2] Yuxin Wu, Alexander Kirillov, Francisco Massa, Wan-Yen Lo and Ross Girshick, Detectron2. https://github.com/facebookresearch/detectron2, 2019.
[3] T.-Y. Lin, P. Dollar, R. Girshick, K. He, B. Hariharan, and S. Belongie. Feature pyramid networks for object detection. In CVPR, 2017.
[4] Kaiming He, Georgia Gkioxari, Piotr Dollar, and Ross Girshick. Mask R-CNN. In ICCV, 2017.
[5] Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster R-CNN: Towards real-time object detection with region proposal networks. In NIPS, 2015.
[6] as of Jan. 5, 2020. The file, directory, and class names are cited from the repository² ( Copyright 2019, Facebook, Inc. )

Digging into Detectron 2 — part 1 | by Hiroto Honda | Medium

  • 7
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值