Skip to content

Commit

Permalink
[Fix]: fix bug of autoassign (#5092)
Browse files Browse the repository at this point in the history
* fix bug of norm pre

* fix init of fpn

* use reg feature
  • Loading branch information
jshilong authored Apr 30, 2021
1 parent 2f2cb37 commit a41b10f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
5 changes: 2 additions & 3 deletions configs/autoassign/autoassign_r50_fpn_8x2_1x_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
start_level=1,
add_extra_convs=True,
extra_convs_on_inputs=True,
caffe2_xavier_init=True,
num_outs=5,
relu_before_extra_convs=True),
relu_before_extra_convs=True,
init_cfg=dict(type='Caffe2Xavier', layer='Conv2d')),
bbox_head=dict(
type='AutoAssignHead',
norm_on_bbox=True,
num_classes=80,
in_channels=256,
stacked_convs=4,
Expand Down
34 changes: 26 additions & 8 deletions mmdet/models/dense_heads/autoassign_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def __init__(self,
neg_loss_weight=0.75,
center_loss_weight=0.75,
**kwargs):
super().__init__(
*args, conv_bias=True, centerness_on_reg=True, **kwargs)
super().__init__(*args, conv_bias=True, **kwargs)
self.center_prior = CenterPrior(
force_topk=force_topk,
topk=topk,
Expand Down Expand Up @@ -187,6 +186,31 @@ def _get_points_single(self,
dim=-1)
return points

def forward_single(self, x, scale, stride):
"""Forward features of a single scale level.
Args:
x (Tensor): FPN feature maps of the specified stride.
scale (:obj: `mmcv.cnn.Scale`): Learnable scale module to resize
the bbox prediction.
stride (int): The corresponding stride for feature maps, only
used to normalize the bbox prediction when self.norm_on_bbox
is True.
Returns:
tuple: scores for each class, bbox predictions and centerness \
predictions of input feature maps.
"""
cls_score, bbox_pred, cls_feat, reg_feat = super(
FCOSHead, self).forward_single(x)
centerness = self.conv_centerness(reg_feat)
# scale the bbox_pred of different level
# float to avoid overflow when enabling FP16
bbox_pred = scale(bbox_pred).float()
bbox_pred = F.relu(bbox_pred)
bbox_pred *= stride
return cls_score, bbox_pred, centerness

def get_pos_loss_single(self, cls_score, objectness, reg_loss, gt_labels,
center_prior_weights):
"""Calculate the positive loss of all points in gt_bboxes.
Expand Down Expand Up @@ -440,7 +464,6 @@ def get_targets(self, points, gt_bboxes_list):
(num_points, num_gt, 4).
"""

num_levels = len(points)
concat_points = torch.cat(points, dim=0)
# the number of points per img, per lvl
num_points = [center.size(0) for center in points]
Expand All @@ -450,11 +473,6 @@ def get_targets(self, points, gt_bboxes_list):
list(bbox_targets.split(num_points, 0))
for bbox_targets in bbox_targets_list
]
if self.norm_on_bbox:
for i in range(num_levels):
for j in range(len(bbox_targets_list)):
bbox_targets_list[j][
i] = bbox_targets_list[j][i] / self.strides[i]
concat_lvl_bbox_targets = [
torch.cat(item, dim=0) for item in bbox_targets_list
]
Expand Down
4 changes: 0 additions & 4 deletions mmdet/models/necks/fpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class FPN(BaseModule):
conv. Default: False.
no_norm_on_lateral (bool): Whether to apply norm on lateral.
Default: False.
caffe2_xavier_init (bool): Whether to apply caffe2_xavier_init on all
conv in FPN. Default: False.
conv_cfg (dict): Config dict for convolution layer. Default: None.
norm_cfg (dict): Config dict for normalization layer. Default: None.
act_cfg (str): Config dict for activation layer in ConvModule.
Expand Down Expand Up @@ -76,7 +74,6 @@ def __init__(self,
extra_convs_on_inputs=True,
relu_before_extra_convs=False,
no_norm_on_lateral=False,
caffe2_xavier_init=False,
conv_cfg=None,
norm_cfg=None,
act_cfg=None,
Expand All @@ -93,7 +90,6 @@ def __init__(self,
self.no_norm_on_lateral = no_norm_on_lateral
self.fp16_enabled = False
self.upsample_cfg = upsample_cfg.copy()
self.caffe2_xavier_init = caffe2_xavier_init

if end_level == -1:
self.backbone_end_level = self.num_ins
Expand Down

0 comments on commit a41b10f

Please sign in to comment.