Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaAndroid committed Apr 28, 2021
2 parents 4a9fbd2 + 0425fb6 commit a11e276
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 87 deletions.
88 changes: 44 additions & 44 deletions docs/tutorials/pytorch2onnx.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,67 +131,67 @@ python tools/deployment/test.py \

### Results and Models

<table>
<table border="1" class="docutils">
<tr>
<th>Model</th>
<th>Config</th>
<th>Metric</th>
<th>PyTorch</th>
<th>ONNX Runtime</th>
<th align="center">Model</th>
<th align="center">Config</th>
<th align="center">Metric</th>
<th align="center">PyTorch</th>
<th align="center">ONNX Runtime</th>
</tr >
<tr >
<td>FCOS</td>
<td>configs/fcos/fcos_r50_caffe_fpn_gn-head_4x4_1x_coco.py</td>
<td>Box AP</td>
<td>36.6</td>
<td>36.5</td>
<td align="center">FCOS</td>
<td align="center"><code>configs/fcos/fcos_r50_caffe_fpn_gn-head_4x4_1x_coco.py</code></td>
<td align="center">Box AP</td>
<td align="center">36.6</td>
<td align="center">36.5</td>
</tr>
<tr >
<td>FSAF</td>
<td>configs/fsaf/fsaf_r50_fpn_1x_coco.py</td>
<td>Box AP</td>
<td>36.0</td>
<td>36.0</td>
<td align="center">FSAF</td>
<td align="center"><code>configs/fsaf/fsaf_r50_fpn_1x_coco.py</code></td>
<td align="center">Box AP</td>
<td align="center">36.0</td>
<td align="center">36.0</td>
</tr>
<tr >
<td>RetinaNet</td>
<td>configs/retinanet/retinanet_r50_fpn_1x_coco.py</td>
<td>Box AP</td>
<td>36.5</td>
<td>36.4</td>
<td align="center">RetinaNet</td>
<td align="center"><code>configs/retinanet/retinanet_r50_fpn_1x_coco.py</code></td>
<td align="center">Box AP</td>
<td align="center">36.5</td>
<td align="center">36.4</td>
</tr>
<tr >
<td >SSD</td>
<td>configs/ssd/ssd300_coco.py</td>
<td>Box AP</td>
<td>25.6</td>
<td>25.6</td>
<td align="center" align="center" >SSD</td>
<td align="center" align="center"><code>configs/ssd/ssd300_coco.py</code></td>
<td align="center" align="center">Box AP</td>
<td align="center" align="center">25.6</td>
<td align="center" align="center">25.6</td>
</tr>
<tr >
<td>YOLOv3</td>
<td>configs/yolo/yolov3_d53_mstrain-608_273e_coco.py</td>
<td>Box AP</td>
<td>33.5</td>
<td>33.5</td>
<td align="center">YOLOv3</td>
<td align="center"><code>configs/yolo/yolov3_d53_mstrain-608_273e_coco.py</code></td>
<td align="center">Box AP</td>
<td align="center">33.5</td>
<td align="center">33.5</td>
</tr>
<tr >
<td>Faster R-CNN</td>
<td>configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py</td>
<td>Box AP</td>
<td>37.4</td>
<td>37.4</td>
<td align="center">Faster R-CNN</td>
<td align="center"><code>configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py</code></td>
<td align="center">Box AP</td>
<td align="center">37.4</td>
<td align="center">37.4</td>
</tr>
<tr >
<td rowspan="2">Mask R-CNN</td>
<td rowspan="2">configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py</td>
<td>Box AP</td>
<td>38.2</td>
<td>38.1</td>
<td align="center" rowspan="2">Mask R-CNN</td>
<td align="center" rowspan="2"><code>configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py</code></td>
<td align="center">Box AP</td>
<td align="center">38.2</td>
<td align="center">38.1</td>
</tr>
<tr>
<td>Mask AP</td>
<td>34.7</td>
<td>33.7</td>
<td align="center">Mask AP</td>
<td align="center">34.7</td>
<td align="center">33.7</td>
</tr>
</table>

Expand Down
59 changes: 20 additions & 39 deletions mmdet/models/builder.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,47 @@
import warnings

