Skip to content
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

Merged
merged 32 commits into from
Aug 20, 2021
Merged

Conversation

JingweiZhang12
Copy link
Collaborator

@JingweiZhang12 JingweiZhang12 commented Jul 30, 2021

This PR mainly refactors the anchor in SiameseRPN++ as follows :

  1. converts the anchor format from [cx, cy, w, h] to [tl_x, tl_y, br_x, br_y].
  2. uses new anchor order in order to be consistent with MMDet.
  3. replaces the grid_anchors with grid_priors to skip the deprecated warnings in MMDet.

@codecov
Copy link

codecov bot commented Jul 30, 2021

Codecov Report

Merging #229 (511fbb1) into master (a3c9d49) will decrease coverage by 0.53%.
The diff coverage is 81.08%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 68.33% <81.08%> (-0.54%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmtrack/core/anchor/sot_anchor_generator.py 85.71% <66.66%> (-4.09%) ⬇️
mmtrack/models/track_heads/siamese_rpn_head.py 90.52% <82.35%> (-2.11%) ⬇️
mmtrack/models/reid/base_reid.py 78.26% <0.00%> (-8.70%) ⬇️
mmtrack/datasets/sot_train_dataset.py 82.82% <0.00%> (-3.04%) ⬇️
mmtrack/datasets/pipelines/transforms.py 85.31% <0.00%> (-2.82%) ⬇️
mmtrack/models/mot/trackers/base_tracker.py 83.20% <0.00%> (-1.53%) ⬇️
mmtrack/__init__.py 91.66% <0.00%> (ø)
mmtrack/apis/test.py 14.73% <0.00%> (ø)
mmtrack/apis/train.py 16.07% <0.00%> (ø)
... and 78 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3c9d49...511fbb1. Read the comment docs.

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]
Copy link
Collaborator

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
Copy link
Collaborator

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。

mmtrack/core/anchor/sot_anchor_generator.py Show resolved Hide resolved
mmtrack/core/anchor/sot_anchor_generator.py Outdated Show resolved Hide resolved
# 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
Copy link
Collaborator

@GT9505 GT9505 Aug 3, 2021

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.
Copy link
Collaborator

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)
Copy link
Collaborator

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)

@GT9505
Copy link
Collaborator

GT9505 commented Aug 9, 2021

The unittest failed.

mmtrack/core/anchor/sot_anchor_generator.py Show resolved Hide resolved
mmtrack/core/anchor/sot_anchor_generator.py Outdated Show resolved Hide resolved
mmtrack/core/anchor/sot_anchor_generator.py Outdated Show resolved Hide resolved
mmtrack/core/anchor/sot_anchor_generator.py Outdated Show resolved Hide resolved
mmtrack/models/track_heads/siamese_rpn_head.py Outdated Show resolved Hide resolved
mmtrack/models/track_heads/siamese_rpn_head.py Outdated Show resolved Hide resolved
mmtrack/models/track_heads/siamese_rpn_head.py Outdated Show resolved Hide resolved
@@ -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)
Copy link
Collaborator

@GT9505 GT9505 Aug 20, 2021

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, ))
Copy link
Collaborator

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)
Copy link
Collaborator

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.
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this line

@GT9505 GT9505 changed the title convert the anchor format from [cx,cy,w,h] to [tl_x,tl_y,br_x,br_y] Refactor the anchor in SiameseRPN++ Aug 20, 2021
@GT9505 GT9505 merged commit a1fb68b into open-mmlab:master Aug 20, 2021
@JingweiZhang12 JingweiZhang12 deleted the anchor branch September 6, 2021 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants