Skip to content

Commit

Permalink
[Fix] Fix Mask2Former (#8436)
Browse files Browse the repository at this point in the history
* fix typos

* fix detr

* remove redundant code

* update

* remove redundant code
  • Loading branch information
chhluo authored and ZwwWayne committed Aug 17, 2022
1 parent b564ad3 commit e799c4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions mmdet/models/dense_heads/detr_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,14 @@ def _get_targets_single(self, cls_score: Tensor, bbox_pred: Tensor,
- pos_inds (Tensor): Sampled positive indices for each image.
- neg_inds (Tensor): Sampled negative indices for each image.
"""

img_h, img_w = img_meta['img_shape']
factor = bbox_pred.new_tensor([img_w, img_h, img_w,
img_h]).unsqueeze(0)
num_bboxes = bbox_pred.size(0)
# convert bbox_pred from xywh, normalized to xyxy, unnormalized
bbox_pred = bbox_cxcywh_to_xyxy(bbox_pred)
bbox_pred = bbox_pred * factor

pred_instances = InstanceData(scores=cls_score, bboxes=bbox_pred)
# assigner and sampler
assign_result = self.assigner.assign(
Expand Down Expand Up @@ -515,13 +520,10 @@ def _get_targets_single(self, cls_score: Tensor, bbox_pred: Tensor,
bbox_targets = torch.zeros_like(bbox_pred)
bbox_weights = torch.zeros_like(bbox_pred)
bbox_weights[pos_inds] = 1.0
img_h, img_w = img_meta['img_shape']

# DETR regress the relative position of boxes (cxcywh) in the image.
# Thus the learning target should be normalized by the image size, also
# the box format should be converted from defaultly x1y1x2y2 to cxcywh.
factor = bbox_pred.new_tensor([img_w, img_h, img_w,
img_h]).unsqueeze(0)
pos_gt_bboxes_normalized = pos_gt_bboxes / factor
pos_gt_bboxes_targets = bbox_xyxy_to_cxcywh(pos_gt_bboxes_normalized)
bbox_targets[pos_inds] = pos_gt_bboxes_targets
Expand Down
6 changes: 3 additions & 3 deletions mmdet/models/dense_heads/mask2former_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def init_weights(self) -> None:
if p.dim() > 1:
nn.init.xavier_normal_(p)

def _get_target_single(self, cls_score: Tensor, mask_pred: Tensor,
gt_instances: InstanceData,
img_meta: dict) -> Tuple[Tensor]:
def _get_targets_single(self, cls_score: Tensor, mask_pred: Tensor,
gt_instances: InstanceData,
img_meta: dict) -> Tuple[Tensor]:
"""Compute classification and mask targets for one image.
Args:
Expand Down

0 comments on commit e799c4c

Please sign in to comment.