from mmcv.runner import Sequential
from mmcv.utils import Registry, build_from_cfg

BACKBONES = Registry('backbone')
NECKS = Registry('neck')
ROI_EXTRACTORS = Registry('roi_extractor')
SHARED_HEADS = Registry('shared_head')
HEADS = Registry('head')
LOSSES = Registry('loss')
DETECTORS = Registry('detector')


def build(cfg, registry, default_args=None):
"""Build a module.
Args:
cfg (dict, list[dict]): The config of modules, is is either a dict
or a list of configs.
registry (:obj:`Registry`): A registry the module belongs to.
default_args (dict, optional): Default arguments to build the module.
Defaults to None.
Returns:
nn.Module: A built nn module.
"""
if isinstance(cfg, list):
modules = [
build_from_cfg(cfg_, registry, default_args) for cfg_ in cfg
]
return Sequential(*modules)
else:
return build_from_cfg(cfg, registry, default_args)
from mmcv.cnn import MODELS as MMCV_MODELS
from mmcv.utils import Registry

MODELS = Registry('models', parent=MMCV_MODELS)

BACKBONES = MODELS
NECKS = MODELS
ROI_EXTRACTORS = MODELS
SHARED_HEADS = MODELS
HEADS = MODELS
LOSSES = MODELS
DETECTORS = MODELS


def build_backbone(cfg):
"""Build backbone."""
return build(cfg, BACKBONES)
return BACKBONES.build(cfg)


def build_neck(cfg):
"""Build neck."""
return build(cfg, NECKS)
return NECKS.build(cfg)


def build_roi_extractor(cfg):
"""Build roi extractor."""
return build(cfg, ROI_EXTRACTORS)
return ROI_EXTRACTORS.build(cfg)


def build_shared_head(cfg):
"""Build shared head."""
return build(cfg, SHARED_HEADS)
return SHARED_HEADS.build(cfg)


def build_head(cfg):
"""Build head."""
return build(cfg, HEADS)
return HEADS.build(cfg)


def build_loss(cfg):
"""Build loss."""
return build(cfg, LOSSES)
return LOSSES.build(cfg)


def build_detector(cfg, train_cfg=None, test_cfg=None):
Expand All @@ -74,4 +54,5 @@ def build_detector(cfg, train_cfg=None, test_cfg=None):
'train_cfg specified in both outer field and model field '
assert cfg.get('test_cfg') is None or test_cfg is None, \
'test_cfg specified in both outer field and model field '
return build(cfg, DETECTORS, dict(train_cfg=train_cfg, test_cfg=test_cfg))
return DETECTORS.build(
cfg, default_args=dict(train_cfg=train_cfg, test_cfg=test_cfg))
8 changes: 4 additions & 4 deletions mmdet/models/roi_heads/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def simple_test_bboxes(self,
cls_score = cls_score.reshape(batch_size, num_proposals_per_img, -1)

if not torch.onnx.is_in_onnx_export():
# remove padding
supplement_mask = rois[..., -1] == 0
# remove padding, ignore batch_index when calculating mask
supplement_mask = rois.abs()[..., 1:].sum(dim=-1) == 0
cls_score[supplement_mask, :] = 0

# bbox_pred would be None in some detector when with_reg is False,
Expand All @@ -137,7 +137,7 @@ def simple_test_bboxes(self,
det_labels = []
for i in range(len(proposals)):
# remove padding
supplement_mask = proposals[i][..., -1] == 0
supplement_mask = proposals[i].abs().sum(dim=-1) == 0
for bbox in bbox_preds[i]:
bbox[supplement_mask] = 0
det_bbox, det_label = self.bbox_head.get_bboxes(
Expand Down Expand Up @@ -320,7 +320,7 @@ def simple_test_mask(self,
det_label = det_labels[i]

# remove padding
supplement_mask = det_bbox[..., -1] != 0
supplement_mask = det_bbox.abs().sum(dim=-1) != 0
mask_pred = mask_pred[supplement_mask]
det_bbox = det_bbox[supplement_mask]
det_label = det_label[supplement_mask]
Expand Down

0 comments on commit a11e276

Please sign in to comment.