forked from open-mmlab/mmdetection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor one-stage get_bboxes logic (open-mmlab#5317)
* revert batch to single * update anchor_head * replace preds with bboxes * add point_bbox_coder * FCOS add get_selected_priori * unified anchor-free and anchor-based get_bbox_single * update code * update reppoints and sabl * add sparse priors * add mlvlpointsgenerator * revert __init__ of core * refactor reppoints * delete label channal * add docstr * fix typo * fix args * fix typo * fix doc * fix stride_h * add offset * Unified bbox coder * add offset * remove point_bbox_coder.py * fix docstr * new interface of single_proir * fix device * add unitest * add cuda unitest * add more cuda unintest * fix reppoints * fix device * update all prior * update vfnet * add unintest for ssd and yolo and rename prior_idxs * add docstr for MlvlPointGenerator * update reppoints and rpnhead * add space * add num_base_priors * update some model * update docstr * fixAugFPN test and lint. * Fix autoassign * add docs * Unified fcos decoding * update docstr * fix train error * Fix Vfnet * Fix some * update centernet * revert * add warnings * fix unittest error * delete duplicated * fix comment * fix docs * fix type Co-authored-by: zhangshilong <[email protected]>
- Loading branch information
Showing
31 changed files
with
1,028 additions
and
1,427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from ..builder import BBOX_CODERS | ||
from ..transforms import bbox2distance, distance2bbox | ||
from .base_bbox_coder import BaseBBoxCoder | ||
|
||
|
||
@BBOX_CODERS.register_module() | ||
class DistancePointBBoxCoder(BaseBBoxCoder): | ||
"""Distance Point BBox coder. | ||
This coder encodes gt bboxes (x1, y1, x2, y2) into (top, bottom, left, | ||
right) and decode it back to the original. | ||
Args: | ||
clip_border (bool, optional): Whether clip the objects outside the | ||
border of the image. Defaults to True. | ||
""" | ||
|
||
def __init__(self, clip_border=True): | ||
super(BaseBBoxCoder, self).__init__() | ||
self.clip_border = clip_border | ||
|
||
def encode(self, points, gt_bboxes, max_dis=None, eps=0.1): | ||
"""Encode bounding box to distances. | ||
Args: | ||
points (Tensor): Shape (N, 2), The format is [x, y]. | ||
gt_bboxes (Tensor): Shape (N, 4), The format is "xyxy" | ||
max_dis (float): Upper bound of the distance. Default None. | ||
eps (float): a small value to ensure target < max_dis, instead <=. | ||
Default 0.1. | ||
Returns: | ||
Tensor: Box transformation deltas. The shape is (N, 4). | ||
""" | ||
assert points.size(0) == gt_bboxes.size(0) | ||
assert points.size(-1) == 2 | ||
assert gt_bboxes.size(-1) == 4 | ||
return bbox2distance(points, gt_bboxes, max_dis, eps) | ||
|
||
def decode(self, points, pred_bboxes, max_shape=None): | ||
"""Decode distance prediction to bounding box. | ||
Args: | ||
points (Tensor): Shape (B, N, 2) or (N, 2). | ||
pred_bboxes (Tensor): Distance from the given point to 4 | ||
boundaries (left, top, right, bottom). Shape (B, N, 4) | ||
or (N, 4) | ||
max_shape (Sequence[int] or torch.Tensor or Sequence[ | ||
Sequence[int]],optional): Maximum bounds for boxes, specifies | ||
(H, W, C) or (H, W). If priors shape is (B, N, 4), then | ||
the max_shape should be a Sequence[Sequence[int]], | ||
and the length of max_shape should also be B. | ||
Default None. | ||
Returns: | ||
Tensor: Boxes with shape (N, 4) or (B, N, 4) | ||
""" | ||
assert points.size(0) == pred_bboxes.size(0) | ||
assert points.size(-1) == 2 | ||
assert pred_bboxes.size(-1) == 4 | ||
if self.clip_border is False: | ||
max_shape = None | ||
return distance2bbox(points, pred_bboxes, max_shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.