-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the anchor in SiameseRPN++ #229
Conversation
Codecov Report
@@ Coverage Diff @@
## master #229 +/- ##
==========================================
- Coverage 68.88% 68.35% -0.54%
==========================================
Files 87 87
Lines 4577 4563 -14
Branches 890 890
==========================================
- Hits 3153 3119 -34
- Misses 1140 1156 +16
- Partials 284 288 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
all_anchors[:, 0] += -(feat_w // 2) * stride[0] | ||
all_anchors[:, 1] += -(feat_h // 2) * stride[1] | ||
all_anchors[:, 2] += -(feat_w // 2) * stride[0] | ||
all_anchors[:, 3] += -(feat_h // 2) * stride[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can simplify it by using slices.
all_anchors[:, 0:4:2] += -(feat_w // 2) * stride[0]
all_anchors = base_anchors[:, None, :] + shifts[None, :, :] | ||
all_anchors = all_anchors.view(-1, 4) | ||
|
||
# transform the coordinate origin from the top left corner to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please capitalize the first letter. Please also fix the problem in other comments。
# Transform the coordinate origin from the top left corner to the | ||
# center in the scaled featurs map. | ||
all_anchors[:, 0:4:2] += -(feat_w // 2) * stride_w | ||
all_anchors[:, 1:4:2] += -(feat_h // 2) * stride_h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can delete this function and move line 78-79 outside of the function, since the function is almost the same as function in mmdet
self.anchors = self.anchor_generator.grid_priors([score_maps_size], | ||
gt_bbox.device)[0] | ||
# Transform the coordinate origin from the top left corner to the | ||
# center in the scaled featurs map. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the scaled score map
labels = gt_bbox.new_zeros((num_anchors, ), dtype=torch.long) | ||
labels_weights = gt_bbox.new_zeros((num_anchors, ), dtype=torch.float) | ||
bbox_weights = gt_bbox.new_zeros((num_anchors, ), dtype=torch.float) | ||
bbox_targets = gt_bbox.new_zeros((num_anchors, ), dtype=torch.float) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bbox_targets = gt_bbox.new_zeros((num_anchors, 4)
The unittest failed. |
@@ -137,8 +137,8 @@ def __init__(self, | |||
init_cfg=None, | |||
*args, | |||
**kwargs): | |||
super(SiameseRPNHead, self).__init__(init_cfg) | |||
self.anchor_generator = build_anchor_generator(anchor_generator) | |||
super(SiameseRPNHead, self).__init__(*args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to pass init_cfg
into the super class.
And the super class can not take *args, **kwargs
as inputs
num_anchors = H * W * num_base_anchors | ||
labels = gt_bbox.new_zeros((num_anchors, ), dtype=torch.long) | ||
labels_weights = gt_bbox.new_zeros((num_anchors, )) | ||
bbox_weights = gt_bbox.new_zeros((num_anchors, )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bbox_weights = gt_bbox.new_zeros((num_anchors, 4))
bbox_targets = bbox_targets.T.reshape(4, C, H, W) | ||
bbox_weights = bbox_weights.reshape(C, H, W) | ||
bbox_weights = bbox_weights[None].repeat(4, 1, 1, 1) | ||
bbox_weights = bbox_weights.view(-1, 1).repeat(1, 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this line
score_maps_size, cls_score.device)[0] | ||
# Transform the coordinate origin from the top left corner to the | ||
# center in the scaled featurs map. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feature map
labels = labels.reshape(C, H, W) | ||
labels_weights = labels_weights.reshape(C, H, W) | ||
bbox_weights = bbox_weights[None].repeat(4, 1, 1, 1) | ||
bbox_weights = bbox_weights.view(-1, 1).repeat(1, 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this line
This PR mainly refactors the anchor in SiameseRPN++ as follows :
[cx, cy, w, h]
to[tl_x, tl_y, br_x, br_y]
.grid_anchors
withgrid_priors
to skip the deprecated warnings in MMDet.